use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Element in project ds3_autogen by SpectraLogic.
the class BaseTypeGenerator_Test method toStructElementsList_FullList_Test.
@Test
public void toStructElementsList_FullList_Test() {
final ImmutableList<StructElement> expectedElements = ImmutableList.of(new StructElement("ElementWithWrapper", "Type", "xml:\"OuterTag>InnerTag\""), new StructElement("ElementAsAttribute", "Type", "xml:\"ElementAsAttribute,attr\""), new StructElement("SimpleElement", "Type", "xml:\"SimpleElement\""));
final ImmutableList<Ds3Element> elements = ImmutableList.of(elementWithWrapper, elementAsAttribute, simpleElement);
final ImmutableList<StructElement> result = generator.toStructElementsList(elements);
assertThat(result.size(), is(expectedElements.size()));
expectedElements.forEach(expected -> assertThat(result, hasItem(expected)));
}
use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Element in project ds3_autogen by SpectraLogic.
the class CommonPrefixGenerator method toElementList.
/**
* Converts a list of Ds3Elements into a list of Element models, while special casing the
* CommonPrefixes element to refer to a list of CommonPrefixes objects (as opposed to a list
* of strings specified within the contract).
*/
@Override
public ImmutableList<Element> toElementList(final ImmutableList<Ds3Element> ds3Elements) {
if (isEmpty(ds3Elements)) {
LOG.error("There are no elements when the CommonPrefixes element was expected");
return ImmutableList.of();
}
final ImmutableList.Builder<Element> builder = ImmutableList.builder();
for (final Ds3Element ds3Element : ds3Elements) {
if (ds3Element.getName().equals(COMMON_PREFIX_ELEMENT)) {
final Ds3Element commonPrefixes = new Ds3Element("CommonPrefixes", "array", "CommonPrefixes", false);
builder.add(toElement(commonPrefixes));
} else {
builder.add(toElement(ds3Element));
}
}
return builder.build();
}
use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Element in project ds3_autogen by SpectraLogic.
the class BaseTypeGenerator method getImportsFromDs3Elements.
/**
* Gets all the required imports that the elements will need in order to properly
* generate the java model
*/
protected static ImmutableList<String> getImportsFromDs3Elements(final ImmutableList<Ds3Element> elements) {
if (isEmpty(elements)) {
return ImmutableList.of();
}
final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
for (final Ds3Element element : elements) {
if (element.getType().contains(".") && !ConvertType.isModelName(element.getType())) {
builder.add(ConvertType.toModelName(element.getType()));
}
if (hasContent(element.getComponentType()) && element.getComponentType().contains(".")) {
if (!ConvertType.isModelName(element.getComponentType())) {
builder.add(ConvertType.toModelName(element.getComponentType()));
}
builder.add("java.util.List");
builder.add("java.util.ArrayList");
builder.add("com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper");
}
if (isAttribute(element.getDs3Annotations())) {
builder.add("com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty");
}
}
return builder.build().asList();
}
use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Element in project ds3_autogen by SpectraLogic.
the class Ds3TypeClassificationUtil_Test method getTestTypeMap.
/**
* Creates a type map with testing values
*/
private static ImmutableMap<String, Ds3Type> getTestTypeMap() {
final Ds3Type enumType = new Ds3Type("TestEnumType", "", ImmutableList.of(), ImmutableList.of(new Ds3EnumConstant("ONE", null)));
final Ds3Type elementType = new Ds3Type("TestElementType", ImmutableList.of(new Ds3Element("Element", "int", null, false)));
return ImmutableMap.of(enumType.getName(), enumType, elementType.getName(), elementType);
}
use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Element in project ds3_autogen by SpectraLogic.
the class Ds3TypeClassificationUtil_Test method getElementNames_Test.
@Test
public void getElementNames_Test() {
final ImmutableList<Ds3Element> elements = ImmutableList.of(new Ds3Element("Code", "java.lang.String", null, true), new Ds3Element("HttpErrorCode", "int", null, false));
final Ds3Type type = createDs3TypeTestData("TestType", elements);
final ImmutableList<String> result = getElementNames(type);
assertThat(result.size(), is(2));
assertTrue(result.contains("Code"));
assertTrue(result.contains("HttpErrorCode"));
}
Aggregations