Updates for Postgres
Anyone running this version will need new SQL files.
This commit is contained in:
parent
e7d6496cea
commit
436c484177
12
.env
12
.env
|
@ -1,4 +1,8 @@
|
|||
COMPOSE_FILE=docker-compose.yml:./optional/docker-db-compose.yml
|
||||
SQL_HOST=docker-mysql
|
||||
SQL_USER=root
|
||||
SQL_PASSWORD=root
|
||||
COMPOSE__FILE=docker-compose.yml:./optional/docker-db-compose.yml
|
||||
SQL_HOST=192.168.1.71
|
||||
SQL_USER=mpede
|
||||
SQL_PASSWORD=password
|
||||
#SQL_DB_DRIVER=com.mysql.cj.jdbc.Driver
|
||||
SQL_DB_DRIVER=org.postgresql.Driver
|
||||
#SQL_CONNECTION_STR=jdbc:mysql://192.168.1.71/reso_data_dictionary_1_7?autoReconnect=true&maxReconnects=4&user=mpede&password=password
|
||||
SQL_CONNECTION_STR=jdbc:postgresql://192.168.1.71:5432/reso_data_dictionary_1_7?autoReconnect=true&maxReconnects=4
|
||||
|
|
5
build.sh
5
build.sh
|
@ -23,6 +23,11 @@ then
|
|||
fi
|
||||
|
||||
java -jar temp/web-api-commander.jar --generateReferenceDDL --useKeyNumeric > sql/reso-reference-ddl-dd-1.7.numeric-keys.sql
|
||||
|
||||
# The following lines should be independent of the SQL logic.
|
||||
java -jar temp/web-api-commander.jar --generateResourceInfoModels
|
||||
mv ResourceInfoModels/* src/main/java/org/reso/service/data/definition/
|
||||
|
||||
else
|
||||
COMPOSE_FILE="docker-compose.yml"
|
||||
fi
|
||||
|
|
|
@ -13,6 +13,8 @@ services:
|
|||
- SQL_HOST
|
||||
- SQL_USER
|
||||
- SQL_PASSWORD
|
||||
- SQL_CONNECTION_STR
|
||||
- SQL_DB_DRIVER
|
||||
volumes:
|
||||
- ./target:/usr/local/tomcat/webapps
|
||||
# depends_on:
|
||||
|
|
|
@ -11,8 +11,6 @@ services:
|
|||
MYSQL_ROOT_HOST: '%'
|
||||
volumes:
|
||||
- ./sql:/docker-entrypoint-initdb.d
|
||||
|
||||
|
||||
ports:
|
||||
- "6033:3306"
|
||||
healthcheck:
|
||||
|
|
6
pom.xml
6
pom.xml
|
@ -33,6 +33,12 @@
|
|||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.2.23</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.olingo</groupId>
|
||||
<artifactId>odata-server-api</artifactId>
|
||||
|
|
|
@ -4,9 +4,7 @@ package org.reso.service.data;
|
|||
import org.apache.olingo.commons.api.data.*;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
|
@ -22,14 +20,13 @@ import org.apache.olingo.server.api.uri.queryoption.expression.Expression;
|
|||
import org.apache.olingo.server.api.uri.queryoption.expression.Member;
|
||||
import org.reso.service.data.common.CommonDataProcessing;
|
||||
import org.reso.service.data.meta.FieldInfo;
|
||||
import org.reso.service.data.meta.FilterExpressionVisitor;
|
||||
import org.reso.service.data.meta.MySQLFilterExpressionVisitor;
|
||||
import org.reso.service.data.meta.PostgreSQLFilterExpressionVisitor;
|
||||
import org.reso.service.data.meta.ResourceInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -38,6 +35,7 @@ public class GenericEntityCollectionProcessor implements EntityCollectionProcess
|
|||
private OData odata;
|
||||
private ServiceMetadata serviceMetadata;
|
||||
private Connection connect = null;
|
||||
private String dbType;
|
||||
HashMap<String, ResourceInfo> resourceList = null;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GenericEntityCollectionProcessor.class);
|
||||
|
||||
|
@ -45,10 +43,11 @@ public class GenericEntityCollectionProcessor implements EntityCollectionProcess
|
|||
* If you use this constructor, make sure to set your resourceInfo
|
||||
* @param connection
|
||||
*/
|
||||
public GenericEntityCollectionProcessor(Connection connection)
|
||||
public GenericEntityCollectionProcessor(Connection connection, String dbType)
|
||||
{
|
||||
this.resourceList = new HashMap<>();
|
||||
this.connect = connection;
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
public void init(OData odata, ServiceMetadata serviceMetadata) {
|
||||
|
@ -157,7 +156,14 @@ public class GenericEntityCollectionProcessor implements EntityCollectionProcess
|
|||
String sqlCriteria = null;
|
||||
if (filter!=null)
|
||||
{
|
||||
sqlCriteria = filter.getExpression().accept(new FilterExpressionVisitor(resource));
|
||||
if (this.dbType.equals("mysql"))
|
||||
{
|
||||
sqlCriteria = filter.getExpression().accept(new MySQLFilterExpressionVisitor(resource));
|
||||
}
|
||||
else if (this.dbType.equals("postgres"))
|
||||
{
|
||||
sqlCriteria = filter.getExpression().accept(new PostgreSQLFilterExpressionVisitor(resource));
|
||||
}
|
||||
}
|
||||
HashMap<String,Boolean> selectLookup = null;
|
||||
|
||||
|
|
|
@ -4,14 +4,12 @@ package org.reso.service.data;
|
|||
import org.apache.olingo.commons.api.data.*;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.server.api.*;
|
||||
import org.apache.olingo.server.api.processor.EntityProcessor;
|
||||
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
|
||||
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.SerializerResult;
|
||||
|
@ -19,12 +17,8 @@ import org.apache.olingo.server.api.uri.UriInfo;
|
|||
import org.apache.olingo.server.api.uri.UriParameter;
|
||||
import org.apache.olingo.server.api.uri.UriResource;
|
||||
import org.apache.olingo.server.api.uri.UriResourceEntitySet;
|
||||
import org.apache.olingo.server.api.uri.queryoption.FilterOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SkipOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.TopOption;
|
||||
import org.reso.service.data.common.CommonDataProcessing;
|
||||
import org.reso.service.data.meta.FieldInfo;
|
||||
import org.reso.service.data.meta.FilterExpressionVisitor;
|
||||
import org.reso.service.data.meta.ResourceInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.reso.service.data.common;
|
||||
|
||||
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
|
@ -19,6 +20,7 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class CommonDataProcessing
|
||||
{
|
||||
|
@ -36,6 +38,13 @@ public class CommonDataProcessing
|
|||
{
|
||||
value = resultSet.getTimestamp(fieldName);
|
||||
}
|
||||
else if (field.getFieldName().equals("EnumTest")) // @TEST CODE
|
||||
{
|
||||
ArrayList<Integer> responses = new ArrayList();
|
||||
responses.add(1);
|
||||
responses.add(2);
|
||||
value = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.info("Field Name: "+field.getFieldName()+" Field type: "+field.getType());
|
||||
|
@ -61,9 +70,17 @@ public class CommonDataProcessing
|
|||
if (selectLookup==null || selectLookup.containsKey(fieldName) )
|
||||
{
|
||||
value = CommonDataProcessing.getFieldValueFromRow(field, resultSet);
|
||||
if (field.isCollection())
|
||||
{
|
||||
Property property = new Property(null, fieldName, ValueType.ENUM, value);
|
||||
ent.addProperty(property);
|
||||
}
|
||||
else
|
||||
{
|
||||
ent.addProperty(new Property(null, fieldName, ValueType.PRIMITIVE, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lookupKey!=null)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,9 @@ package org.reso.service.data.definition;
|
|||
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
|
||||
import org.reso.service.data.meta.EnumFieldInfo;
|
||||
import org.reso.service.data.meta.EnumValueInfo;
|
||||
import org.reso.service.data.meta.FieldInfo;
|
||||
import org.reso.service.data.meta.ResourceInfo;
|
||||
|
||||
|
@ -53,6 +56,23 @@ public class LookupDefinition extends ResourceInfo
|
|||
fieldInfo = new FieldInfo("ModificationTimestamp", EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName());
|
||||
list.add(fieldInfo);
|
||||
|
||||
//// Enum Test code
|
||||
EnumFieldInfo enumFieldInfo = new EnumFieldInfo("EnumTest", EdmPrimitiveTypeKind.Int64.getFullQualifiedName());
|
||||
|
||||
/**
|
||||
enumFieldInfo.setLookupName("EnumTest");
|
||||
//enumFieldInfo.setCollection();
|
||||
enumFieldInfo.setFlags();
|
||||
EnumValueInfo enumValue = new EnumValueInfo("Awnings");
|
||||
enumFieldInfo.addValue(enumValue);
|
||||
enumValue = new EnumValueInfo("Boatslip");
|
||||
enumFieldInfo.addValue(enumValue);
|
||||
list.add(enumFieldInfo);
|
||||
|
||||
// END Test code
|
||||
/**/
|
||||
|
||||
|
||||
return LookupDefinition.fieldList;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ public class EnumFieldInfo extends FieldInfo
|
|||
private ArrayList<EnumValueInfo> values = new ArrayList<>();
|
||||
private static final Logger LOG = LoggerFactory.getLogger(EnumFieldInfo.class);
|
||||
private boolean isCollection = false;
|
||||
private boolean isFlags = false;
|
||||
|
||||
private static String LOOKUP_COLUMN_NAME = "LookupValue";
|
||||
|
||||
|
@ -116,4 +117,14 @@ public class EnumFieldInfo extends FieldInfo
|
|||
isCollection = true;
|
||||
}
|
||||
|
||||
public void setFlags()
|
||||
{
|
||||
isFlags = true;
|
||||
}
|
||||
|
||||
public boolean isFlags()
|
||||
{
|
||||
return isFlags;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -120,4 +120,14 @@ public class FieldInfo
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isFlags()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isComplex()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,16 +18,13 @@ import org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* $filter
|
||||
*/
|
||||
public class FilterExpressionVisitor implements ExpressionVisitor<String> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FilterExpressionVisitor.class);
|
||||
public class MySQLFilterExpressionVisitor implements ExpressionVisitor<String> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MySQLFilterExpressionVisitor.class);
|
||||
private static final Map<BinaryOperatorKind, String> BINARY_OPERATORS = new HashMap<BinaryOperatorKind, String>() {{
|
||||
put(BinaryOperatorKind.ADD, " + ");
|
||||
put(BinaryOperatorKind.AND, " AND ");
|
||||
|
@ -47,7 +44,7 @@ public class FilterExpressionVisitor implements ExpressionVisitor<String> {
|
|||
private String entityAlias;
|
||||
private ResourceInfo resourceInfo;
|
||||
|
||||
public FilterExpressionVisitor(ResourceInfo resourceInfo) {
|
||||
public MySQLFilterExpressionVisitor(ResourceInfo resourceInfo) {
|
||||
this.entityAlias = resourceInfo.getTableName();
|
||||
this.resourceInfo = resourceInfo;
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
package org.reso.service.data.meta;
|
||||
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.uri.UriResource;
|
||||
import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* $filter
|
||||
*/
|
||||
public class PostgreSQLFilterExpressionVisitor implements ExpressionVisitor<String> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PostgreSQLFilterExpressionVisitor.class);
|
||||
private static final Map<BinaryOperatorKind, String> BINARY_OPERATORS = new HashMap<BinaryOperatorKind, String>() {{
|
||||
put(BinaryOperatorKind.ADD, " + ");
|
||||
put(BinaryOperatorKind.AND, " AND ");
|
||||
put(BinaryOperatorKind.DIV, " / ");
|
||||
put(BinaryOperatorKind.EQ, " = ");
|
||||
put(BinaryOperatorKind.GE, " >= ");
|
||||
put(BinaryOperatorKind.GT, " > ");
|
||||
put(BinaryOperatorKind.LE, " <= ");
|
||||
put(BinaryOperatorKind.LT, " < ");
|
||||
put(BinaryOperatorKind.MOD, " % ");
|
||||
put(BinaryOperatorKind.MUL, " * ");
|
||||
put(BinaryOperatorKind.NE, " <> ");
|
||||
put(BinaryOperatorKind.OR, " OR ");
|
||||
put(BinaryOperatorKind.SUB, " - ");
|
||||
}};
|
||||
|
||||
private String entityAlias;
|
||||
private ResourceInfo resourceInfo;
|
||||
|
||||
public PostgreSQLFilterExpressionVisitor(ResourceInfo resourceInfo) {
|
||||
this.entityAlias = resourceInfo.getTableName();
|
||||
this.resourceInfo = resourceInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitBinaryOperator(BinaryOperatorKind operator, String left, String right)
|
||||
throws ExpressionVisitException, ODataApplicationException {
|
||||
String strOperator = BINARY_OPERATORS.get(operator);
|
||||
|
||||
if (strOperator == null) {
|
||||
throw new ODataApplicationException("Unsupported binary operation: " + operator.name(),
|
||||
operator == BinaryOperatorKind.HAS ?
|
||||
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode() :
|
||||
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ENGLISH);
|
||||
}
|
||||
return left + strOperator + right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitUnaryOperator(UnaryOperatorKind operator, String operand)
|
||||
throws ExpressionVisitException, ODataApplicationException {
|
||||
switch (operator) {
|
||||
case NOT:
|
||||
return "NOT " + operand;
|
||||
case MINUS:
|
||||
return "-" + operand;
|
||||
}
|
||||
throw new ODataApplicationException("Wrong unary operator: " + operator,
|
||||
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitMethodCall(MethodKind methodCall, List<String> parameters)
|
||||
throws ExpressionVisitException, ODataApplicationException {
|
||||
if (parameters.isEmpty() && methodCall.equals(MethodKind.NOW)) {
|
||||
return "CURRENT_DATE";
|
||||
}
|
||||
String firsEntityParam = parameters.get(0);
|
||||
switch (methodCall) {
|
||||
case CONTAINS:
|
||||
return firsEntityParam + " LIKE '%" + extractFromStringValue(parameters.get(1)) + "%'";
|
||||
case STARTSWITH:
|
||||
return firsEntityParam + " LIKE '" + extractFromStringValue(parameters.get(1)) + "%'";
|
||||
case ENDSWITH:
|
||||
return firsEntityParam + " LIKE '%" + extractFromStringValue(parameters.get(1));
|
||||
case DAY:
|
||||
return "DAY(" + firsEntityParam + ")";
|
||||
case MONTH:
|
||||
return "MONTH(" + firsEntityParam + ")";
|
||||
case YEAR:
|
||||
return "YEAR(" + firsEntityParam + ")";
|
||||
}
|
||||
throw new ODataApplicationException("Method call " + methodCall + " not implemented",
|
||||
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitLiteral(Literal literal) throws ExpressionVisitException, ODataApplicationException {
|
||||
String literalAsString = literal.getText();
|
||||
if (literal.getType() == null) {
|
||||
literalAsString = "NULL";
|
||||
}
|
||||
if (literal.getType().getFullQualifiedName().equals( EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName() ) )
|
||||
{
|
||||
return "'"+literalAsString+"'";
|
||||
}
|
||||
|
||||
return literalAsString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitMember(Member member) throws ExpressionVisitException, ODataApplicationException {
|
||||
List<UriResource> resources = member.getResourcePath().getUriResourceParts();
|
||||
|
||||
UriResource first = resources.get(0);
|
||||
|
||||
// TODO: Enum and ComplexType; joins
|
||||
if (resources.size() == 1 && first instanceof UriResourcePrimitiveProperty) {
|
||||
UriResourcePrimitiveProperty primitiveProperty = (UriResourcePrimitiveProperty) first;
|
||||
return entityAlias + "." + primitiveProperty.getProperty().getName();
|
||||
} else {
|
||||
throw new ODataApplicationException("Only primitive properties are implemented in filter expressions",
|
||||
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitEnum(EdmEnumType type, List<String> enumValues)
|
||||
throws ExpressionVisitException, ODataApplicationException {
|
||||
throw new ODataApplicationException("Enums are not implemented", HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(),
|
||||
Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitLambdaExpression(String lambdaFunction, String lambdaVariable, Expression expression)
|
||||
throws ExpressionVisitException, ODataApplicationException {
|
||||
throw new ODataApplicationException("Lambda expressions are not implemented",
|
||||
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitAlias(String aliasName) throws ExpressionVisitException, ODataApplicationException {
|
||||
throw new ODataApplicationException("Aliases are not implemented",
|
||||
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitTypeLiteral(EdmType type) throws ExpressionVisitException, ODataApplicationException {
|
||||
throw new ODataApplicationException("Type literals are not implemented",
|
||||
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitLambdaReference(String variableName) throws ExpressionVisitException, ODataApplicationException {
|
||||
throw new ODataApplicationException("Lambda references are not implemented",
|
||||
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
|
||||
}
|
||||
|
||||
private String extractFromStringValue(String val) {
|
||||
return val.substring(1, val.length() - 1);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package org.reso.service.edmprovider;
|
|||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.provider.*;
|
||||
import org.apache.olingo.commons.api.ex.ODataException;
|
||||
import org.reso.service.data.meta.EnumFieldInfo;
|
||||
import org.reso.service.data.meta.EnumValueInfo;
|
||||
import org.reso.service.data.meta.FieldInfo;
|
||||
|
@ -24,6 +25,7 @@ public class RESOedmProvider extends CsdlAbstractEdmProvider
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RESOedmProvider.class);
|
||||
|
||||
@Override
|
||||
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName)
|
||||
{
|
||||
for (ResourceInfo defn :resourceList)
|
||||
|
@ -36,21 +38,28 @@ public class RESOedmProvider extends CsdlAbstractEdmProvider
|
|||
return null;
|
||||
}
|
||||
|
||||
public CsdlEntityType getEntityType(ResourceInfo defn)
|
||||
@Override
|
||||
public CsdlComplexType getComplexType(FullQualifiedName complexTypeName) throws ODataException
|
||||
{
|
||||
for (ResourceInfo defn :resourceList)
|
||||
{
|
||||
if (complexTypeName.equals(defn.getFqn(NAMESPACE)))
|
||||
{
|
||||
return getComplexType(defn);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CsdlComplexType getComplexType(ResourceInfo defn)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArrayList<FieldInfo> fields = defn.getFieldList();
|
||||
String primaryFieldName = defn.getPrimaryKeyName();
|
||||
|
||||
ArrayList<CsdlProperty> propertyList = new ArrayList<>();
|
||||
|
||||
// create CsdlPropertyRef for Key element
|
||||
CsdlPropertyRef propertyRef = new CsdlPropertyRef();
|
||||
propertyRef.setName(primaryFieldName);
|
||||
LOG.debug("Primary key is: "+primaryFieldName);
|
||||
|
||||
for (FieldInfo field : fields)
|
||||
for (FieldInfo field : fields) if (field.isComplex())
|
||||
{
|
||||
String fieldName = field.getFieldName();
|
||||
|
||||
|
@ -82,6 +91,74 @@ public class RESOedmProvider extends CsdlAbstractEdmProvider
|
|||
propertyList.add(property);
|
||||
}
|
||||
|
||||
CsdlComplexType complexType = new CsdlComplexType();
|
||||
complexType.setName(defn.getResourceName());
|
||||
complexType.setProperties(propertyList);
|
||||
|
||||
return complexType;
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
if (defn==null)
|
||||
LOG.error("Null Resource definition provided.", e);
|
||||
else
|
||||
LOG.error("Server Error occurred in reading "+defn.getResourceName(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public CsdlEntityType getEntityType(ResourceInfo defn)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArrayList<FieldInfo> fields = defn.getFieldList();
|
||||
String primaryFieldName = defn.getPrimaryKeyName();
|
||||
|
||||
ArrayList<CsdlProperty> propertyList = new ArrayList<>();
|
||||
|
||||
// create CsdlPropertyRef for Key element
|
||||
CsdlPropertyRef propertyRef = new CsdlPropertyRef();
|
||||
propertyRef.setName(primaryFieldName);
|
||||
LOG.debug("Primary key is: "+primaryFieldName);
|
||||
|
||||
for (FieldInfo field : fields) if (!field.isComplex())
|
||||
{
|
||||
String fieldName = field.getFieldName();
|
||||
|
||||
CsdlProperty property = new CsdlProperty().setName(fieldName).setType(field.getType()).setCollection(field.isCollection());
|
||||
Integer maxLength = field.getMaxLength();
|
||||
if (null!=maxLength)
|
||||
{
|
||||
property.setMaxLength(maxLength);
|
||||
}
|
||||
|
||||
Integer precision = field.getPrecision();
|
||||
if (null!=precision)
|
||||
{
|
||||
property.setPrecision(precision);
|
||||
}
|
||||
|
||||
Integer scale = field.getScale();
|
||||
if (null!=scale)
|
||||
{
|
||||
property.setScale(scale);
|
||||
}
|
||||
|
||||
ArrayList<CsdlAnnotation> annotations = field.getAnnotations();
|
||||
if (annotations!=null)
|
||||
{
|
||||
property.setAnnotations(annotations);
|
||||
}
|
||||
|
||||
if (field.isCollection())
|
||||
{
|
||||
property.setCollection(true);
|
||||
}
|
||||
|
||||
propertyList.add(property);
|
||||
}
|
||||
|
||||
CsdlEntityType entityType = new CsdlEntityType();
|
||||
entityType.setName(defn.getResourceName());
|
||||
entityType.setProperties(propertyList);
|
||||
|
@ -175,6 +252,8 @@ public class RESOedmProvider extends CsdlAbstractEdmProvider
|
|||
|
||||
// add EntityTypes
|
||||
List<CsdlEntityType> entityTypes = new ArrayList<>();
|
||||
List<CsdlComplexType> complexTypes = new ArrayList<>();
|
||||
|
||||
|
||||
HashMap<String, Boolean> enumList = new HashMap<>();
|
||||
|
||||
|
@ -199,15 +278,19 @@ public class RESOedmProvider extends CsdlAbstractEdmProvider
|
|||
CsdlEnumType type = new CsdlEnumType();
|
||||
ArrayList<CsdlEnumMember> csdlMembers = new ArrayList<>();
|
||||
|
||||
int bitValue = 1;
|
||||
|
||||
for (EnumValueInfo value: values)
|
||||
{
|
||||
CsdlEnumMember member = new CsdlEnumMember().setName(value.getValue());
|
||||
CsdlEnumMember member = new CsdlEnumMember().setName(value.getValue()).setValue(""+bitValue);
|
||||
member.setAnnotations(value.getAnnotations());
|
||||
csdlMembers.add(member);
|
||||
bitValue = bitValue*2;
|
||||
}
|
||||
|
||||
type.setMembers(csdlMembers);
|
||||
type.setName(enumName);
|
||||
type.setFlags(enumField.isFlags());
|
||||
type.setUnderlyingType(EdmPrimitiveTypeKind.Int64.getFullQualifiedName());
|
||||
|
||||
enumSchema.getEnumTypes().add(type);
|
||||
|
@ -218,9 +301,11 @@ public class RESOedmProvider extends CsdlAbstractEdmProvider
|
|||
}
|
||||
|
||||
entityTypes.add(getEntityType(defn));
|
||||
complexTypes.add(getComplexType(defn));
|
||||
}
|
||||
|
||||
schema.setEntityTypes(entityTypes);
|
||||
//schema.setComplexTypes(complexTypes);
|
||||
|
||||
// add EntityContainer
|
||||
schema.setEntityContainer(getEntityContainer());
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.sql.Connection;
|
|||
import java.sql.DriverManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.*;
|
||||
|
@ -35,6 +36,7 @@ public class RESOservlet extends HttpServlet
|
|||
private static final long serialVersionUID = 1L;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RESOservlet.class);
|
||||
private static Connection connect = null;
|
||||
private String dbType;
|
||||
private Validator validator = null;
|
||||
private OData odata = null;
|
||||
ODataHttpHandler handler = null;
|
||||
|
@ -63,24 +65,51 @@ public class RESOservlet extends HttpServlet
|
|||
// this.validator.addProvider(new BasicAuthProvider()); // We're using this for the token auth. Only use here for easy browser testing.
|
||||
this.validator.addProvider(new BearerAuthProvider());
|
||||
|
||||
String mysqlHost = env.get("SQL_HOST");
|
||||
String mysqlUser = env.get("SQL_USER");
|
||||
String mysqlPwd = env.get("SQL_PASSWORD");
|
||||
String dbHost = env.get("SQL_HOST");
|
||||
String dbUser = env.get("SQL_USER");
|
||||
String dbPwd = env.get("SQL_PASSWORD");
|
||||
String dbConnString = env.get("SQL_CONNECTION_STR");
|
||||
String dbDriverStr = env.get("SQL_DB_DRIVER");
|
||||
|
||||
if (dbConnString!=null)
|
||||
{
|
||||
String[] dbConnSplitStr = dbConnString.split(":");
|
||||
if (dbConnSplitStr.length>1)
|
||||
{
|
||||
this.dbType = dbConnSplitStr[1].toLowerCase(); // should be of the form "jdbc","mysql","//192.168.1.71/reso_data_dictionary_1_7..."
|
||||
LOG.info("DB Type: "+this.dbType);
|
||||
}
|
||||
else LOG.info("DB String unknown form: "+dbConnString);
|
||||
}
|
||||
LOG.info("DB String empty");
|
||||
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
|
||||
Class.forName(dbDriverStr).newInstance();
|
||||
LOG.debug("looking to connect to " + dbConnString);
|
||||
|
||||
LOG.info("looking to connect to jdbc:mysql://"+mysqlHost+"/reso_data_dictionary_1_7");
|
||||
if (this.dbType.equals("mysql"))
|
||||
{
|
||||
|
||||
connect = DriverManager
|
||||
.getConnection("jdbc:mysql://"+mysqlHost+"/reso_data_dictionary_1_7?autoReconnect=true&maxReconnects=4&"
|
||||
+ "user="+mysqlUser+"&password="+mysqlPwd);
|
||||
.getConnection(dbConnString);
|
||||
}
|
||||
else if (this.dbType.equals("postgresql"))
|
||||
{
|
||||
connect = DriverManager
|
||||
.getConnection(dbConnString,dbUser,dbPwd);
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.error("Server Error occurred in connecting to the database", e);
|
||||
}
|
||||
|
||||
if (connect != null) {
|
||||
LOG.info("Connected to the database!");
|
||||
} else {
|
||||
LOG.error("Failed to make connection!");
|
||||
}
|
||||
|
||||
// Set up ODATA
|
||||
this.odata = OData.newInstance();
|
||||
RESOedmProvider edmProvider = new RESOedmProvider();
|
||||
|
@ -123,7 +152,7 @@ public class RESOservlet extends HttpServlet
|
|||
// create odata handler and configure it with CsdlEdmProvider and Processor
|
||||
this.handler = odata.createHandler(edm);
|
||||
|
||||
GenericEntityCollectionProcessor entityCollectionProcessor = new GenericEntityCollectionProcessor(this.connect);
|
||||
GenericEntityCollectionProcessor entityCollectionProcessor = new GenericEntityCollectionProcessor(this.connect, dbType);
|
||||
GenericEntityProcessor entityProcessor = new GenericEntityProcessor(this.connect);
|
||||
|
||||
this.handler.register(entityCollectionProcessor);
|
||||
|
|
Loading…
Reference in New Issue