Search in sources :

Example 51 with NodeService

use of org.alfresco.service.cmr.repository.NodeService 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());
}
Also used : TransactionService(org.alfresco.service.transaction.TransactionService) HashMap(java.util.HashMap) NodeService(org.alfresco.service.cmr.repository.NodeService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.alfresco.repo.model.Repository) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) JettyComponent(org.alfresco.repo.web.util.JettyComponent) OpenCMISClientContext(org.alfresco.opencmis.OpenCMISClientContext) Before(org.junit.Before)

Example 52 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project alfresco-remote-api by Alfresco.

the class TestPeople method setUp.

@Before
public void setUp() throws Exception {
    people = publicApiClient.people();
    accountsIt = getTestFixture().getNetworksIt();
    account1 = accountsIt.next();
    account2 = accountsIt.next();
    // Networks are very expensive to create, so do this once only and store statically.
    if (account3 == null) {
        account3 = createNetwork("account3");
    }
    if (account4 == null) {
        // Use account 4 only for the sorting and paging tests, so that the data doesn't change between tests.
        account4 = createNetwork("account4");
        account4Admin = "admin@" + account4.getId();
        publicApiClient.setRequestContext(new RequestContext(account4.getId(), account4Admin, "admin"));
        personAlice = new Person();
        personAlice.setUserName("alice@" + account4.getId());
        personAlice.setId("alice@" + account4.getId());
        personAlice.setFirstName("Alice");
        personAlice.setLastName("Smith");
        personAlice.setEmail("alison.smith@example.com");
        personAlice.setPassword("password");
        personAlice.setEnabled(true);
        personAlice.setProperties(Collections.singletonMap("papi:lunch", "Magical sandwich"));
        people.create(personAlice);
        personAliceD = new Person();
        personAliceD.setUserName("aliced@" + account4.getId());
        personAliceD.setId("aliced@" + account4.getId());
        personAliceD.setFirstName("Alice");
        personAliceD.setLastName("Davis");
        personAliceD.setEmail("alison.davis@example.com");
        personAliceD.setPassword("password");
        personAliceD.setEnabled(true);
        people.create(personAliceD);
        personBen = new Person();
        personBen.setUserName("ben@" + account4.getId());
        personBen.setId("ben@" + account4.getId());
        personBen.setFirstName("Ben");
        personBen.setLastName("Carson");
        personBen.setEmail("ben.smythe@example.com");
        personBen.setPassword("password");
        personBen.setEnabled(true);
        people.create(personBen);
    }
    account1Admin = "admin@" + account1.getId();
    account2Admin = "admin@" + account2.getId();
    account3Admin = "admin@" + account3.getId();
    account1PersonIt = account1.getPersonIds().iterator();
    account2PersonIt = account2.getPersonIds().iterator();
    nodeService = applicationContext.getBean("NodeService", NodeService.class);
    personService = applicationContext.getBean("PersonService", PersonService.class);
    // Capture authentication pre-test, so we can restore it again afterwards.
    AuthenticationUtil.pushAuthentication();
}
Also used : NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) Before(org.junit.Before)

Example 53 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project records-management by Alfresco.

the class ScheduledDispositionJob method execute.

/**
 * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
 */
public void execute(JobExecutionContext context) throws JobExecutionException {
    RecordsManagementActionService rmActionService = (RecordsManagementActionService) context.getJobDetail().getJobDataMap().get("recordsManagementActionService");
    NodeService nodeService = (NodeService) context.getJobDetail().getJobDataMap().get("nodeService");
    // Calculate the date range used in the query
    Calendar cal = Calendar.getInstance();
    String year = String.valueOf(cal.get(Calendar.YEAR));
    String month = String.valueOf(cal.get(Calendar.MONTH) + 1);
    String dayOfMonth = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
    // TODO These pad() calls are in RMActionExecuterAbstractBase. I've copied them
    // here as I have no access to that class.
    final String currentDate = padString(year, 2) + "-" + padString(month, 2) + "-" + padString(dayOfMonth, 2) + "T00:00:00.00Z";
    if (logger.isDebugEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("Executing ").append(this.getClass().getSimpleName()).append(" with currentDate ").append(currentDate);
        logger.debug(msg.toString());
    }
    // TODO Copied the 1970 start date from the old RM JavaScript impl.
    String dateRange = "[\"1970-01-01T00:00:00.00Z\" TO \"" + currentDate + "\"]";
    // Execute the query and process the results
    String query = "+ASPECT:\"rma:record\" +ASPECT:\"rma:dispositionSchedule\" +@rma\\:dispositionAsOf:" + dateRange;
    SearchService search = (SearchService) context.getJobDetail().getJobDataMap().get("searchService");
    ResultSet results = search.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_FTS_ALFRESCO, query);
    List<NodeRef> resultNodes = results.getNodeRefs();
    results.close();
    if (logger.isDebugEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("Found ").append(resultNodes.size()).append(" records eligible for disposition.");
        logger.debug(msg.toString());
    }
    for (NodeRef node : resultNodes) {
        String dispActionName = (String) nodeService.getProperty(node, RecordsManagementModel.PROP_DISPOSITION_ACTION_NAME);
        // destroy and transfer and anything else should be manual for now
        if (dispActionName != null && dispActionName.equalsIgnoreCase("cutoff")) {
            rmActionService.executeRecordsManagementAction(node, dispActionName);
            if (logger.isDebugEnabled()) {
                logger.debug("Performing " + dispActionName + " dispoition action on disposable item " + node.toString());
            }
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeService(org.alfresco.service.cmr.repository.NodeService) Calendar(java.util.Calendar) SearchService(org.alfresco.service.cmr.search.SearchService) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Aggregations

NodeService (org.alfresco.service.cmr.repository.NodeService)53 NodeRef (org.alfresco.service.cmr.repository.NodeRef)36 QName (org.alfresco.service.namespace.QName)15 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)11 ResponseWriter (javax.faces.context.ResponseWriter)10 IOException (java.io.IOException)8 UserTransaction (javax.transaction.UserTransaction)8 ServiceRegistry (org.alfresco.service.ServiceRegistry)8 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)8 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)7 PermissionService (org.alfresco.service.cmr.security.PermissionService)7 PersonService (org.alfresco.service.cmr.security.PersonService)7 SearchService (org.alfresco.service.cmr.search.SearchService)6 ArrayList (java.util.ArrayList)5 ResourceBundle (java.util.ResourceBundle)5 FileInfo (org.alfresco.service.cmr.model.FileInfo)5 Path (org.alfresco.service.cmr.repository.Path)5 TransactionService (org.alfresco.service.transaction.TransactionService)5