Search in sources :

Example 1 with CheckOutCheckInService

use of org.alfresco.service.cmr.coci.CheckOutCheckInService in project alfresco-remote-api by Alfresco.

the class PutMethodTest 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);
    authenticationService = ctx.getBean("authenticationService", MutableAuthenticationService.class);
    personService = ctx.getBean("PersonService", PersonService.class);
    lockService = ctx.getBean("LockService", LockService.class);
    contentService = ctx.getBean("contentService", ContentService.class);
    checkOutCheckInService = ctx.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
    permissionService = ctx.getBean("PermissionService", PermissionService.class);
    namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
    actionService = ctx.getBean("ActionService", ActionService.class);
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    companyHomeNodeRef = repositoryHelper.getCompanyHome();
    txn = transactionService.getUserTransaction();
    txn.begin();
    createUser(USER1_NAME);
    createUser(USER2_NAME);
    InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
    InputStream davLockInfoAdminIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_ADMIN);
    InputStream davLockInfoUser2IS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_USER2);
    testDataFile = IOUtils.toByteArray(testDataIS);
    davLockInfoAdminFile = IOUtils.toByteArray(davLockInfoAdminIS);
    davLockInfoUser2File = IOUtils.toByteArray(davLockInfoUser2IS);
    testDataIS.close();
    davLockInfoAdminIS.close();
    davLockInfoUser2IS.close();
    // Create a test file with versionable aspect and content
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    versionableDocName = "doc-" + GUID.generate();
    properties.put(ContentModel.PROP_NAME, versionableDocName);
    versionableDoc = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, versionableDocName), ContentModel.TYPE_CONTENT, properties).getChildRef();
    contentService.getWriter(versionableDoc, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");
    nodeService.addAspect(versionableDoc, ContentModel.ASPECT_VERSIONABLE, null);
    txn.commit();
    txn = transactionService.getUserTransaction();
    txn.begin();
}
Also used : Serializable(java.io.Serializable) TransactionService(org.alfresco.service.transaction.TransactionService) LockService(org.alfresco.service.cmr.lock.LockService) HashMap(java.util.HashMap) InputStream(java.io.InputStream) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) ContentService(org.alfresco.service.cmr.repository.ContentService) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) PermissionService(org.alfresco.service.cmr.security.PermissionService) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) ActionService(org.alfresco.service.cmr.action.ActionService) Before(org.junit.Before)

Example 2 with CheckOutCheckInService

use of org.alfresco.service.cmr.coci.CheckOutCheckInService in project alfresco-remote-api by Alfresco.

the class NodeVersionsRelation method revertById.

@Operation("revert")
@WebApiDescription(title = "Revert Version", description = "Reverts (ie. promotes) specified version to become a new, most recent, version", successStatus = HttpServletResponse.SC_OK)
public Node revertById(String nodeId, String versionId, VersionOptions versionOptions, Parameters parameters, WithResponse withResponse) {
    Version v = findVersion(nodeId, versionId);
    if (v != null) {
        CheckOutCheckInService cociService = sr.getCheckOutCheckInService();
        NodeRef nodeRef = v.getVersionedNodeRef();
        String versionComment = versionOptions.getComment();
        VersionType versionType = VersionType.MINOR;
        Boolean versionMajor = versionOptions.getMajorVersion();
        if ((versionMajor != null) && (versionMajor)) {
            versionType = VersionType.MAJOR;
        }
        Map<String, Serializable> versionProperties = new HashMap<>(2);
        versionProperties.put(VersionModel.PROP_VERSION_TYPE, versionType);
        if (versionComment != null) {
            versionProperties.put(VersionModel.PROP_DESCRIPTION, versionComment);
        }
        // cancel editing if we want to revert
        if (sr.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)) {
            nodeRef = cociService.cancelCheckout(nodeRef);
        }
        // TODO review default for deep and/or whether we should make it an option
        versionService.revert(nodeRef, v, false);
        // Checkout/Checkin the node - to store the new version in version history
        NodeRef wcNodeRef = cociService.checkout(nodeRef);
        cociService.checkin(wcNodeRef, versionProperties);
        // get latest version
        v = versionService.getVersionHistory(nodeRef).getHeadVersion();
        Node node = nodes.getFolderOrDocumentFullInfo(v.getFrozenStateNodeRef(), null, null, parameters, null);
        mapVersionInfo(v, node);
        return node;
    }
    throw new EntityNotFoundException(nodeId + "-" + versionId);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) Version(org.alfresco.service.cmr.version.Version) HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) VersionType(org.alfresco.service.cmr.version.VersionType) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) Operation(org.alfresco.rest.framework.Operation)

Example 3 with CheckOutCheckInService

use of org.alfresco.service.cmr.coci.CheckOutCheckInService in project acs-community-packaging by Alfresco.

the class UnlockDocEvaluator method evaluate.

