Skip to content

Commit

Permalink
Update the merge save
Browse files Browse the repository at this point in the history
  • Loading branch information
vvalerio-priv committed Jan 9, 2024
1 parent 55e6bb7 commit 742c21c
Show file tree
Hide file tree
Showing 14 changed files with 992 additions and 777 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/epos/handler/dbapi/DBAPIClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ public <T extends EPOSDataModelEntity> void update(EPOSDataModelEntity instance,
if (transactionModeAuto) startTransaction();

if (query.hardUpdate) {
//dbapi.hardUpdate(instance.getInstanceId(), (T) instance, em);
dbapi.save((T)instance, em);
dbapi.hardUpdate(instance.getInstanceId(), (T) instance, em);
//dbapi.save((T)instance, em);
}

if (query.state != null){
dbapi.save((T)instance, em);
//dbapi.updateStatus(instance.getInstanceId(), query.state, em);
//dbapi.save((T)instance, em);
dbapi.updateStatus(instance.getInstanceId(), query.state, em);
}

if (transactionModeAuto) closeTransaction(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.epos.handler.dbapi.dbapiimplementation;

import org.epos.eposdatamodel.DataProduct;
import org.epos.eposdatamodel.EPOSDataModelEntity;
import org.epos.eposdatamodel.LinkedEntity;
import org.epos.eposdatamodel.State;
Expand Down Expand Up @@ -323,5 +324,4 @@ public List<T> getAllByState(State state) {
em.close();
return list;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ public ContactPointDBAPI() {
}

@Override
public void hardUpdate(String instanceId, ContactPoint eposDataModelObject, EntityManager em) {
EDMContactpoint edmObject = getOneFromDB(em, EDMContactpoint.class,
"contactpoint.findByInstanceId",
"INSTANCEID", instanceId);
if(edmObject.getInstanceId().equals(eposDataModelObject.getInstanceId())) {
generateEntity(edmObject, eposDataModelObject, em,instanceId,true);
em.merge(edmObject);
}
}

@Override
public LinkedEntity save(ContactPoint eposDataModelObject, EntityManager em, String edmInstanceId) {

if (eposDataModelObject.getState().equals(State.PUBLISHED)
Expand All @@ -34,8 +45,9 @@ && isAlreadyPublished(EDMContactpoint.class, "contactpoint.findByUidAndState", e

//search for a existing instance placeholder to be populated
EDMContactpoint edmObject = getOneFromDB(em, EDMContactpoint.class,
"contactpoint.findByUid",
"UID", eposDataModelObject.getUid());
"contactpoint.findByUidAndState",
"UID", eposDataModelObject.getUid(),
"STATE", State.PLACEHOLDER.toString());

//if there's a placeholder for the entity check if is passed a specific metaid
//only if the metaid is the same of the placeholder merge the two (the placeholder and the passed entity)
Expand All @@ -46,7 +58,6 @@ && isAlreadyPublished(EDMContactpoint.class, "contactpoint.findByUidAndState", e
(eposDataModelObject.getMetaId() == null || (eposDataModelObject.getMetaId() != null && eposDataModelObject.getMetaId().equals(edmObject.getMetaId())))) {
//em.merge(edmObject);
merged = true;
edmInstanceId = eposDataModelObject.getInstanceId();

} else {
edmObject = new EDMContactpoint();
Expand Down Expand Up @@ -74,7 +85,17 @@ && isAlreadyPublished(EDMContactpoint.class, "contactpoint.findByUidAndState", e

edmObject.setUid(eposDataModelObject.getUid());

if (Objects.nonNull(eposDataModelObject.getGroups())){
generateEntity(edmObject, eposDataModelObject, em,edmInstanceId,merged);

return new LinkedEntity().entityType(entityString)
.instanceId(edmInstanceId)
.metaId(edmObject.getEdmEntityIdByMetaId().getMetaId())
.uid(edmObject.getUid());
}


private void generateEntity(EDMContactpoint edmObject, ContactPoint eposDataModelObject, EntityManager em, String instanceId, boolean merged) {
if (Objects.nonNull(eposDataModelObject.getGroups())){
for (Group group : eposDataModelObject.getGroups()){

EDMGroup edmGroup = getOneFromDB(em, EDMGroup.class, "group.findById",
Expand Down Expand Up @@ -233,13 +254,8 @@ && isAlreadyPublished(EDMContactpoint.class, "contactpoint.findByUidAndState", e
edmObject.setEdmEntityIdByMetaOrganizationId(edmMetaOrganization);
}


return new LinkedEntity().entityType(entityString)
.instanceId(edmInstanceId)
.metaId(edmObject.getEdmEntityIdByMetaId().getMetaId())
.uid(edmObject.getUid());
}


}

@Override
protected ContactPoint mapFromDB(Object edmObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ public class DataProductDBAPI extends AbstractDBAPI<DataProduct> {
public DataProductDBAPI() {
super("dataproduct", EDMDataproduct.class);
}

@Override
public void hardUpdate(String instanceId, DataProduct eposDataModelObject, EntityManager em) {
EDMDataproduct edmObject = getOneFromDB(em, EDMDataproduct.class,
"dataproduct.findByInstanceId",
"INSTANCEID", instanceId);
if(edmObject.getInstanceId().equals(eposDataModelObject.getInstanceId())) {
generateEntity(edmObject, eposDataModelObject, em,instanceId,true);
em.merge(edmObject);
}
}

@Override
public LinkedEntity save(DataProduct eposDataModelObject, EntityManager em, String edmInstanceId) {
Expand All @@ -27,8 +38,9 @@ && isAlreadyPublished(EDMDataproduct.class, "dataproduct.findByUidAndState", em,

//search for a existing instance placeholder to be populated
EDMDataproduct edmObject = getOneFromDB(em, EDMDataproduct.class,
"dataproduct.findByUid",
"UID", eposDataModelObject.getUid());
"dataproduct.findByUidAndState",
"UID", eposDataModelObject.getUid(),
"STATE", State.PLACEHOLDER.toString());

//if there's a placeholder for the entity check if is passed a specific metaid
//only if the metaid is the same of the placeholder merge the two (the placeholder and the passed entity)
Expand All @@ -39,7 +51,6 @@ && isAlreadyPublished(EDMDataproduct.class, "dataproduct.findByUidAndState", em,
if (edmObject != null &&
(eposDataModelObject.getMetaId() == null || (eposDataModelObject.getMetaId() != null && eposDataModelObject.getMetaId().equals(edmObject.getMetaId())))) {
merged = true;
edmInstanceId = eposDataModelObject.getInstanceId();
//em.merge(edmObject);
} else {
edmObject = new EDMDataproduct();
Expand All @@ -66,6 +77,17 @@ && isAlreadyPublished(EDMDataproduct.class, "dataproduct.findByUidAndState", em,

}
edmObject.setUid(eposDataModelObject.getUid());

generateEntity(edmObject, eposDataModelObject, em,edmInstanceId,merged);

return new LinkedEntity().entityType(entityString)
.instanceId(edmInstanceId)
.metaId(edmObject.getEdmEntityIdByMetaId().getMetaId())
.uid(eposDataModelObject.getUid());

}

protected EDMDataproduct generateEntity(EDMDataproduct edmObject, DataProduct eposDataModelObject, EntityManager em, String edmInstanceId, boolean merged) {

if (Objects.nonNull(eposDataModelObject.getGroups())){
for (Group group : eposDataModelObject.getGroups()){
Expand Down Expand Up @@ -478,11 +500,7 @@ && isAlreadyPublished(EDMDataproduct.class, "dataproduct.findByUidAndState", em,
edmObject.setDocumentation(eposDataModelObject.getDocumentation());
edmObject.setQualityassurance(eposDataModelObject.getQualityAssurance());
edmObject.setHasQualityAnnotation(eposDataModelObject.getHasQualityAnnotation());

return new LinkedEntity().entityType(entityString)
.instanceId(edmInstanceId)
.metaId(edmObject.getEdmEntityIdByMetaId().getMetaId())
.uid(eposDataModelObject.getUid());
return edmObject;

}

Expand Down
Loading

0 comments on commit 742c21c

Please sign in to comment.