Skip to content
Snippets Groups Projects
Verified Commit b426cbea authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: fix server 154

parent 505aa61e
No related branches found
No related tags found
1 merge request!30Draft: CheckDatatypePresent.checkIfOverride
Pipeline #11068 failed
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
package org.caosdb.server.jobs.core; package org.caosdb.server.jobs.core;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.caosdb.server.database.exceptions.EntityDoesNotExistException; import org.caosdb.server.database.exceptions.EntityDoesNotExistException;
import org.caosdb.server.database.exceptions.EntityWasNotUniqueException; import org.caosdb.server.database.exceptions.EntityWasNotUniqueException;
import org.caosdb.server.datatype.AbstractCollectionDatatype; import org.caosdb.server.datatype.AbstractCollectionDatatype;
...@@ -153,28 +154,41 @@ public final class CheckDatatypePresent extends EntityJob { ...@@ -153,28 +154,41 @@ public final class CheckDatatypePresent extends EntityJob {
checkPermission(datatype, EntityPermission.USE_AS_DATA_TYPE); checkPermission(datatype, EntityPermission.USE_AS_DATA_TYPE);
} }
private void checkIfOverride(final EntityInterface foreign) {
if (foreign.hasDatatype() && !foreign.getDatatype().equals(getEntity().getDatatype())) {
// is override!
getEntity().setDatatypeOverride(true);
} else if (!foreign.hasDatatype()) {
// non-matching reference datatype
if (getEntity().getDatatype() instanceof ReferenceDatatype2) {
final ReferenceDatatype2 datatype = (ReferenceDatatype2) getEntity().getDatatype();
if (!Objects.equals(foreign.getId(), datatype.getId())
&& !(Objects.equals(foreign.getName(), datatype.getName())
&& datatype.getId() == null)) {
getEntity().setDatatypeOverride(true);
}
} else {
getEntity().setDatatypeOverride(true);
}
}
}
private void checkIfOverride() throws Message { private void checkIfOverride() throws Message {
if (getEntity().hasId() && getEntity().getId() > 0) { if (getEntity().hasId() && getEntity().getId() > 0) {
// get data type from database // get data type from database
final EntityInterface foreign = retrieveValidSparseEntityById(getEntity().getId(), null); final EntityInterface foreign = retrieveValidSparseEntityById(getEntity().getId(), null);
checkIfOverride(foreign);
if (foreign.hasDatatype() && !foreign.getDatatype().equals(getEntity().getDatatype())) {
// is override!
getEntity().setDatatypeOverride(true);
}
} else { } else {
// get data type from container // get data type from container
EntityInterface abstractProperty = null; EntityInterface foreign = null;
if (getEntity().hasId()) { if (getEntity().hasId()) {
abstractProperty = getEntityById(getEntity().getId()); foreign = getEntityById(getEntity().getId());
} else if (getEntity().hasName()) { } else if (getEntity().hasName()) {
abstractProperty = getEntityByName(getEntity().getName()); foreign = getEntityByName(getEntity().getName());
} }
if (abstractProperty != null && abstractProperty.hasDatatype()) { if (foreign != null) {
if (!getEntity().getDatatype().equals(abstractProperty.getDatatype())) { checkIfOverride(foreign);
// is override!
getEntity().setDatatypeOverride(true);
}
} }
} }
} }
......
...@@ -167,14 +167,5 @@ public class CheckPropValid extends EntityJob { ...@@ -167,14 +167,5 @@ public class CheckPropValid extends EntityJob {
child.setDescription(parent.getDescription()); child.setDescription(parent.getDescription());
} }
} }
if (!Objects.equal(child.getDatatype(), parent.getDatatype())) {
if (child.hasDatatype()
// FIXME why this?
&& (!child.getDatatype().toString().equals("REFERENCE") || parent.hasDatatype())) {
child.setDatatypeOverride(true);
} else {
child.setDatatype(parent.getDatatype());
}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment