Improved code

porting-to-sg4
Luca Frosini 3 years ago
parent dd88daecab
commit 4e43217b63

@ -189,7 +189,7 @@ public abstract class RelationElementManagement<SEM extends EntityElementManagem
element = oDatabaseDocument.newEdge(source, target, typeName);
updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
return element;
}

@ -21,6 +21,7 @@ import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
@ -282,7 +283,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
}
logger.info("Created {} is {}", OVertex.class.getSimpleName(),
logger.debug("Created {} is {}", OVertex.class.getSimpleName(),
Utility.toJsonString((OVertex) element, true));
return element;
@ -349,7 +350,8 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
@Override
public void addToContext(UUID contextUUID) throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException {
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
String contextFullName = ContextCache.getInstance().getContextFullNameByUUID(contextUUID);
logger.info("Going to add {} with UUID {} to Context with UUID {} (i.e. {})", accessType.getName(), uuid, contextUUID, contextFullName);
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try {
workingContext = ContextUtility.getAdminSecurityContext();
@ -367,15 +369,15 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
}else {
oDatabaseDocument.rollback();
}
logger.info("{} with UUID {} successfully added to Context with UUID {}", typeName, uuid, contextUUID);
logger.info("{} with UUID {} successfully added to Context with UUID {} (i.e. {})", typeName, uuid, contextUUID, contextFullName);
} catch(ResourceRegistryException e) {
logger.error("Unable to add {} with UUID {} to Context with UUID {} - Reason is {}", typeName, uuid, contextUUID, e.getMessage());
logger.error("Unable to add {} with UUID {} to Context with UUID {} (i.e. {}) - Reason is {}", typeName, uuid, contextUUID, contextFullName, e.getMessage());
if(oDatabaseDocument != null) {
oDatabaseDocument.rollback();
}
throw e;
} catch(Exception e) {
logger.error("Unable to add {} with UUID {} to Context with UUID {}", typeName, uuid, contextUUID, e);
logger.error("Unable to add {} with UUID {} to Context with UUID {} (i.e. {})", typeName, uuid, contextUUID, contextFullName, e);
if(oDatabaseDocument != null) {
oDatabaseDocument.rollback();
}

@ -20,6 +20,7 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
@ -258,7 +259,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
AddConstraint addConstraint = propagationConstraint.getAddConstraint();
if(addConstraint == null) {
addConstraint = defaultPropagationConstraint.getAddConstraint();
logger.warn("Unable to get {}. Default value ({}) will be used", AddConstraint.class.getSimpleName(),
logger.debug("Unable to get {}. Default value ({}) will be used", AddConstraint.class.getSimpleName(),
addConstraint);
}
propagationConstraintOrient.setAddConstraint(addConstraint);
@ -266,7 +267,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
RemoveConstraint removeConstraint = propagationConstraint.getRemoveConstraint();
if(removeConstraint == null) {
removeConstraint = defaultPropagationConstraint.getRemoveConstraint();
logger.warn("Unable to get {}. Default value ({}) will be used", RemoveConstraint.class.getSimpleName(),
logger.debug("Unable to get {}. Default value ({}) will be used", RemoveConstraint.class.getSimpleName(),
removeConstraint);
}else {
if (this instanceof ConsistsOfManagement && removeConstraint == RemoveConstraint.keep) {
@ -293,7 +294,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
checkPropagationConstraint();
logger.info("{} successfully created", typeName);
logger.trace("{} successfully created", typeName);
return element;
}
@ -349,7 +350,8 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
@Override
protected OEdge reallyUpdate() throws ResourceRegistryException {
logger.debug("Trying to update {} : {}", typeName, jsonNode);
logger.trace("Trying to update {} with UUID {}", typeName, uuid);
logger.trace("Trying to update {} : {}", typeName, jsonNode);
OEdge edge = getElement();
updateProperties(oClass, edge, jsonNode, ignoreKeys, ignoreStartWithKeys);
@ -365,7 +367,8 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
}
}
logger.info("{} {} successfully updated", typeName, jsonNode);
logger.info("{} with UUID {} successfully updated", typeName, uuid);
logger.trace("{} {} successfully updated", typeName, jsonNode);
return edge;
@ -486,8 +489,9 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
}
@Override
public void addToContext(UUID contextUUID) throws NotFoundException, ContextException {
logger.debug("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
public void addToContext(UUID contextUUID) throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException {
String contextFullName = ContextCache.getInstance().getContextFullNameByUUID(contextUUID);
logger.debug("Going to add {} with UUID {} to Context with UUID {} (i.e {})", accessType.getName(), uuid, contextUUID, contextFullName);
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try {
workingContext = ContextUtility.getAdminSecurityContext();
@ -506,11 +510,10 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
}else {
oDatabaseDocument.rollback();
}
logger.info("{} with UUID {} successfully added to Context with UUID {}", accessType.getName(), uuid,
contextUUID);
logger.info("{} with UUID {} successfully added to Context with UUID {} (i.e {})", accessType.getName(), uuid, contextUUID, contextFullName);
} catch(Exception e) {
logger.error("Unable to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid,
contextUUID, e);
logger.error("Unable to add {} with UUID {} to Context with UUID {} (i.e. {})", accessType.getName(), uuid,
contextUUID, contextFullName, e);
if(oDatabaseDocument != null) {
oDatabaseDocument.rollback();
}

@ -799,7 +799,8 @@ public class SchemaManagement {
try {
AccessType accessType = type.getAccessType();
logger.info("Trying to update {} {} : {}", accessType.getName(), type.getName(), json);
logger.info("Trying to update {} type definition", accessType.getName(), type.getName(), json);
logger.debug("Trying to update {} {} : {}", accessType.getName(), type.getName(), json);
if(typeName.compareTo(type.getName()) != 0) {
String error = String.format(

@ -170,7 +170,7 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
logger.info("Created {} is {}", OVertex.class.getSimpleName(), Utility.toJsonString(element, true));
logger.debug("Created {} is {}", OVertex.class.getSimpleName(), Utility.toJsonString(element, true));
return element;
} catch (ResourceRegistryException e) {

@ -105,7 +105,7 @@ public class Utility {
if(resultSet == null || !resultSet.hasNext()) {
String error = String.format("No %s with UUID %s was found", elementType, uuid.toString());
logger.info(error);
logger.debug(error);
throw new NotFoundException(error);
}

@ -2,19 +2,17 @@ package org.gcube.informationsystem.resourceregistry.instances.multicontext;
import java.net.URI;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.reference.properties.Header;
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.RemoveConstraint;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement;
@ -159,60 +157,39 @@ public class AddToContextTest extends MultiContextTest {
Dataset r1 = ElementMapper.unmarshal(Dataset.class, getResourceManagement(datasetR1).read());
@SuppressWarnings("unchecked")
List<String> contextsR1 = (List<String>) r1.getHeader().getAdditionalProperty(Header.__CONTEXTS);
/*
Set<UUID> contextsR1UUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(contextsR1);
Set<String> contextsR1Fullname = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(contextsR1UUID);
logger.debug("{}", contextsR1Fullname);
*/
logger.info("Contexts of {} with UUID {} and Id {} are {}", Dataset.NAME, r1.getHeader().getUUID(), ((IdentifierFacet)r1.getIdentificationFacets().get(0)).getValue(), contextsR1Fullname);
Assert.assertTrue(contextsR1.size()==r1Number);
Dataset r2 = ElementMapper.unmarshal(Dataset.class, getResourceManagement(datasetR2).read());
@SuppressWarnings("unchecked")
List<String> contextsR2 = (List<String>) r2.getHeader().getAdditionalProperty(Header.__CONTEXTS);
/*
Set<UUID> contextsR2UUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(contextsR2);
Set<String> contextsR2Fullname = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(contextsR2UUID);
logger.debug("{}", contextsR2Fullname);
*/
logger.info("Contexts of {} with UUID {} and Id {} are {}", Dataset.NAME, r2.getHeader().getUUID(), ((IdentifierFacet)r2.getIdentificationFacets().get(0)).getValue(), contextsR2Fullname);
Assert.assertTrue(contextsR2.size()==r2Number);
Dataset r3 = ElementMapper.unmarshal(Dataset.class, getResourceManagement(datasetR3).read());
@SuppressWarnings("unchecked")
List<String> contextsR3 = (List<String>) r3.getHeader().getAdditionalProperty(Header.__CONTEXTS);
/*
Set<UUID> contextsR3UUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(contextsR3);
Set<String> contextsR3Fullname = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(contextsR3UUID);
logger.debug("{}", contextsR3Fullname);
*/
logger.info("Contexts of {} with UUID {} and Id {} are {}", Dataset.NAME, r3.getHeader().getUUID(), ((IdentifierFacet)r3.getIdentificationFacets().get(0)).getValue(), contextsR3Fullname);
Assert.assertTrue(contextsR3.size()==r3Number);
ContextUtility.getHierarchicalMode().set(false);
ContextUtility.getIncludeInstanceContexts().set(false);
}
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
@Override
public List<Context> renew() throws ResourceRegistryException {
try {
ContextManagement contextManagement = new ContextManagement();
String allString = contextManagement.all(false);
logger.trace(allString);
List<Context> all = ElementMapper.unmarshalList(Context.class, allString);
return all;
}catch (Exception e) {
throw new ResourceRegistryException(e);
}
}
};
@Test
public void testAddToContextFromDifferentSourceContext() throws Exception {
setContextByName(GCUBE);
/* Needed to init context cache */
ContextManagement contextManagement = new ContextManagement();
contextManagement.all(false);
Dataset datasetR1 = createDataset("R1", "da111111-dada-1111-1111-111111111111");
Dataset datasetR2 = null;
Dataset datasetR3 = null;

@ -9,8 +9,8 @@
</appender>
<logger name="org.gcube" level="INFO" />
<logger name="org.gcube.informationsystem" level="TRACE" />
<logger name="org.gcube" level="ERROR" />
<logger name="org.gcube.informationsystem" level="INFO" />
<logger name="org.gcube.informationsystem.types" level="INFO" />
<logger name="org.gcube.informationsystem.resourceregistry.dbinitialization" level="INFO" />
<logger name="org.gcube.informationsystem.utils.discovery" level="ERROR" />

Loading…
Cancel
Save