Relation instances request returns relations and not Resources
This commit is contained in:
parent
113c3ceb9e
commit
85c773fb1b
|
@ -16,6 +16,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||||
- Prepared Query has been fixed to properly consider polymorphic parameter and provided constraint [#20298]
|
- Prepared Query has been fixed to properly consider polymorphic parameter and provided constraint [#20298]
|
||||||
- Add tests to check the proper behaviour of operation involving Propagation Constraints [#20923]
|
- Add tests to check the proper behaviour of operation involving Propagation Constraints [#20923]
|
||||||
- The contexts property is not included in header is not requested [#21953]
|
- The contexts property is not included in header is not requested [#21953]
|
||||||
|
- When serialising a resource the ConsistsOf does not include source [#22001]
|
||||||
|
- Getting all the relations of a type it is returned a list of relations and not the list of Resources sources of such relation [#22003]
|
||||||
|
|
||||||
|
|
||||||
## [v4.0.0]
|
## [v4.0.0]
|
||||||
|
|
||||||
|
@ -24,6 +27,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||||
- Added support to add contexts in instances header for instances safe methods only [#20012]
|
- Added support to add contexts in instances header for instances safe methods only [#20012]
|
||||||
- Switched JSON management to gcube-jackson [#19116]
|
- Switched JSON management to gcube-jackson [#19116]
|
||||||
|
|
||||||
|
|
||||||
## [v3.0.0] [r4.21.0] - 2020-03-30
|
## [v3.0.0] [r4.21.0] - 2020-03-30
|
||||||
|
|
||||||
- Refactored code to support IS Model reorganization (e.g naming, packages)
|
- Refactored code to support IS Model reorganization (e.g naming, packages)
|
||||||
|
|
|
@ -1,18 +1,25 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.instances.model.relations;
|
package org.gcube.informationsystem.resourceregistry.instances.model.relations;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
|
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
||||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||||
|
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAvailableInAnotherContextException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||||
|
import org.gcube.informationsystem.types.reference.entities.EntityType;
|
||||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,6 +63,40 @@ public class IsRelatedToManagement extends RelationManagement<ResourceManagement
|
||||||
return resourceManagement;
|
return resourceManagement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
||||||
|
JsonNode relation = serializeSelfAsJsonNode();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(includeSource) {
|
||||||
|
EntityElementManagement<? extends EntityElement, ? extends EntityType> sourceEntityManagement = getSourceEntityManagement();
|
||||||
|
((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelfAsJsonNode());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(includeTarget) {
|
||||||
|
EntityElementManagement<? extends EntityElement, ? extends EntityType> targetEntityManagement = getTargetEntityManagement();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function differ from the super implementation in RelationElementManagement from the following line of code
|
||||||
|
* An IsRelatedTo must not include the whole target Resource (with all the facets) instead only the Resource entity.
|
||||||
|
*
|
||||||
|
* ((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeAsJsonNode());
|
||||||
|
*/
|
||||||
|
((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeSelfAsJsonNode());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch(ResourceRegistryException e) {
|
||||||
|
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
||||||
|
throw e;
|
||||||
|
} catch(Exception e) {
|
||||||
|
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return relation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.instances.model.relations;
|
package org.gcube.informationsystem.resourceregistry.instances.model.relations;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -187,34 +188,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
return sourceEntityManagement;
|
return sourceEntityManagement;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Override
|
|
||||||
public JsonNode createCompleteJsonNode(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
|
|
||||||
JsonNode relation = serializeSelfAsJsonNode();
|
|
||||||
|
|
||||||
try {
|
|
||||||
if(includeSource) {
|
|
||||||
ResourceManagement sourceEntityManagement = getSourceEntityManagement();
|
|
||||||
((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelfAsJsonNode());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(includeTarget) {
|
|
||||||
T targetEntityManagement = getTargetEntityManagement();
|
|
||||||
((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeAsJsonNode());
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch(ResourceRegistryException e) {
|
|
||||||
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
|
||||||
throw e;
|
|
||||||
} catch(Exception e) {
|
|
||||||
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
|
||||||
throw new ResourceRegistryException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return relation;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected Map<String,JsonNode> fullSerialize(Map<String,JsonNode> visitedSourceResources)
|
protected Map<String,JsonNode> fullSerialize(Map<String,JsonNode> visitedSourceResources)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
|
|
||||||
|
@ -765,20 +738,21 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
|
|
||||||
protected Collection<JsonNode> serializeEdges(Iterable<ODocument> edges, boolean postFilterPolymorphic)
|
protected Collection<JsonNode> serializeEdges(Iterable<ODocument> edges, boolean postFilterPolymorphic)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
Map<String,JsonNode> visitedSourceResources = new HashMap<>();
|
// Map<String,JsonNode> visitedSourceResources = new HashMap<>();
|
||||||
|
List<JsonNode> serilizedEdges = new ArrayList<>();
|
||||||
for(ODocument d : edges) {
|
for(ODocument d : edges) {
|
||||||
OEdge edge = (OEdge) d;
|
OEdge edge = (OEdge) d;
|
||||||
|
|
||||||
// TODO check because it was using compare
|
|
||||||
if(postFilterPolymorphic && getOClass().isSubClassOf(typeName)) {
|
if(postFilterPolymorphic && getOClass().isSubClassOf(typeName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
RelationManagement<?, ?> relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(),
|
RelationManagement<?, ?> relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(),
|
||||||
oDatabaseDocument, edge);
|
oDatabaseDocument, edge);
|
||||||
visitedSourceResources = relationManagement.fullSerialize(visitedSourceResources);
|
// visitedSourceResources = relationManagement.fullSerialize(visitedSourceResources);
|
||||||
|
serilizedEdges.add(relationManagement.serializeAsJsonNode());
|
||||||
}
|
}
|
||||||
return visitedSourceResources.values();
|
return serilizedEdges;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String serializeJsonNodeCollectionAsString(Collection<JsonNode> collection) throws ResourceRegistryException {
|
protected String serializeJsonNodeCollectionAsString(Collection<JsonNode> collection) throws ResourceRegistryException {
|
||||||
|
@ -797,7 +771,5 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
Collection<JsonNode> collection = serializeEdges(edges, false);
|
Collection<JsonNode> collection = serializeEdges(edges, false);
|
||||||
return serializeJsonNodeCollectionAsString(collection);
|
return serializeJsonNodeCollectionAsString(collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue