提交 4fc554c2 编写于 作者: M meyerd

Activiti Cycle: re-enabled download content actions

上级 0419f2b6
......@@ -2,6 +2,7 @@ package org.activiti.cycle;
import java.io.Serializable;
import org.activiti.cycle.action.DownloadContentAction;
/**
* TODO: javadoc
......@@ -42,6 +43,12 @@ public interface ContentRepresentation extends Serializable {
*/
public RepositoryArtifactType getRepositoryArtifactType();
/**
* Indicates whether cycle should create a {@link DownloadContentAction} for
* this content representation.
*/
public boolean isForDownload();
// TODO: Think about that, maybe as annotation in the Plugin-Config
// public boolean isDownloadable();
}
\ No newline at end of file
......@@ -11,21 +11,16 @@ import org.activiti.cycle.action.DownloadContentAction;
*
* @author ruecker
*/
//@CycleComponent(context = CycleContextType.APPLICATION)
// not a @CycleComponent, instantiated by the cycle plugin service for each
// ContentRepresentation
public class DownloadContentActionImpl extends AbstractArtifactActionImpl implements DownloadContentAction {
private static final long serialVersionUID = 1L;
private final ContentRepresentation contentRepresentation;
// public DownloadContentActionImpl(ContentRepresentation
// contentRepresentation) {
// this.contentRepresentation = contentRepresentation;
// }
public DownloadContentActionImpl() {
super("Download");
this.contentRepresentation = null;
public DownloadContentActionImpl(ContentRepresentation contentRepresentation) {
this("Download " + contentRepresentation.getId(), contentRepresentation);
}
public DownloadContentActionImpl(String actionId, ContentRepresentation contentRepresentation) {
......
......@@ -9,7 +9,6 @@ import org.activiti.cycle.CycleComponentFactory;
import org.activiti.cycle.RepositoryArtifactType;
import org.activiti.cycle.action.Action;
import org.activiti.cycle.action.CreateUrlAction;
import org.activiti.cycle.action.DownloadContentAction;
import org.activiti.cycle.action.ParameterizedAction;
import org.activiti.cycle.annotations.CycleComponent;
import org.activiti.cycle.context.CycleApplicationContext;
......@@ -27,10 +26,8 @@ public class Actions {
private Set<ParameterizedAction> globalParameterizedActions = new HashSet<ParameterizedAction>();
private Set<CreateUrlAction> globalCreateUrlActions = new HashSet<CreateUrlAction>();
private Set<DownloadContentAction> globalDownloadContentActions = new HashSet<DownloadContentAction>();
private Map<RepositoryArtifactType, Set<ParameterizedAction>> parameterizedActionsMap = new HashMap<RepositoryArtifactType, Set<ParameterizedAction>>();
private Map<RepositoryArtifactType, Set<CreateUrlAction>> createUrlActionsMap = new HashMap<RepositoryArtifactType, Set<CreateUrlAction>>();
private Map<RepositoryArtifactType, Set<DownloadContentAction>> downloadContentActionsMap = new HashMap<RepositoryArtifactType, Set<DownloadContentAction>>();
public Set<ParameterizedAction> getParameterizedActions(RepositoryArtifactType forType) {
ensureMapInitialized();
......@@ -42,16 +39,6 @@ public class Actions {
return resultSet;
}
public Set<DownloadContentAction> getDownloadContentActions(RepositoryArtifactType forType) {
ensureMapInitialized();
Set<DownloadContentAction> resultSet = new HashSet<DownloadContentAction>(globalDownloadContentActions);
Set<DownloadContentAction> actionsForThisType = downloadContentActionsMap.get(forType);
if (actionsForThisType != null) {
resultSet.addAll(actionsForThisType);
}
return resultSet;
}
public Set<CreateUrlAction> getCreateUrlActions(RepositoryArtifactType forType) {
ensureMapInitialized();
Set<CreateUrlAction> resultSet = new HashSet<CreateUrlAction>(globalCreateUrlActions);
......@@ -70,10 +57,8 @@ public class Actions {
}
parameterizedActionsMap = new HashMap<RepositoryArtifactType, Set<ParameterizedAction>>();
createUrlActionsMap = new HashMap<RepositoryArtifactType, Set<CreateUrlAction>>();
downloadContentActionsMap = new HashMap<RepositoryArtifactType, Set<DownloadContentAction>>();
loadMap(parameterizedActionsMap, globalParameterizedActions, ParameterizedAction.class);
loadMap(createUrlActionsMap, globalCreateUrlActions, CreateUrlAction.class);
loadMap(downloadContentActionsMap, globalDownloadContentActions, DownloadContentAction.class);
initialized = true;
}
}
......
......@@ -57,5 +57,9 @@ public abstract class AbstractPngProvider extends SignavioContentRepresentationP
public RenderInfo getRenderInfo() {
return RenderInfo.IMAGE;
}
public boolean isForDownload() {
return true;
}
}
......@@ -68,6 +68,10 @@ public class ActivitiCompliantBpmn20Provider extends SignavioContentRepresentati
public RepositoryArtifactType getRepositoryArtifactType() {
return CycleApplicationContext.get(SignavioBpmn20ArtifactType.class);
}
public boolean isForDownload() {
return true;
}
public static String createBpmnXml(RepositoryConnector connector, RepositoryArtifact artifact) {
String sourceJson = getBpmn20Json(artifact);
......
......@@ -62,6 +62,10 @@ public class Bpmn20Provider extends SignavioContentRepresentationProvider {
throw new RepositoryException("Error while accessing Signavio repository", ex);
}
}
public boolean isForDownload() {
return true;
}
public String getId() {
return NAME;
......
......@@ -62,6 +62,10 @@ public class EmbeddableModelProvider extends SignavioContentRepresentationProvid
// TODO: ?
return RenderInfo.HTML;
}
public boolean isForDownload() {
return false;
}
public MimeType getRepresentationMimeType() {
return CycleApplicationContext.get(HtmlMimeType.class);
......
......@@ -67,6 +67,10 @@ public class Jpdl4Provider extends SignavioContentRepresentationProvider {
public RenderInfo getRenderInfo() {
return RenderInfo.CODE;
}
public boolean isForDownload() {
return true;
}
public RepositoryArtifactType getRepositoryArtifactType() {
return CycleApplicationContext.get(SignavioJpdl4ArtifactType.class);
......
......@@ -62,6 +62,10 @@ public class JsonProvider extends SignavioContentRepresentationProvider {
public RenderInfo getRenderInfo() {
return RenderInfo.CODE;
}
public boolean isForDownload() {
return true;
}
public RepositoryArtifactType getRepositoryArtifactType() {
return CycleApplicationContext.get(SignavioBpmn20ArtifactType.class);
......
......@@ -60,6 +60,10 @@ public class SignavioDiffProvider extends SignavioContentRepresentationProvider
public RepositoryArtifactType getRepositoryArtifactType() {
return CycleApplicationContext.get(SignavioBpmn20ArtifactType.class);
}
public boolean isForDownload() {
return false;
}
public Content getContent(RepositoryArtifact artifact) {
......
......@@ -21,7 +21,8 @@ public class SvgApiProvider extends SignavioContentRepresentationProvider {
private static final long serialVersionUID = 1L;
public Content getContent(RepositoryArtifact artifact) {
SignavioConnectorInterface signavioConnector = (SignavioConnectorInterface) CycleSessionContext.get(RuntimeConnectorList.class).getConnectorById(artifact.getConnectorId());
SignavioConnectorInterface signavioConnector = (SignavioConnectorInterface) CycleSessionContext.get(RuntimeConnectorList.class).getConnectorById(
artifact.getConnectorId());
Content content = new Content();
String text = new SignavioSvgApiBuilder(signavioConnector, artifact).buildHtml();
content.setValue(text);
......@@ -31,7 +32,7 @@ public class SvgApiProvider extends SignavioContentRepresentationProvider {
public String getId() {
return "SvgApi";
}
public MimeType getRepresentationMimeType() {
return CycleApplicationContext.get(HtmlMimeType.class);
}
......@@ -44,4 +45,8 @@ public class SvgApiProvider extends SignavioContentRepresentationProvider {
return CycleApplicationContext.get(SignavioBpmn20ArtifactType.class);
}
public boolean isForDownload() {
return false;
}
}
......@@ -42,4 +42,8 @@ public abstract class AbstractBasicArtifactTypeContentRepresentation implements
return true;
}
public boolean isForDownload() {
return true;
}
}
......@@ -52,8 +52,7 @@ public class CycleContentServiceImpl implements CycleContentService {
return CycleApplicationContext.get(Transformations.class).transformContent(content, fromType, toType);
}
public List<ContentRepresentation> getcontentRepresentations(RepositoryArtifact artifact) {
RepositoryArtifactType type = artifact.getArtifactType();
public List<ContentRepresentation> getContentRepresentations(RepositoryArtifactType type) {
Set<ContentRepresentation> representations = CycleApplicationContext.get(ContentRepresentations.class).getContentRepresentations(type);
removeExcludedContentRepresentations(representations);
List<ContentRepresentation> sortedList = new ArrayList<ContentRepresentation>(representations);
......@@ -61,16 +60,20 @@ public class CycleContentServiceImpl implements CycleContentService {
return sortedList;
}
public List<ContentRepresentation> getContentRepresentations(RepositoryArtifact artifact) {
return getContentRepresentations(artifact.getArtifactType());
}
private void sortContentReprsentations(List<ContentRepresentation> sortedList) {
Collections.sort(sortedList, new CycleComponentComparator());
}
private void removeExcludedContentRepresentations(Set<?> represenations) {
private void removeExcludedContentRepresentations(Set< ? > represenations) {
CycleComponentFactory.removeExcludedComponents(represenations);
}
public ContentRepresentation getContentRepresentation(RepositoryArtifact artifact, String contentRepresentationId) {
List<ContentRepresentation> representations = getcontentRepresentations(artifact);
List<ContentRepresentation> representations = getContentRepresentations(artifact);
for (ContentRepresentation contentRepresentation : representations) {
if (!contentRepresentation.getId().equals(contentRepresentationId)) {
continue;
......
......@@ -7,6 +7,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.activiti.cycle.ContentRepresentation;
import org.activiti.cycle.CycleComponentFactory;
import org.activiti.cycle.RepositoryArtifact;
import org.activiti.cycle.RepositoryArtifactType;
......@@ -20,8 +21,10 @@ import org.activiti.cycle.components.RuntimeConnectorList;
import org.activiti.cycle.context.CycleApplicationContext;
import org.activiti.cycle.context.CycleSessionContext;
import org.activiti.cycle.impl.CycleComponentComparator;
import org.activiti.cycle.impl.DownloadContentActionImpl;
import org.activiti.cycle.impl.action.Actions;
import org.activiti.cycle.service.CyclePluginService;
import org.activiti.cycle.service.CycleServiceFactory;
/**
* Default Implementation of the {@link CyclePluginService}
......@@ -39,8 +42,17 @@ public class CyclePluginServiceImpl implements CyclePluginService {
}
public Set<DownloadContentAction> getDownloadContentActions(RepositoryArtifactType type) {
return CycleApplicationContext.get(Actions.class).getDownloadContentActions(type);
public List<DownloadContentAction> getDownloadContentActions(RepositoryArtifactType type) {
List<DownloadContentAction> actions = new ArrayList<DownloadContentAction>();
List<ContentRepresentation> contentRepresentations = CycleServiceFactory.getContentService().getContentRepresentations(type);
// will be sorted according to the sort on the represenations
for (ContentRepresentation representation : contentRepresentations) {
if (representation.isForDownload()) {
actions.add(new DownloadContentActionImpl(representation));
}
}
return actions;
}
public List<ParameterizedAction> getParameterizedActions(RepositoryArtifact artifact) {
......@@ -57,9 +69,8 @@ public class CyclePluginServiceImpl implements CyclePluginService {
}
public List<DownloadContentAction> getDownloadContentActions(RepositoryArtifact artifact) {
Set<DownloadContentAction> actions = getDownloadContentActions(artifact.getArtifactType());
removeExcludedActions(actions);
return sortActions(actions, artifact);
List<DownloadContentAction> actions = getDownloadContentActions(artifact.getArtifactType());
return actions;
}
private void removeNonApplicableActions(Set<ParameterizedAction> actions, RepositoryArtifact forArtifact) {
......
......@@ -31,22 +31,34 @@ public interface CycleContentService {
public Set<RepositoryArtifactType> getAvailableArtifactTypes();
/**
* Returns a set of available content representations for the provided
* Returns a List of available content representations for the provided
* {@link RepositoryArtifact}
*
* @param type
* @return a {@link Set} of {@link ContentRepresentation}s for the provided
* @param artifact
* @return a {@link List} of {@link ContentRepresentation}s for the provided
* {@link RepositoryArtifact}. Returns an empty {@link Set} if no
* {@link ContentRepresentation}s are available.
*/
public List<ContentRepresentation> getcontentRepresentations(RepositoryArtifact artifact);
public List<ContentRepresentation> getContentRepresentations(RepositoryArtifact artifact);
/**
* Returns a List of available content representations for the provided
* {@link RepositoryArtifactType}
*
* @param type
* @return a {@link List} of {@link ContentRepresentation}s for the provided
* {@link RepositoryArtifactType}. Returns an empty {@link List} if no
* {@link ContentRepresentation}s are available.
*/
public List<ContentRepresentation> getContentRepresentations(RepositoryArtifactType type);
/**
* Return the {@link ContentRepresentation} for a provided {@link RepositoryArtifact} and a
* contentRepresentationId.
* Return the {@link ContentRepresentation} for a provided
* {@link RepositoryArtifact} and a contentRepresentationId.
*
* @param artifact
* the {@link RepositoryArtifact} to retrieve the {@link ContentRepresentation} for
* the {@link RepositoryArtifact} to retrieve the
* {@link ContentRepresentation} for
* @param contentRepresentationId
* the string of the corresponding {@link ContentRepresentation}
* @return {@link ContentRepresentation}
......
......@@ -23,7 +23,7 @@ public interface CyclePluginService {
public Set<CreateUrlAction> getCreateUrlActions(RepositoryArtifactType type);
public Set<DownloadContentAction> getDownloadContentActions(RepositoryArtifactType type);
public List<DownloadContentAction> getDownloadContentActions(RepositoryArtifactType type);
public List<ParameterizedAction> getParameterizedActions(RepositoryArtifact artifact);
......
......@@ -2,9 +2,7 @@ package org.activiti.cycle.impl.connector.fs;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import org.activiti.cycle.Content;
......@@ -52,7 +50,7 @@ public class FileSystemConnectorTest {
if (repositoryNode instanceof RepositoryArtifact) {
RepositoryArtifact artifact = (RepositoryArtifact) repositoryNode;
List<ContentRepresentation> contentRepresentations = contentService.getcontentRepresentations(artifact);
List<ContentRepresentation> contentRepresentations = contentService.getContentRepresentations(artifact);
for (ContentRepresentation contentRepresentation : contentRepresentations) {
Content content = conn.getContent(artifact.getNodeId());
System.out.println(contentRepresentation.getId() + " -> " + content.asString());
......
......@@ -21,15 +21,11 @@ import java.util.Map;
import org.activiti.cycle.ContentRepresentation;
import org.activiti.cycle.RepositoryArtifact;
import org.activiti.cycle.action.DownloadContentAction;
import org.activiti.cycle.service.CycleContentService;
import org.activiti.cycle.service.CyclePluginService;
import org.activiti.cycle.service.CycleServiceFactory;
import org.activiti.rest.api.cycle.dto.DownloadActionView;
import org.activiti.rest.util.ActivitiRequest;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
/**
*
* @author Nils Preusker (nils.preusker@camunda.com)
......@@ -51,7 +47,7 @@ public class ArtifactGet extends ActivitiCycleWebScript {
RepositoryArtifact artifact = repositoryService.getRepositoryArtifact(connectorId, artifactId);
List<String> contentRepresentations = new ArrayList<String>();
for (ContentRepresentation representation : contentService.getcontentRepresentations(artifact)) {
for (ContentRepresentation representation : contentService.getContentRepresentations(artifact)) {
contentRepresentations.add(representation.getId());
}
......@@ -61,18 +57,18 @@ public class ArtifactGet extends ActivitiCycleWebScript {
// Create downloadContentView DTOs
List<DownloadActionView> downloads = new ArrayList<DownloadActionView>();
// for (DownloadContentAction action : pluginService.getDownloadContentActions(artifact)) {
// try {
// String url = restProxyUri + "content?connectorId=" + URLEncoder.encode(connectorId, "UTF-8") + "&artifactId=" + URLEncoder.encode(artifactId, "UTF-8")
// + "&contentRepresentationId=" + URLEncoder.encode(action.getContentRepresentation().getId(), "UTF-8");
// downloads.add(new DownloadActionView(action.getId(), url, action.getContentRepresentation().getMimeType().getContentType(), action
// .getContentRepresentation().getId()));
// } catch (UnsupportedEncodingException e) {
// // should never be reached as long as we use UTF-8, which is valid in
// // java on all platforms
// throw new RuntimeException(e);
// }
// }
for (DownloadContentAction action : pluginService.getDownloadContentActions(artifact)) {
try {
String url = restProxyUri + "content?connectorId=" + URLEncoder.encode(connectorId, "UTF-8") + "&artifactId=" + URLEncoder.encode(artifactId, "UTF-8")
+ "&contentRepresentationId=" + URLEncoder.encode(action.getContentRepresentation().getId(), "UTF-8");
downloads.add(new DownloadActionView(action.getId(), url, action.getContentRepresentation().getRepresentationMimeType().getContentType(), action
.getContentRepresentation().getId()));
} catch (UnsupportedEncodingException e) {
// should never be reached as long as we use UTF-8, which is valid in
// java on all platforms
throw new RuntimeException(e);
}
}
model.put("downloads", downloads);
model.put("links", pluginService.getArtifactOpenLinkActions(artifact));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册