Skip to content

Commit

Permalink
#338 createResourceItem() and getResourceOutcome() did not use version
Browse files Browse the repository at this point in the history
  • Loading branch information
kovax committed Feb 27, 2020
1 parent c51ab3b commit 7e29a99
Showing 1 changed file with 10 additions and 6 deletions.
Expand Up @@ -27,6 +27,7 @@
import static org.cristalise.kernel.process.resource.ResourceImportHandler.Status.NEW;
import static org.cristalise.kernel.process.resource.ResourceImportHandler.Status.OVERWRITTEN;
import static org.cristalise.kernel.process.resource.ResourceImportHandler.Status.SKIPPED;
import static org.cristalise.kernel.process.resource.ResourceImportHandler.Status.REMOVED;
import static org.cristalise.kernel.process.resource.ResourceImportHandler.Status.UPDATED;
import static org.cristalise.kernel.property.BuiltInItemProperties.MODULE;
import static org.cristalise.kernel.property.BuiltInItemProperties.NAME;
Expand Down Expand Up @@ -140,7 +141,7 @@ public Outcome getResourceOutcome(String name, String ns, String location, Integ

if (data == null) throw new ObjectNotFoundException("No data found for "+type.getSchemaName()+" "+name);

return new Outcome(0, data, LocalObjectLoader.getSchema(type.getSchemaName(), 0));
return new Outcome(-1, data, LocalObjectLoader.getSchema(type.getSchemaName(), version));
}

@Override
Expand Down Expand Up @@ -214,15 +215,15 @@ private DomainPath verifyResource(String ns, String itemName, int version, ItemP
log.debug("verifyResource() - "+getName()+" "+itemName+" not found. Creating new.");

if (itemPath == null) itemPath = new ItemPath(); //itemPath can be hardcoded in the bootstrap for example
thisProxy = createResourceItem(itemName, ns, itemPath);
thisProxy = createResourceItem(itemName, version, ns, itemPath);
}

// Verify/Import Outcome, creating events and views as necessary
Status status = checkToStoreOutcomeVersion(thisProxy, outcome, version, reset);

log.info("verifyResource() - Outcome {} of item:{} schema:{} version:{} ", status.name(), thisProxy.getName(), outcome.getSchema().getName(), version);

if (status != IDENTICAL && status != SKIPPED) {
if (status == NEW || status == UPDATED || status == OVERWRITTEN) {
// validate it, but not for kernel objects (ns == null) because those are to validate the rest
if (ns != null) outcome.validateAndCheck();

Expand All @@ -237,6 +238,9 @@ private DomainPath verifyResource(String ns, String itemName, int version, ItemP
Gateway.getStorage().put(thisProxy.getPath(), col, null);
}
}
else if (status == REMOVED) {
// TODO implement
}

resourceChangeDetails = convertToResourceChangeDetails(itemName, version, outcome.getSchema(), status);

Expand Down Expand Up @@ -290,7 +294,7 @@ private ItemProxy verifyPathAndModuleProperty(String ns, String itemName, ItemPa
}

/**
*
* TODO implement REMOVED
*/
private Status checkToStoreOutcomeVersion(ItemProxy item, Outcome newOutcome, int version, boolean reset)
throws PersistencyException, InvalidDataException, ObjectNotFoundException
Expand Down Expand Up @@ -326,7 +330,7 @@ private Status checkToStoreOutcomeVersion(ItemProxy item, Outcome newOutcome, in
* @return
* @throws Exception
*/
private ItemProxy createResourceItem(String itemName, String ns, ItemPath itemPath) throws Exception {
private ItemProxy createResourceItem(String itemName, int version, String ns, ItemPath itemPath) throws Exception {
// create props
PropertyDescriptionList pdList = getPropDesc();
PropertyArrayList props = new PropertyArrayList();
Expand All @@ -346,7 +350,7 @@ private ItemProxy createResourceItem(String itemName, String ns, ItemPath itemPa

CompositeActivity ca = new CompositeActivity();
try {
ca = (CompositeActivity) ((CompositeActivityDef)LocalObjectLoader.getActDef(getWorkflowName(), 0)).instantiate();
ca = (CompositeActivity) ((CompositeActivityDef)LocalObjectLoader.getActDef(getWorkflowName(), version)).instantiate();
}
catch (ObjectNotFoundException ex) {
// FIXME check if this could be a real error
Expand Down

0 comments on commit 7e29a99

Please sign in to comment.