use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.
the class DictionaryGet method executeImpl.
/**
* Execute the webscript
*
* @param req WebScriptRequest
* @param status Status
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
List<QName> qnames = new ArrayList<QName>(256);
Set<String> namespaces = new HashSet<String>();
Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
// check configured list of model namespaces to ignore when retrieving all models
for (String ns : this.namespaceService.getURIs()) {
if (!ignoreNamespaces.contains(ns)) {
namespaces.add(ns);
}
}
// specific model qname provided or will process all available models
String strModel = req.getParameter("model");
if (strModel != null && strModel.length() != 0) {
// handle full QName and prefixed shortname of a model
QName modelQName = (strModel.charAt(0) == QName.NAMESPACE_BEGIN ? QName.createQName(strModel) : QName.createQName(strModel, this.namespaceService));
ModelDefinition modelDef = this.dictionaryservice.getModel(modelQName);
if (modelDef != null) {
qnames.addAll(this.dictionaryservice.getAspects(modelQName));
qnames.addAll(this.dictionaryservice.getTypes(modelQName));
}
} else {
// walk all models and extract the aspects and types
for (QName qname : this.dictionaryservice.getAllModels()) {
if (namespaces.contains(qname.getNamespaceURI())) {
qnames.addAll(this.dictionaryservice.getAspects(qname));
qnames.addAll(this.dictionaryservice.getTypes(qname));
}
}
}
// get the class definitions and the properties and associations
for (QName qname : qnames) {
ClassDefinition classDef = this.dictionaryservice.getClass(qname);
classdef.put(qname, classDef);
propdef.put(qname, classDef.getProperties().values());
assocdef.put(qname, classDef.getAssociations().values());
}
Map<String, Object> model = new HashMap<String, Object>();
model.put(MODEL_CLASS_DEFS, classdef.values());
model.put(MODEL_PROPERTY_DEFS, propdef.values());
model.put(MODEL_ASSOCIATION_DEFS, assocdef.values());
model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, this.dictionaryservice);
return model;
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.
the class ProcessesImpl method create.
@Override
public ProcessInfo create(ProcessInfo process) {
if (process == null) {
throw new InvalidArgumentException("post body expected when starting a new process instance");
}
boolean definitionExistingChecked = false;
RuntimeService runtimeService = activitiProcessEngine.getRuntimeService();
String processDefinitionId = null;
if (process.getProcessDefinitionId() != null) {
processDefinitionId = process.getProcessDefinitionId();
} else if (process.getProcessDefinitionKey() != null) {
ProcessDefinition definition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(getProcessDefinitionKey(process.getProcessDefinitionKey())).latestVersion().singleResult();
if (definition == null) {
throw new InvalidArgumentException("No workflow definition could be found with key '" + process.getProcessDefinitionKey() + "'.");
}
processDefinitionId = definition.getId();
definitionExistingChecked = true;
} else {
throw new InvalidArgumentException("Either processDefinitionId or processDefinitionKey is required");
}
if (definitionExistingChecked == false) {
// Check if the required definition actually exists
ProcessDefinitionQuery query = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionId(processDefinitionId);
if (tenantService.isEnabled() && deployWorkflowsInTenant) {
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
}
if (query.count() == 0) {
throw new InvalidArgumentException("No workflow definition could be found with id '" + processDefinitionId + "'.");
}
}
Map<QName, Serializable> startParams = new HashMap<QName, Serializable>();
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processDefinitionId);
if (startFormData != null) {
if (CollectionUtils.isEmpty(process.getVariables()) == false) {
TypeDefinition startTaskType = getWorkflowFactory().getTaskFullTypeDefinition(startFormData.getFormKey(), true);
// Lookup type definition for the startTask
Map<QName, PropertyDefinition> taskProperties = startTaskType.getProperties();
Map<String, QName> propNameMap = new HashMap<String, QName>();
for (QName key : taskProperties.keySet()) {
propNameMap.put(key.getPrefixString().replace(':', '_'), key);
}
Map<QName, AssociationDefinition> taskAssociations = startTaskType.getAssociations();
for (QName key : taskAssociations.keySet()) {
propNameMap.put(key.getPrefixString().replace(':', '_'), key);
}
for (String variableName : process.getVariables().keySet()) {
if (propNameMap.containsKey(variableName)) {
Object variableValue = process.getVariables().get(variableName);
if (taskAssociations.containsKey(propNameMap.get(variableName))) {
AssociationDefinition associationDef = taskAssociations.get(propNameMap.get(variableName));
variableValue = convertAssociationDefinitionValue(associationDef, variableName, variableValue);
} else if (taskProperties.containsKey(propNameMap.get(variableName))) {
PropertyDefinition propDef = taskProperties.get(propNameMap.get(variableName));
DataTypeDefinition propDataType = propDef.getDataType();
if ("java.util.Date".equalsIgnoreCase(propDataType.getJavaClassName())) {
// fix for different ISO 8601 Date format classes in Alfresco (org.alfresco.util and Spring Surf)
variableValue = ISO8601DateFormat.parse((String) variableValue);
}
}
if (variableValue instanceof Serializable) {
startParams.put(propNameMap.get(variableName), (Serializable) variableValue);
}
}
}
}
}
String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser();
Authentication.setAuthenticatedUserId(currentUserName);
NodeRef workflowPackageNodeRef = null;
try {
workflowPackageNodeRef = workflowPackageComponent.createPackage(null);
startParams.put(WorkflowModel.ASSOC_PACKAGE, workflowPackageNodeRef);
} catch (Exception e) {
throw new ApiException("couldn't create workflow package: " + e.getMessage(), e);
}
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(process.getItems())) {
try {
for (String item : process.getItems()) {
NodeRef itemNodeRef = getNodeRef(item);
QName workflowPackageItemId = QName.createQName("wpi", itemNodeRef.toString());
nodeService.addChild(workflowPackageNodeRef, itemNodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, workflowPackageItemId);
}
} catch (Exception e) {
throw new ApiException("Error while adding items to package: " + e.getMessage(), e);
}
}
// Set start task properties. This should be done before instance is started, since it's id will be used
Map<String, Object> variables = getPropertyConverter().getStartVariables(processDefinitionId, startParams);
variables.put(WorkflowConstants.PROP_CANCELLED, Boolean.FALSE);
// Add company home
Object companyHome = getNodeConverter().convertNode(repositoryHelper.getCompanyHome());
variables.put(WorkflowConstants.PROP_COMPANY_HOME, companyHome);
// Add the initiator
NodeRef initiator = getPersonNodeRef(currentUserName);
if (initiator != null) {
variables.put(WorkflowConstants.PROP_INITIATOR, nodeConverter.convertNode(initiator));
// Also add the initiator home reference, if one exists
NodeRef initiatorHome = (NodeRef) nodeService.getProperty(initiator, ContentModel.PROP_HOMEFOLDER);
if (initiatorHome != null) {
variables.put(WorkflowConstants.PROP_INITIATOR_HOME, nodeConverter.convertNode(initiatorHome));
}
}
if (tenantService.isEnabled()) {
// Specify which tenant domain the workflow was started in.
variables.put(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
}
// Start the process-instance
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId, process.getBusinessKey(), variables);
if (processInstance.isEnded() == false) {
runtimeService.setVariable(processInstance.getProcessInstanceId(), ActivitiConstants.PROP_START_TASK_END_DATE, new Date());
}
HistoricProcessInstance historicProcessInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
return createProcessInfo(historicProcessInstance);
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.
the class WorkflowRestImpl method getFormModelElements.
/**
* @param type the type to get the elements for
* @param paging Paging
* @return collection with all valid form-model elements for the given type.
*/
public CollectionWithPagingInfo<FormModelElement> getFormModelElements(TypeDefinition type, Paging paging) {
Map<QName, PropertyDefinition> taskProperties = type.getProperties();
Set<QName> typesToExclude = getTypesToExclude(type);
List<FormModelElement> page = new ArrayList<FormModelElement>();
for (Entry<QName, PropertyDefinition> entry : taskProperties.entrySet()) {
String name = entry.getKey().toPrefixString(namespaceService).replace(':', '_');
// Only add properties which are not part of an excluded type
if (!typesToExclude.contains(entry.getValue().getContainerClass().getName()) && excludeModelTypes.contains(name) == false) {
FormModelElement element = new FormModelElement();
element.setName(name);
element.setQualifiedName(entry.getKey().toString());
element.setTitle(entry.getValue().getTitle(dictionaryService));
element.setRequired(entry.getValue().isMandatory());
element.setDataType(entry.getValue().getDataType().getName().toPrefixString(namespaceService));
element.setDefaultValue(entry.getValue().getDefaultValue());
if (entry.getValue().getConstraints() != null) {
for (ConstraintDefinition constraintDef : entry.getValue().getConstraints()) {
Constraint constraint = constraintDef.getConstraint();
if (constraint != null && constraint instanceof ListOfValuesConstraint) {
ListOfValuesConstraint valuesConstraint = (ListOfValuesConstraint) constraint;
if (valuesConstraint.getAllowedValues() != null && valuesConstraint.getAllowedValues().size() > 0) {
element.setAllowedValues(valuesConstraint.getAllowedValues());
}
}
}
}
page.add(element);
}
}
Map<QName, AssociationDefinition> taskAssociations = type.getAssociations();
for (Entry<QName, AssociationDefinition> entry : taskAssociations.entrySet()) {
// Only add associations which are not part of an excluded type
if (!typesToExclude.contains(entry.getValue().getSourceClass().getName())) {
FormModelElement element = new FormModelElement();
element.setName(entry.getKey().toPrefixString(namespaceService).replace(':', '_'));
element.setQualifiedName(entry.getKey().toString());
element.setTitle(entry.getValue().getTitle(dictionaryService));
element.setRequired(entry.getValue().isTargetMandatory());
element.setDataType(entry.getValue().getTargetClass().getName().toPrefixString(namespaceService));
page.add(element);
}
}
return CollectionWithPagingInfo.asPaged(paging, page, false, page.size());
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method setCustomPropertyDefinitionLabel.
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#setCustomPropertyDefinitionLabel(org.alfresco.service.namespace.QName, java.lang.String)
*/
public QName setCustomPropertyDefinitionLabel(QName propQName, String newLabel) {
mandatory("propQName", propQName);
PropertyDefinition propDefn = getDictionaryService().getProperty(propQName);
if (propDefn == null) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQName));
}
if (newLabel == null) {
return propQName;
}
NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
M2Model deserializedModel = readCustomContentModel(modelRef);
M2Property targetProperty = findProperty(propQName, deserializedModel);
targetProperty.setTitle(newLabel);
writeCustomContentModel(modelRef, deserializedModel);
if (logger.isInfoEnabled()) {
logger.info("setCustomPropertyDefinitionLabel: " + propQName + "=" + newLabel);
}
return propQName;
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project records-management by Alfresco.
the class DispositionPropertiesGet method executeImpl.
/*
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
boolean recordLevel = false;
String recordLevelValue = req.getParameter("recordlevel");
if (recordLevelValue != null) {
recordLevel = Boolean.valueOf(recordLevelValue);
}
String dispositionAction = req.getParameter("dispositionaction");
Collection<DispositionProperty> dispositionProperties = dispositionService.getDispositionProperties(recordLevel, dispositionAction);
List<Map<String, String>> items = new ArrayList<Map<String, String>>(dispositionProperties.size());
for (DispositionProperty dispositionProperty : dispositionProperties) {
PropertyDefinition propDef = dispositionProperty.getPropertyDefinition();
QName propName = dispositionProperty.getQName();
if (propDef != null) {
Map<String, String> item = new HashMap<String, String>(2);
String propTitle = propDef.getTitle(dictionaryService);
if (propTitle == null || propTitle.length() == 0) {
propTitle = StringUtils.capitalize(propName.getLocalName());
}
item.put("label", propTitle);
item.put("value", propName.toPrefixString(this.namespaceService));
items.add(item);
}
}
// create model object with the lists model
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("properties", items);
return model;
}
Aggregations