use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class VirtualNodeServiceExtension method createAssociation.
@Override
public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) {
Reference targetReference = Reference.fromNodeRef(targetRef);
if (targetReference != null && getTrait().getType(materializeIfPossible(sourceRef)).equals(DownloadModel.TYPE_DOWNLOAD)) {
// NOTE : this is enables downloads of virtual structures
createDownloadAssociation(sourceRef, targetRef);
AssociationRef assocRef = new AssociationRef(sourceRef, assocTypeQName, targetRef);
return assocRef;
} else {
return getTrait().createAssociation(materializeIfPossible(sourceRef), materializeIfPossible(targetRef), assocTypeQName);
}
}
use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class VirtualNodeServiceExtension method getChildAssocs.
@Override
public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef) {
NodeServiceTrait theTrait = getTrait();
boolean canVirtualize = canVirtualizeAssocNodeRef(nodeRef);
if (canVirtualize) {
Reference reference = smartStore.virtualize(nodeRef);
List<ChildAssociationRef> virtualAssociations = smartStore.getChildAssocs(reference, RegexQNamePattern.MATCH_ALL, RegexQNamePattern.MATCH_ALL, Integer.MAX_VALUE, false);
List<ChildAssociationRef> associations = new LinkedList<>(virtualAssociations);
if (smartStore.canMaterialize(reference)) {
NodeRef materialReference = smartStore.materialize(reference);
List<ChildAssociationRef> actualAssociations = theTrait.getChildAssocs(materialReference, RegexQNamePattern.MATCH_ALL, RegexQNamePattern.MATCH_ALL, Integer.MAX_VALUE, false);
associations.addAll(actualAssociations);
}
return associations;
} else {
return theTrait.getChildAssocs(nodeRef);
}
}
use of org.alfresco.repo.virtual.ref.Reference 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.Reference in project alfresco-repository by Alfresco.
the class VirtualVersionServiceExtension method isVersioned.
@Override
public boolean isVersioned(NodeRef nodeRef) {
VersionServiceTrait theTrait = getTrait();
Reference reference = Reference.fromNodeRef(nodeRef);
if (reference == null) {
return theTrait.isVersioned(nodeRef);
} else {
NodeRef materialNode = smartStore.materialize(reference);
return theTrait.isVersioned(materialNode);
}
}
use of org.alfresco.repo.virtual.ref.Reference in project alfresco-repository by Alfresco.
the class VirtualVersionServiceExtension method deleteVersion.
@Override
public void deleteVersion(NodeRef nodeRef, Version version) {
VersionServiceTrait theTrait = getTrait();
Reference reference = Reference.fromNodeRef(nodeRef);
if (reference == null) {
theTrait.deleteVersion(nodeRef, version);
} else {
NodeRef materialNode = smartStore.materialize(reference);
Version actualVersion = materializeVersionIfReference(version);
theTrait.deleteVersion(materialNode, actualVersion);
}
}
Aggregations