Fixed bugs

This commit is contained in:
Luca Frosini 2021-02-19 15:31:26 +01:00
parent 799aa5a770
commit b7a2e6c6eb
4 changed files with 26 additions and 17 deletions

View File

@ -513,14 +513,14 @@ public abstract class ElementManagement<El extends OElement> {
element = internalCreate(); element = internalCreate();
} }
sanityCheck(null);
oDatabaseDocument.commit(); oDatabaseDocument.commit();
if(update) { if(update) {
setReload(true); setReload(true);
} }
sanityCheck(null);
// TODO Notify to subscriptionNotification // TODO Notify to subscriptionNotification
return serializeAsJsonNode().toString(); return serializeAsJsonNode().toString();
@ -556,10 +556,10 @@ public abstract class ElementManagement<El extends OElement> {
element = internalCreate(); element = internalCreate();
oDatabaseDocument.commit();
sanityCheck(null); sanityCheck(null);
oDatabaseDocument.commit();
// TODO Notify to subscriptionNotification // TODO Notify to subscriptionNotification
return serializeAsJsonNode().toString(); return serializeAsJsonNode().toString();
@ -621,12 +621,12 @@ public abstract class ElementManagement<El extends OElement> {
element = internalUpdate(); element = internalUpdate();
sanityCheck(null);
oDatabaseDocument.commit(); oDatabaseDocument.commit();
setReload(true); setReload(true);
sanityCheck(null);
// TODO Notify to subscriptionNotification // TODO Notify to subscriptionNotification
return serializeAsJsonNode().toString(); return serializeAsJsonNode().toString();

View File

@ -338,9 +338,11 @@ public class ResourceManagement extends EntityManagement<Resource> {
ResourceType resourceType = (ResourceType) cachedType.getType(); ResourceType resourceType = (ResourceType) cachedType.getType();
List<LinkedEntity> linkedEntities = resourceType.getFacets(); List<LinkedEntity> linkedEntities = resourceType.getFacets();
for(LinkedEntity linkedEntity : linkedEntities) { if(linkedEntities!=null) {
if(linkedEntity.getMin()>0 || linkedEntity.getMax()>0) { for(LinkedEntity linkedEntity : linkedEntities) {
constraints.add(linkedEntity); if(linkedEntity.getMin()>0 || (linkedEntity.getMax()!=null && linkedEntity.getMax()>0)) {
constraints.add(linkedEntity);
}
} }
} }
@ -352,9 +354,11 @@ public class ResourceManagement extends EntityManagement<Resource> {
ResourceType resourceSuperType = (ResourceType) cachedSuperType.getType(); ResourceType resourceSuperType = (ResourceType) cachedSuperType.getType();
List<LinkedEntity> linkedEnt = resourceSuperType.getFacets(); List<LinkedEntity> linkedEnt = resourceSuperType.getFacets();
for(LinkedEntity linkedEntity : linkedEnt) { if(linkedEnt!=null) {
if(linkedEntity.getMin()>0 || linkedEntity.getMax()>0) { for(LinkedEntity linkedEntity : linkedEnt) {
constraints.add(linkedEntity); if(linkedEntity.getMin()>0 || (linkedEntity.getMax()!=null && linkedEntity.getMax()>0)) {
constraints.add(linkedEntity);
}
} }
} }
} }
@ -377,6 +381,9 @@ public class ResourceManagement extends EntityManagement<Resource> {
stringBuffer.append(". Found "); stringBuffer.append(". Found ");
stringBuffer.append(occurrence); stringBuffer.append(occurrence);
stringBuffer.append(" instances"); stringBuffer.append(" instances");
stringBuffer.append(". The constraint has been defined by ");
stringBuffer.append(linkedEntity.getSource());
stringBuffer.append(" type.");
return stringBuffer.toString(); return stringBuffer.toString();
} }
@ -415,7 +422,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
@Override @Override
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException { public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException {
JsonNode resourceInstance = serializeAsJsonNode().deepCopy(); JsonNode resourceInstance = createCompleteJsonNode();
TypesCache typesCache = TypesCache.getInstance(); TypesCache typesCache = TypesCache.getInstance();
@ -489,8 +496,8 @@ public class ResourceManagement extends EntityManagement<Resource> {
throw new SchemaViolationException(message); throw new SchemaViolationException(message);
} }
int max = linkedEntity.getMax(); Integer max = linkedEntity.getMax();
if(max>0 && satisfiedTimes>max) { if((max!=null && max>0) && satisfiedTimes>max) {
String message = constraintNotSatisfiedErrorMessage(linkedEntity, satisfiedTimes); String message = constraintNotSatisfiedErrorMessage(linkedEntity, satisfiedTimes);
throw new SchemaViolationException(message); throw new SchemaViolationException(message);
} }

View File

@ -34,6 +34,7 @@ import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
@ -167,7 +168,7 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(deleted); Assert.assertTrue(deleted);
} }
@Test @Test(expected = SchemaViolationException.class)
public void testCreateRunningPlugin() throws Exception { public void testCreateRunningPlugin() throws Exception {
RunningPlugin runningPlugin = new RunningPluginImpl(); RunningPlugin runningPlugin = new RunningPluginImpl();

View File

@ -14,6 +14,7 @@
<logger name="org.gcube.informationsystem.types" level="INFO" /> <logger name="org.gcube.informationsystem.types" level="INFO" />
<logger name="org.gcube.informationsystem.resourceregistry.dbinitialization" level="INFO" /> <logger name="org.gcube.informationsystem.resourceregistry.dbinitialization" level="INFO" />
<logger name="org.gcube.informationsystem.utils.discovery" level="ERROR" /> <logger name="org.gcube.informationsystem.utils.discovery" level="ERROR" />
<logger name="org.gcube.informationsystem.resourceregistry.types" level="INFO" />
<root level="WARN"> <root level="WARN">
<appender-ref ref="STDOUT" /> <appender-ref ref="STDOUT" />