use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class CreateUserWizard method setPersonPropertiesAndCreateHomeSpaceIfNeeded.
protected void setPersonPropertiesAndCreateHomeSpaceIfNeeded(Map<QName, Serializable> props, NodeRef oldHomeFolderRef, FacesContext context) {
props.put(ContentModel.PROP_USERNAME, this.userName);
props.put(ContentModel.PROP_FIRSTNAME, this.firstName);
props.put(ContentModel.PROP_LASTNAME, this.lastName);
NodeRef homeSpaceNodeRef;
if (this.homeSpaceLocation != null && this.homeSpaceName.length() != 0) {
// create new
props.put(ContentModel.PROP_HOME_FOLDER_PROVIDER, "userHomesHomeFolderProvider");
homeSpaceNodeRef = createHomeSpace(this.homeSpaceLocation.getId(), this.homeSpaceName, oldHomeFolderRef, true);
} else if (this.homeSpaceLocation != null) {
// set to existing - first ensure it is NOT "User Homes" space!
if (this.defaultHomeSpaceRef.equals(this.homeSpaceLocation)) {
throw new AlfrescoRuntimeException(Application.getMessage(context, MSG_ERROR_NEWUSER_HOME_SPACE));
}
// shared folder
props.put(ContentModel.PROP_HOME_FOLDER_PROVIDER, "companyHomeFolderProvider");
homeSpaceNodeRef = this.homeSpaceLocation;
setupHomeSpacePermissions(homeSpaceNodeRef);
} else {
// default to Company Home
// shared folder
props.put(ContentModel.PROP_HOME_FOLDER_PROVIDER, "companyHomeFolderProvider");
homeSpaceNodeRef = getCompanyHomeSpace();
}
props.put(ContentModel.PROP_HOMEFOLDER, homeSpaceNodeRef);
props.put(ContentModel.PROP_EMAIL, this.email);
props.put(ContentModel.PROP_ORGID, this.companyId);
props.put(ContentModel.PROP_ORGANIZATION, this.organisation);
props.put(ContentModel.PROP_JOBTITLE, this.jobtitle);
props.put(ContentModel.PROP_LOCATION, this.location);
props.put(ContentModel.PROP_PRESENCEPROVIDER, this.presenceProvider);
props.put(ContentModel.PROP_PRESENCEUSERNAME, this.presenceUsername);
}
use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class CreateUserWizard method createHomeSpace.
/**
* Create the specified home space if it does not exist, and return the ID
*
* @param locationId Parent location
* @param spaceName Home space to create, can be null to simply return the parent
* @param oldHomeFolderRef the previous home space, for the case where the the user is being updated.
* It may not have changed.
* @param error True to throw an error if the space already exists, else ignore and return
* @return ID of the home space
*/
protected NodeRef createHomeSpace(String locationId, String spaceName, NodeRef oldHomeFolderRef, boolean error) {
NodeRef homeSpaceNodeRef = null;
if (spaceName != null && spaceName.length() != 0) {
NodeRef parentRef = new NodeRef(Repository.getStoreRef(), locationId);
// check for existence of home space with same name - return immediately
// if it exists or throw an exception an give user chance to enter another name
NodeRef childRef = this.getNodeService().getChildByName(parentRef, ContentModel.ASSOC_CONTAINS, spaceName);
if (childRef != null) {
if (childRef.equals(oldHomeFolderRef)) {
return oldHomeFolderRef;
}
if (error) {
throw new AlfrescoRuntimeException("A Home Space with the same name already exists.");
} else {
return childRef;
}
}
// space does not exist already, create a new Space under it with
// the specified name
String qname = QName.createValidLocalName(spaceName);
ChildAssociationRef assocRef = this.getNodeService().createNode(parentRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, qname), ContentModel.TYPE_FOLDER);
NodeRef nodeRef = assocRef.getChildRef();
// set the name property on the node
this.getNodeService().setProperty(nodeRef, ContentModel.PROP_NAME, spaceName);
if (logger.isDebugEnabled())
logger.debug("Created Home Space for with name: " + spaceName);
// apply the uifacets aspect - icon, title and description props
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(3);
uiFacetsProps.put(ApplicationModel.PROP_ICON, CreateSpaceWizard.DEFAULT_SPACE_ICON_NAME);
uiFacetsProps.put(ContentModel.PROP_TITLE, spaceName);
this.getNodeService().addAspect(nodeRef, ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
setupHomeSpacePermissions(nodeRef);
// return the ID of the created space
homeSpaceNodeRef = nodeRef;
}
return homeSpaceNodeRef;
}
use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class NewUserWizard method createHomeSpace.
/**
* Create the specified home space if it does not exist, and return the ID
*
* @param locationId
* Parent location
* @param spaceName
* Home space to create, can be null to simply return the parent
* @param error
* True to throw an error if the space already exists, else
* ignore and return
*
* @return ID of the home space
*/
private NodeRef createHomeSpace(String locationId, String spaceName, boolean error) {
NodeRef homeSpaceNodeRef = null;
if (spaceName != null && spaceName.length() != 0) {
NodeRef parentRef = new NodeRef(Repository.getStoreRef(), locationId);
// check for existance of home space with same name - return immediately
// if it exists or throw an exception an give user chance to enter another name
// TODO: this might be better replaced with an XPath query!
List<ChildAssociationRef> children = this.getNodeService().getChildAssocs(parentRef);
for (ChildAssociationRef ref : children) {
String childNodeName = (String) this.getNodeService().getProperty(ref.getChildRef(), ContentModel.PROP_NAME);
if (spaceName.equals(childNodeName)) {
if (error) {
throw new AlfrescoRuntimeException("A Home Space with the same name already exists.");
} else {
return ref.getChildRef();
}
}
}
// space does not exist already, create a new Space under it with
// the specified name
String qname = QName.createValidLocalName(spaceName);
ChildAssociationRef assocRef = this.getNodeService().createNode(parentRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, qname), ContentModel.TYPE_FOLDER);
NodeRef nodeRef = assocRef.getChildRef();
// set the name property on the node
this.getNodeService().setProperty(nodeRef, ContentModel.PROP_NAME, spaceName);
if (logger.isDebugEnabled())
logger.debug("Created Home Space for with name: " + spaceName);
// apply the uifacets aspect - icon, title and description props
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(3);
uiFacetsProps.put(ApplicationModel.PROP_ICON, CreateSpaceWizard.DEFAULT_SPACE_ICON_NAME);
uiFacetsProps.put(ContentModel.PROP_TITLE, spaceName);
this.getNodeService().addAspect(nodeRef, ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
setupHomeSpacePermissions(nodeRef);
// return the ID of the created space
homeSpaceNodeRef = nodeRef;
}
return homeSpaceNodeRef;
}
use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class WizardManager method determineCurrentPage.
/**
* Sets up the current page to show in the wizard
*/
protected void determineCurrentPage() {
// reset the current page config in the state object
this.currentWizardState.setCurrentPageCfg(null);
PageConfig currentPageCfg = null;
// get the config for the current step position
StepConfig stepCfg = this.currentWizardState.getSteps().get(this.currentWizardState.getCurrentStep() - 1);
// is the step conditional?
if (stepCfg.hasConditionalPages()) {
FacesContext context = FacesContext.getCurrentInstance();
// test each conditional page in turn
List<ConditionalPageConfig> pages = stepCfg.getConditionalPages();
for (ConditionalPageConfig pageCfg : pages) {
String condition = pageCfg.getCondition();
if (logger.isDebugEnabled())
logger.debug("Evaluating condition: " + condition);
ValueBinding vb = context.getApplication().createValueBinding(condition);
Object obj = vb.getValue(context);
if (obj instanceof Boolean && ((Boolean) obj).booleanValue()) {
currentPageCfg = pageCfg;
break;
}
}
}
// if none of the conditions passed use the default page
if (currentPageCfg == null) {
currentPageCfg = stepCfg.getDefaultPage();
}
if (currentPageCfg == null) {
throw new AlfrescoRuntimeException("Failed to determine page for step '" + stepCfg.getName() + "'. Make sure a default page is configured.");
}
// save the current page config in the state object
this.currentWizardState.setCurrentPageCfg(currentPageCfg);
if (logger.isDebugEnabled())
logger.debug("Config for current page: " + this.currentWizardState.getCurrentPageCfg());
}
use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class Column method toXML.
/**
* Convert this config to an XML definition which can be serialized.
* Example:
* <code>
* <?xml version="1.0"?>
* <dashboard>
* <page id="main" layout-id="narrow-left-2column">
* <column>
* <dashlet idref="clock" />
* <dashlet idref="random-joke" />
* </column>
* <column>
* <dashlet idref="getting-started" />
* <dashlet idref="task-list" />
* <dashlet idref="my-checkedout-docs" />
* <dashlet idref="my-documents" />
* </column>
* </page>
* </dashboard>
* </code>
*
* @return XML for this config
*/
public String toXML() {
try {
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement(ELEMENT_DASHBOARD);
for (Page page : pages) {
Element pageElement = root.addElement(ELEMENT_PAGE);
pageElement.addAttribute(ATTR_ID, page.getId());
pageElement.addAttribute(ATTR_LAYOUTID, page.getLayoutDefinition().Id);
for (Column column : page.getColumns()) {
Element columnElement = pageElement.addElement(ELEMENT_COLUMN);
for (DashletDefinition dashletDef : column.getDashlets()) {
columnElement.addElement(ELEMENT_DASHLET).addAttribute(ATTR_REFID, dashletDef.Id);
}
}
}
StringWriter out = new StringWriter(512);
XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint());
writer.setWriter(out);
writer.write(doc);
return out.toString();
} catch (Throwable err) {
throw new AlfrescoRuntimeException("Unable to serialize Dashboard PageConfig to XML: " + err.getMessage(), err);
}
}
Aggregations