DocumentModel eventDocModel = docEventContext.getSourceDocument();
String eventType = event.getName();
boolean isAboutToBeRemovedEvent = eventType.equals(DocumentEventTypes.ABOUT_TO_REMOVE);
-
+
//
// Ensure this event relates to a relationship record (between cataloging and movement records) or a movement record. If so, get the CSID
// of the corresponding movement record. Otherwise, exit.
private static final Logger logger = LoggerFactory.getLogger(UpdateObjectLocationAndCrateOnMove.class);
// FIXME: Get values below from external constants
- private final static String COLLECTIONOBJECTS_ANTHROPOLOGY_SCHEMA = "collectionobjects_anthropology";
- private final static String MOVEMENTS_ANTHROPOLOGY_SCHEMA = "movements_anthropology";
- private final static String CRATE_PROPERTY = "crate";
+ private final static String TENANT_COLLECTIONOBJECTS_SCHEMANAME_KEY = "TENANT_COLLECTIONOBJECTS_SCHEMANAME_KEY"; // For this listener, this is the key value to find the Nuxeo document schema name for the CollectionObject document from the tenant binding's parameter list.
private final static String COMPUTED_CRATE_PROPERTY = "computedCrate";
+ private final static String TENANT_MOVEMENTS_SCHEMANAME_KEY = "TENANT_MOVEMENTS_SCHEMANAME_KEY"; // For this listener, this is the key value to find the Nuxeo document schema name for the Movement document from the tenant binding's parameter list.
+ private final static String CRATE_PROPERTY = "crate";
@Override
protected boolean updateCollectionObjectLocation(DocumentModel collectionObjectDocModel,
private DocumentModel updateComputedCrateValue(DocumentModel collectionObjectDocModel,
DocumentModel movementDocModel)
throws ClientException {
-
+
// Get the current crate value from the Movement (the "new" value)
- String crateRefName =
- (String) movementDocModel.getProperty(MOVEMENTS_ANTHROPOLOGY_SCHEMA, CRATE_PROPERTY);
+ String crateRefName = (String) movementDocModel.getProperty(getParamValue(TENANT_MOVEMENTS_SCHEMANAME_KEY),
+ CRATE_PROPERTY);
// Check that the value returned, which is expected to be a
// reference (refName) to an authority term:
}
// Get the computed crate value of the CollectionObject
// (the "existing" value)
- String existingCrateRefName =
- (String) collectionObjectDocModel.getProperty(COLLECTIONOBJECTS_ANTHROPOLOGY_SCHEMA,
+ String existingCrateRefName = (String) collectionObjectDocModel.getProperty(getParamValue(TENANT_COLLECTIONOBJECTS_SCHEMANAME_KEY),
COMPUTED_CRATE_PROPERTY);
if (logger.isTraceEnabled()) {
logger.trace("Existing crate refName=" + existingCrateRefName);
// If the new value is blank, any non-blank existing value should always
// be overwritten ('nulled out') with a blank value.
if (Tools.isBlank(crateRefName) && Tools.notBlank(existingCrateRefName)) {
- collectionObjectDocModel.setProperty(COLLECTIONOBJECTS_ANTHROPOLOGY_SCHEMA,
+ collectionObjectDocModel.setProperty(TENANT_COLLECTIONOBJECTS_SCHEMANAME_KEY,
COMPUTED_CRATE_PROPERTY, (Serializable) null);
// Otherwise, if the new value is not blank, and
// * the existing value is blank, or
}
// ... update the existing value in the CollectionObject with the
// new value from the Movement.
- collectionObjectDocModel.setProperty(COLLECTIONOBJECTS_ANTHROPOLOGY_SCHEMA,
+ collectionObjectDocModel.setProperty(TENANT_COLLECTIONOBJECTS_SCHEMANAME_KEY,
COMPUTED_CRATE_PROPERTY, crateRefName);
} else {
if (logger.isTraceEnabled()) {
<event>aboutToRemove</event>
</listener>
</extension>
+
+ <extension target="org.nuxeo.ecm.core.event.EventServiceComponent" point="listener">
+ <listener name="updateobjectlocationonandcrateonmovelistener" async="true" postCommit="true"
+ class="org.collectionspace.services.listener.UpdateObjectLocationAndCrateOnMove">
+ <event>documentCreated</event>
+ <event>documentModified</event>
+ <event>lifecycle_transition_event</event>
+ <event>aboutToRemove</event>
+ </listener>
+ </extension>
</component>
"AND (ecm:currentLifeCycleState <> 'deleted') "
+ NONVERSIONED_NONPROXY_DOCUMENT_WHERE_CLAUSE_FRAGMENT;
static final String DOCMODEL_CONTEXT_PROPERTY_PREFIX = ScopeType.DEFAULT.getScopePrefix();
+ private String currentRepositoryName;
public AbstractCSEventListenerImpl() {
// Intentionally left blank
return result;
}
+
+ @Override
+ public void setCurrentRepository(Event event) {
+ currentRepositoryName = event.getContext().getRepositoryName();
+ }
+
+ @Override
+ public String getCurrentRepository() {
+ return currentRepositoryName;
+ }
/*
* This method is meant to be the bottleneck for handling a Nuxeo document event.
try {
if (isRegistered && shouldHandleEvent(event)) {
+ setCurrentRepository(event);
handleCSEvent(event);
getLogger().debug(String.format("Eventlistener '%s' accepted '%s' event.",
getClass().getName(), event.getName()));
return result;
}
- protected void setName(String repositoryName, String eventListenerName) {
- nameMap.put(repositoryName, eventListenerName);
- }
-
@Override
public Map<String, String> getParams(Event event) {
Map<String, String> result = null;
}
return result;
}
+
+ @Override
+ public String getParamValue(String key) {
+ String result = null;
+
+
+ Map<String, Map<String, Map<String, String>>> allTenantallListenerParamMaps = getEventListenerParamsMap();
+ if (allTenantallListenerParamMaps != null && !allTenantallListenerParamMaps.isEmpty()) {
+ Map<String, Map<String, String>> allListenersParamsMap = allTenantallListenerParamMaps.get(getCurrentRepository());
+ if (allListenersParamsMap != null && !allListenersParamsMap.isEmpty()) {
+ Map<String, String> paramsMap = allListenersParamsMap.get(getName(getCurrentRepository()));
+ if (paramsMap != null && !paramsMap.isEmpty()) {
+ result = paramsMap.get(key);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public void setName(String repositoryName, String eventListenerName) {
+ nameMap.put(repositoryName + "." + this.getClass().getSimpleName(), eventListenerName);
+ }
@Override
public String getName(String repositoryName) {
- return nameMap.get(repositoryName);
+ return nameMap.get(repositoryName + "." + this.getClass().getSimpleName());
}
//
* Returns the name of the event listener as defined during registration -see register() method.
* @return
*/
- String getName(String repositoryName);
+ String getName(String repositoryName);
+
+ /*
+ * Used to set the name of the current repository at setup to event handling
+ */
+ void setCurrentRepository(Event event);
+
+ /*
+ * Returns the name of the event's current repository -see method setCurrentRepository()
+ */
+ String getCurrentRepository();
+
+ /**
+ * Returns a parameter value for the given key for the given repository/tenant
+ * @param key
+ * @return
+ */
+ String getParamValue(String key);
+
+ /**
+ * For a given repository/tenant, set the name of the listener as defined in the tenant bindings.
+ *
+ * @param repositoryName
+ * @param eventListenerName
+ */
+ void setName(String repositoryName, String eventListenerName);
}