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);
}
}
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);
}
}
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);
}
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);
}
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;
}
Aggregations