Refactoring

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@141519 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-01-11 17:00:21 +00:00
parent 35bc8a6c83
commit 2b55c43477
4 changed files with 21 additions and 20 deletions

View File

@ -16,6 +16,7 @@ import java.util.UUID;
import org.codehaus.jettison.json.JSONObject;
import org.gcube.informationsystem.impl.utils.Entities;
import org.gcube.informationsystem.model.ER;
import org.gcube.informationsystem.model.embedded.Header;
import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.entity.Facet;
@ -60,7 +61,7 @@ import com.tinkerpop.blueprints.impls.orient.OrientGraph;
* @author Luca Frosini (ISTI - CNR)
*
*/
public abstract class ERManagement<ER, El extends Element> {
public abstract class ERManagement<ERType extends ER, El extends Element> {
private static Logger logger = LoggerFactory.getLogger(ERManagement.class);
@ -70,7 +71,7 @@ public abstract class ERManagement<ER, El extends Element> {
protected final Set<String> ignoreKeys;
protected final Set<String> ignoreStartWithKeys;
protected Class<ER> erClass;
protected Class<ERType> erTypeClass;
protected String baseType;
protected OrientGraph orientGraph;
@ -168,8 +169,8 @@ public abstract class ERManagement<ER, El extends Element> {
}
protected ERManagement(Class<ER> erClass) {
this.erClass = erClass;
protected ERManagement(Class<ERType> erClass) {
this.erTypeClass = erClass;
this.ignoreKeys = new HashSet<String>();
@ -180,7 +181,7 @@ public abstract class ERManagement<ER, El extends Element> {
}
protected ERManagement(Class<ER> erClass, OrientGraph orientGraph) {
protected ERManagement(Class<ERType> erClass, OrientGraph orientGraph) {
this(erClass);
this.orientGraph = orientGraph;
}
@ -211,16 +212,16 @@ public abstract class ERManagement<ER, El extends Element> {
public void setElementType(String erType) throws ResourceRegistryException {
this.erType = erType;
if (erType == null || erType.compareTo("") == 0) {
if (Facet.class.isAssignableFrom(erClass)) {
if (Facet.class.isAssignableFrom(erTypeClass)) {
this.erType = Facet.NAME;
}
if (Resource.class.isAssignableFrom(erClass)) {
if (Resource.class.isAssignableFrom(erTypeClass)) {
this.erType = Resource.NAME;
}
if (ConsistsOf.class.isAssignableFrom(erClass)) {
if (ConsistsOf.class.isAssignableFrom(erTypeClass)) {
this.erType = ConsistsOf.NAME;
}
if (IsRelatedTo.class.isAssignableFrom(erClass)) {
if (IsRelatedTo.class.isAssignableFrom(erTypeClass)) {
this.erType = IsRelatedTo.NAME;
}
throw new ResourceRegistryException("Invalid type " + erType
@ -318,11 +319,11 @@ public abstract class ERManagement<ER, El extends Element> {
throws EntityNotFoundException, RelationNotFoundException,
ResourceRegistryException {
if (Resource.class.isAssignableFrom(erClass)) {
if (Resource.class.isAssignableFrom(erTypeClass)) {
throw new ResourceNotFoundException(e);
} else if (Facet.class.isAssignableFrom(erClass)) {
} else if (Facet.class.isAssignableFrom(erTypeClass)) {
throw new FacetNotFoundException(e);
} else if (Relation.class.isAssignableFrom(erClass)) {
} else if (Relation.class.isAssignableFrom(erTypeClass)) {
throw new RelationNotFoundException(e);
}

View File

@ -100,7 +100,7 @@ public abstract class EntityManagement<E extends Entity> extends
entityHeader = HeaderUtility.addHeader(element, null);
}
if (Resource.class.isAssignableFrom(erClass)) {
if (Resource.class.isAssignableFrom(erTypeClass)) {
// Facet and relation are created in calling method
} else {
ERManagement.updateProperties(element, jsonNode, ignoreKeys,

View File

@ -210,7 +210,7 @@ public abstract class RelationManagement<R extends Relation> extends ERManagemen
Edge edge = getElement();
ERManagement.updateProperties(edge, jsonNode, ignoreKeys, ignoreStartWithKeys);
if (ConsistsOf.class.isAssignableFrom(erClass)) {
if (ConsistsOf.class.isAssignableFrom(erTypeClass)) {
JsonNode target = jsonNode.get(Relation.TARGET_PROPERTY);
if (target != null) {
FacetManagement fm = new FacetManagement(orientGraph);
@ -342,14 +342,14 @@ public abstract class RelationManagement<R extends Relation> extends ERManagemen
protected EntityManagement getEntityManagement()
throws ResourceRegistryException {
EntityManagement entityManagement;
if (ConsistsOf.class.isAssignableFrom(erClass)) {
if (ConsistsOf.class.isAssignableFrom(erTypeClass)) {
entityManagement = new FacetManagement(orientGraph);
} else if (IsRelatedTo.class.isAssignableFrom(erClass)) {
} else if (IsRelatedTo.class.isAssignableFrom(erTypeClass)) {
entityManagement = new ResourceManagement(orientGraph);
} else {
String error = String.format("{%s is not a %s nor a %s. "
+ "This is really strange ad should not occur. "
+ "Please Investigate it.", erClass, ConsistsOf.NAME,
+ "Please Investigate it.", erTypeClass, ConsistsOf.NAME,
IsRelatedTo.NAME);
throw new ResourceRegistryException(error);
}

View File

@ -495,10 +495,10 @@ public class ERManagementTest extends ScopedTest {
/* Removing created Entity and Realtion to have a clean DB */
/* Removing created Entity and Relation to have a clean DB */
list = resources.get(HostingNode.NAME);
for(Resource r : list){
List<Resource> resourceList = resources.get(HostingNode.NAME);
for(Resource r : resourceList){
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(r.getHeader().getUUID());
resourceManagement.delete();