use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class CustomEmailMappingServiceImpl method saveConfig.
/**
* @param customMappingsToSave
*/
private void saveConfig(Set<CustomMapping> customMappingsToSave) {
if (!nodeService.exists(CONFIG_NODE_REF)) {
// create the config node
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(2);
properties.put(ContentModel.PROP_NAME, CONFIG_NAME);
properties.put(ContentModel.PROP_NODE_UUID, CONFIG_NODE_REF.getId());
nodeService.createNode(CONFIG_FOLDER_NODE_REF, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, CONFIG_NAME), ContentModel.TYPE_CONTENT, properties);
}
// build JSON array of mappings
JSONArray jsonMappings = new JSONArray();
try {
for (CustomMapping mapping : customMappingsToSave) {
JSONObject obj = new JSONObject();
obj.put("from", mapping.getFrom());
obj.put("to", mapping.getTo());
jsonMappings.put(obj);
}
} catch (JSONException je) {
throw new AlfrescoRuntimeException("Unable to create JSON email mapping configuration during save.", je);
}
// update the content
ContentWriter writer = this.contentService.getWriter(CONFIG_NODE_REF, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(jsonMappings.toString());
}
use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class HoldServiceImpl method removeFromHolds.
/**
* @see org.alfresco.module.org_alfresco_module_rm.hold.HoldService#removeFromHolds(java.util.List, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public void removeFromHolds(List<NodeRef> holds, final NodeRef nodeRef) {
ParameterCheck.mandatory("holds", holds);
ParameterCheck.mandatory("nodeRef", nodeRef);
if (holds != null && !holds.isEmpty()) {
for (final NodeRef hold : holds) {
if (!instanceOf(hold, TYPE_HOLD)) {
throw new AlfrescoRuntimeException("Can't remove from hold, because it isn't a hold. (hold=" + hold + ")");
}
if (getHeld(hold).contains(nodeRef)) {
// run as system so we don't run into further permission issues
// we already know we have to have the correct capability to get here
authenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() {
// remove from hold
nodeService.removeChild(hold, nodeRef);
// audit that the node has been remove from the hold
// TODO add details of the hold that the node was removed from
recordsManagementAuditService.auditEvent(nodeRef, AUDIT_REMOVE_FROM_HOLD);
return null;
}
});
}
}
// run as system as we can't be sure if have remove aspect rights on node
authenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() {
removeFreezeAspect(nodeRef, 0);
return null;
}
});
}
}
use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class HoldServiceImpl method getHold.
/**
* @see org.alfresco.module.org_alfresco_module_rm.hold.HoldService#getHold(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
*/
@Override
public NodeRef getHold(NodeRef filePlan, String name) {
ParameterCheck.mandatory("filePlan", filePlan);
ParameterCheck.mandatory("name", name);
// get the root hold container
NodeRef holdContainer = filePlanService.getHoldContainer(filePlan);
// get the hold by name
NodeRef hold = nodeService.getChildByName(holdContainer, ContentModel.ASSOC_CONTAINS, name);
if (hold != null && !isHold(hold)) {
throw new AlfrescoRuntimeException("Can not get hold, because the named node reference isn't a hold.");
}
return hold;
}
use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class RecordsManagementAdminBase method writeCustomContentModel.
/**
* Updates the content of the custom model
*
* @param modelRef The node reference of the model
* @param deserializedModel The deserialized model
*/
protected void writeCustomContentModel(NodeRef modelRef, M2Model deserializedModel) {
ContentWriter writer = getContentService().getWriter(modelRef, ContentModel.TYPE_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_XML);
writer.setEncoding("UTF-8");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
deserializedModel.toXML(baos);
String updatedModelXml;
try {
updatedModelXml = baos.toString("UTF-8");
writer.putContent(updatedModelXml);
// putContent closes all resources.
// so we don't have to.
} catch (UnsupportedEncodingException uex) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_ERROR_WRITE_CUSTOM_MODEL, modelRef.toString()), uex);
}
}
use of org.alfresco.error.AlfrescoRuntimeException in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method removeCustomPropertyDefinition.
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#removeCustomPropertyDefinition(org.alfresco.service.namespace.QName)
*/
public void removeCustomPropertyDefinition(QName propQName) {
mandatory("propQName", propQName);
NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
M2Model deserializedModel = readCustomContentModel(modelRef);
String propQNameAsString = propQName.toPrefixString(getNamespaceService());
String aspectName = null;
boolean found = false;
// attempt to delete the property definition.
for (QName customisableType : getCustomisable()) {
aspectName = getCustomAspect(customisableType).toPrefixString(getNamespaceService());
M2Aspect customPropsAspect = deserializedModel.getAspect(aspectName);
if (customPropsAspect == null) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNKNOWN_ASPECT, aspectName));
}
M2Property prop = customPropsAspect.getProperty(propQNameAsString);
if (prop != null) {
if (logger.isDebugEnabled()) {
StringBuilder msg = new StringBuilder();
msg.append("Attempting to delete custom property: ");
msg.append(propQNameAsString);
logger.debug(msg.toString());
}
found = true;
customPropsAspect.removeProperty(propQNameAsString);
break;
}
}
if (!found) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQNameAsString));
}
writeCustomContentModel(modelRef, deserializedModel);
if (logger.isInfoEnabled()) {
logger.info("deleteCustomPropertyDefinition: " + propQNameAsString + " from aspect: " + aspectName);
}
}
Aggregations