Solved rawtypes and Removed some @SuppressWarnings("rawtypes")

This commit is contained in:
Luca Frosini 2021-03-05 15:04:27 +01:00
parent 05a8825635
commit 6b999a54ef
7 changed files with 28 additions and 31 deletions

View File

@ -38,8 +38,7 @@ public abstract class EntityElementManagement<E extends EntityElement, ET extend
* Provide a cache edge-internal-id -> RelationManagement * Provide a cache edge-internal-id -> RelationManagement
* this avoid to recreate the relationManagement of already visited edges * this avoid to recreate the relationManagement of already visited edges
*/ */
@SuppressWarnings("rawtypes") protected Map<String,RelationElementManagement<?,?,?,?>> relationManagements;
protected Map<String,RelationElementManagement> relationManagements;
protected EntityElementManagement(AccessType accessType) { protected EntityElementManagement(AccessType accessType) {
super(accessType); super(accessType);
@ -61,16 +60,15 @@ public abstract class EntityElementManagement<E extends EntityElement, ET extend
setWorkingContext(workingContext); setWorkingContext(workingContext);
} }
@SuppressWarnings("rawtypes")
/* /*
* It works perfectly in case of any kind of update. In case of use from create * It works perfectly in case of any kind of update. In case of use from create
* the cache does not work by using the ID because until commit the edge has a * the cache does not work by using the ID because until commit the edge has a
* fake id starting with - (minus) sign. This not imply any collateral effect * fake id starting with - (minus) sign. This not imply any collateral effect
* but a better solution is a desiderata. * but a better solution is a desiderata.
*/ */
protected RelationElementManagement getBaseRelationManagement(OEdge edge) throws ResourceRegistryException { protected RelationElementManagement<?,?,?,?> getBaseRelationManagement(OEdge edge) throws ResourceRegistryException {
String id = edge.getIdentity().toString(); String id = edge.getIdentity().toString();
RelationElementManagement relationManagement = relationManagements.get(id); RelationElementManagement<?,?,?,?> relationManagement = relationManagements.get(id);
if(relationManagement == null) { if(relationManagement == null) {
relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(), oDatabaseDocument, edge); relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(), oDatabaseDocument, edge);
relationManagements.put(id, relationManagement); relationManagements.put(id, relationManagement);
@ -78,7 +76,7 @@ public abstract class EntityElementManagement<E extends EntityElement, ET extend
return relationManagement; return relationManagement;
} }
protected void addToRelationManagement(@SuppressWarnings("rawtypes") RelationElementManagement baseRelationManagement) protected void addToRelationManagement(RelationElementManagement<?,?,?,?> baseRelationManagement)
throws ResourceRegistryException { throws ResourceRegistryException {
OElement elem = baseRelationManagement.getElement(); OElement elem = baseRelationManagement.getElement();
String id = elem.getIdentity().toString(); String id = elem.getIdentity().toString();

View File

@ -205,7 +205,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
return relationManagement; return relationManagement;
} }
protected void addToRelationManagement(@SuppressWarnings("rawtypes") RelationManagement relationManagement) public void addToRelationManagement(RelationManagement<?,?> relationManagement)
throws ResourceRegistryException { throws ResourceRegistryException {
OElement elem = relationManagement.getElement(); OElement elem = relationManagement.getElement();
String id = elem.getIdentity().toString(); String id = elem.getIdentity().toString();
@ -534,8 +534,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
if(referenceUUID != null) { if(referenceUUID != null) {
OElement element = ElementManagementUtility.getAnyElementByUUID(oDatabaseDocument, referenceUUID); OElement element = ElementManagementUtility.getAnyElementByUUID(oDatabaseDocument, referenceUUID);
if(element instanceof OVertex) { if(element instanceof OVertex) {
@SuppressWarnings("unchecked") EntityManagement<?, ?> entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(),
EntityManagement<Entity, EntityType> entityManagement = (EntityManagement<Entity, EntityType>) ElementManagementUtility.getEntityManagement(getWorkingContext(),
oDatabaseDocument, (OVertex) element); oDatabaseDocument, (OVertex) element);
String elementType = entityManagement.getTypeName(); String elementType = entityManagement.getTypeName();
@ -644,8 +643,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
@SuppressWarnings("rawtypes") EntityManagement<?,?> entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(),
EntityManagement entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(),
oDatabaseDocument, vertex); oDatabaseDocument, vertex);
try { try {
@ -655,8 +653,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
JsonNode jsonNode; JsonNode jsonNode;
if(includeRelationInResult) { if(includeRelationInResult) {
@SuppressWarnings("rawtypes") RelationManagement<?,?> relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(),
RelationManagement relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(),
oDatabaseDocument, edge); oDatabaseDocument, edge);
jsonNode = relationManagement.serializeAsJsonNode(); jsonNode = relationManagement.serializeAsJsonNode();
}else { }else {
@ -761,8 +758,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
OVertex vertex = (OVertex) element; OVertex vertex = (OVertex) element;
@SuppressWarnings("rawtypes") EntityManagement<?,?> entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(),
EntityManagement entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(),
oDatabaseDocument, vertex); oDatabaseDocument, vertex);
try { try {
if(constraint.containsKey(Entity.HEADER_PROPERTY + "." + Header.UUID_PROPERTY)) { if(constraint.containsKey(Entity.HEADER_PROPERTY + "." + Header.UUID_PROPERTY)) {

View File

@ -16,10 +16,12 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
import org.gcube.informationsystem.resourceregistry.instances.model.Operation; import org.gcube.informationsystem.resourceregistry.instances.model.Operation;
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
import org.gcube.informationsystem.types.reference.entities.FacetType; import org.gcube.informationsystem.types.reference.entities.FacetType;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument; import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.record.ODirection; import com.orientechnologies.orient.core.record.ODirection;
import com.orientechnologies.orient.core.record.OEdge;
import com.orientechnologies.orient.core.record.OVertex; import com.orientechnologies.orient.core.record.OVertex;
/** /**
@ -27,6 +29,7 @@ import com.orientechnologies.orient.core.record.OVertex;
*/ */
public class FacetManagement extends EntityManagement<Facet, FacetType> { public class FacetManagement extends EntityManagement<Facet, FacetType> {
protected ConsistsOfManagement consistsOfManagement;
protected ResourceManagement resourceManagement; protected ResourceManagement resourceManagement;
public FacetManagement() { public FacetManagement() {
@ -79,6 +82,14 @@ public class FacetManagement extends EntityManagement<Facet, FacetType> {
@Override @Override
protected void reallyDelete() throws FacetNotFoundException, ResourceRegistryException { protected void reallyDelete() throws FacetNotFoundException, ResourceRegistryException {
if(consistsOfManagement==null) {
OEdge oEdge = getElement().getEdges(ODirection.IN).iterator().next();
consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElement(oEdge);
consistsOfManagement.setTargetEntityManagement(this);
affectedInstances.put(uuid, consistsOfManagement.serializeSelfAsJsonNode());
}
if(entryPoint) { if(entryPoint) {
OVertex oVertex = getElement().getVertices(ODirection.IN).iterator().next(); OVertex oVertex = getElement().getVertices(ODirection.IN).iterator().next();
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();

View File

@ -755,8 +755,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
continue; continue;
} }
@SuppressWarnings("unchecked") RelationManagement<?, ?> relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(),
RelationManagement<T, TET> relationManagement = (RelationManagement<T, TET>) ElementManagementUtility.getRelationManagement(getWorkingContext(),
oDatabaseDocument, edge); oDatabaseDocument, edge);
visitedSourceResources = relationManagement.fullSerialize(visitedSourceResources); visitedSourceResources = relationManagement.fullSerialize(visitedSourceResources);
} }

View File

@ -75,8 +75,7 @@ public class QueryImpl implements Query {
if(raw) { if(raw) {
jsonNode = Utility.toJsonNode(element, false); jsonNode = Utility.toJsonNode(element, false);
} else { } else {
@SuppressWarnings("rawtypes") ElementManagement<?,?> erManagement = ElementManagementUtility.getERManagement(securityContext, oDatabaseDocument,
ElementManagement erManagement = ElementManagementUtility.getERManagement(securityContext, oDatabaseDocument,
element); element);
jsonNode = erManagement.serializeAsJsonNode(); jsonNode = erManagement.serializeAsJsonNode();
} }

View File

@ -121,8 +121,7 @@ public class Access extends BaseRest {
checkHierarchicalMode(); checkHierarchicalMode();
checkIncludeInstancesContexts(); checkIncludeInstancesContexts();
@SuppressWarnings("rawtypes") ElementManagement<?,?> erManagement = ElementManagementUtility.getERManagement(type);
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
return erManagement.all(polymorphic); return erManagement.all(polymorphic);
} }
@ -142,8 +141,7 @@ public class Access extends BaseRest {
checkHierarchicalMode(); checkHierarchicalMode();
checkIncludeInstancesContexts(); checkIncludeInstancesContexts();
@SuppressWarnings("rawtypes") ElementManagement<?,?> erManagement = ElementManagementUtility.getERManagement(type);
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
try { try {
erManagement.setUUID(UUID.fromString(uuid)); erManagement.setUUID(UUID.fromString(uuid));
@ -203,8 +201,7 @@ public class Access extends BaseRest {
logger.info("Requested to get contexts of {} with UUID {}", type, instanceId); logger.info("Requested to get contexts of {} with UUID {}", type, instanceId);
CalledMethodProvider.instance.set("getInstanceContexts"); CalledMethodProvider.instance.set("getInstanceContexts");
@SuppressWarnings("rawtypes") ElementManagement<?,?> erManagement = ElementManagementUtility.getERManagement(type);
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
erManagement.setUUID(UUID.fromString(instanceId)); erManagement.setUUID(UUID.fromString(instanceId));
return erManagement.getContexts(); return erManagement.getContexts();
} }

View File

@ -53,8 +53,7 @@ public class InstancesManager extends BaseRest {
checkHierarchicalMode(); checkHierarchicalMode();
checkIncludeInstancesContexts(); checkIncludeInstancesContexts();
@SuppressWarnings("rawtypes") ElementManagement<?,?> erManagement = ElementManagementUtility.getERManagement(type);
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
return erManagement.all(polymorphic); return erManagement.all(polymorphic);
} }
@ -113,8 +112,7 @@ public class InstancesManager extends BaseRest {
checkHierarchicalMode(); checkHierarchicalMode();
checkIncludeInstancesContexts(); checkIncludeInstancesContexts();
@SuppressWarnings("rawtypes") ElementManagement<?,?> erManagement = ElementManagementUtility.getERManagement(type);
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
erManagement.setElementType(type); erManagement.setElementType(type);
erManagement.setUUID(UUID.fromString(uuid)); erManagement.setUUID(UUID.fromString(uuid));
return erManagement.read().toString(); return erManagement.read().toString();
@ -157,8 +155,7 @@ public class InstancesManager extends BaseRest {
logger.info("Requested to delete {} with id {}", type, uuid); logger.info("Requested to delete {} with id {}", type, uuid);
CalledMethodProvider.instance.set("deleteInstance"); CalledMethodProvider.instance.set("deleteInstance");
@SuppressWarnings("rawtypes") ElementManagement<?,?> erManagement = ElementManagementUtility.getERManagement(type);
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
erManagement.setUUID(UUID.fromString(uuid)); erManagement.setUUID(UUID.fromString(uuid));
erManagement.delete(); erManagement.delete();