diff --git a/conf/core/jobs.csv b/conf/core/jobs.csv index d9fffbc3cc2fa7c69685c59af67921d739db5a70..490d192a073e3473fd1c9f4e54fa48cafde15fda 100644 --- a/conf/core/jobs.csv +++ b/conf/core/jobs.csv @@ -33,6 +33,7 @@ 0,0,UPDATE,CheckValueParsable,ERROR 0,0,DELETE,CheckDependenciesBeforeDeletion,ERROR 0,0,INSERT,RegisterPID,ERROR +0,0,UPDATE,RegisterPID,ERROR 0,0,DELETE,DeletePID,ERROR diff --git a/src/main/java/org/caosdb/server/doa/DoipUtils.java b/src/main/java/org/caosdb/server/doa/DoipUtils.java index 32d67594a2353445e71741ad70c8e4b5e73e8568..e1f8d827d192ab5cc95aa72a355e8861ac05349b 100644 --- a/src/main/java/org/caosdb/server/doa/DoipUtils.java +++ b/src/main/java/org/caosdb/server/doa/DoipUtils.java @@ -305,7 +305,11 @@ public class DoipUtils { } DigitalObject result = new DigitalObject(); result.id = entity.getId().toString(); - result.type = DoipUtils.TYPE_DO; + if (isFDO(entity)) { + result.type = DoipUtils.TYPE_FDO; + } else { + result.type = DoipUtils.TYPE_DO; + } JsonObject content = new JsonObject(); for (Property p : entity.getProperties()) { content.add(p.getName(), new JsonPrimitive(p.getValue().toString())); @@ -314,6 +318,15 @@ public class DoipUtils { return result; } + private boolean isFDO(EntityInterface entity) { + for (Parent p : entity.getParents()) { + if (FDO_RECORD_TYPE.equals(p.getId())) { + return true; + } + } + return false; + } + public DigitalObject appendFilesMetadata(DigitalObject d_o, EntityInterface entityInterface) throws FileNotFoundException, DoipException { FileProperties fileProperties = entityInterface.getFileProperties(); diff --git a/src/main/java/org/caosdb/server/jobs/core/RegisterPID.java b/src/main/java/org/caosdb/server/jobs/core/RegisterPID.java index 096d25ab267c0f3bc8dd69e81383c205345fa206..d750963c56c6363e31ce5605ae805cafae76dafc 100644 --- a/src/main/java/org/caosdb/server/jobs/core/RegisterPID.java +++ b/src/main/java/org/caosdb/server/jobs/core/RegisterPID.java @@ -6,13 +6,17 @@ import java.io.IOException; import java.util.ArrayList; import net.handle.api.HSAdapter; import net.handle.api.HSAdapterFactory; -import net.handle.hdllib.*; +import net.handle.hdllib.Common; +import net.handle.hdllib.HandleException; +import net.handle.hdllib.HandleValue; +import net.handle.hdllib.Util; import org.caosdb.server.CaosDBServer; import org.caosdb.server.ServerProperties; import org.caosdb.server.doa.DoipUtils; import org.caosdb.server.entity.EntityInterface; import org.caosdb.server.entity.InsertEntity; import org.caosdb.server.entity.Message; +import org.caosdb.server.entity.UpdateEntity; import org.caosdb.server.entity.wrapper.Parent; import org.caosdb.server.entity.wrapper.Property; import org.caosdb.server.jobs.EntityJob; @@ -20,7 +24,7 @@ import org.caosdb.server.jobs.JobAnnotation; import org.caosdb.server.jobs.TransactionStage; import org.caosdb.server.utils.ServerMessages; -@JobAnnotation(stage = TransactionStage.PRE_TRANSACTION) +@JobAnnotation(stage = TransactionStage.POST_TRANSACTION) public class RegisterPID extends EntityJob { private static String serviceId = @@ -54,7 +58,8 @@ public class RegisterPID extends EntityJob { @Override protected void run() throws Message { - if (getEntity().hasId() && getEntity() instanceof InsertEntity) { + if (getEntity().hasId() + && (getEntity() instanceof InsertEntity || getEntity() instanceof UpdateEntity)) { try { HSAdapter adapter = HSAdapterFactory.newInstance(ADMIN_HANDLE, 300, ADMIN_KEY, null); @@ -64,31 +69,22 @@ public class RegisterPID extends EntityJob { ArrayList<HandleValue> valuesPrep = new ArrayList<HandleValue>(); valuesPrep.add(admin_value); valuesPrep.add(url); - InsertEntity ent = (InsertEntity) getEntity(); - Integer hdlCounter = 2; boolean hasProfile = false; - for (Property p : ent.getProperties()) { + for (Property p : getEntity().getProperties()) { switch (p.getName()) { case DoipUtils.FDO_MD_REF: - valuesPrep.add( - new HandleValue(hdlCounter, DoipUtils.FDO_MD_REF, p.getValue().toString())); - hdlCounter += 1; + valuesPrep.add(new HandleValue(5, DoipUtils.FDO_MD_REF, p.getValue().toString())); break; case DoipUtils.FDO_DATA_REF: - valuesPrep.add( - new HandleValue(hdlCounter, DoipUtils.FDO_DATA_REF, p.getValue().toString())); - hdlCounter += 1; + valuesPrep.add(new HandleValue(4, DoipUtils.FDO_DATA_REF, p.getValue().toString())); break; case DoipUtils.FDO_TYPE_REF: - valuesPrep.add( - new HandleValue(hdlCounter, DoipUtils.FDO_TYPE_REF, p.getValue().toString())); - hdlCounter += 1; + valuesPrep.add(new HandleValue(3, DoipUtils.FDO_TYPE_REF, p.getValue().toString())); break; case DoipUtils.FDO_PROFILE_REF: hasProfile = true; valuesPrep.add( - new HandleValue(hdlCounter, DoipUtils.FDO_PROFILE_REF, p.getValue().toString())); - hdlCounter += 1; + new HandleValue(2, DoipUtils.FDO_PROFILE_REF, p.getValue().toString())); break; case DoipUtils.TYPE_URL: valuesPrep.set( @@ -102,7 +98,7 @@ public class RegisterPID extends EntityJob { } } boolean isFDO = false; - for (Parent p : ent.getParents()) { + for (Parent p : getEntity().getParents()) { if (p.getId().equals(DoipUtils.FDO_RECORD_TYPE)) { isFDO = true; } @@ -110,25 +106,28 @@ public class RegisterPID extends EntityJob { if (isFDO && !hasProfile) { valuesPrep.add( - new HandleValue( - hdlCounter, DoipUtils.FDO_PROFILE_REF, Util.encodeString(DoipUtils.FDO_KIP))); - hdlCounter += 1; + new HandleValue(2, DoipUtils.FDO_PROFILE_REF, Util.encodeString(DoipUtils.FDO_KIP))); } - if (isFDO) { - Property status = getStatus(ent); - if (status != null) { - valuesPrep.add( - new HandleValue(hdlCounter, DoipUtils.FDO_STATUS, status.getValue().toString())); - hdlCounter += 1; - } + Property status = getStatus(getEntity()); + if (status != null) { + valuesPrep.add(new HandleValue(6, DoipUtils.FDO_STATUS, status.getValue().toString())); } valuesPrep.add( - new HandleValue(hdlCounter, DoipUtils.TYPE_DOIP_SERVICE, Util.encodeString(serviceId))); - hdlCounter += 1; + adapter.createHandleValue(7, "EntityVersionId", getEntity().getVersion().getId())); + + valuesPrep.add( + new HandleValue(8, DoipUtils.TYPE_DOIP_SERVICE, Util.encodeString(serviceId))); HandleValue[] values = new HandleValue[valuesPrep.size()]; values = valuesPrep.toArray(values); - adapter.createHandle(getEntity().getId().toString(), values); + if (getEntity() instanceof InsertEntity) { + adapter.createHandle(getEntity().getId().toString(), values); + } else if (getEntity() instanceof UpdateEntity) { + HandleValue[] old = + adapter.resolveHandle(getEntity().getId().toString(), null, null, true); + adapter.deleteHandleValues(getEntity().getId().toString(), old); + adapter.addHandleValues(getEntity().getId().toString(), values); + } } catch (HandleException e) { e.printStackTrace(); getEntity().addError(ServerMessages.COULD_NOT_REGISTER_HANDLE); @@ -152,8 +151,8 @@ public class RegisterPID extends EntityJob { return Util.encodeString(sb.toString()); } - private Property getStatus(InsertEntity ent) { - Property status = ent.getProperties().getEntityById(DoipUtils.FDO_STATUS_PROPERTY); + private Property getStatus(EntityInterface entity) { + Property status = entity.getProperties().getEntityById(DoipUtils.FDO_STATUS_PROPERTY); return status; } }