use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class ActionsImpl method executeAction.
@Override
public Action executeAction(Action action, Parameters parameters) {
if (action == null) {
throw new InvalidArgumentException("action is null");
}
if (action.getActionDefinitionId() == null || action.getActionDefinitionId().isEmpty()) {
throw new InvalidArgumentException("action.actionDefinitionId is null or empty");
}
org.alfresco.service.cmr.action.ActionDefinition actionDef = null;
try {
actionDef = actionService.getActionDefinition(action.getActionDefinitionId());
} catch (NoSuchBeanDefinitionException nsbdx) {
// Intentionally empty.
}
// the result of getActionDefinition can be null and not throw the exception.
if (actionDef == null) {
throw new EntityNotFoundException(action.getActionDefinitionId());
}
// targetId is optional, however, currently targetId must be a valid node ID.
NodeRef actionedUponNodeRef = null;
if (action.getTargetId() != null && !action.getTargetId().isEmpty()) {
// Does it exist in the repo?
actionedUponNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, action.getTargetId());
if (!nodeService.exists(actionedUponNodeRef)) {
throw new EntityNotFoundException(action.getTargetId());
}
}
org.alfresco.service.cmr.action.Action cmrAction;
if (action.getParams() != null && !action.getParams().isEmpty()) {
cmrAction = actionService.createAction(action.getActionDefinitionId(), extractActionParams(actionDef, action.getParams()));
} else {
cmrAction = actionService.createAction(action.getActionDefinitionId());
}
actionService.executeAction(cmrAction, actionedUponNodeRef, true, true);
// Create user result.
Action result = new Action();
result.setId(cmrAction.getId());
return result;
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class ActivitiesImpl method getUserActivities.
public CollectionWithPagingInfo<Activity> getUserActivities(String personId, final Parameters parameters) {
personId = people.validatePerson(personId);
Paging paging = parameters.getPaging();
String siteId = parameters.getParameter("siteId");
String who = parameters.getParameter("who");
ActivityWho activityWho = null;
if (who != null) {
try {
activityWho = ActivityWho.valueOf(who);
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException("Parameter who should be one of " + Arrays.toString(ActivityWho.values()));
}
}
if (siteId != null && !siteId.equals("")) {
SiteInfo siteInfo = sites.validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new EntityNotFoundException(siteId);
}
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
siteId = siteInfo.getShortName();
}
try {
PagingResults<ActivityFeedEntity> activities = null;
if (activityWho == null) {
activities = activityService.getPagedUserFeedEntries(personId, siteId, false, false, -1, Util.getPagingRequest(paging));
} else if (activityWho.equals(ActivityWho.me)) {
activities = activityService.getPagedUserFeedEntries(personId, siteId, false, true, -1, Util.getPagingRequest(paging));
} else if (activityWho.equals(ActivityWho.others)) {
activities = activityService.getPagedUserFeedEntries(personId, siteId, true, false, -1, Util.getPagingRequest(paging));
} else {
throw new InvalidArgumentException("Who argument is invalid.");
}
List<ActivityFeedEntity> feedEntities = activities.getPage();
List<Activity> ret = new ArrayList<Activity>(feedEntities.size());
for (ActivityFeedEntity entity : feedEntities) {
String feedSiteId = getSiteId(entity.getSiteNetwork());
String networkId = tenantService.getDomain(entity.getSiteNetwork());
Activity activity = new Activity(entity.getId(), networkId, feedSiteId, entity.getFeedUserId(), entity.getPostUserId(), entity.getPostDate(), entity.getActivityType(), getActivitySummary(entity));
ret.add(activity);
}
return CollectionWithPagingInfo.asPaged(paging, ret, activities.hasMoreItems(), activities.getTotalResultCount().getFirst());
} catch (JSONException e) {
throw new AlfrescoRuntimeException("", e);
}
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class AuditImpl method getAuditEntry.
@Override
public AuditEntry getAuditEntry(String auditAppId, long auditEntryId, Parameters parameters) {
checkEnabled();
AuditService.AuditApplication auditApplication = findAuditAppByIdOr404(auditAppId);
// Execute the query
AuditQueryParameters params = new AuditQueryParameters();
params.setApplicationName(auditApplication.getName());
params.setFromId(auditEntryId);
params.setToId(auditEntryId + 1);
List<String> includeParam = new ArrayList<>();
if (parameters != null) {
includeParam.addAll(parameters.getInclude());
}
// Add values for single get
includeParam.add(PARAM_INCLUDE_VALUES);
final List<AuditEntry> results = new ArrayList<>();
// create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback() {
public boolean valuesRequired() {
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
}
public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) {
throw new AlfrescoRuntimeException("Failed to retrieve audit data.", error);
}
public boolean handleAuditEntry(Long entryId, String applicationName, String userName, long time, Map<String, Serializable> values) {
UserInfo userInfo = Node.lookupUserInfo(userName, new HashMap<>(0), personService);
AuditEntry auditEntry = new AuditEntry(entryId, auditAppId, userInfo, new Date(time), values);
results.add(auditEntry);
return true;
}
};
auditService.auditQuery(callback, params, 1);
if (results.size() != 1) {
throw new EntityNotFoundException("" + auditEntryId);
}
return results.get(0);
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class DeploymentsImpl method getDeployment.
@Override
public Deployment getDeployment(String deploymentId) {
// Only admin-user is allowed to get deployments
if (!authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
throw new PermissionDeniedException();
}
RepositoryService repositoryService = activitiProcessEngine.getRepositoryService();
DeploymentQuery query = repositoryService.createDeploymentQuery().deploymentId(deploymentId);
if (tenantService.isEnabled() && deployWorkflowsInTenant) {
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
}
org.activiti.engine.repository.Deployment deployment = null;
try {
deployment = query.singleResult();
} catch (ActivitiException e) {
// The next exception will cause a response status 400: Bad request
throw new InvalidArgumentException("Invalid deployment id: " + deploymentId);
}
if (deployment == null) {
// The next exception will cause a response status 404: Not found
throw new EntityNotFoundException(deploymentId);
}
Deployment deploymentRest = new Deployment(deployment);
return deploymentRest;
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionsImpl method getProcessDefinitionImage.
@Override
public BinaryResource getProcessDefinitionImage(String definitionId) {
ProcessDefinitionQuery query = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionId(definitionId);
if (tenantService.isEnabled() && deployWorkflowsInTenant) {
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
}
org.activiti.engine.repository.ProcessDefinition processDefinition = query.singleResult();
if (processDefinition == null) {
throw new EntityNotFoundException(definitionId);
}
try {
InputStream processDiagram = activitiProcessEngine.getRepositoryService().getProcessDiagram(definitionId);
if (processDiagram != null) {
File file = TempFileProvider.createTempFile(definitionId + UUID.randomUUID(), ".png");
FileOutputStream fos = new FileOutputStream(file);
IOUtils.copy(processDiagram, fos);
fos.close();
return new FileBinaryResource(file);
} else {
throw new ApiException("No image available for definitionId " + definitionId);
}
} catch (IOException error) {
throw new ApiException("Error while getting process definition image.");
}
}
Aggregations