use of org.apache.sling.api.resource.PersistenceException in project acs-aem-commons by Adobe-Consulting-Services.
the class OnDeployExecutorImpl method getOrCreateStatusTrackingResource.
protected Resource getOrCreateStatusTrackingResource(ResourceResolver resourceResolver, Class<?> scriptClass) {
String scriptClassName = scriptClass.getName();
Resource resource = resourceResolver.getResource(SCRIPT_STATUS_JCR_FOLDER + "/" + scriptClassName);
if (resource == null) {
Resource folder = resourceResolver.getResource(SCRIPT_STATUS_JCR_FOLDER);
try {
resource = resourceResolver.create(folder, scriptClassName, Collections.singletonMap(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED));
} catch (PersistenceException re) {
logger.error("On-deploy script cannot be run because the system could not find or create the script status node: {}/{}", SCRIPT_STATUS_JCR_FOLDER, scriptClassName);
throw new OnDeployEarlyTerminationException(re);
}
}
return resource;
}
use of org.apache.sling.api.resource.PersistenceException in project acs-aem-commons by Adobe-Consulting-Services.
the class AssetFolderCreator method createAssetFolder.
/**
* Creates an Asset Folder.
*
* @param assetFolderDefinition the asset folder definition to create.
* @param resourceResolver the resource resolver object used to create the asset folder.
* @throws PersistenceException
* @throws RepositoryException
*/
protected void createAssetFolder(final AssetFolderDefinition assetFolderDefinition, final ResourceResolver resourceResolver) {
ReportRowStatus status;
Resource folder = resourceResolver.getResource(assetFolderDefinition.getPath());
try {
if (folder == null) {
final Map<String, Object> folderProperties = new HashMap<>();
folderProperties.put(JcrConstants.JCR_PRIMARYTYPE, assetFolderDefinition.getNodeType());
folder = resourceResolver.create(resourceResolver.getResource(assetFolderDefinition.getParentPath()), assetFolderDefinition.getName(), folderProperties);
status = ReportRowStatus.CREATED;
} else {
status = ReportRowStatus.UPDATED_FOLDER_TITLES;
}
final Resource jcrContent = folder.getChild(JcrConstants.JCR_CONTENT);
if (jcrContent == null) {
final Map<String, Object> jcrContentProperties = new HashMap<>();
jcrContentProperties.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
resourceResolver.create(folder, JcrConstants.JCR_CONTENT, jcrContentProperties);
}
setTitles(folder, assetFolderDefinition);
record(status, assetFolderDefinition.getPath(), assetFolderDefinition.getTitle());
log.debug("Created Asset Folder [ {} -> {} ]", assetFolderDefinition.getPath(), assetFolderDefinition.getTitle());
} catch (Exception e) {
record(ReportRowStatus.FAILED_TO_CREATE, assetFolderDefinition.getPath(), assetFolderDefinition.getTitle());
log.error("Unable to create Asset Folder [ {} -> {} ]", new String[] { assetFolderDefinition.getPath(), assetFolderDefinition.getTitle() }, e);
}
}
use of org.apache.sling.api.resource.PersistenceException in project acs-aem-commons by Adobe-Consulting-Services.
the class BulkWorkflowEngineImpl method deactivate.
@Deactivate
protected final void deactivate(final Map<String, String> args) {
ResourceResolver adminResourceResolver = null;
try {
adminResourceResolver = resourceResolverFactory.getServiceResourceResolver(AUTH_INFO);
final Resource root = adminResourceResolver.getResource(BULK_WORKFLOW_MANAGER_PAGE_FOLDER_PATH);
if (root == null) {
return;
}
final ConfigResourceVisitor visitor = new ConfigResourceVisitor();
visitor.accept(root);
final List<Resource> configs = visitor.getConfigs();
for (Resource config : configs) {
ModifiableValueMap properties = config.getChild(Workspace.NN_WORKSPACE).adaptTo(ModifiableValueMap.class);
if (StringUtils.equals(Status.RUNNING.name(), properties.get(Workspace.PN_STATUS, String.class))) {
properties.put(Workspace.PN_STATUS, Status.STOPPED.name());
properties.put(Workspace.PN_SUB_STATUS, SubStatus.DEACTIVATED.name());
}
}
if (root.getResourceResolver().hasChanges()) {
root.getResourceResolver().commit();
}
} catch (LoginException e) {
log.error("Could not obtain resource resolver for finding stopped Bulk Workflow jobs", e);
} catch (PersistenceException e) {
log.error("Could not resume bulk workflow manager configuration", e);
} finally {
if (adminResourceResolver != null) {
adminResourceResolver.close();
}
}
}
use of org.apache.sling.api.resource.PersistenceException in project acs-aem-commons by Adobe-Consulting-Services.
the class Payload method updateWith.
public void updateWith(Workflow workflow) throws PersistenceException {
if (StringUtils.isBlank(getWorkflowInstanceId())) {
workflowInstanceId = workflow.getId();
properties.put(PN_WORKFLOW_INSTANCE_ID, dereference(workflowInstanceId));
} else if (!StringUtils.equals(getWorkflowInstanceId(), workflow.getId())) {
throw new PersistenceException("Batch Entry workflow instance does not match. [ " + workflowInstanceId + " ] vs [ " + workflow.getId() + " ]");
}
if (!StringUtils.equals(status, workflow.getState())) {
// Status is different, so update
setStatus(EnumUtils.getEnum(Status.class, workflow.getState()));
}
}
use of org.apache.sling.api.resource.PersistenceException in project sling by apache.
the class OakDiscoveryService method doUpdateProperties.
/**
* Update the properties by inquiring the PropertyProvider's current values.
* <p>
* This method is invoked regularly by the heartbeatHandler.
* The properties are stored in the repository under Config.getClusterInstancesPath()
* and announced in the topology.
* <p>
* @see Config#getClusterInstancesPath()
*/
private void doUpdateProperties() {
// SLING-5382 : the caller must ensure that this method
// is not invoked after deactivation or before activation.
// so this method doesn't have to do any further synchronization.
// what we do nevertheless is a paranoia way of checking if
// all variables are available and do a NOOP if that's not the case.
final ResourceResolverFactory rrf = resourceResolverFactory;
final Config c = config;
final String sid = slingId;
if (rrf == null || c == null || sid == null) {
// cannot update the properties then..
logger.debug("doUpdateProperties: too early to update the properties. " + "resourceResolverFactory ({}), config ({}) or slingId ({}) not yet set.", new Object[] { rrf, c, sid });
return;
} else {
logger.debug("doUpdateProperties: updating properties now..");
}
final Map<String, String> newProps = new HashMap<String, String>();
for (final ProviderInfo info : this.providerInfos) {
info.refreshProperties();
newProps.putAll(info.properties);
}
ResourceResolver resourceResolver = null;
try {
resourceResolver = rrf.getServiceResourceResolver(null);
Resource myInstance = ResourceHelper.getOrCreateResource(resourceResolver, c.getClusterInstancesPath() + "/" + sid + "/properties");
// SLING-2879 - revert/refresh resourceResolver here to work
// around a potential issue with jackrabbit in a clustered environment
resourceResolver.revert();
resourceResolver.refresh();
final ModifiableValueMap myInstanceMap = myInstance.adaptTo(ModifiableValueMap.class);
final Set<String> keys = new HashSet<String>(myInstanceMap.keySet());
for (final String key : keys) {
if (newProps.containsKey(key)) {
// perfect
continue;
} else if (key.indexOf(":") != -1) {
// ignore
continue;
} else {
// remove
myInstanceMap.remove(key);
}
}
boolean anyChanges = false;
for (final Entry<String, String> entry : newProps.entrySet()) {
Object existingValue = myInstanceMap.get(entry.getKey());
if (entry.getValue().equals(existingValue)) {
// SLING-3389: dont rewrite the properties if nothing changed!
if (logger.isDebugEnabled()) {
logger.debug("doUpdateProperties: unchanged: {}={}", entry.getKey(), entry.getValue());
}
continue;
}
if (logger.isDebugEnabled()) {
logger.debug("doUpdateProperties: changed: {}={}", entry.getKey(), entry.getValue());
}
anyChanges = true;
myInstanceMap.put(entry.getKey(), entry.getValue());
}
if (anyChanges) {
resourceResolver.commit();
}
} catch (LoginException e) {
logger.error("handleEvent: could not log in administratively: " + e, e);
throw new RuntimeException("Could not log in to repository (" + e + ")", e);
} catch (PersistenceException e) {
logger.error("handleEvent: got a PersistenceException: " + e, e);
throw new RuntimeException("Exception while talking to repository (" + e + ")", e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
logger.debug("doUpdateProperties: updating properties done.");
}
Aggregations