use of org.alfresco.service.namespace.NamespaceService in project acs-community-packaging by Alfresco.
the class BaseInviteUsersWizard method getEmailTemplates.
/**
* @return Returns the list of email templates for user notification
*/
public List<SelectItem> getEmailTemplates() {
List<SelectItem> wrappers = null;
try {
FacesContext fc = FacesContext.getCurrentInstance();
NodeRef rootNodeRef = this.getNodeService().getRootNode(Repository.getStoreRef());
NamespaceService resolver = Repository.getServiceRegistry(fc).getNamespaceService();
List<NodeRef> results = this.getSearchService().selectNodes(rootNodeRef, getEmailTemplateXPath(), null, resolver, false);
wrappers = new ArrayList<SelectItem>(results.size() + 1);
if (results.size() != 0) {
DictionaryService dd = Repository.getServiceRegistry(fc).getDictionaryService();
for (NodeRef ref : results) {
if (this.getNodeService().exists(ref) == true) {
Node childNode = new Node(ref);
if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT)) {
wrappers.add(new SelectItem(childNode.getId(), childNode.getName()));
}
}
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(wrappers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
} catch (AccessDeniedException accessErr) {
// ignore the result if we cannot access the root
}
// add an entry (at the start) to instruct the user to select an item
if (wrappers == null) {
wrappers = new ArrayList<SelectItem>(1);
}
wrappers.add(0, new SelectItem("none", Application.getMessage(FacesContext.getCurrentInstance(), "select_a_template")));
return wrappers;
}
use of org.alfresco.service.namespace.NamespaceService in project acs-community-packaging by Alfresco.
the class SearchContext method toXML.
/**
* @return this SearchContext as XML
*
* Example:
* <code>
* <?xml version="1.0" encoding="UTF-8"?>
* <search>
* <text>CDATA</text>
* <mode>int</mode>
* <location>XPath</location>
* <categories>
* <category>XPath</category>
* </categories>
* <content-type>String</content-type>
* <folder-type>String</folder-type>
* <mimetype>String</mimetype>
* <attributes>
* <attribute name="String">String</attribute>
* </attributes>
* <ranges>
* <range name="String">
* <lower>String</lower>
* <upper>String</upper>
* <inclusive>boolean</inclusive>
* </range>
* </ranges>
* <fixed-values>
* <value name="String">String</value>
* </fixed-values>
* <query>CDATA</query>
* </search>
* </code>
*/
public String toXML() {
try {
NamespaceService ns = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNamespaceService();
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement(ELEMENT_SEARCH);
root.addElement(ELEMENT_TEXT).addCDATA(this.text);
root.addElement(ELEMENT_MODE).addText(Integer.toString(this.mode));
if (this.location != null) {
root.addElement(ELEMENT_LOCATION).addText(this.location);
}
Element categories = root.addElement(ELEMENT_CATEGORIES);
for (String path : this.categories) {
categories.addElement(ELEMENT_CATEGORY).addText(path);
}
if (this.contentType != null) {
root.addElement(ELEMENT_CONTENT_TYPE).addText(this.contentType);
}
if (this.folderType != null) {
root.addElement(ELEMENT_FOLDER_TYPE).addText(this.folderType);
}
if (this.mimeType != null && this.mimeType.length() != 0) {
root.addElement(ELEMENT_MIMETYPE).addText(this.mimeType);
}
Element attributes = root.addElement(ELEMENT_ATTRIBUTES);
for (QName attrName : this.queryAttributes.keySet()) {
attributes.addElement(ELEMENT_ATTRIBUTE).addAttribute(ELEMENT_NAME, attrName.toPrefixString(ns)).addCDATA(this.queryAttributes.get(attrName));
}
Element ranges = root.addElement(ELEMENT_RANGES);
for (QName rangeName : this.rangeAttributes.keySet()) {
RangeProperties rangeProps = this.rangeAttributes.get(rangeName);
Element range = ranges.addElement(ELEMENT_RANGE);
range.addAttribute(ELEMENT_NAME, rangeName.toPrefixString(ns));
range.addElement(ELEMENT_LOWER).addText(rangeProps.lower);
range.addElement(ELEMENT_UPPER).addText(rangeProps.upper);
range.addElement(ELEMENT_INCLUSIVE).addText(Boolean.toString(rangeProps.inclusive));
}
Element values = root.addElement(ELEMENT_FIXED_VALUES);
for (QName valueName : this.queryFixedValues.keySet()) {
values.addElement(ELEMENT_VALUE).addAttribute(ELEMENT_NAME, valueName.toPrefixString(ns)).addCDATA(this.queryFixedValues.get(valueName));
}
// outputing the full lucene query may be useful for some situations
Element query = root.addElement(ELEMENT_QUERY);
String queryString = buildQuery(0);
if (queryString != null) {
query.addCDATA(queryString);
}
StringWriter out = new StringWriter(1024);
XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint());
writer.setWriter(out);
writer.write(doc);
return out.toString();
} catch (Throwable err) {
throw new AlfrescoRuntimeException("Failed to export SearchContext to XML.", err);
}
}
use of org.alfresco.service.namespace.NamespaceService in project acs-community-packaging by Alfresco.
the class User method getUserPreferencesRef.
/**
* Get or create the node used to store user preferences.
* Utilises the 'configurable' aspect on the Person linked to this user.
*/
synchronized NodeRef getUserPreferencesRef(WebApplicationContext context) {
final ServiceRegistry registry = (ServiceRegistry) context.getBean("ServiceRegistry");
final NodeService nodeService = registry.getNodeService();
final SearchService searchService = registry.getSearchService();
final NamespaceService namespaceService = registry.getNamespaceService();
final TransactionService txService = registry.getTransactionService();
final ConfigurableService configurableService = (ConfigurableService) context.getBean("ConfigurableService");
RetryingTransactionHelper txnHelper = registry.getTransactionService().getRetryingTransactionHelper();
return txnHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>() {
public NodeRef execute() throws Throwable {
NodeRef prefRef = null;
NodeRef person = getPerson();
if (nodeService.hasAspect(person, ApplicationModel.ASPECT_CONFIGURABLE) == false) {
// if the repository is in read-only mode just return null
if (txService.isReadOnly()) {
return null;
} else {
// create the configuration folder for this Person node
configurableService.makeConfigurable(person);
}
}
// target of the assoc is the configurations folder ref
NodeRef configRef = configurableService.getConfigurationFolder(person);
if (configRef == null) {
throw new IllegalStateException("Unable to find associated 'configurations' folder for node: " + person);
}
String xpath = NamespaceService.APP_MODEL_PREFIX + ":" + "preferences";
List<NodeRef> nodes = searchService.selectNodes(configRef, xpath, null, namespaceService, false);
if (nodes.size() == 1) {
prefRef = nodes.get(0);
} else {
// create the preferences Node for this user (if repo is not read-only)
if (txService.isReadOnly() == false) {
ChildAssociationRef childRef = nodeService.createNode(configRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "preferences"), ContentModel.TYPE_CMOBJECT);
prefRef = childRef.getChildRef();
}
}
return prefRef;
}
}, txService.isReadOnly());
}
use of org.alfresco.service.namespace.NamespaceService in project alfresco-remote-api by Alfresco.
the class WebDAVonContentUpdateTest method setUp.
@Before
public void setUp() throws Exception {
searchService = ctx.getBean("SearchService", SearchService.class);
fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
nodeService = ctx.getBean("NodeService", NodeService.class);
transactionService = ctx.getBean("transactionService", TransactionService.class);
webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
lockService = ctx.getBean("LockService", LockService.class);
policyComponent = ctx.getBean("policyComponent", PolicyComponent.class);
namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
companyHomeNodeRef = repositoryHelper.getCompanyHome();
InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
InputStream davLockInfoIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_XML);
testDataFile = IOUtils.toByteArray(testDataIS);
davLockInfoFile = IOUtils.toByteArray(davLockInfoIS);
testDataIS.close();
davLockInfoIS.close();
txn = transactionService.getUserTransaction();
txn.begin();
}
use of org.alfresco.service.namespace.NamespaceService in project alfresco-remote-api by Alfresco.
the class TestEnterpriseAtomPubTCK method setup.
@Before
public void setup() throws Exception {
JettyComponent jetty = getTestFixture().getJettyComponent();
final SearchService searchService = (SearchService) jetty.getApplicationContext().getBean("searchService");
;
final NodeService nodeService = (NodeService) jetty.getApplicationContext().getBean("nodeService");
final FileFolderService fileFolderService = (FileFolderService) jetty.getApplicationContext().getBean("fileFolderService");
final NamespaceService namespaceService = (NamespaceService) jetty.getApplicationContext().getBean("namespaceService");
final TransactionService transactionService = (TransactionService) jetty.getApplicationContext().getBean("transactionService");
final String name = "abc" + System.currentTimeMillis();
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
Repository repositoryHelper = (Repository) jetty.getApplicationContext().getBean("repositoryHelper");
NodeRef companyHome = repositoryHelper.getCompanyHome();
fileFolderService.create(companyHome, name, ContentModel.TYPE_FOLDER).getNodeRef();
return null;
}
}, false, true);
int port = jetty.getPort();
Map<String, String> cmisParameters = new HashMap<String, String>();
cmisParameters.put(TestParameters.DEFAULT_RELATIONSHIP_TYPE, "R:cm:replaces");
cmisParameters.put(TestParameters.DEFAULT_TEST_FOLDER_PARENT, "/" + name);
clientContext = new OpenCMISClientContext(BindingType.ATOMPUB, MessageFormat.format(CMIS_URL, "localhost", String.valueOf(port), "alfresco"), "admin", "admin", cmisParameters, jetty.getApplicationContext());
overrideVersionableAspectProperties(jetty.getApplicationContext());
}
Aggregations