Logger.error(this, "Could not load files : ", e2);
}
Contentlet contentlet;
WorkflowStep wfStep;
WorkflowScheme wfScheme = null;
for (Versionable file : files) {
if (file == null)
continue;
List<Integer> permissions = new ArrayList<Integer>();
try {
permissions = permissionAPI.getPermissionIdsFromRoles(
(Permissionable) file, roles, user);
} catch (DotDataException e) {
Logger.error(this, "Could not load permissions : ", e);
}
List<WorkflowAction> wfActions = new ArrayList<WorkflowAction>();
contentlet = null;
if (file instanceof com.dotmarketing.portlets.fileassets.business.FileAsset)
contentlet = (Contentlet) file;
try {
if (contentlet != null) {
wfStep = APILocator.getWorkflowAPI().findStepByContentlet(
contentlet);
wfScheme = APILocator.getWorkflowAPI().findScheme(
wfStep.getSchemeId());
wfActions = APILocator.getWorkflowAPI()
.findAvailableActions(contentlet, user);
}
} catch (Exception e) {
Logger.error(this, "Could not load workflow actions : ", e);
// wfActions = new ArrayList();
}
boolean contentEditable = false;
if (contentlet != null) {
if (perAPI.doesUserHavePermission(contentlet,
PermissionAPI.PERMISSION_WRITE, user)
&& contentlet.isLocked()) {
String lockedUserId = APILocator.getVersionableAPI()
.getLockedBy(contentlet);
if (user.getUserId().equals(lockedUserId)) {
contentEditable = true;
} else {
contentEditable = false;
}
} else {
contentEditable = false;
}
}
try {
if (permissions.contains(PERMISSION_READ)) {
boolean hasPushPublishActionlet = false;
if (!showArchived && file.isArchived()) {
continue;
}
IFileAsset fileAsset = (IFileAsset) file;
List<Map<String, Object>> wfActionMapList = new ArrayList<Map<String, Object>>();
for (WorkflowAction action : wfActions) {
List<WorkflowActionClass> actionlets = APILocator
.getWorkflowAPI().findActionClasses(action);
if (action.requiresCheckout()) {
continue;
}
Map<String, Object> wfActionMap = new HashMap<String, Object>();
wfActionMap.put("name", action.getName());
wfActionMap.put("id", action.getId());
wfActionMap.put("icon", action.getIcon());
wfActionMap.put("assignable", action.isAssignable());
wfActionMap.put("commentable", action.isCommentable()
|| UtilMethods.isSet(action.getCondition()));
wfActionMap.put("requiresCheckout",
action.requiresCheckout());
wfActionMap.put("wfActionNameStr",
LanguageUtil.get(user, action.getName()));
for (WorkflowActionClass actionlet : actionlets) {
if (actionlet
.getActionlet()
.getClass()
.getCanonicalName()
.equals(PushPublishActionlet.class
.getCanonicalName())) {
hasPushPublishActionlet = true;
}
}
wfActionMap.put("hasPushPublishActionlet",
hasPushPublishActionlet);
wfActionMapList.add(wfActionMap);
}
if (wfScheme != null && wfScheme.isMandatory()) {
permissions.remove(new Integer(
PermissionAPI.PERMISSION_PUBLISH));
}
// check for multilingual. we don't need to see the item
// more than once for every language
boolean skip = false;
if (contentlet != null) {
List<Map<String, Object>> toDelete = new ArrayList<Map<String, Object>>();
for (Map<String, Object> map : returnList) {
if (map.get("identifier").equals(
contentlet.getIdentifier())) {
if (contentlet.getLanguageId() != APILocator
.getLanguageAPI().getDefaultLanguage()
.getId()) {
// if this is no for the default lang and
// there is another one in the list skip.
skip = true;
} else {
// if this is for def lang then delete any
// other we find
toDelete.add(map);
}
}
}
returnList.removeAll(toDelete);
}
if (skip)
continue;
Map<String, Object> fileMap = fileAsset.getMap();
Identifier ident = APILocator.getIdentifierAPI().find(
fileAsset.getVersionId());
fileMap.put("wfMandatoryWorkflow", wfScheme!=null && wfScheme.isMandatory());
fileMap.put("permissions", permissions);
fileMap.put("mimeType", APILocator.getFileAPI()
.getMimeType(fileAsset.getFileName()));
fileMap.put("name", ident.getAssetName());
fileMap.put("fileName", ident.getAssetName());