Search in sources :

Example 76 with AssociationRef

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

the class TestPeople method deleteAvatarDirect.

private void deleteAvatarDirect(NodeRef personRef) {
    List<ChildAssociationRef> assocs = nodeService.getChildAssocs(personRef).stream().filter(x -> x.getTypeQName().equals(ContentModel.ASSOC_PREFERENCE_IMAGE)).collect(Collectors.toList());
    if (assocs.size() > 0) {
        nodeService.deleteNode(assocs.get(0).getChildRef());
    }
    // remove old association if it exists
    List<AssociationRef> refs = nodeService.getTargetAssocs(personRef, ContentModel.ASSOC_AVATAR);
    if (refs.size() == 1) {
        NodeRef existingRef = refs.get(0).getTargetRef();
        nodeService.removeAssociation(personRef, existingRef, ContentModel.ASSOC_AVATAR);
    }
    if (assocs.size() > 1 || refs.size() > 1) {
        fail(String.format("Pref images: %d, Avatar assocs: %d", assocs.size(), refs.size()));
    }
}
Also used : Pair(org.alfresco.rest.api.tests.client.Pair) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) Date(java.util.Date) Renditions(org.alfresco.rest.api.Renditions) Client(org.alfresco.rest.api.model.Client) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) PersonService(org.alfresco.service.cmr.security.PersonService) ContentModel(org.alfresco.model.ContentModel) After(org.junit.After) Map(java.util.Map) Thread.sleep(java.lang.Thread.sleep) Assert.fail(org.junit.Assert.fail) NodeService(org.alfresco.service.cmr.repository.NodeService) HttpStatus(org.apache.commons.httpclient.HttpStatus) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) Company(org.alfresco.rest.api.tests.client.data.Company) Set(java.util.Set) UUID(java.util.UUID) ContentLimitProvider(org.alfresco.repo.content.ContentLimitProvider) Collectors(java.util.stream.Collectors) ContentService(org.alfresco.service.cmr.repository.ContentService) Serializable(java.io.Serializable) List(java.util.List) JSONAble(org.alfresco.rest.api.tests.client.data.JSONAble) JSONObject(org.json.simple.JSONObject) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) Assert.assertFalse(org.junit.Assert.assertFalse) NamespaceService(org.alfresco.service.namespace.NamespaceService) Person(org.alfresco.rest.api.tests.client.data.Person) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) PreferenceService(org.alfresco.service.cmr.preference.PreferenceService) RestApiUtil(org.alfresco.rest.api.tests.util.RestApiUtil) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ClassPathResource(org.springframework.core.io.ClassPathResource) HashMap(java.util.HashMap) LoginTicketResponse(org.alfresco.rest.api.model.LoginTicketResponse) Rendition(org.alfresco.rest.api.model.Rendition) ArrayList(java.util.ArrayList) People(org.alfresco.rest.api.tests.client.PublicApiClient.People) GUID(org.alfresco.util.GUID) ResetPasswordServiceImplTest.getWorkflowIdAndKeyFromUrl(org.alfresco.repo.security.authentication.ResetPasswordServiceImplTest.getWorkflowIdAndKeyFromUrl) QName(org.alfresco.service.namespace.QName) ThumbnailService(org.alfresco.service.cmr.thumbnail.ThumbnailService) LinkedList(java.util.LinkedList) EmailUtil(org.alfresco.util.email.EmailUtil) Before(org.junit.Before) PasswordReset(org.alfresco.rest.api.model.PasswordReset) EmptyStackException(java.util.EmptyStackException) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) HttpServletResponse(javax.servlet.http.HttpServletResponse) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) MimeMessage(javax.mail.internet.MimeMessage) PublicApiClient(org.alfresco.rest.api.tests.client.PublicApiClient) File(java.io.File) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Assert.assertNull(org.junit.Assert.assertNull) LoginTicket(org.alfresco.rest.api.model.LoginTicket) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) ResetPasswordServiceImpl(org.alfresco.repo.security.authentication.ResetPasswordServiceImpl) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 77 with AssociationRef

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