/**
 * @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
 */
public boolean evaluate(Node node) {
    if (node.isLocked()) {
        FacesContext fc = FacesContext.getCurrentInstance();
        CheckOutCheckInService checkOutCheckInService = (CheckOutCheckInService) FacesHelper.getManagedBean(fc, "CheckoutCheckinService");
        if (checkOutCheckInService.getWorkingCopy(node.getNodeRef()) == null) {
            return true;
        }
    }
    return false;
}
Also used : FacesContext(javax.faces.context.FacesContext) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService)

Example 4 with CheckOutCheckInService

use of org.alfresco.service.cmr.coci.CheckOutCheckInService in project acs-community-packaging by Alfresco.

the class ForumsCheckinDocEvaluator method evaluate.

/**
 * @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
 */
public boolean evaluate(Node node) {
    boolean allow = false;
    if (node.hasAspect(ContentModel.ASPECT_WORKING_COPY) && node.getProperties().get(ContentModel.PROP_WORKING_COPY_MODE) == null) {
        if (node.hasAspect(ForumModel.ASPECT_DISCUSSABLE)) {
            CheckOutCheckInService checkOutCheckInService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getCheckOutCheckInService();
            // get the original locked node (via the copiedfrom aspect)
            NodeRef lockedNodeRef = checkOutCheckInService.getCheckedOut(node.getNodeRef());
            if (lockedNodeRef != null) {
                Node lockedNode = new Node(lockedNodeRef);
                allow = (node.hasPermission(PermissionService.CHECK_IN) && lockedNode.hasPermission(PermissionService.CONTRIBUTOR));
            }
        } else {
            // there is no discussion so just check they have checkin permission for the node
            allow = node.hasPermission(PermissionService.CHECK_IN);
        }
    }
    return allow;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) Node(org.alfresco.web.bean.repository.Node)

Example 5 with CheckOutCheckInService

use of org.alfresco.service.cmr.coci.CheckOutCheckInService in project alfresco-remote-api by Alfresco.

the class TestActions method canGetActionDefinitionsForNode.

