use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class NodeParameterProcessor method process.
/**
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public String process(String value, NodeRef actionedUponNodeRef) {
// the default position is to return the value un-changed
String result = value;
// strip the processor name from the value
value = stripName(value);
if (!value.isEmpty()) {
QName qname = QName.createQName(value, namespaceService);
PropertyDefinition propertyDefinition = dictionaryService.getProperty(qname);
if (propertyDefinition == null) {
throw new AlfrescoRuntimeException("The property " + value + " does not have a property definition.");
}
QName type = propertyDefinition.getDataType().getName();
if (ArrayUtils.contains(supportedDataTypes, type)) {
Serializable propertyValue = nodeService.getProperty(actionedUponNodeRef, qname);
if (propertyValue != null) {
result = propertyValue.toString();
} else {
// set the result to the empty string
result = "";
}
} else {
throw new AlfrescoRuntimeException("The property " + value + " is of type " + type.toString() + " which is not supported by parameter substitution.");
}
}
return result;
}
use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class RMCaveatConfigComponentImpl method convertToJSONString.
/**
* @param config the configuration to convert
* @return a String containing the JSON representation of the configuration.
*/
private String convertToJSONString(SimpleCache<String, Map<String, List<String>>> config) {
JSONObject configJSONObject = new JSONObject();
Collection<String> listNames = config.getKeys();
for (String listName : listNames) {
Map<String, List<String>> members = config.get(listName);
Set<String> authorityNames = members.keySet();
JSONObject listMembers = new JSONObject();
for (String authorityName : authorityNames) {
List<String> authorities = members.get(authorityName);
try {
listMembers.put(authorityName, authorities);
} catch (JSONException error) {
StringBuilder sb = new StringBuilder();
sb.append("Cannot add the key '");
sb.append(authorityName);
sb.append("' with the value '");
sb.append(authorities);
sb.append("' to the JSONObject 'listMembers' '");
sb.append(listMembers);
sb.append("': ");
sb.append(getFullStackTrace(error));
throw new AlfrescoRuntimeException(sb.toString());
}
}
try {
configJSONObject.put(listName, listMembers);
} catch (JSONException error) {
StringBuilder sb = new StringBuilder();
sb.append("Cannot add the key '");
sb.append(listName);
sb.append("' with the value '");
sb.append(listMembers);
sb.append("' to the JSONObject 'configJSONObject' '");
sb.append(configJSONObject);
sb.append("': ");
sb.append(getFullStackTrace(error));
throw new AlfrescoRuntimeException(sb.toString());
}
}
return configJSONObject.toString();
}
use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class RMCaveatConfigComponentImpl method validateAndReset.
/**
* Validate the caveat config and optionally update the cache.
*
* @param nodeRef The nodeRef of the config
* @param updateCache Set to <code>true</code> to update the cache
*/
@SuppressWarnings("unchecked")
protected void validateAndReset(NodeRef nodeRef) {
ContentReader cr = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
if (cr != null) {
// TODO - check who can change caveat config !
// TODO - locking (or checkout/checkin)
String caveatConfigData = cr.getContentString();
if (caveatConfigData != null) {
NodeRef existing = getCaveatConfigNode();
if ((existing != null && (!existing.equals(nodeRef)))) {
throw new AlfrescoRuntimeException("Cannot create more than one caveat config (existing=" + existing + ", new=" + nodeRef + ")");
}
try {
if (logger.isTraceEnabled()) {
logger.trace(caveatConfigData);
}
Set<QName> models = new HashSet<QName>(1);
Set<QName> props = new HashSet<QName>(10);
Set<String> expectedPrefixes = new HashSet<String>(10);
if (caveatModelQNames.size() > 0) {
models.addAll(caveatModelQNames);
} else {
models.addAll(dictionaryService.getAllModels());
}
if (logger.isTraceEnabled()) {
logger.trace("validateAndReset: models to check " + models);
}
for (QName model : models) {
props.addAll(dictionaryService.getProperties(model, DATATYPE_TEXT));
expectedPrefixes.addAll(namespaceService.getPrefixes(model.getNamespaceURI()));
}
if (props.size() == 0) {
logger.warn("validateAndReset: no caveat properties found");
} else {
if (logger.isTraceEnabled()) {
logger.trace("validateAndReset: properties to check " + props);
}
}
Map<String, Object> caveatConfigMap = JSONtoFmModel.convertJSONObjectToMap(caveatConfigData);
for (Map.Entry<String, Object> conEntry : caveatConfigMap.entrySet()) {
String conStr = conEntry.getKey();
QName conQName = QName.resolveToQName(namespaceService, conStr);
// check prefix
String conPrefix = QName.splitPrefixedQName(conStr)[0];
boolean prefixFound = false;
for (String expectedPrefix : expectedPrefixes) {
if (conPrefix.equals(expectedPrefix)) {
prefixFound = true;
}
}
if (!prefixFound) {
throw new AlfrescoRuntimeException("Unexpected prefix: " + conPrefix + " (" + conStr + ") expected one of " + expectedPrefixes + ")");
}
Map<String, List<String>> caveatMap = (Map<String, List<String>>) conEntry.getValue();
List<String> allowedValues = null;
@SuppressWarnings("unused") boolean found = false;
for (QName propertyName : props) {
PropertyDefinition propDef = dictionaryService.getProperty(propertyName);
List<ConstraintDefinition> conDefs = propDef.getConstraints();
for (ConstraintDefinition conDef : conDefs) {
final Constraint con = conDef.getConstraint();
if (con instanceof RMListOfValuesConstraint) {
String conName = ((RMListOfValuesConstraint) con).getShortName();
if (conName.equals(conStr)) {
// note: assumes only one caveat/LOV against a given property
allowedValues = AuthenticationUtil.runAs(new RunAsWork<List<String>>() {
public List<String> doWork() {
return ((RMListOfValuesConstraint) con).getAllowedValues();
}
}, AuthenticationUtil.getSystemUserName());
found = true;
break;
}
}
}
}
if (allowedValues != null) {
if (logger.isInfoEnabled()) {
logger.info("Processing constraint: " + conQName);
}
for (Map.Entry<String, List<String>> caveatEntry : caveatMap.entrySet()) {
String authorityName = caveatEntry.getKey();
List<String> caveatList = caveatEntry.getValue();
// validate authority (user or group) - note: groups are configured with fullname (ie. GROUP_xxx)
if ((!authorityService.authorityExists(authorityName) && !personService.personExists(authorityName))) {
// TODO - review warnings (& I18N)
String msg = "User/group does not exist: " + authorityName + " (constraint=" + conStr + ")";
logger.warn(msg);
}
// validate caveat list
for (String value : caveatList) {
if (!allowedValues.contains(value)) {
// TODO - review warnings (& add I18N)
String msg = "Invalid value in list: " + value + " (authority=" + authorityName + ", constraint=" + conStr + ")";
logger.warn(msg);
}
}
}
}
}
try {
writeLock.lock();
// we can't just clear the cache, as all puts to the cache afterwards in this transaction will be ignored
// first delete all keys that are now not in the config
caveatConfig.getKeys().retainAll(caveatConfigMap.keySet());
for (Map.Entry<String, Object> conEntry : caveatConfigMap.entrySet()) {
String conStr = conEntry.getKey();
Map<String, List<String>> caveatMap = (Map<String, List<String>>) conEntry.getValue();
Map<String, List<String>> cacheValue = caveatConfig.get(conStr);
if (cacheValue == null || !cacheValue.equals(caveatMap)) {
// update the cache
caveatConfig.put(conStr, caveatMap);
}
}
} finally {
writeLock.unlock();
}
} catch (JSONException e) {
throw new AlfrescoRuntimeException("Invalid caveat config syntax: " + e);
}
}
}
}
use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class RecordsManagementNotificationHelper method recordsDueForReviewEmailNotification.
/**
* Sends records due for review email notification.
*
* @param records records due for review
*/
public void recordsDueForReviewEmailNotification(final List<NodeRef> records) {
ParameterCheck.mandatory("records", records);
if (!records.isEmpty()) {
if (nodeService.hasAspect(records.get(0), RecordsManagementModel.ASPECT_RECORD)) {
NodeRef root = getRMRoot(records.get(0));
String groupName = getGroupName(root);
if (doesGroupContainUsers(groupName)) {
NotificationContext notificationContext = new NotificationContext();
notificationContext.setSubject(I18NUtil.getMessage(MSG_SUBJECT_RECORDS_DUE_FOR_REVIEW));
notificationContext.setAsyncNotification(false);
notificationContext.setIgnoreNotificationFailure(true);
notificationContext.setBodyTemplate(getDueForReviewTemplate().toString());
Map<String, Serializable> args = new HashMap<String, Serializable>(1, 1.0f);
args.put("records", (Serializable) records);
args.put("site", getSiteName(root));
notificationContext.setTemplateArgs(args);
notificationContext.addTo(groupName);
notificationService.sendNotification(EMailNotificationProvider.NAME, notificationContext);
} else {
if (logger.isWarnEnabled()) {
logger.warn("Unable to send record due for review email notification, because notification group was empty.");
}
throw new AlfrescoRuntimeException("Unable to send record due for review email notification, because notification group was empty.");
}
}
}
}
use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class RmSiteType method beforeDeleteNode.
/**
* @see org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy#beforeDeleteNode(org.alfresco.service.cmr.repository.NodeRef)
*/
@Behaviour(kind = BehaviourKind.CLASS, notificationFrequency = NotificationFrequency.FIRST_EVENT)
public void beforeDeleteNode(NodeRef nodeRef) {
final SiteInfo siteInfo = siteService.getSite(nodeRef);
if (siteInfo != null) {
// grab the file plan for the RM site
NodeRef filePlan = AuthenticationUtil.runAsSystem(new RunAsWork<NodeRef>() {
@Override
public NodeRef doWork() {
return siteService.getContainer(siteInfo.getShortName(), COMPONENT_DOCUMENT_LIBRARY);
}
});
if (filePlan != null) {
// determine whether the current user has delete capability on the file plan node
AccessStatus accessStatus = capabilityService.getCapabilityAccessState(filePlan, "Delete");
if (AccessStatus.DENIED.equals(accessStatus)) {
throw new AlfrescoRuntimeException("The records management site can not be deleted, because the user doesn't have sufficient privillages to delete the file plan.");
}
// work around for MNT-11038 .. we want to ensure that the RM site can be created once it's been deleted since we only
// allow one short name for the RM site
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() {
// delete the authority
String siteGroup = siteService.getSiteGroup(siteInfo.getShortName());
authorityService.deleteAuthority(siteGroup, true);
return null;
}
});
filePlanType.disable();
}
}
}
Aggregations