Search in sources :

Example 1 with GetActualNodeRefMethod

use of org.alfresco.repo.virtual.ref.GetActualNodeRefMethod in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method addProperties.

@Override
public void addProperties(NodeRef nodeRef, Map<QName, Serializable> properties) {
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference != null) {
        NodeRef actualNodeRef = reference.execute(new GetActualNodeRefMethod(null));
        getTrait().addProperties(actualNodeRef, properties);
    } else {
        getTrait().addProperties(nodeRef, properties);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Reference(org.alfresco.repo.virtual.ref.Reference) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)

Example 2 with GetActualNodeRefMethod

use of org.alfresco.repo.virtual.ref.GetActualNodeRefMethod in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method getParentAssocs.

@Override
public List<ChildAssociationRef> getParentAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern) {
    NodeServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference != null) {
        Reference parent = reference.execute(new GetParentReferenceMethod());
        if (parent == null) {
            return theTrait.getParentAssocs(reference.execute(new GetActualNodeRefMethod(environment)), typeQNamePattern, qnamePattern);
        } else {
            if (typeQNamePattern.isMatch(ContentModel.ASSOC_CONTAINS)) {
                Reference parentsParent = parent.execute(new GetParentReferenceMethod());
                NodeRef parentNodeRef = parent.toNodeRef();
                if (parentsParent == null) {
                    parentNodeRef = parent.execute(new GetActualNodeRefMethod(environment));
                }
                NodeRef referenceNodeRef = reference.toNodeRef();
                Map<QName, Serializable> properties = smartStore.getProperties(reference);
                Serializable name = properties.get(ContentModel.PROP_NAME);
                QName assocChildName = QName.createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, name.toString());
                if (qnamePattern.isMatch(assocChildName)) {
                    ChildAssociationRef assoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentNodeRef, assocChildName, referenceNodeRef);
                    return Arrays.asList(assoc);
                } else {
                    return Collections.emptyList();
                }
            } else {
                return Collections.emptyList();
            }
        }
    } else {
        return theTrait.getParentAssocs(nodeRef, typeQNamePattern, qnamePattern);
    }
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 3 with GetActualNodeRefMethod

use of org.alfresco.repo.virtual.ref.GetActualNodeRefMethod in project alfresco-repository by Alfresco.

the class VirtualPreferenceServiceExtension method setPreferences.

/**
 * If the favorites preferences are changed then for virtual references the
 * actual nodeRef is added/removed from favorites preferences instead of
 * virtual nodeRef. For non virtual entries or for preferences that are not
 * related to favorites the original implementation from
 * PreferenceServiceImpl is used.
 */
@Override
public void setPreferences(String userName, Map<String, Serializable> preferences) throws Throwable {
    final String comma = ",";
    String extKey = getExtPreferenceKey(preferences);
    if (extKey != null) {
        String extFavKey;
        String favKey;
        if (extKey.startsWith(EXT_DOCUMENTS_FAVOURITES)) // favorites for documents
        {
            extFavKey = EXT_DOCUMENTS_FAVOURITES;
            favKey = DOCUMENTS_FAVOURITES_KEY;
        } else // favorites for folders
        {
            extFavKey = EXT_FOLDERS_FAVOURITES;
            favKey = FOLDERS_FAVOURITES_KEY;
        }
        String pattern = "^" + extFavKey + "(\\S+)" + CREATED_AT + "$";
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(extKey);
        if (m.find()) {
            String documentNodeRefStr = m.group(1);
            String favorites = (String) preferences.get(favKey);
            if (documentNodeRefStr != null && !documentNodeRefStr.isEmpty()) {
                NodeRef documentNodeRef = new NodeRef(documentNodeRefStr);
                Reference reference = Reference.fromNodeRef(documentNodeRef);
                if (reference != null) {
                    NodeRef actualNodeRef = reference.execute(new GetActualNodeRefMethod(null));
                    String actualNodeRefStr = actualNodeRef.toString();
                    String actualExtPreference = extFavKey + actualNodeRefStr + CREATED_AT;
                    List<String> elements = new ArrayList<String>(Arrays.asList(favorites.split(comma)));
                    boolean elementsChanged = false;
                    if (favorites.contains(documentNodeRefStr)) // add favorite
                    {
                        if (!preferences.containsKey(actualExtPreference)) {
                            Serializable value = preferences.get(extKey);
                            preferences.put(actualExtPreference, value);
                        }
                        preferences.remove(extKey);
                        if (!favorites.contains(actualNodeRefStr)) {
                            favorites = favorites.replace(documentNodeRefStr, actualNodeRefStr);
                        } else {
                            if (elements.contains(documentNodeRefStr)) {
                                elements.remove(documentNodeRefStr);
                                elementsChanged = true;
                            }
                        }
                    } else // remove favorite
                    {
                        if (elements.contains(actualNodeRefStr)) {
                            elements.remove(actualNodeRefStr);
                            preferenceService.clearPreferences(userName, actualExtPreference);
                            elementsChanged = true;
                        }
                    }
                    if (elementsChanged) {
                        favorites = EMPTY_STRING;
                        for (String element : elements) {
                            if (favorites.isEmpty()) {
                                favorites = element;
                            } else {
                                favorites = favorites + comma + element;
                            }
                        }
                    }
                    preferences.put(favKey, favorites);
                }
            }
        }
    }
    getTrait().setPreferences(userName, preferences);
}
Also used : Pattern(java.util.regex.Pattern) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Matcher(java.util.regex.Matcher) Reference(org.alfresco.repo.virtual.ref.Reference) ArrayList(java.util.ArrayList) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)

