data.getDigest(result.getURL(), result.getDigest()),
result.getPriority(),
data.getDataFile(),
null);
final RegisteredResource rr = this.persistentList.addOrUpdate(internalResource);
final TransformationResult transRes = new TransformationResult();
// use the old entity id
final int pos = erl.getResourceId().indexOf(':');
transRes.setId(erl.getResourceId().substring(pos + 1));
transRes.setResourceType(resourceType);
if ( attributes != null ) {
transRes.setAttributes(attributes);
}
this.persistentList.transform(rr, new TransformationResult[] {
transRes
});
final EntityResourceList newGroup = this.persistentList.getEntityResourceList(key);
newGroup.setFinishState(ResourceState.INSTALLED);
newGroup.compact();
} else {
// resource has been updated or moved
((RegisteredResourceImpl)tr).update(
data.getDataFile(), data.getDictionary(),
data.getDigest(result.getURL(), result.getDigest()),
result.getPriority(),
result.getURL());
// We first set the state of the resource to install to make setFinishState work in all cases
((RegisteredResourceImpl)tr).setState(ResourceState.INSTALL);
erl.setFinishState(ResourceState.INSTALLED);
erl.compact();
}
updated = true;
}
} finally {
if ( localIS != null ) {
// always close the input stream!
try {
localIS.close();
} catch (final IOException ignore) {
// ignore
}
}
}
}
}
boolean created = false;
if ( !updated ) {
// create
final List<UpdateHandler> handlerList = this.updateHandlerTracker.getSortedServices();
for(final UpdateHandler handler : handlerList) {
final InputStream localIS = data.getInputStream();
try {
final UpdateResult result = (localIS == null ? handler.handleUpdate(resourceType, entityId, null, data.getDictionary(), attributes)
: handler.handleUpdate(resourceType, entityId, null, localIS, attributes));
if ( result != null ) {
final InternalResource internalResource = new InternalResource(result.getScheme(),
result.getResourceId(),
null,
data.getDictionary(),
(data.getDictionary() != null ? InstallableResource.TYPE_PROPERTIES : InstallableResource.TYPE_FILE),
data.getDigest(result.getURL(), result.getDigest()),
result.getPriority(),
data.getDataFile(),
null);
final RegisteredResource rr = this.persistentList.addOrUpdate(internalResource);
final TransformationResult transRes = new TransformationResult();
transRes.setId(entityId);
transRes.setResourceType(resourceType);
if ( attributes != null ) {
transRes.setAttributes(attributes);
}
this.persistentList.transform(rr, new TransformationResult[] {
transRes
});
final EntityResourceList newGroup = this.persistentList.getEntityResourceList(key);