the class NodeTargetsRelation method readAll.

/**
 * List targets
 *
 * @param sourceNodeId String id of source node
 */
@Override
@WebApiDescription(title = "Return a paged list of target nodes based on (peer) assocs")
public CollectionWithPagingInfo<Node> readAll(String sourceNodeId, Parameters parameters) {
    NodeRef sourceNodeRef = nodes.validateOrLookupNode(sourceNodeId, null);
    QNamePattern assocTypeQNameParam = getAssocTypeFromWhereElseAll(parameters);
    List<AssociationRef> assocRefs = nodeService.getTargetAssocs(sourceNodeRef, assocTypeQNameParam);
    return listNodePeerAssocs(assocRefs, parameters, true);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RegexQNamePattern(org.alfresco.service.namespace.RegexQNamePattern) QNamePattern(org.alfresco.service.namespace.QNamePattern) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 78 with AssociationRef

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

the class NodeSourcesRelation method readAll.

/**
 * List sources
 *
 * @param targetNodeId String id of target node
 */
@Override
@WebApiDescription(title = "Return a paged list of sources nodes based on (peer) assocs")
public CollectionWithPagingInfo<Node> readAll(String targetNodeId, Parameters parameters) {
    NodeRef targetNodeRef = nodes.validateOrLookupNode(targetNodeId, null);
    QNamePattern assocTypeQNameParam = getAssocTypeFromWhereElseAll(parameters);
    List<AssociationRef> assocRefs = nodeService.getSourceAssocs(targetNodeRef, assocTypeQNameParam);
    return listNodePeerAssocs(assocRefs, parameters, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QNamePattern(org.alfresco.service.namespace.QNamePattern) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 79 with AssociationRef

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

the class FormRestApiJsonPost_Test method testRemoveAssociationsFromNode.

/**
 * This test method attempts to remove an existing association between two existing
 * nodes.
 */
public void testRemoveAssociationsFromNode() throws Exception {
    List<NodeRef> associatedNodes;
    checkOriginalAssocsBeforeChanges();
    // Remove an association
    JSONObject jsonPostData = new JSONObject();
    String assocsToRemove = associatedDoc_B.toString();
    jsonPostData.put(ASSOC_CM_REFERENCES_REMOVED, assocsToRemove);
    String jsonPostString = jsonPostData.toString();
    sendRequest(new PostRequest(referencingNodeUpdateUrl, jsonPostString, APPLICATION_JSON), 200);
    // Check the now updated associations via the node service
    List<AssociationRef> modifiedAssocs = nodeService.getTargetAssocs(referencingDocNodeRef, RegexQNamePattern.MATCH_ALL);
    assertEquals(1, modifiedAssocs.size());
    // Extract the target nodeRefs to make them easier to examine
    associatedNodes = new ArrayList<NodeRef>(5);
    for (AssociationRef assocRef : modifiedAssocs) {
        associatedNodes.add(assocRef.getTargetRef());
    }
    assertTrue(associatedNodes.contains(associatedDoc_A));
// The Rest API should also give us the modified assocs.
/*Response response = sendRequest(new GetRequest(referencingNodeUpdateUrl), 200);
        String jsonRspString = response.getContentAsString();
        JSONObject jsonGetResponse = new JSONObject(jsonRspString);
        JSONObject jsonData = (JSONObject)jsonGetResponse.get("data");
        assertNotNull(jsonData);

        JSONObject jsonFormData = (JSONObject)jsonData.get("formData");
        assertNotNull(jsonFormData);
        
        String jsonAssocs = (String)jsonFormData.get(ASSOC_CM_REFERENCES);
        
        // We expect exactly 1 assoc on the test node
        assertEquals(1, jsonAssocs.split(",").length);
        for (AssociationRef assocRef : modifiedAssocs)
        {
            assertTrue(jsonAssocs.contains(assocRef.getTargetRef().toString()));
        }*/
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 80 with AssociationRef

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

the class RMAfterInvocationProvider method decide.

@SuppressWarnings({ "unchecked", "rawtypes" })
private Collection decide(Authentication authentication, Object object, ConfigAttributeDefinition config, Collection returnedObject) {
    if (returnedObject == null) {
        return null;
    }
    List<ConfigAttributeDefintion> supportedDefinitions = extractSupportedDefinitions(config);
    if (logger.isDebugEnabled()) {
        logger.debug("Entries are " + supportedDefinitions);
    }
    if (supportedDefinitions.size() == 0) {
        return returnedObject;
    }
    // Default to the system-wide values and we'll see if they need to be reduced
    long targetResultCount = returnedObject.size();
    int maxPermissionChecks = Integer.MAX_VALUE;
    long maxPermissionCheckTimeMillis = this.maxPermissionCheckTimeMillis;
    if (returnedObject instanceof PermissionCheckCollection<?>) {
        PermissionCheckCollection permissionCheckCollection = (PermissionCheckCollection) returnedObject;
        // Get values
        targetResultCount = permissionCheckCollection.getTargetResultCount();
        if (permissionCheckCollection.getCutOffAfterCount() > 0) {
            maxPermissionChecks = permissionCheckCollection.getCutOffAfterCount();
        }
        if (permissionCheckCollection.getCutOffAfterTimeMs() > 0) {
            maxPermissionCheckTimeMillis = permissionCheckCollection.getCutOffAfterTimeMs();
        }
    }
    // Start timer and counter for cut-off
    boolean cutoff = false;
    long startTimeMillis = System.currentTimeMillis();
    int count = 0;
    // Keep values explicitly
    List<Object> keepValues = new ArrayList<Object>(returnedObject.size());
    for (Object nextObject : returnedObject) {
        // if the maximum result size or time has been exceeded, then we have to remove only
        long currentTimeMillis = System.currentTimeMillis();
        // NOTE: for reference - the "maxPermissionChecks" has never been honoured by this loop (since previously the count was not being incremented)
        if (count >= targetResultCount) {
            // We have enough results.  We stop without cutoff.
            break;
        } else if (count >= maxPermissionChecks) {
            // We have been cut off by count
            cutoff = true;
            if (logger.isDebugEnabled()) {
                logger.debug("decide (collection) cut-off: " + count + " checks exceeded " + maxPermissionChecks + " checks");
            }
            break;
        } else if ((currentTimeMillis - startTimeMillis) > maxPermissionCheckTimeMillis) {
            // We have been cut off by time
            cutoff = true;
            if (logger.isDebugEnabled()) {
                logger.debug("decide (collection) cut-off: " + (currentTimeMillis - startTimeMillis) + "ms exceeded " + maxPermissionCheckTimeMillis + "ms");
            }
            break;
        }
        boolean allowed = true;
        for (ConfigAttributeDefintion cad : supportedDefinitions) {
            if (cad.mode.equalsIgnoreCase("FilterNode")) {
                NodeRef testNodeRef = null;
                if (cad.parent) {
                    if (StoreRef.class.isAssignableFrom(nextObject.getClass())) {
                        // Will be allowed
                        testNodeRef = null;
                    } else if (NodeRef.class.isAssignableFrom(nextObject.getClass())) {
                        testNodeRef = nodeService.getPrimaryParent((NodeRef) nextObject).getParentRef();
                    } else if (ChildAssociationRef.class.isAssignableFrom(nextObject.getClass())) {
                        testNodeRef = ((ChildAssociationRef) nextObject).getParentRef();
                    } else if (AssociationRef.class.isAssignableFrom(nextObject.getClass())) {
                        testNodeRef = ((AssociationRef) nextObject).getSourceRef();
                    } else if (PermissionCheckValue.class.isAssignableFrom(nextObject.getClass())) {
                        NodeRef nodeRef = ((PermissionCheckValue) nextObject).getNodeRef();
                        testNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
                    } else {
                        throw new ACLEntryVoterException("The specified parameter is recognized: " + nextObject.getClass());
                    }
                } else {
                    if (StoreRef.class.isAssignableFrom(nextObject.getClass())) {
                        testNodeRef = nodeService.getRootNode((StoreRef) nextObject);
                    } else if (NodeRef.class.isAssignableFrom(nextObject.getClass())) {
                        testNodeRef = (NodeRef) nextObject;
                    } else if (ChildAssociationRef.class.isAssignableFrom(nextObject.getClass())) {
                        testNodeRef = ((ChildAssociationRef) nextObject).getChildRef();
                    } else if (AssociationRef.class.isAssignableFrom(nextObject.getClass())) {
                        testNodeRef = ((AssociationRef) nextObject).getTargetRef();
                    } else if (PermissionCheckValue.class.isAssignableFrom(nextObject.getClass())) {
                        testNodeRef = ((PermissionCheckValue) nextObject).getNodeRef();
                    } else {
                        throw new ACLEntryVoterException("The specified parameter is recognized: " + nextObject.getClass());
                    }
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("\t" + cad.typeString + " test on " + testNodeRef + " from " + nextObject.getClass().getName());
                }
                // Null allows
                if (isUnfiltered(testNodeRef)) {
                    // Continue to next ConfigAttributeDefintion
                    continue;
                }
                if (allowed && testNodeRef != null && checkRead(testNodeRef) != AccessDecisionVoter.ACCESS_GRANTED) {
                    allowed = false;
                    // No point evaluating more ConfigAttributeDefintions
                    break;
                }
            }
        }
        // Failure or success, increase the count
        count++;
        if (allowed) {
            keepValues.add(nextObject);
        }
    }
    // Work out how many were left unchecked (for whatever reason)
    int sizeOriginal = returnedObject.size();
    int checksRemaining = sizeOriginal - count;
    // So make sure that the collection needs modification at all
    if (keepValues.size() < sizeOriginal) {
        // There are values that need to be removed.  We have to modify the collection.
        try {
            returnedObject.clear();
            returnedObject.addAll(keepValues);
        } catch (UnsupportedOperationException e) {
            throw new AccessDeniedException("Permission-checked list must be modifiable", e);
        }
    }
    // Attach the extra permission-check data to the collection
    return PermissionCheckedCollectionMixin.create(returnedObject, cutoff, checksRemaining, sizeOriginal);
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) AccessDeniedException(net.sf.acegisecurity.AccessDeniedException) ArrayList(java.util.ArrayList) ACLEntryVoterException(org.alfresco.repo.security.permissions.impl.acegi.ACLEntryVoterException) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PermissionCheckValue(org.alfresco.repo.security.permissions.PermissionCheckValue) PermissionCheckCollection(org.alfresco.repo.security.permissions.PermissionCheckCollection)

Aggregations

AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)138 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)112 NodeRef (org.alfresco.service.cmr.repository.NodeRef)102 QName (org.alfresco.service.namespace.QName)56 ArrayList (java.util.ArrayList)44 Serializable (java.io.Serializable)30 Test (org.junit.Test)26 HashMap (java.util.HashMap)24 List (java.util.List)15 Pair (org.alfresco.util.Pair)14 HashSet (java.util.HashSet)13 Map (java.util.Map)13 StoreRef (org.alfresco.service.cmr.repository.StoreRef)12 BaseSpringTest (org.alfresco.util.BaseSpringTest)10 Extend (org.alfresco.traitextender.Extend)8 Iterator (java.util.Iterator)7 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)7 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)7 Path (org.alfresco.service.cmr.repository.Path)6 Version (org.alfresco.service.cmr.version.Version)6