-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Special cased commands with request payload of id list in python and …
…python 3 modules
- Loading branch information
1 parent
e6674e6
commit 23ce9c7
Showing
17 changed files
with
413 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
.../com/spectralogic/ds3autogen/python/generators/request/IdListRequestPayloadGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Copyright 2014-2018 Spectra Logic Corporation. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
* this file except in compliance with the License. A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. | ||
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* **************************************************************************** | ||
*/ | ||
|
||
package com.spectralogic.ds3autogen.python.generators.request; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.spectralogic.ds3autogen.api.models.Arguments; | ||
import com.spectralogic.ds3autogen.api.models.apispec.Ds3Request; | ||
import com.spectralogic.ds3autogen.python.model.request.ConstructorParam; | ||
import com.spectralogic.ds3autogen.utils.collections.GuavaCollectors; | ||
import com.spectralogic.ds3autogen.utils.comparators.CustomArgumentComparator; | ||
|
||
import static com.spectralogic.ds3autogen.python.helpers.PythonHelper.pythonIndent; | ||
import static com.spectralogic.ds3autogen.utils.Helper.camelToUnderscore; | ||
import static com.spectralogic.ds3autogen.utils.RequestConverterUtil.getNonVoidArgsFromParamList; | ||
|
||
/** | ||
* Generates Python request handlers that take in a list of strings and marshals them into a list of ids. | ||
*/ | ||
public class IdListRequestPayloadGenerator extends BaseRequestGenerator { | ||
|
||
protected static final String PAYLOAD_NAME = "id_list"; | ||
|
||
/** | ||
* Gets the sorted list of required constructor parameters including the request payload | ||
*/ | ||
@Override | ||
public ImmutableList<ConstructorParam> toRequiredConstructorParams(final Ds3Request ds3Request) { | ||
final ImmutableList.Builder<Arguments> builder = ImmutableList.builder(); | ||
builder.addAll(getNonVoidArgsFromParamList(ds3Request.getRequiredQueryParams())); | ||
builder.addAll(getAssignmentArguments(ds3Request)); | ||
builder.add(new Arguments("string", PAYLOAD_NAME)); | ||
|
||
return builder.build().stream() | ||
.sorted(new CustomArgumentComparator()) | ||
.map(arg -> new ConstructorParam(camelToUnderscore(arg.getName()), false)) | ||
.collect(GuavaCollectors.immutableList()); | ||
} | ||
|
||
/** | ||
* Gets the python code that handles processing the request payload and headers | ||
*/ | ||
@Override | ||
public String getAdditionalContent(final Ds3Request ds3Request, final String requestName) { | ||
return "if " + PAYLOAD_NAME + " is not None:\n" + | ||
pythonIndent(3) + "if not (isinstance(cur_id, basestring) for cur_id in " + PAYLOAD_NAME + "):\n" + | ||
pythonIndent(4) + "raise TypeError(\n" + | ||
pythonIndent(5) + "'" + requestName + " should have request payload of type: list of strings')\n" + | ||
pythonIndent(3) + "xml_id_list = IdsList(" + PAYLOAD_NAME + ")\n" + | ||
pythonIndent(3) + "self.body = xmldom.tostring(xml_id_list.to_xml())\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...spectralogic.ds3autogen.python/generators/request/IdListRequestPayloadGenerator_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Copyright 2014-2018 Spectra Logic Corporation. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
* this file except in compliance with the License. A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. | ||
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* **************************************************************************** | ||
*/ | ||
|
||
package com.spectralogic.ds3autogen.python.generators.request; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.spectralogic.ds3autogen.python.model.request.ConstructorParam; | ||
import com.spectralogic.ds3autogen.utils.collections.GuavaCollectors; | ||
import org.junit.Test; | ||
|
||
import static com.spectralogic.ds3autogen.testutil.Ds3ModelFixtures.clearSuspectBlobAzureTargetsRequest; | ||
import static org.hamcrest.CoreMatchers.hasItem; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class IdListRequestPayloadGenerator_Test { | ||
|
||
private static final IdListRequestPayloadGenerator generator = new IdListRequestPayloadGenerator(); | ||
|
||
@Test | ||
public void getAdditionalContentTest() { | ||
final String expected = "if id_list is not None:\n" + | ||
" if not (isinstance(cur_id, basestring) for cur_id in id_list):\n" + | ||
" raise TypeError(\n" + | ||
" 'ClearSuspectBlobAzureTargetsSpectraS3Request should have request payload of type: list of strings')\n" + | ||
" xml_id_list = IdsList(id_list)\n" + | ||
" self.body = xmldom.tostring(xml_id_list.to_xml())\n"; | ||
final String result = generator.getAdditionalContent(clearSuspectBlobAzureTargetsRequest(), "ClearSuspectBlobAzureTargetsSpectraS3Request"); | ||
assertThat(result, is(expected)); | ||
} | ||
|
||
@Test | ||
public void toRequiredConstructorParamsTest() { | ||
final ImmutableList<ConstructorParam> reqParams = generator | ||
.toRequiredConstructorParams(clearSuspectBlobAzureTargetsRequest()); | ||
|
||
final ImmutableList<String> result = reqParams.stream() | ||
.map(ConstructorParam::toPythonCode) | ||
.collect(GuavaCollectors.immutableList()); | ||
|
||
assertThat(result.size(), is(1)); | ||
assertThat(result, hasItem("id_list")); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
ds3-autogen-python/src/test/resources/input/requests/clearSuspectBlobAzureTargets.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<Data> | ||
<Contract> | ||
<RequestHandlers> | ||
<RequestHandler Classification="spectrads3" Name="com.spectralogic.s3.server.handler.reqhandler.spectrads3.degradation.ClearSuspectBlobAzureTargetsRequestHandler"> | ||
<Request Action="BULK_DELETE" HttpVerb="DELETE" IncludeIdInPath="false" Resource="SUSPECT_BLOB_AZURE_TARGET" ResourceType="NON_SINGLETON"> | ||
<OptionalQueryParams> | ||
<Param Name="Force" Type="void"/> | ||
</OptionalQueryParams> | ||
<RequiredQueryParams/> | ||
</Request> | ||
<ResponseCodes> | ||
<ResponseCode> | ||
<Code>204</Code> | ||
<ResponseTypes> | ||
<ResponseType Type="null"/> | ||
</ResponseTypes> | ||
</ResponseCode> | ||
<ResponseCode> | ||
<Code>400</Code> | ||
<ResponseTypes> | ||
<ResponseType Type="com.spectralogic.s3.server.domain.HttpErrorResultApiBean"/> | ||
</ResponseTypes> | ||
</ResponseCode> | ||
<ResponseCode> | ||
<Code>409</Code> | ||
<ResponseTypes> | ||
<ResponseType Type="com.spectralogic.s3.server.domain.HttpErrorResultApiBean"/> | ||
</ResponseTypes> | ||
</ResponseCode> | ||
</ResponseCodes> | ||
<Version>1.F51C99474F629A2CFD5CDB6BC5CB7C6D</Version> | ||
</RequestHandler> | ||
</RequestHandlers> | ||
</Contract> | ||
</Data> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...kotlin/com/spectralogic/ds3autogen/python3/generators/request/P3IdListRequestGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Copyright 2014-2018 Spectra Logic Corporation. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
* this file except in compliance with the License. A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. | ||
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* **************************************************************************** | ||
*/ | ||
|
||
package com.spectralogic.ds3autogen.python3.generators.request | ||
|
||
import com.spectralogic.ds3autogen.api.models.apispec.Ds3Request | ||
import com.spectralogic.ds3autogen.python.generators.request.IdListRequestPayloadGenerator | ||
import com.spectralogic.ds3autogen.python.helpers.PythonHelper.pythonIndent | ||
|
||
/** | ||
* Creates the Python 3 request model for the clear blob and mark blob commands | ||
*/ | ||
class P3IdListRequestGenerator : IdListRequestPayloadGenerator() { | ||
|
||
/** | ||
* Gets the Python 3 code that handles processing the request payload and headers | ||
*/ | ||
override fun getAdditionalContent(ds3Request: Ds3Request, requestName : String) : String { | ||
return "if $PAYLOAD_NAME is not None:\n" + | ||
pythonIndent(3) + "if not (isinstance(cur_id, str) for cur_id in $PAYLOAD_NAME):\n" + | ||
pythonIndent(4) + "raise TypeError(\n" + | ||
pythonIndent(5) + "'" + requestName + " should have request payload of type: list of strings')\n" + | ||
pythonIndent(3) + "xml_id_list = IdsList($PAYLOAD_NAME)\n" + | ||
pythonIndent(3) + "self.body = xmldom.tostring(xml_id_list.to_xml())\n" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.