Code cleanup and moving object definitions to new folder
This commit is contained in:
parent
f1cbd7ddba
commit
40a3445941
|
@ -82,7 +82,7 @@ done
|
||||||
|
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
APP_NAME="reso-web-api-reference-server"
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
|
|
@ -34,8 +34,8 @@ public class GenericEntityCollectionProcessor implements EntityCollectionProcess
|
||||||
{
|
{
|
||||||
private OData odata;
|
private OData odata;
|
||||||
private ServiceMetadata serviceMetadata;
|
private ServiceMetadata serviceMetadata;
|
||||||
private Connection connect = null;
|
private Connection connect = null;
|
||||||
private String dbType;
|
private final String dbType;
|
||||||
HashMap<String, ResourceInfo> resourceList = null;
|
HashMap<String, ResourceInfo> resourceList = null;
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(GenericEntityCollectionProcessor.class);
|
private static final Logger LOG = LoggerFactory.getLogger(GenericEntityCollectionProcessor.class);
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ import java.util.*;
|
||||||
public class GenericEntityProcessor implements EntityProcessor
|
public class GenericEntityProcessor implements EntityProcessor
|
||||||
{
|
{
|
||||||
private OData odata;
|
private OData odata;
|
||||||
private ServiceMetadata serviceMetadata;
|
private ServiceMetadata serviceMetadata;
|
||||||
private Connection connect;
|
private final Connection connect;
|
||||||
HashMap<String, ResourceInfo> resourceList = null;
|
HashMap<String, ResourceInfo> resourceList = null;
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(GenericEntityCollectionProcessor.class);
|
private static final Logger LOG = LoggerFactory.getLogger(GenericEntityCollectionProcessor.class);
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ public class GenericEntityProcessor implements EntityProcessor
|
||||||
|
|
||||||
private URI createId(String entitySetName, Object id) {
|
private URI createId(String entitySetName, Object id) {
|
||||||
try {
|
try {
|
||||||
return new URI(entitySetName + "('" + String.valueOf(id) + "')");
|
return new URI(entitySetName + "('" + id + "')");
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
|
throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class CommonDataProcessing
|
||||||
|
|
||||||
private static URI createId(String entitySetName, Object id) {
|
private static URI createId(String entitySetName, Object id) {
|
||||||
try {
|
try {
|
||||||
return new URI(entitySetName + "('" + String.valueOf(id) + "')");
|
return new URI(entitySetName + "('" + id + "')");
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
|
throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.util.*;
|
||||||
|
|
||||||
public class FieldDefinition extends ResourceInfo
|
public class FieldDefinition extends ResourceInfo
|
||||||
{
|
{
|
||||||
private static String STANDARD_NAME = "RESO.OData.Metadata.StandardName";
|
private static final String STANDARD_NAME = "RESO.OData.Metadata.StandardName";
|
||||||
|
|
||||||
private static ArrayList<FieldInfo> fieldList = null;
|
private static ArrayList<FieldInfo> fieldList = null;
|
||||||
private ArrayList<ResourceInfo> resources;
|
private ArrayList<ResourceInfo> resources;
|
||||||
|
|
|
@ -33,9 +33,9 @@ public class BreakdownOfFilterExpressionVisitor implements ExpressionVisitor<Str
|
||||||
put(BinaryOperatorKind.SUB, " - ");
|
put(BinaryOperatorKind.SUB, " - ");
|
||||||
}};
|
}};
|
||||||
|
|
||||||
private HashMap<String,String> representations = new HashMap<>();
|
private final HashMap<String,String> representations = new HashMap<>();
|
||||||
|
|
||||||
private ResourceInfo resourceInfo;
|
private final ResourceInfo resourceInfo;
|
||||||
|
|
||||||
public BreakdownOfFilterExpressionVisitor(ResourceInfo resourceInfo) {
|
public BreakdownOfFilterExpressionVisitor(ResourceInfo resourceInfo) {
|
||||||
this.resourceInfo = resourceInfo;
|
this.resourceInfo = resourceInfo;
|
||||||
|
|
|
@ -19,13 +19,13 @@ import static org.reso.service.servlet.RESOservlet.getConnection;
|
||||||
|
|
||||||
public class EnumFieldInfo extends FieldInfo
|
public class EnumFieldInfo extends FieldInfo
|
||||||
{
|
{
|
||||||
private String lookupName;
|
private String lookupName;
|
||||||
private ArrayList<EnumValueInfo> values = new ArrayList<>();
|
private final ArrayList<EnumValueInfo> values = new ArrayList<>();
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(EnumFieldInfo.class);
|
private static final Logger LOG = LoggerFactory.getLogger(EnumFieldInfo.class);
|
||||||
private boolean isCollection = false;
|
private boolean isCollection = false;
|
||||||
private boolean isFlags = false;
|
private boolean isFlags = false;
|
||||||
|
|
||||||
private static String LOOKUP_COLUMN_NAME = "LookupValue";
|
private static final String LOOKUP_COLUMN_NAME = "LookupValue";
|
||||||
|
|
||||||
public EnumFieldInfo(String fieldName, FullQualifiedName type)
|
public EnumFieldInfo(String fieldName, FullQualifiedName type)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,8 +8,8 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class EnumValueInfo
|
public class EnumValueInfo
|
||||||
{
|
{
|
||||||
private String value;
|
private final String value;
|
||||||
private ArrayList<CsdlAnnotation> annotations = new ArrayList<>();
|
private final ArrayList<CsdlAnnotation> annotations = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
public EnumValueInfo(String value)
|
public EnumValueInfo(String value)
|
||||||
|
|
|
@ -42,8 +42,8 @@ public class MySQLFilterExpressionVisitor implements ExpressionVisitor<String>
|
||||||
put(BinaryOperatorKind.SUB, " - ");
|
put(BinaryOperatorKind.SUB, " - ");
|
||||||
}};
|
}};
|
||||||
|
|
||||||
private String entityAlias;
|
private final String entityAlias;
|
||||||
private ResourceInfo resourceInfo;
|
private final ResourceInfo resourceInfo;
|
||||||
|
|
||||||
public MySQLFilterExpressionVisitor(ResourceInfo resourceInfo) {
|
public MySQLFilterExpressionVisitor(ResourceInfo resourceInfo) {
|
||||||
this.entityAlias = resourceInfo.getTableName();
|
this.entityAlias = resourceInfo.getTableName();
|
||||||
|
|
|
@ -38,8 +38,8 @@ public class PostgreSQLFilterExpressionVisitor implements ExpressionVisitor<Stri
|
||||||
put(BinaryOperatorKind.SUB, " - ");
|
put(BinaryOperatorKind.SUB, " - ");
|
||||||
}};
|
}};
|
||||||
|
|
||||||
private String entityAlias;
|
private final String entityAlias;
|
||||||
private ResourceInfo resourceInfo;
|
private final ResourceInfo resourceInfo;
|
||||||
|
|
||||||
public PostgreSQLFilterExpressionVisitor(ResourceInfo resourceInfo) {
|
public PostgreSQLFilterExpressionVisitor(ResourceInfo resourceInfo) {
|
||||||
this.entityAlias = resourceInfo.getTableName();
|
this.entityAlias = resourceInfo.getTableName();
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package org.reso.service.data.meta.builder;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class AnnotationObject extends GenericGSONobject<Object>
|
||||||
|
{
|
||||||
|
private static final Map<String, Object> PROPERTIES_META = Stream.of(
|
||||||
|
new AbstractMap.SimpleEntry<>("term", String.class),
|
||||||
|
new AbstractMap.SimpleEntry<>("value", String.class) )
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
|
||||||
|
public AnnotationObject(JsonReader reader)
|
||||||
|
{
|
||||||
|
super(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getPropertiesMeta()
|
||||||
|
{
|
||||||
|
return PROPERTIES_META;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
package org.reso.service.data.meta;
|
package org.reso.service.data.meta.builder;
|
||||||
|
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
|
import org.reso.service.data.meta.*;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
@ -11,214 +12,28 @@ import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
class GenericGSONobject<SubType>
|
|
||||||
{
|
|
||||||
protected static String subArrayName = "annotations";
|
|
||||||
|
|
||||||
protected JsonReader reader;
|
|
||||||
protected HashMap<String,Object> properties = new HashMap<>();
|
|
||||||
protected ArrayList<SubType> subArrayList = new ArrayList<>();
|
|
||||||
|
|
||||||
public GenericGSONobject(JsonReader reader)
|
|
||||||
{
|
|
||||||
this.reader = reader;
|
|
||||||
this.readObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Object> getPropertiesMeta()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void readObject()
|
|
||||||
{
|
|
||||||
Map<String, Object> PROPERTIES_META = this.getPropertiesMeta();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
reader.beginObject();
|
|
||||||
|
|
||||||
while (reader.hasNext()) {
|
|
||||||
|
|
||||||
String name = reader.nextName();
|
|
||||||
|
|
||||||
if (PROPERTIES_META.containsKey(name))
|
|
||||||
{
|
|
||||||
Object classType = PROPERTIES_META.get(name);
|
|
||||||
|
|
||||||
if (classType.equals(String.class))
|
|
||||||
{
|
|
||||||
properties.put(name,reader.nextString() );
|
|
||||||
}
|
|
||||||
else if (classType.equals(Boolean.class))
|
|
||||||
{
|
|
||||||
properties.put(name,reader.nextBoolean() );
|
|
||||||
}
|
|
||||||
else if (classType.equals(Integer.class))
|
|
||||||
{
|
|
||||||
properties.put(name,reader.nextInt() );
|
|
||||||
}
|
|
||||||
} else if (name.equals(subArrayName)) {
|
|
||||||
// read array
|
|
||||||
reader.beginArray();
|
|
||||||
|
|
||||||
|
|
||||||
while (reader.hasNext()) {
|
|
||||||
GenericGSONobject subArrayItem = this.createSubType();
|
|
||||||
|
|
||||||
subArrayList.add((SubType)subArrayItem);
|
|
||||||
}
|
|
||||||
reader.endArray();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
reader.skipValue(); //avoid some unhandle events
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reader.endObject();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getProperty(String name)
|
|
||||||
{
|
|
||||||
return properties.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected GenericGSONobject createSubType() // must also be of type GenericGSONobject
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the annotations for this field.
|
|
||||||
* @return the sub-array for this generic object
|
|
||||||
*/
|
|
||||||
public ArrayList<SubType> getSubArrayList()
|
|
||||||
{
|
|
||||||
return subArrayList;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class FieldObject extends GenericGSONobject<AnnotationObject>
|
|
||||||
{
|
|
||||||
private static Map<String, Object> PROPERTIES_META = Stream.of(
|
|
||||||
new AbstractMap.SimpleEntry<>("resourceName", String.class),
|
|
||||||
new AbstractMap.SimpleEntry<>("fieldName", String.class),
|
|
||||||
new AbstractMap.SimpleEntry<>("type", String.class),
|
|
||||||
new AbstractMap.SimpleEntry<>("nullable", Boolean.class),
|
|
||||||
new AbstractMap.SimpleEntry<>("maxLength", Integer.class),
|
|
||||||
new AbstractMap.SimpleEntry<>("scale", Integer.class),
|
|
||||||
new AbstractMap.SimpleEntry<>("precision", Integer.class),
|
|
||||||
new AbstractMap.SimpleEntry<>("isCollection", Boolean.class),
|
|
||||||
new AbstractMap.SimpleEntry<>("unicode", Boolean.class) )
|
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
|
||||||
|
|
||||||
protected static String subArrayName = "annotations";
|
|
||||||
|
|
||||||
public FieldObject(JsonReader reader)
|
|
||||||
{
|
|
||||||
super(reader);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Object> getPropertiesMeta()
|
|
||||||
{
|
|
||||||
return PROPERTIES_META;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected GenericGSONobject createSubType() // must also be of type GenericGSONobject
|
|
||||||
{
|
|
||||||
return new AnnotationObject(reader);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the annotations for this field.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ArrayList<AnnotationObject> getAnnotations()
|
|
||||||
{
|
|
||||||
return getSubArrayList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LookupObject extends GenericGSONobject<AnnotationObject>
|
|
||||||
{
|
|
||||||
private static Map<String, Object> PROPERTIES_META = Stream.of(
|
|
||||||
new AbstractMap.SimpleEntry<>("lookupName", String.class),
|
|
||||||
new AbstractMap.SimpleEntry<>("lookupValue", String.class),
|
|
||||||
new AbstractMap.SimpleEntry<>("type", String.class) )
|
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
|
||||||
|
|
||||||
protected static String subArrayName = "annotations";
|
|
||||||
|
|
||||||
public LookupObject(JsonReader reader)
|
|
||||||
{
|
|
||||||
super(reader);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Object> getPropertiesMeta()
|
|
||||||
{
|
|
||||||
return PROPERTIES_META;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected GenericGSONobject createSubType() // must also be of type GenericGSONobject
|
|
||||||
{
|
|
||||||
return new AnnotationObject(reader);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the annotations for this field.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ArrayList<AnnotationObject> getAnnotations()
|
|
||||||
{
|
|
||||||
return getSubArrayList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class AnnotationObject extends GenericGSONobject<Object>
|
|
||||||
{
|
|
||||||
private static Map<String, Object> PROPERTIES_META = Stream.of(
|
|
||||||
new AbstractMap.SimpleEntry<>("term", String.class),
|
|
||||||
new AbstractMap.SimpleEntry<>("value", String.class) )
|
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
|
||||||
|
|
||||||
public AnnotationObject(JsonReader reader)
|
|
||||||
{
|
|
||||||
super(reader);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Object> getPropertiesMeta()
|
|
||||||
{
|
|
||||||
return PROPERTIES_META;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DefinitionBuilder
|
public class DefinitionBuilder
|
||||||
{
|
{
|
||||||
// Constants
|
// Constants
|
||||||
|
|
||||||
private static String EDM_ENUM = "org.reso.metadata.enums";
|
private static final String EDM_ENUM = "org.reso.metadata.enums";
|
||||||
|
|
||||||
private static Map<String, FullQualifiedName> EDM_MAP = Stream.of(
|
private static final Map<String, FullQualifiedName> EDM_MAP = Stream.of(
|
||||||
new AbstractMap.SimpleEntry<>("Edm.String", EdmPrimitiveTypeKind.String.getFullQualifiedName() ),
|
new AbstractMap.SimpleEntry<>("Edm.String", EdmPrimitiveTypeKind.String.getFullQualifiedName() ),
|
||||||
new AbstractMap.SimpleEntry<>("Edm.Boolean", EdmPrimitiveTypeKind.Boolean.getFullQualifiedName() ),
|
new AbstractMap.SimpleEntry<>("Edm.Boolean", EdmPrimitiveTypeKind.Boolean.getFullQualifiedName() ),
|
||||||
new AbstractMap.SimpleEntry<>("Edm.Decimal", EdmPrimitiveTypeKind.Int64.getFullQualifiedName() ))
|
new AbstractMap.SimpleEntry<>("Edm.Decimal", EdmPrimitiveTypeKind.Int64.getFullQualifiedName() ))
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
|
||||||
private static Map<String, Boolean> HEADER_FIELDS = Stream.of(
|
private static final Map<String, Boolean> HEADER_FIELDS = Stream.of(
|
||||||
new AbstractMap.SimpleEntry<>("description", true),
|
new AbstractMap.SimpleEntry<>("description", true),
|
||||||
new AbstractMap.SimpleEntry<>("generatedOn", true),
|
new AbstractMap.SimpleEntry<>("generatedOn", true),
|
||||||
new AbstractMap.SimpleEntry<>("version", true))
|
new AbstractMap.SimpleEntry<>("version", true))
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
|
||||||
// Internals
|
// Internals
|
||||||
private String fileName;
|
private final String fileName;
|
||||||
private JsonReader reader;
|
private JsonReader reader;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public DefinitionBuilder(String fileName)
|
public DefinitionBuilder(String fileName)
|
||||||
|
@ -356,12 +171,41 @@ public class DefinitionBuilder
|
||||||
String lookupName = fieldType.substring(EDM_ENUM.length()+1 );
|
String lookupName = fieldType.substring(EDM_ENUM.length()+1 );
|
||||||
EnumFieldInfo enumFieldInfo = new EnumFieldInfo(fieldName, EdmPrimitiveTypeKind.Int64.getFullQualifiedName());
|
EnumFieldInfo enumFieldInfo = new EnumFieldInfo(fieldName, EdmPrimitiveTypeKind.Int64.getFullQualifiedName());
|
||||||
enumFieldInfo.setLookupName(lookupName);
|
enumFieldInfo.setLookupName(lookupName);
|
||||||
|
if (isCollection==true)
|
||||||
|
{
|
||||||
|
enumFieldInfo.setCollection();
|
||||||
|
}
|
||||||
newField = enumFieldInfo;
|
newField = enumFieldInfo;
|
||||||
|
|
||||||
ArrayList<GenericGSONobject> lookupList = lookupMap.get(fieldType);
|
ArrayList<GenericGSONobject> lookupList = lookupMap.get(fieldType);
|
||||||
|
boolean setFlags = lookupList.size()>1;
|
||||||
|
|
||||||
for (GenericGSONobject lookupItem: lookupList)
|
for (GenericGSONobject lookupItem: lookupList)
|
||||||
{
|
{
|
||||||
EnumValueInfo enumValue = new EnumValueInfo((String)lookupItem.getProperty("lookupValue"));
|
String enumValueString = (String)lookupItem.getProperty("lookupValue");
|
||||||
|
EnumValueInfo enumValue = new EnumValueInfo(enumValueString);
|
||||||
|
|
||||||
|
/**
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Long enumLongValue = Long.parseLong(enumValueString);
|
||||||
|
if (enumLongValue<=0)
|
||||||
|
{
|
||||||
|
setFlags = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
long hob = Long.highestOneBit(enumLongValue);
|
||||||
|
long lob = Long.lowestOneBit(enumLongValue);
|
||||||
|
setFlags = (hob==lob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
setFlags = false;
|
||||||
|
}
|
||||||
|
/**/
|
||||||
|
|
||||||
|
|
||||||
ArrayList<AnnotationObject> annotations = null;
|
ArrayList<AnnotationObject> annotations = null;
|
||||||
if (lookupItem.getClass().equals(LookupObject.class))
|
if (lookupItem.getClass().equals(LookupObject.class))
|
||||||
|
@ -379,6 +223,11 @@ public class DefinitionBuilder
|
||||||
enumFieldInfo.addValue(enumValue);
|
enumFieldInfo.addValue(enumValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setFlags)
|
||||||
|
{
|
||||||
|
enumFieldInfo.setFlags();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newField != null)
|
if (newField != null)
|
|
@ -0,0 +1,51 @@
|
||||||
|
package org.reso.service.data.meta.builder;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class FieldObject extends GenericGSONobject<AnnotationObject>
|
||||||
|
{
|
||||||
|
private static final Map<String, Object> PROPERTIES_META = Stream.of(
|
||||||
|
new AbstractMap.SimpleEntry<>("resourceName", String.class),
|
||||||
|
new AbstractMap.SimpleEntry<>("fieldName", String.class),
|
||||||
|
new AbstractMap.SimpleEntry<>("type", String.class),
|
||||||
|
new AbstractMap.SimpleEntry<>("nullable", Boolean.class),
|
||||||
|
new AbstractMap.SimpleEntry<>("maxLength", Integer.class),
|
||||||
|
new AbstractMap.SimpleEntry<>("scale", Integer.class),
|
||||||
|
new AbstractMap.SimpleEntry<>("precision", Integer.class),
|
||||||
|
new AbstractMap.SimpleEntry<>("isCollection", Boolean.class),
|
||||||
|
new AbstractMap.SimpleEntry<>("unicode", Boolean.class) )
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
|
||||||
|
protected static String subArrayName = "annotations";
|
||||||
|
|
||||||
|
public FieldObject(JsonReader reader)
|
||||||
|
{
|
||||||
|
super(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getPropertiesMeta()
|
||||||
|
{
|
||||||
|
return PROPERTIES_META;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected GenericGSONobject createSubType() // must also be of type GenericGSONobject
|
||||||
|
{
|
||||||
|
return new AnnotationObject(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the annotations for this field.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ArrayList<AnnotationObject> getAnnotations()
|
||||||
|
{
|
||||||
|
return getSubArrayList();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
package org.reso.service.data.meta.builder;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class GenericGSONobject<SubType>
|
||||||
|
{
|
||||||
|
protected static String subArrayName = "annotations";
|
||||||
|
|
||||||
|
protected JsonReader reader;
|
||||||
|
protected HashMap<String,Object> properties = new HashMap<>();
|
||||||
|
protected ArrayList<SubType> subArrayList = new ArrayList<>();
|
||||||
|
|
||||||
|
public GenericGSONobject(JsonReader reader)
|
||||||
|
{
|
||||||
|
this.reader = reader;
|
||||||
|
this.readObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getPropertiesMeta()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readObject()
|
||||||
|
{
|
||||||
|
Map<String, Object> PROPERTIES_META = this.getPropertiesMeta();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
reader.beginObject();
|
||||||
|
|
||||||
|
while (reader.hasNext()) {
|
||||||
|
|
||||||
|
String name = reader.nextName();
|
||||||
|
|
||||||
|
if (PROPERTIES_META.containsKey(name))
|
||||||
|
{
|
||||||
|
Object classType = PROPERTIES_META.get(name);
|
||||||
|
|
||||||
|
if (classType.equals(String.class))
|
||||||
|
{
|
||||||
|
properties.put(name,reader.nextString() );
|
||||||
|
}
|
||||||
|
else if (classType.equals(Boolean.class))
|
||||||
|
{
|
||||||
|
properties.put(name,reader.nextBoolean() );
|
||||||
|
}
|
||||||
|
else if (classType.equals(Integer.class))
|
||||||
|
{
|
||||||
|
properties.put(name,reader.nextInt() );
|
||||||
|
}
|
||||||
|
} else if (name.equals(subArrayName)) {
|
||||||
|
// read array
|
||||||
|
reader.beginArray();
|
||||||
|
|
||||||
|
|
||||||
|
while (reader.hasNext()) {
|
||||||
|
GenericGSONobject subArrayItem = this.createSubType();
|
||||||
|
|
||||||
|
subArrayList.add((SubType)subArrayItem);
|
||||||
|
}
|
||||||
|
reader.endArray();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
reader.skipValue(); //avoid some unhandle events
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.endObject();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getProperty(String name)
|
||||||
|
{
|
||||||
|
return properties.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected GenericGSONobject createSubType() // must also be of type GenericGSONobject
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the annotations for this field.
|
||||||
|
* @return the sub-array for this generic object
|
||||||
|
*/
|
||||||
|
public ArrayList<SubType> getSubArrayList()
|
||||||
|
{
|
||||||
|
return subArrayList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.reso.service.data.meta.builder;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class LookupObject extends GenericGSONobject<AnnotationObject>
|
||||||
|
{
|
||||||
|
private static final Map<String, Object> PROPERTIES_META = Stream.of(
|
||||||
|
new AbstractMap.SimpleEntry<>("lookupName", String.class),
|
||||||
|
new AbstractMap.SimpleEntry<>("lookupValue", String.class),
|
||||||
|
new AbstractMap.SimpleEntry<>("type", String.class) )
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
|
||||||
|
protected static String subArrayName = "annotations";
|
||||||
|
|
||||||
|
public LookupObject(JsonReader reader)
|
||||||
|
{
|
||||||
|
super(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getPropertiesMeta()
|
||||||
|
{
|
||||||
|
return PROPERTIES_META;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected GenericGSONobject createSubType() // must also be of type GenericGSONobject
|
||||||
|
{
|
||||||
|
return new AnnotationObject(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the annotations for this field.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ArrayList<AnnotationObject> getAnnotations()
|
||||||
|
{
|
||||||
|
return getSubArrayList();
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,9 +15,9 @@ import java.util.*;
|
||||||
|
|
||||||
public class RESOedmProvider extends CsdlAbstractEdmProvider
|
public class RESOedmProvider extends CsdlAbstractEdmProvider
|
||||||
{
|
{
|
||||||
private ArrayList<ResourceInfo> resourceList = new ArrayList<ResourceInfo>();
|
private final ArrayList<ResourceInfo> resourceList = new ArrayList<ResourceInfo>();
|
||||||
// Service Namespace
|
// Service Namespace
|
||||||
public static final String NAMESPACE = "org.reso.metadata";
|
public static final String NAMESPACE = "org.reso.metadata";
|
||||||
|
|
||||||
// EDM Container
|
// EDM Container
|
||||||
public static final String CONTAINER_NAME = "Container";
|
public static final String CONTAINER_NAME = "Container";
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.apache.olingo.server.api.ServiceMetadata;
|
||||||
import org.reso.service.data.GenericEntityCollectionProcessor;
|
import org.reso.service.data.GenericEntityCollectionProcessor;
|
||||||
import org.reso.service.data.GenericEntityProcessor;
|
import org.reso.service.data.GenericEntityProcessor;
|
||||||
import org.reso.service.data.definition.LookupDefinition;
|
import org.reso.service.data.definition.LookupDefinition;
|
||||||
import org.reso.service.data.meta.DefinitionBuilder;
|
import org.reso.service.data.meta.builder.DefinitionBuilder;
|
||||||
import org.reso.service.data.definition.FieldDefinition;
|
import org.reso.service.data.definition.FieldDefinition;
|
||||||
import org.reso.service.data.meta.ResourceInfo;
|
import org.reso.service.data.meta.ResourceInfo;
|
||||||
import org.reso.service.edmprovider.RESOedmProvider;
|
import org.reso.service.edmprovider.RESOedmProvider;
|
||||||
|
@ -125,7 +125,7 @@ public class RESOservlet extends HttpServlet
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
resource.findPrimaryKey(this.connect);
|
resource.findPrimaryKey(connect);
|
||||||
resources.add(resource);
|
resources.add(resource);
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
|
@ -136,7 +136,7 @@ public class RESOservlet extends HttpServlet
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Get all classes with constructors with 0 parameters. LookupDefinition should not work.
|
// Get all classes with constructors with 0 parameters. This is deprecated as the Cert metadata report should work for more people.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Class[] classList = ClassLoader.getClasses("org.reso.service.data.definition.custom");
|
Class[] classList = ClassLoader.getClasses("org.reso.service.data.definition.custom");
|
||||||
|
@ -156,7 +156,7 @@ public class RESOservlet extends HttpServlet
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
resource.findPrimaryKey(this.connect);
|
resource.findPrimaryKey(connect);
|
||||||
resources.add(resource);
|
resources.add(resource);
|
||||||
resourceLookup.put(resource.getResourceName(), resource);
|
resourceLookup.put(resource.getResourceName(), resource);
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ public class RESOservlet extends HttpServlet
|
||||||
ResourceInfo defn = new LookupDefinition();
|
ResourceInfo defn = new LookupDefinition();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
defn.findPrimaryKey(this.connect);
|
defn.findPrimaryKey(connect);
|
||||||
resources.add(defn);
|
resources.add(defn);
|
||||||
resourceLookup.put(defn.getResourceName(), defn);
|
resourceLookup.put(defn.getResourceName(), defn);
|
||||||
}
|
}
|
||||||
|
@ -191,8 +191,8 @@ public class RESOservlet extends HttpServlet
|
||||||
// create odata handler and configure it with CsdlEdmProvider and Processor
|
// create odata handler and configure it with CsdlEdmProvider and Processor
|
||||||
this.handler = odata.createHandler(edm);
|
this.handler = odata.createHandler(edm);
|
||||||
|
|
||||||
GenericEntityCollectionProcessor entityCollectionProcessor = new GenericEntityCollectionProcessor(this.connect, dbType);
|
GenericEntityCollectionProcessor entityCollectionProcessor = new GenericEntityCollectionProcessor(connect, dbType);
|
||||||
GenericEntityProcessor entityProcessor = new GenericEntityProcessor(this.connect);
|
GenericEntityProcessor entityProcessor = new GenericEntityProcessor(connect);
|
||||||
|
|
||||||
this.handler.register(entityCollectionProcessor);
|
this.handler.register(entityCollectionProcessor);
|
||||||
this.handler.register(entityProcessor);
|
this.handler.register(entityProcessor);
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.reso.service.servlet.util;
|
||||||
|
|
||||||
public class SimpleError
|
public class SimpleError
|
||||||
{
|
{
|
||||||
private String error;
|
private final String error;
|
||||||
|
|
||||||
// Constants for standard errors.
|
// Constants for standard errors.
|
||||||
static public String AUTH_REQUIRED = "auth_required";
|
static public String AUTH_REQUIRED = "auth_required";
|
||||||
|
|
Loading…
Reference in New Issue