com.adobe.cq.screens.assignment.AssignmentService Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2017 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
************************************************************************/
package com.adobe.cq.screens.assignment;
import aQute.bnd.annotation.ProviderType;
import com.adobe.cq.screens.binding.ScreensConstants;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Comparator;
import java.util.Iterator;
/**
* Manages the assignments in the repository.
*/
@ProviderType
public interface AssignmentService extends AssignmentResolver {
/**
* Checks whether the specified resource is an assignment.
* @param resource The resource to check
* @return {@code true} if the resource is an assignment, {@code false} otherwise
*/
boolean isAssignment(@Nonnull Resource resource);
/**
* Find the root assignments for the specified resource
* (i.e. the assignments under a display that directly or indirectly point to that resource)
* @param resource The referenced resource
* @return The root assignments that point to this resource
*/
@Nonnull
Iterator findRootAssignmentsForEntity(@Nonnull Resource resource);
/**
* Find the displays that reference the specified resource.
* @param resource The referenced resource
* @return The displays that point to this resource
*/
@Nonnull
Iterator findDisplaysForEntity(@Nonnull Resource resource);
/**
* Gets the parent entity (display or schedule) that contains this assignment.
* @param assignment The assignment to get the parent of
* @return The parent entity for the specified assignment
*/
@Nullable
Resource getParentEntity(@Nonnull Resource assignment);
/**
* Resolves the channel or schedule resource in the context of the given parent resource.
* @param resolver The resource resolver
* @param parent The parent in which to look for the assignment
* @param assignment The assignment resource
* @return The resolved schedule resource, or null
*/
@Deprecated
Resource resolve(@Nonnull ResourceResolver resolver, @Nonnull Resource parent, Resource assignment);
/**
* Returns the role of the channel assignment of the provided channel or schedule assignment.
* @param channel The channel
* @param assignment The assignment
* @return The role, or null
*/
@Nullable
String getRoleForAssignment(@Nonnull Resource channel, @Nonnull Resource assignment);
/**
* Deletes the provided assignment and the associated copied configs.
*
* @param assignment The channel assignment in question
* @throws PersistenceException if there is an error deleting the assignment
*/
void delete(@Nonnull Resource assignment) throws PersistenceException;
/**
* Sorts a list of channel assignments based on priority property.
*/
Comparator CHANNEL_ASSIGNMENT_PRIORITY_COMPARATOR =
new Comparator(){
@Override
public int compare(final Resource r1, Resource r2) {
Long p1 = r1.getValueMap().get(ScreensConstants.PN_PRIORITY, 0L);
Long p2 = r2.getValueMap().get(ScreensConstants.PN_PRIORITY, 0L);
return p2.intValue() - p1.intValue();
}
};
}