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

ENH: update PID on update

parent f7044ed5
No related branches found
No related tags found
No related merge requests found
Pipeline #57031 failed
......@@ -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
......
......@@ -305,7 +305,11 @@ public class DoipUtils {
}
DigitalObject result = new DigitalObject();
result.id = entity.getId().toString();
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();
......
......@@ -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);
Property status = getStatus(getEntity());
if (status != null) {
valuesPrep.add(
new HandleValue(hdlCounter, DoipUtils.FDO_STATUS, status.getValue().toString()));
hdlCounter += 1;
}
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);
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment