本文整理汇总了Java中org.apache.sling.api.resource.PersistenceException类的典型用法代码示例。如果您正苦于以下问题:Java PersistenceException类的具体用法?Java PersistenceException怎么用?Java PersistenceException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PersistenceException类属于org.apache.sling.api.resource包,在下文中一共展示了PersistenceException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOrCreate
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
private Resource getOrCreate(String path, Map<String, Object> properties) throws PersistenceException, RepositoryException {
ResourceResolver resolver = client.getResourceResolver();
Resource resource = resolver.getResource(path);
if (properties.containsKey("unit:vanityTarget")) {
resource = resolver.resolve((String) properties.get("unit:vanityTarget"));
} else {
Resource parent = resolver.getResource("/");
PathIterator it = new PathIterator(path);
it.first();
while (it.hasNext()) {
String curPath = it.next();
String segment = StringUtils.substringAfterLast(curPath, "/");
resource = resolver.getResource(curPath);
if (resource == null) {
if (it.hasNext()) {
resource = resolver.create(parent, segment, new HashMap<>());
} else {
resource = resolver.create(parent, segment, properties);
}
}
parent = resource;
}
}
return resource;
}
示例2: getParentResouce
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
/**
* Gets the parent resouce.
* If the parent resource (to hold our entries) does not exist, create it.
*
* @return the parent resouce
*/
private Resource getParentResouce() {
Resource parentResource = resourceResolver.getResource(UPTIME_CALENDAR_PATH);
if(parentResource == null) {
Resource publicResource = resourceResolver.getResource("/etc/pugranch/public");
Map<String,Object> properties = new HashMap<String,Object>();
properties.put(JcrConstants.JCR_PRIMARYTYPE, "sling:OrderedFolder");
try {
parentResource = resourceResolver.create(publicResource, "uptimeCalendar", properties);
resourceResolver.commit();
} catch (PersistenceException e) {
e.printStackTrace();
}
}
return parentResource;
}
示例3: ImportSummaryModel
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
@Inject
public ImportSummaryModel(SlingHttpServletRequest request, @OSGiService ScriptManager scriptManager,
@OSGiService JobResultsCache jobResultsCache, @OSGiService ScriptFinder scriptFinder)
throws RepositoryException, PersistenceException {
ResourceResolver resolver = request.getResourceResolver();
this.mode = request.getParameter(MODE_PARAMETER) != null ?
Mode.valueOf(request.getParameter(MODE_PARAMETER)) :
null;
final String scriptPath = request.getParameter(FILE_PARAMETER);
final String progressJobId = request.getParameter(JOB_ID_PARAMETER);
this.script = scriptFinder.find(scriptPath, resolver);
Progress progress;
if (StringUtils.isNotBlank(progressJobId)) {
progress = jobResultsCache.get(progressJobId);
if (progress == null) {
progress = new ProgressImpl(resolver.getUserID());
}
} else {
progress = scriptManager.process(script, mode, resolver);
}
this.progressLogger = progress;
}
示例4: process
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
@Override
public JobResult process(final Job job) {
LOG.info("Script runner job consumer started");
final String id = job.getId();
final Mode mode = getMode(job);
final String userId = getUserId(job);
return SlingHelper.resolveDefault(resolverFactory, userId, new ResolveCallback<JobResult>() {
@Override
public JobResult resolve(ResourceResolver resolver) {
JobResult result = JobResult.FAILED;
final Script script = getScript(job, resolver);
if (script != null && mode != null) {
try {
final Progress progressLogger = scriptManager.process(script, mode, resolver);
jobResultsCache.put(id, progressLogger);
result = JobResult.OK;
} catch (RepositoryException | PersistenceException e) {
LOG.error("Script manager failed to process script", e);
result = JobResult.FAILED;
}
}
return result;
}
}, JobResult.FAILED);
}
示例5: process
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
private void process(final Script script, final Mode mode, final boolean success,
ResourceResolver resolver) throws PersistenceException {
final ModifiableScript modifiableScript = new ModifiableScriptWrapper(resolver, script);
if (Arrays.asList(Mode.RUN, Mode.AUTOMATIC_RUN).contains(mode)) {
modifiableScript.setExecuted(true);
}
if (Arrays.asList(Mode.DRY_RUN, Mode.RUN, Mode.AUTOMATIC_RUN).contains(mode)) {
modifiableScript.setDryRunStatus(success);
}
if (mode.equals(Mode.VALIDATION)) {
modifiableScript.setValid(success);
}
}
示例6: evaluate
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
@Override
public Progress evaluate(String scriptContent, Mode mode, Map<String, String> customDefinitions,
ResourceResolver resolver) throws RepositoryException, PersistenceException {
Script script = scriptFinder.find(ScriptManager.FILE_FOR_EVALUATION, false, resolver);
if (script != null) {
scriptStorage.remove(script, resolver);
}
InputStream stream = new ByteArrayInputStream(scriptContent.getBytes(StandardCharsets.UTF_8));
script = scriptStorage.save(FILE_FOR_EVALUATION, stream, true, resolver);
Progress progress = process(script, mode, customDefinitions, resolver);
scriptStorage.remove(script, resolver);
return progress;
}
示例7: updateLikeCounter
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
private void updateLikeCounter(SlingHttpServletRequest request) throws PersistenceException {
ValueMap props = request.getResource().getValueMap();
// check if a user with this ip address has already liked this
String ipAddress = request.getRemoteAddr();
String[] likedAddresses = props.get("likedAddresses", new String[0]);
if (ArrayUtils.contains(likedAddresses, ipAddress)) {
return;
}
// increment like counter and store ip address
ValueMap writeProps = request.getResource().adaptTo(ModifiableValueMap.class);
writeProps.put("likes", writeProps.get("likes", 0L) + 1);
List<String> updatedLikedAddresses = new ArrayList<>(Arrays.asList(likedAddresses));
updatedLikedAddresses.add(ipAddress);
writeProps.put("likedAddresses", updatedLikedAddresses.toArray());
// save to repository
request.getResourceResolver().commit();
}
示例8: isSpam
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
/**
* Check comment against Akismet servers.
*
* Be aware that this method returns whether the submission is spam or not.
* A false response means that the submission was successful and that the
* comment is not spam. This behavior is inline with Akismet's behavior.
*
* @param commentResource The publick:comment resource to act upon.
* @return true if comment is spam, false if comment is valid.
*/
public boolean isSpam(final Resource commentResource) {
final boolean result = doAkismet(AkismetAction.CHECK_COMMENT, commentResource);
if (result) {
try {
final ModifiableValueMap properties = commentResource.adaptTo(ModifiableValueMap.class);
properties.put(PublickConstants.COMMENT_PROPERTY_SPAM, true);
commentResource.getResourceResolver().commit();
} catch (PersistenceException e) {
LOGGER.error("Could not save spam properties", e);
}
}
return result;
}
示例9: submitSpam
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
/**
* Submit comment as spam to the Akismet servers.
*
* If a comment gets checked and incorrectly is reported as ham, this will
* submit it back to the servers as spam to help make the world a better
* place.
*
* @param commentResource The publick:comment resource to act upon.
* @return true if submission was successful.
*/
public boolean submitSpam(final Resource commentResource) {
final boolean result = doAkismet(AkismetAction.SUBMIT_SPAM, commentResource);
if (result) {
try {
final ModifiableValueMap properties = commentResource.adaptTo(ModifiableValueMap.class);
properties.put(PublickConstants.COMMENT_PROPERTY_SPAM, true);
properties.put(PublickConstants.COMMENT_PROPERTY_DISPLAY, false);
commentResource.getResourceResolver().commit();
} catch (PersistenceException e) {
LOGGER.error("Could not save spam properties", e);
}
}
return result;
}
示例10: submitHam
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
/**
* Submit comment as ham to the Akismet servers.
*
* If a comment gets checked and incorrectly is reported as spam, this will
* submit it back to the servers as ham to correct a false positive.
*
* @param commentResource The publick:comment resource to act upon.
* @return true if submission was successful.
*/
public boolean submitHam(final Resource commentResource) {
final boolean result = doAkismet(AkismetAction.SUBMIT_HAM, commentResource);
if (result) {
try {
final ModifiableValueMap properties = commentResource.adaptTo(ModifiableValueMap.class);
properties.put(PublickConstants.COMMENT_PROPERTY_SPAM, false);
properties.put(PublickConstants.COMMENT_PROPERTY_DISPLAY, true);
commentResource.getResourceResolver().commit();
} catch (PersistenceException e) {
LOGGER.error("Could not save spam properties", e);
}
}
return result;
}
示例11: setReplicationStatus
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public final void setReplicationStatus(final ResourceResolver resourceResolver,
final String replicatedBy,
final Calendar replicatedAt,
final Status status,
final String... paths) throws RepositoryException, PersistenceException {
for (final String path : paths) {
final Resource resource = resourceResolver.getResource(path);
if (resource == null) {
log.warn("Requesting a replication status update for a resource that does not exist: {}", path);
continue;
}
this.setReplicationStatus(resourceResolver, replicatedBy, replicatedAt, status, resource);
}
}
示例12: recordErrors
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
private void recordErrors(int step, List<Failure> failures, ResourceResolver rr) {
if (failures.isEmpty()) {
return;
}
failures.stream().map(ArchivedProcessFailure::adapt).collect(Collectors.toCollection(infoBean::getReportedErrors));
try {
String errFolder = getPath() + "/jcr:content/failures/step" + (step + 1);
JcrUtil.createPath(errFolder, "nt:unstructured", rr.adaptTo(Session.class));
if (rr.hasChanges()) {
rr.commit();
rr.refresh();
}
for (int i = 0; i < failures.size(); i++) {
String errPath = errFolder + "/err" + i;
Map<String, Object> values = new HashMap<>();
ValueMapSerializer.serializeToMap(values, failures.get(i));
ResourceUtil.getOrCreateResource(rr, errPath, values, null, false);
}
rr.commit();
} catch (RepositoryException | PersistenceException ex) {
LOG.error("Unable to record errors", ex);
}
}
示例13: start
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
@Override
public final void start(Config config) throws PersistenceException {
Workspace workspace = config.getWorkspace();
workspace.getRunner().start(workspace);
Runnable job = workspace.getRunner().getRunnable(config);
ScheduleOptions options = workspace.getRunner().getOptions(config);
if (options != null) {
scheduler.schedule(job, options);
} else {
job.run();
}
workspace.commit();
}
示例14: complete
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
public void complete(ResourceResolver resourceResolver, String workspacePath, ActionManager manager, int success) throws PersistenceException, RepositoryException {
Workspace workspace = resourceResolver.getResource(workspacePath).adaptTo(Workspace.class);
workspace.setCompleteCount(success);
for (com.adobe.acs.commons.fam.Failure f : manager.getFailureList()) {
workspace.addFailure(f.getNodePath(), null, f.getTime());
workspace.incrementFailCount();
}
super.complete(workspace);
manager.closeAllResolvers();
if (actionManagerFactoryRef != null) {
actionManagerFactoryRef.purgeCompletedTasks();
} else {
log.warn("Action Manager Factory reference is null. Please purge completed tasks via the JMX console.");
}
}
示例15: purge
import org.apache.sling.api.resource.PersistenceException; //导入依赖的package包/类
private void purge(Payload payload) throws PersistenceException, WorkflowException {
Workflow workflow = payload.getWorkflow();
if (workflow != null) {
ResourceResolver resourceResolver = payload.getResourceResolver();
final Resource resource = resourceResolver.getResource(workflow.getId());
if (resource != null) {
try {
String path = resource.getPath();
resource.adaptTo(Node.class).remove();
log.info("Purging working instance [ {} ]", path);
} catch (RepositoryException e) {
throw new PersistenceException("Unable to purge workflow instance node.", e);
}
} else {
log.warn("Could not find workflow instance at [ {} ] to purge.", workflow.getId());
}
}
}