Example 4 with GetActualNodeRefMethod

use of org.alfresco.repo.virtual.ref.GetActualNodeRefMethod in project alfresco-repository by Alfresco.

the class VirtualRatingServiceExtensionTest method testApplyRatings.

@Test
public void testApplyRatings() throws Exception {
    Reference reference = Reference.fromNodeRef(virtualContent);
    assertNotNull(reference);
    NodeRef actualNodeRef = reference.execute(new GetActualNodeRefMethod(environment));
    applyRatingAs(virtualContent, 1f, LIKES_RATING_SCHEME, user1);
    applyRatingAs(virtualContent, 1f, LIKES_RATING_SCHEME, user2);
    double delta = 0.0000001;
    assertEquals(1f, ratingService.getAverageRating(virtualContent, LIKES_RATING_SCHEME), delta);
    assertEquals(1f, ratingService.getAverageRating(actualNodeRef, LIKES_RATING_SCHEME), delta);
    applyRatingAs(virtualContent, 1f, FIVE_STAR_RATING_SCHEME, user1);
    applyRatingAs(virtualContent, 3f, FIVE_STAR_RATING_SCHEME, user2);
    assertEquals(2f, ratingService.getAverageRating(virtualContent, FIVE_STAR_RATING_SCHEME), delta);
    assertEquals(2f, ratingService.getAverageRating(actualNodeRef, FIVE_STAR_RATING_SCHEME), delta);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Reference(org.alfresco.repo.virtual.ref.Reference) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod) VirtualizationIntegrationTest(org.alfresco.repo.virtual.VirtualizationIntegrationTest) Test(org.junit.Test)

Example 5 with GetActualNodeRefMethod

use of org.alfresco.repo.virtual.ref.GetActualNodeRefMethod in project alfresco-repository by Alfresco.

the class TemplateFilingRule method parentNodeRefFor.

private NodeRef parentNodeRefFor(Reference parentReference, boolean failIfNotFound) {
    NodeRef fParentRef;
    if (path == null || path.length() == 0) {
        fParentRef = parentReference.execute(new GetActualNodeRefMethod(env));
    } else {
        String[] pathElements = NodeRefPathExpression.splitAndNormalizePath(path);
        for (int i = 0; i < pathElements.length; i++) {
            pathElements[i] = ISO9075.decode(pathElements[i]);
        }
        fParentRef = env.findQNamePath(pathElements);
    }
    boolean noReadPermissions = false;
    if (fParentRef != null && !env.hasPermission(fParentRef, PermissionService.READ_PERMISSIONS)) {
        fParentRef = null;
        noReadPermissions = true;
    }
    if (logger.isDebugEnabled()) {
        if (fParentRef == null) {
            if (noReadPermissions) {
                logger.debug("Current user does not have READ_PERMISSIONS for filing path" + path + ".");
            } else {
                logger.debug("The filing path " + path + " doesn't exist.");
            }
        }
    }
    if (failIfNotFound && fParentRef == null) {
        throw new VirtualizationException("The filing path " + path + " could not be resolved.");
    }
    return fParentRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Aggregations

GetActualNodeRefMethod (org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)12 NodeRef (org.alfresco.service.cmr.repository.NodeRef)12 Reference (org.alfresco.repo.virtual.ref.Reference)8 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)5 Serializable (java.io.Serializable)4 QName (org.alfresco.service.namespace.QName)4 VirtualizationIntegrationTest (org.alfresco.repo.virtual.VirtualizationIntegrationTest)3 Test (org.junit.Test)3 GetParentReferenceMethod (org.alfresco.repo.virtual.ref.GetParentReferenceMethod)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 NodeServiceTrait (org.alfresco.repo.node.db.traitextender.NodeServiceTrait)1 NodePermissionEntry (org.alfresco.repo.security.permissions.NodePermissionEntry)1 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)1 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)1