001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thomas Roger 018 */ 019 020package org.nuxeo.ecm.admin.permissions; 021 022import java.io.Serializable; 023 024import org.jboss.seam.ScopeType; 025import org.jboss.seam.annotations.In; 026import org.jboss.seam.annotations.Install; 027import org.jboss.seam.annotations.Name; 028import org.jboss.seam.annotations.Scope; 029import org.nuxeo.ecm.core.api.DocumentModel; 030import org.nuxeo.ecm.core.work.api.WorkManager; 031import org.nuxeo.ecm.platform.contentview.jsf.ContentView; 032import org.nuxeo.ecm.platform.contentview.seam.ContentViewActions; 033import org.nuxeo.runtime.api.Framework; 034 035/** 036 * @since 7.4 037 */ 038@Name("adminPermissionsActions") 039@Scope(ScopeType.CONVERSATION) 040@Install(precedence = Install.FRAMEWORK) 041public class AdminPermissionsActions implements Serializable { 042 043 private static final long serialVersionUID = 1L; 044 045 public final static String PERMISSIONS_PURGE_CONTENT_VIEW = "PERMISSIONS_PURGE"; 046 047 public static final String CATEGORY_PURGE_WORK = "permissionsPurge"; 048 049 public static final String ACE_STATUS_ALL = "all"; 050 051 @In(create = true) 052 protected ContentViewActions contentViewActions; 053 054 protected String purgeWorkId; 055 056 protected String selectedACEStatus = ACE_STATUS_ALL; 057 058 public String getSelectedACEStatus() { 059 return selectedACEStatus; 060 } 061 062 public void setSelectedACEStatus(String selectedACEStatus) { 063 this.selectedACEStatus = selectedACEStatus; 064 } 065 066 public String getACEStatusFixedPart() { 067 switch (selectedACEStatus) { 068 case ACE_STATUS_ALL: 069 return null; 070 case "0": 071 return "AND ecm:acl/*1/status = 0"; 072 case "1": 073 return "AND (ecm:acl/*1/status IS NULL OR ecm:acl/*1/status = 1)"; 074 case "2": 075 return "AND ecm:acl/*1/status = 2"; 076 default: 077 return null; 078 } 079 } 080 081 public void doPurge() { 082 ContentView contentView = contentViewActions.getContentView(PERMISSIONS_PURGE_CONTENT_VIEW); 083 DocumentModel searchDocumentModel = contentView.getSearchDocumentModel(); 084 PermissionsPurgeWork work = new PermissionsPurgeWork(searchDocumentModel); 085 purgeWorkId = work.launch(); 086 } 087 088 public void cancelPurge() { 089 ContentView contentView = contentViewActions.getContentView(PERMISSIONS_PURGE_CONTENT_VIEW); 090 contentView.resetSearchDocumentModel(); 091 purgeWorkId = null; 092 } 093 094 public boolean canStartPurge() { 095 WorkManager workManager = Framework.getLocalService(WorkManager.class); 096 return workManager.getMetrics(PermissionsPurgeWork.CATEGORY).getRunning().intValue() <= 0; 097 } 098 099 public PurgeWorkStatus getPurgeStatus() { 100 if (purgeWorkId == null) { 101 return null; 102 } 103 104 return PermissionsPurgeWork.getStatus(purgeWorkId); 105 } 106 107}