use of org.alfresco.repo.virtual.ActualEnvironmentException in project alfresco-repository by Alfresco.
the class GetAspectsMethod method execute.
@Override
public Set<QName> execute(VirtualProtocol virtualProtocol, Reference reference) throws ProtocolMethodException {
try {
Set<QName> aspects = createVirtualAspects();
String path = virtualProtocol.getTemplatePath(reference);
if (PATH_SEPARATOR.equals(path.trim())) {
NodeRef nodeRef;
nodeRef = virtualProtocol.getActualNodeLocation(reference).asNodeRef(environment);
Set<QName> nodeAspects = nodeServiceTrait.getAspects(nodeRef);
aspects.addAll(nodeAspects);
}
return aspects;
} catch (ActualEnvironmentException e) {
throw new ProtocolMethodException(e);
}
}
use of org.alfresco.repo.virtual.ActualEnvironmentException in project alfresco-repository by Alfresco.
the class TemplateResourceProcessor method process.
/**
* Processes the JavaScript template given by the {@link RepositoryResource}
* and creates a {@link VirtualFolderDefinition} (composite) structure that
* represents the virtual folder.
*
* @param A {@link RepositoryResource} reference.
* @return A {@link VirtualFolderDefinition} reference that represents the
* structure (tree of nodes) of the virtual folder.
*/
@SuppressWarnings("unchecked")
@Override
public VirtualFolderDefinition process(RepositoryResource repositoryResource) throws ResourceProcessingError {
Object result;
try {
NodeRef templateNodeRef = repositoryResource.getLocation().asNodeRef(context.getActualEnviroment());
result = context.getActualEnviroment().executeScript(templateNodeRef, createScriptParameters(context));
return asVirtualStructure(context, (Map<String, Object>) result);
} catch (ActualEnvironmentException e) {
throw new ResourceProcessingError(e);
}
}
use of org.alfresco.repo.virtual.ActualEnvironmentException in project alfresco-repository by Alfresco.
the class VirtualNodeServiceExtension method createDownloadAssociation.
private void createDownloadAssociation(NodeRef sourceNodeRef, NodeRef targetRef) {
NodeRef tempFolderNodeRef = downloadAssociationsFolder.resolve(true);
String tempFileName = sourceNodeRef.getId();
NodeRef tempFileNodeRef = environment.getChildByName(tempFolderNodeRef, ContentModel.ASSOC_CONTAINS, tempFileName);
if (tempFileNodeRef == null) {
FileInfo newTempFileInfo = environment.create(tempFolderNodeRef, tempFileName, ContentModel.TYPE_CONTENT);
tempFileNodeRef = newTempFileInfo.getNodeRef();
ContentWriter writer = environment.getWriter(tempFileNodeRef, ContentModel.PROP_CONTENT, true);
writer.setMimetype("text/plain");
writer.putContent(targetRef.toString());
} else {
ContentWriter writer = environment.getWriter(tempFileNodeRef, ContentModel.PROP_CONTENT, true);
try {
List<String> readLines = IOUtils.readLines(environment.openContentStream(tempFileNodeRef), StandardCharsets.UTF_8);
String targetRefString = targetRef.toString();
if (!readLines.contains(targetRefString)) {
readLines.add(targetRefString);
}
String text = "";
for (String line : readLines) {
if (text.isEmpty()) {
text = line;
} else {
text = text + IOUtils.LINE_SEPARATOR + line;
}
}
writer.putContent(text);
} catch (IOException e) {
throw new ActualEnvironmentException(e);
}
}
}
Aggregations