Cleaning commented code
This commit is contained in:
parent
dfccd87a62
commit
ca51189cab
|
@ -22,7 +22,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.EntityAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.ServerContextCache;
|
||||
|
@ -150,8 +149,8 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
this.relationManagements = new HashMap<>();
|
||||
|
||||
/*
|
||||
* By the default the system honour the propagation constraints
|
||||
* so this variable is initialised as true.
|
||||
* By the default the system honor the propagation constraints
|
||||
* so this variable is initialized as true.
|
||||
*/
|
||||
this.honourPropagationConstraintsInContextSharing = true;
|
||||
|
||||
|
@ -527,225 +526,6 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
}
|
||||
}
|
||||
|
||||
public boolean propertyMatchRequestedValue(OVertex v, String key, String requestedValue, Object instanceValue) throws SchemaException, ResourceRegistryException {
|
||||
return requestedValue.compareTo(instanceValue.toString())==0;
|
||||
|
||||
|
||||
/*
|
||||
OClass oClass = ElementManagement.getOClass(v);
|
||||
OProperty oProperty = oClass.getProperty(key);
|
||||
if(oProperty==null){
|
||||
// It is an additional property
|
||||
return requestedValue.compareTo(instanceValue.toString())==0;
|
||||
}
|
||||
OType oType = oProperty.getType();
|
||||
switch (oType) {
|
||||
case BOOLEAN:
|
||||
Boolean requested = Boolean.valueOf(requestedValue.toLowerCase());
|
||||
return requested == (Boolean) instanceValue;
|
||||
|
||||
case STRING:
|
||||
return requestedValue.compareTo((String) instanceValue)==0;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
public String reallyQuery(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
|
||||
boolean polymorphic, Map<String,String> constraint, boolean includeRelationInResult) throws ResourceRegistryException {
|
||||
*/
|
||||
// public String reallyQuery(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
|
||||
// boolean polymorphic, Map<String,String> constraint) throws ResourceRegistryException {
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
// ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||
//
|
||||
// ServerRequestInfo requestInfo = RequestUtility.getRequestInfo().get();
|
||||
// int limit = requestInfo.getLimit();
|
||||
// int offset = requestInfo.getOffset();
|
||||
//
|
||||
// int position = -1;
|
||||
// int count = 0;
|
||||
//
|
||||
// Iterable<?> references = null;
|
||||
//
|
||||
// if(referenceUUID != null) {
|
||||
// OElement element = null;
|
||||
// try {
|
||||
// element = ElementManagementUtility.getAnyElementByUUID(oDatabaseDocument, referenceUUID);
|
||||
// }catch (ResourceRegistryException e) {
|
||||
// String error = String.format("No instace with UUID %s exists", referenceUUID.toString());
|
||||
// throw new InvalidQueryException(error);
|
||||
// }
|
||||
//
|
||||
// if(element instanceof OVertex) {
|
||||
// EntityManagement<?, ?> entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
// oDatabaseDocument, (OVertex) element);
|
||||
//
|
||||
// String elementType = entityManagement.getTypeName();
|
||||
// if(elementType.compareTo(referenceType) != 0) {
|
||||
// if(polymorphic && getOClass().isSubClassOf(referenceType)) {
|
||||
// // OK
|
||||
// } else {
|
||||
// String error = String.format("Referenced instance with UUID %s is not a %s", referenceUUID, referenceType);
|
||||
// throw new InvalidQueryException(error);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// List<OVertex> vertexes = new ArrayList<>();
|
||||
// vertexes.add((OVertex) element);
|
||||
// references = vertexes;
|
||||
//
|
||||
// } else {
|
||||
// String error = String.format("Referenced instance with UUID %s is not a %s", referenceUUID, referenceType);
|
||||
// throw new InvalidQueryException(error);
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// references = oDatabaseDocument.browseClass(referenceType, polymorphic);
|
||||
// }
|
||||
//
|
||||
// Set<ORID> analysed = new HashSet<>();
|
||||
//
|
||||
// outerloop:
|
||||
// for(Object r : references) {
|
||||
// OVertex v = (OVertex) r;
|
||||
//
|
||||
// boolean skip = false;
|
||||
// // checking if the constraints are satisfied
|
||||
// for(String key : constraint.keySet()) {
|
||||
// String value = constraint.get(key);
|
||||
// Object o = v.getProperty(key);
|
||||
// if(value==null) {
|
||||
// if(o==null) {
|
||||
// //ok
|
||||
// }else {
|
||||
// skip = true;
|
||||
// break;
|
||||
// }
|
||||
// }else {
|
||||
// if(o==null) {
|
||||
// // The vertex has not a required property to be tested
|
||||
// // or the property is null
|
||||
// skip = true;
|
||||
// break;
|
||||
// }else {
|
||||
// skip = !propertyMatchRequestedValue(v, key, value, o);
|
||||
// if(skip) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if(skip) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// List<ODirection> directions = new ArrayList<>();
|
||||
// if(direction==ODirection.BOTH) {
|
||||
// directions.add(ODirection.IN);
|
||||
// directions.add(ODirection.OUT);
|
||||
// }else {
|
||||
// directions.add(direction);
|
||||
// }
|
||||
//
|
||||
// for(ODirection d : directions) {
|
||||
//
|
||||
// Iterable<OEdge> edges = v.getEdges(d.opposite(), relationType);
|
||||
// for(OEdge edge : edges) {
|
||||
// OVertex vertex = edge.getVertex(d);
|
||||
//
|
||||
// ORID vertexORID = vertex.getIdentity();
|
||||
//
|
||||
// if(analysed.contains(vertexORID)) {
|
||||
// continue;
|
||||
// }
|
||||
// analysed.add(vertexORID);
|
||||
//
|
||||
// if(v.getIdentity().compareTo(vertexORID) == 0) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// OClass oClass = ElementManagementUtility.getOClass(vertex);
|
||||
//
|
||||
// /*
|
||||
// * If the requested type (i.e. elementType)
|
||||
// * differs form the resulting type (i.e. oClass.getName())
|
||||
// * we need to evaluate if polymorphism is requested and
|
||||
// * if the resulting type is a subclass of the requested type
|
||||
// *
|
||||
// */
|
||||
// if(oClass.getName().compareTo(typeName)!=0) {
|
||||
// if(polymorphic && oClass.isSubClassOf(typeName)) {
|
||||
// // OK
|
||||
// } else {
|
||||
// // excluding from results
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// EntityManagement<?,?> entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
// oDatabaseDocument, vertex);
|
||||
//
|
||||
// try {
|
||||
// if(referenceUUID!=null && entityManagement.getUUID().compareTo(referenceUUID) == 0) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /*
|
||||
// * This is the only position where we can put
|
||||
// * pagination check because we need matching results
|
||||
// */
|
||||
// if(++position < offset) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// JsonNode jsonNode;
|
||||
// if(includeRelationInResult) {
|
||||
// RelationManagement<?,?> relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(),
|
||||
// oDatabaseDocument, edge);
|
||||
// jsonNode = relationManagement.serializeAsJsonNode();
|
||||
// }else {
|
||||
// jsonNode = entityManagement.serializeAsJsonNode();
|
||||
// }
|
||||
// */
|
||||
// entityManagement.setAsEntryPoint();
|
||||
//
|
||||
//
|
||||
// JsonNode node = entityManagement.serializeAsJsonNode();
|
||||
// arrayNode.add(node);
|
||||
//
|
||||
// /*
|
||||
// * This is the only position where we can put
|
||||
// * pagination check because we need matching results
|
||||
// */
|
||||
// if(limit > 0 && ++count >= limit) {
|
||||
// break outerloop;
|
||||
// }
|
||||
//
|
||||
// } catch(ResourceRegistryException e) {
|
||||
// logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
|
||||
// vertex.toString(), OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// return objectMapper.writeValueAsString(arrayNode);
|
||||
// } catch(JsonProcessingException e) {
|
||||
// throw new ResourceRegistryException(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
public String reallyQuery(String relationType, String referenceType, UUID referenceUUID,
|
||||
ODirection direction, boolean polymorphic, Map<String,String> constraint) throws ResourceRegistryException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
@ -767,81 +547,77 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
* WHERE @class='EService' // if polymorphic is false
|
||||
*/
|
||||
|
||||
StringBuilder selectStringBuilder = new StringBuilder("SELECT FROM (TRAVERSE ");
|
||||
StringBuffer selectStringBuffer = new StringBuffer();
|
||||
selectStringBuffer.append("SELECT FROM (TRAVERSE ");
|
||||
selectStringBuffer.append(direction.name().toLowerCase());
|
||||
selectStringBuffer.append("V('");
|
||||
selectStringBuffer.append(typeName);
|
||||
selectStringBuffer.append("')");
|
||||
|
||||
selectStringBuilder.append(direction.name().toLowerCase());
|
||||
selectStringBuilder.append("V('");
|
||||
selectStringBuilder.append(typeName);
|
||||
selectStringBuilder.append("')");
|
||||
selectStringBuffer.append(", ");
|
||||
|
||||
selectStringBuilder.append(", ");
|
||||
selectStringBuffer.append(direction.opposite().name().toLowerCase());
|
||||
selectStringBuffer.append("E('");
|
||||
selectStringBuffer.append(relationType);
|
||||
selectStringBuffer.append("')");
|
||||
|
||||
selectStringBuilder.append(direction.opposite().name().toLowerCase());
|
||||
selectStringBuilder.append("E('");
|
||||
selectStringBuilder.append(relationType);
|
||||
selectStringBuilder.append("')");
|
||||
|
||||
selectStringBuilder.append(" FROM (SELECT FROM ");
|
||||
selectStringBuilder.append(referenceType);
|
||||
selectStringBuffer.append(" FROM (SELECT FROM ");
|
||||
selectStringBuffer.append(referenceType);
|
||||
boolean first = true;
|
||||
for(String key : constraint.keySet()) {
|
||||
if(first) {
|
||||
selectStringBuilder.append(" WHERE ");
|
||||
selectStringBuffer.append(" WHERE ");
|
||||
first = false;
|
||||
} else {
|
||||
selectStringBuilder.append(" AND ");
|
||||
selectStringBuffer.append(" AND ");
|
||||
}
|
||||
selectStringBuilder.append(key);
|
||||
selectStringBuilder.append("=");
|
||||
selectStringBuffer.append(key);
|
||||
selectStringBuffer.append("=");
|
||||
String value = constraint.get(key).trim();
|
||||
selectStringBuilder.append("'");
|
||||
selectStringBuilder.append(value);
|
||||
selectStringBuilder.append("'");
|
||||
selectStringBuffer.append("'");
|
||||
selectStringBuffer.append(value);
|
||||
selectStringBuffer.append("'");
|
||||
}
|
||||
selectStringBuilder.append(" ))");
|
||||
selectStringBuffer.append(" ))");
|
||||
|
||||
|
||||
selectStringBuilder.append(" WHERE @class");
|
||||
selectStringBuffer.append(" WHERE @class");
|
||||
if(polymorphic) {
|
||||
selectStringBuilder.append(" INSTANCEOF '");
|
||||
selectStringBuffer.append(" INSTANCEOF '");
|
||||
} else {
|
||||
selectStringBuilder.append("='");
|
||||
selectStringBuffer.append("='");
|
||||
}
|
||||
selectStringBuilder.append(typeName);
|
||||
selectStringBuilder.append("'");
|
||||
selectStringBuffer.append(typeName);
|
||||
selectStringBuffer.append("'");
|
||||
|
||||
|
||||
String select = selectStringBuilder.toString();
|
||||
ServerRequestInfo requestInfo = RequestUtility.getRequestInfo().get();
|
||||
Integer limit = requestInfo.getLimit();
|
||||
if(limit==null) {
|
||||
limit = -1;
|
||||
}
|
||||
Integer offset = requestInfo.getOffset();
|
||||
if(offset == null) {
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
selectStringBuffer.append(" SKIP :offset");
|
||||
selectStringBuffer.append(" LIMIT :limit");
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("offset", offset);
|
||||
map.put("limit", limit);
|
||||
|
||||
|
||||
String select = selectStringBuffer.toString();
|
||||
logger.trace(select);
|
||||
|
||||
OResultSet resultSet = oDatabaseDocument.command(select,new HashMap<>());
|
||||
OResultSet resultSet = oDatabaseDocument.command(select, map);
|
||||
|
||||
while(resultSet.hasNext()) {
|
||||
OResult oResult = resultSet.next();
|
||||
OElement element = ElementManagementUtility.getElementFromOptional(oResult.getElement());
|
||||
|
||||
/*
|
||||
if(polymorphic) {
|
||||
OClass oClass = null;
|
||||
try {
|
||||
if(element instanceof OEdge) {
|
||||
continue;
|
||||
}
|
||||
oClass = ElementManagementUtility.getOClass(element);
|
||||
} catch(Exception e) {
|
||||
String error = String.format("Unable to detect type of %s. %s", element.toString(),
|
||||
OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
logger.error(error, e);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
||||
if(oClass.isSubClassOf(typeName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
OVertex vertex = (OVertex) element;
|
||||
|
||||
EntityManagement<?,?> entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
|
@ -869,10 +645,6 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public String query(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
|
||||
boolean polymorphic, Map<String,String> constraint, boolean includeRelationInResult) throws ResourceRegistryException {
|
||||
*/
|
||||
public String query(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
|
||||
boolean polymorphic, Map<String,String> constraint) throws ResourceRegistryException {
|
||||
|
||||
|
|
|
@ -122,11 +122,6 @@ public class JsonQuery {
|
|||
offset = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
int position = -1;
|
||||
int count = 0;
|
||||
*/
|
||||
|
||||
StringBuffer stringBuffer = createQuery();
|
||||
stringBuffer.append(" SKIP :offset");
|
||||
stringBuffer.append(" LIMIT :limit");
|
||||
|
@ -145,11 +140,7 @@ public class JsonQuery {
|
|||
|
||||
while(resultSet.hasNext()) {
|
||||
OResult oResult = resultSet.next();
|
||||
/*
|
||||
if(++position < offset) {
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
OElement element = ElementManagementUtility.getElementFromOptional(oResult.getElement());
|
||||
|
||||
|
@ -160,34 +151,6 @@ public class JsonQuery {
|
|||
erManagement.setAsEntryPoint();
|
||||
jsonNodeResult = erManagement.serializeAsJsonNode();
|
||||
arrayNode.add(jsonNodeResult);
|
||||
/*
|
||||
if(limit > 0 && ++count >= limit) {
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
// To support polymorphism we do not include @class = "TypeName" in query. So we need post processing filtering of results
|
||||
|
||||
String requestedType = entryPoint.getType();
|
||||
String gotType = erManagement.getTypeName();
|
||||
CachedType<?> cachedType = TypesCache.getInstance().getCachedType(gotType);
|
||||
|
||||
if(requestedType.compareTo(gotType)==0 || cachedType.getSuperTypes().contains(requestedType)) {
|
||||
erManagement.setAsEntryPoint();
|
||||
jsonNodeResult = erManagement.serializeAsJsonNode();
|
||||
arrayNode.add(jsonNodeResult);
|
||||
if(limit > 0 && ++count >= limit) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
|
||||
element.toString(), OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
|
|
Loading…
Reference in New Issue