@Test
public void canGetActionDefinitionsForNode() throws Exception {
    final String person1 = account1PersonIt.next();
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
    // Get the actions available on the -my- node-ref alias
    {
        ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitionsForNode("-my-", emptyParams, 200);
        assertNotNull("Action definition list should not be null", actionDefs);
        assertFalse("Action definition list should not be empty", actionDefs.getList().isEmpty());
        // Check defaults, given that no paging params were sent in the request
        assertEquals(Paging.DEFAULT_MAX_ITEMS, actionDefs.getPaging().getMaxItems().intValue());
        assertEquals(Paging.DEFAULT_SKIP_COUNT, actionDefs.getPaging().getSkipCount().intValue());
        // Check ActionDefinition fields
        List<ActionDefinition> actionDefinitions = actionDefs.getList().stream().filter(ad -> ad.getName().equals("add-features")).collect(Collectors.toList());
        assertEquals(1, actionDefinitions.size());
        ActionDefinition action = actionDefinitions.get(0);
        assertEquals("add-features", action.getId());
        assertEquals("add-features", action.getName());
        assertEquals("Add aspect", action.getTitle());
        assertEquals("This will add an aspect to the matched item.", action.getDescription());
        // Applicable types
        assertEquals(0, action.getApplicableTypes().size());
        assertEquals(false, action.isTrackStatus());
        // Parameter definitions
        assertEquals(1, action.getParameterDefinitions().size());
        ActionDefinition.ParameterDefinition paramDefs = action.getParameterDefinitions().get(0);
        assertEquals(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, paramDefs.getName());
        assertEquals("d:qname", paramDefs.getType());
        assertEquals(true, paramDefs.isMandatory());
        assertEquals("Aspect", paramDefs.getDisplayLabel());
        assertEquals(false, paramDefs.isMultiValued());
        assertEquals("ac-aspects", paramDefs.getParameterConstraintName());
    }
    AuthenticationUtil.setFullyAuthenticatedUser(person1);
    // Get the actions for a "checked out" node - there should be a "check-in" action present.
    // Inspect the fields, to make sure that they're all there. Especially applicableTypes, as
    // this isn't available on any of the actions that appear for the "-my-" alias in the test above.
    {
        NodeRef nodeForCheckout = nodeService.createNode(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, getMyNodeId()), ContentModel.ASSOC_CONTAINS, QName.createQName("test", "test-node-checkedout"), ContentModel.TYPE_CONTENT).getChildRef();
        CheckOutCheckInService coci = applicationContext.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
        coci.checkout(nodeForCheckout);
        ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitionsForNode(nodeForCheckout.getId(), emptyParams, 200);
        List<ActionDefinition> actionDefinitions = actionDefs.getList().stream().filter(ad -> ad.getName().equals("check-in")).collect(Collectors.toList());
        assertEquals(1, actionDefinitions.size());
        ActionDefinition action = actionDefinitions.get(0);
        assertEquals("check-in", action.getId());
        assertEquals("check-in", action.getName());
        assertEquals("Check in", action.getTitle());
        assertEquals("This will check in the matched content.", action.getDescription());
        // Applicable types
        assertEquals(1, action.getApplicableTypes().size());
        assertEquals("cm:content", action.getApplicableTypes().get(0));
        assertEquals(false, action.isTrackStatus());
        // Parameter definitions
        assertEquals(2, action.getParameterDefinitions().size());
        // "description"
        ActionDefinition.ParameterDefinition paramDefs = action.getParameterDefinitions().get(0);
        assertEquals(CheckInActionExecuter.PARAM_DESCRIPTION, paramDefs.getName());
        assertEquals("d:text", paramDefs.getType());
        assertEquals(false, paramDefs.isMandatory());
        assertEquals("Description", paramDefs.getDisplayLabel());
        assertEquals(false, paramDefs.isMultiValued());
        assertEquals(null, paramDefs.getParameterConstraintName());
        // "minorChange"
        paramDefs = action.getParameterDefinitions().get(1);
        assertEquals(CheckInActionExecuter.PARAM_MINOR_CHANGE, paramDefs.getName());
        assertEquals("d:boolean", paramDefs.getType());
        assertEquals(false, paramDefs.isMandatory());
        assertEquals("Minor change", paramDefs.getDisplayLabel());
        assertEquals(false, paramDefs.isMultiValued());
        assertEquals(null, paramDefs.getParameterConstraintName());
    }
    String myNode = getMyNodeId();
    NodeRef validNode = nodeService.createNode(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, myNode), ContentModel.ASSOC_CONTAINS, QName.createQName("test", "test-node"), ContentModel.TYPE_CONTENT).getChildRef();
    // Get the actions available using a specific node ID
    {
        ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitionsForNode(validNode.getId(), emptyParams, 200);
        assertNotNull("Action definition list should not be null", actionDefs);
        assertFalse("Action definition list should not be empty", actionDefs.getList().isEmpty());
    }
    // Basic/default paging and sorting
    checkBasicPagingAndSorting(// Expected
    () -> actionService.getActionDefinitions(validNode).stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getName)).map(ParameterizedItemDefinition::getName).collect(Collectors.toList()), // Actual results
    paging -> actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, null), 200));
    // Test explicit sorting by title
    checkSorting(// Expected
    () -> actionService.getActionDefinitions(validNode).stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getTitle, nullsFirst(naturalOrder()))).map(act -> new Pair<>(act.getName(), act.getTitle())).collect(Collectors.toList()), // Actual results
    (paging, orderBy) -> actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, orderBy), 200), "title");
    // Test explicit sorting by name
    checkSorting(// Expected
    () -> actionService.getActionDefinitions(validNode).stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getName, nullsFirst(naturalOrder()))).map(act -> new Pair<>(act.getName(), act.getTitle())).collect(Collectors.toList()), // Actual results
    (paging, orderBy) -> actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, orderBy), 200), "name");
    // Badly formed request -> 400
    {
        // -1 is not acceptable
        PublicApiClient.Paging paging = getPaging(0, -1);
        actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, null), 400);
    }
    // Non-existent node ID
    {
        NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "750a2867-ecfa-478c-8343-fa0e39d27be3");
        assertFalse("Test pre-requisite: node must not exist", nodeService.exists(nodeRef));
        actions.getActionDefinitionsForNode(nodeRef.getId(), emptyParams, 404);
    }
    // Unauthorized -> 401
    {
        publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1, "invalid-password"));
        actions.getActionDefinitionsForNode(validNode.getId(), emptyParams, 401);
    }
}
Also used : ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ActionDefinition(org.alfresco.rest.api.model.ActionDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) ParameterizedItemDefinition(org.alfresco.service.cmr.action.ParameterizedItemDefinition) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Aggregations

CheckOutCheckInService (org.alfresco.service.cmr.coci.CheckOutCheckInService)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 InputStream (java.io.InputStream)1 List (java.util.List)1 FacesContext (javax.faces.context.FacesContext)1 ActionDefinition (org.alfresco.rest.api.model.ActionDefinition)1 Node (org.alfresco.rest.api.model.Node)1 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)1 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)1 Operation (org.alfresco.rest.framework.Operation)1 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 Paging (org.alfresco.rest.framework.resource.parameters.Paging)1 ActionService (org.alfresco.service.cmr.action.ActionService)1 ParameterizedItemDefinition (org.alfresco.service.cmr.action.ParameterizedItemDefinition)1 LockService (org.alfresco.service.cmr.lock.LockService)1 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)1 ContentService (org.alfresco.service.cmr.repository.ContentService)1