Sfoglia il codice sorgente

Fix permessi asseverazioni, avvisi e allegati

master
Salvatore La Manna 4 anni fa
parent
commit
439cfc1443
  1. 2
      liferay-plugins-sdk-6.2/build.portos.properties
  2. 248
      liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/mwg/sismica/bo/util/SismicaUtil.java

2
liferay-plugins-sdk-6.2/build.portos.properties

@ -1,3 +1,5 @@
# Managed by Liferay IDE (remove this comment to prevent future updates)
app.server.tomcat.lib.global.dir = /home/portos/bin/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/lib/ext
app.server.tomcat.deploy.dir = /home/portos/bin/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps
app.server.parent.dir = /home/portos/bin/liferay-portal-6.2-ce-ga6

248
liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/mwg/sismica/bo/util/SismicaUtil.java

@ -48,7 +48,9 @@ import java.util.TreeMap;
import org.apache.commons.io.IOUtils;
import com.itextpdf.text.pdf.codec.Base64.InputStream;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.NoSuchRepositoryEntryException;
import com.liferay.portal.NoSuchResourcePermissionException;
import com.liferay.portal.kernel.dao.jdbc.DataAccess;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.exception.PortalException;
@ -1017,10 +1019,15 @@ public class SismicaUtil {
return new ArrayList<>(sorted.values());
}
private static Map<Long, PermissionChecker> orgPc;
private static long userRoleId;
private static ResourceAction raFileEntry;
private static ResourceAction raFolder;
public static List<String> generaDocumenti(long companyId) throws PortalException, SystemException {
List<String> esito = new ArrayList<>();
Map<Long, PermissionChecker> orgPc = new HashMap<>();
orgPc = new HashMap<>();
for (Organization org : OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS,
QueryUtil.ALL_POS)) {
if (0 == org.getSuborganizationsSize()) {
@ -1036,70 +1043,221 @@ public class SismicaUtil {
}
}
long userRoleId = RoleLocalServiceUtil.getRole(companyId, RoleConstants.USER).getRoleId();
ResourceAction resourceAction = ResourceActionLocalServiceUtil.getResourceAction(
DLFileEntry.class.getName(), ActionKeys.VIEW);
userRoleId = RoleLocalServiceUtil.getRole(companyId, RoleConstants.USER).getRoleId();
raFileEntry = ResourceActionLocalServiceUtil.getResourceAction(DLFileEntry.class.getName(),
ActionKeys.VIEW);
raFolder = ResourceActionLocalServiceUtil
.getResourceAction(DLFolder.class.getName(), ActionKeys.VIEW);
esito.addAll(riparaPermessiAsseverazioni(companyId));
esito.addAll(riparaPermessiAvvisi(companyId));
esito.addAll(riparaPermessiDocPratica(companyId));
return esito;
}
public static List<String> riparaPermessiAsseverazioni(long companyId) throws SystemException,
PortalException {
List<String> esito = new ArrayList<>();
List<Long> mancanti = new ArrayList<>();
int inizio = 0;
int totali = 0;
List<Asseverazione> asseverazioni = null;
List<Asseverazione> documenti = null;
String tipoDocumento = null;
do {
asseverazioni = AsseverazioneLocalServiceUtil.getAsseveraziones(inizio, inizio + SLICE);
for (Asseverazione asseverazione : asseverazioni) {
documenti = AsseverazioneLocalServiceUtil.getAsseveraziones(inizio, inizio + SLICE);
for (Asseverazione documento : documenti) {
if (Validator.isNull(tipoDocumento)) {
tipoDocumento = documento.getClass().getSimpleName();
}
IntPratica pratica = null;
try {
pratica = IntPraticaLocalServiceUtil.getIntPratica(asseverazione.getIntPraticaId());
pratica = IntPraticaLocalServiceUtil.getIntPratica(documento.getIntPraticaId());
} catch (PortalException e) {
}
if (Validator.isNotNull(pratica)) {
if (Validator.isNotNull(pratica) && (documento.getFileEntryId() != 0)) {
Territorio territorio = TerritorioLocalServiceUtil.getTerritorio(pratica
.getTerritorioId());
PermissionChecker pc = orgPc.get(territorio.getGroupId());
FileEntry fileEntry = null;
try {
fileEntry = DLAppServiceUtil.getFileEntry(asseverazione.getFileEntryId());
fileEntry = DLAppServiceUtil.getFileEntry(documento.getFileEntryId());
} catch (Exception e) {
_log.info(e.getClass() + ": " + e.getMessage());
}
if (Validator.isNotNull(fileEntry)) {
if (!fileEntry.containsPermission(pc, ActionKeys.VIEW)) {
_log.info("Pratica " + pratica.getNumeroProgetto() + " ("
+ pratica.getIntPraticaId() + "), asseverazione "
+ asseverazione.getAsseverazioneId() + " non ha i permessi");
ResourcePermission resourcePermission = null;
try {
resourcePermission = ResourcePermissionLocalServiceUtil
.getResourcePermission(companyId, DLFileEntry.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(fileEntry.getPrimaryKey()), userRoleId);
} catch (Exception e) {
_log.info(e.getClass() + ": " + e.getMessage());
}
resourcePermission.setActionIds(resourceAction.getBitwiseValue());
ResourcePermissionLocalServiceUtil.updateResourcePermission(resourcePermission);
Folder folder = fileEntry.getFolder();
while (Validator.isNotNull(folder)) {
if (!folder.containsPermission(pc, ActionKeys.VIEW)) {
_log.info("folder " + folder.getName() + " non ha i permessi");
resourcePermission = ResourcePermissionLocalServiceUtil
.getResourcePermission(companyId, DLFolder.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(folder.getPrimaryKey()), userRoleId);
}
folder = folder.getParentFolder();
}
}
esito.addAll(riparaPermessiFileEntry(companyId, territorio.getGroupId(), fileEntry,
"Pratica " + pratica.getNumeroProgetto() + " (" + pratica.getIntPraticaId()
+ "), " + tipoDocumento + " " + documento.getPrimaryKey()));
}
}
inizio += SLICE;
if (documenti.size() > 0) {
totali += documenti.size();
_log.info(totali + " " + tipoDocumento);
}
} while (documenti.size() > 0);
return esito;
}
public static List<String> riparaPermessiAvvisi(long companyId) throws SystemException, PortalException {
List<String> esito = new ArrayList<>();
int inizio = 0;
int totali = 0;
List<Avviso> documenti = null;
String tipoDocumento = null;
do {
documenti = AvvisoLocalServiceUtil.getAvvisos(inizio, inizio + SLICE);
for (Avviso documento : documenti) {
if (Validator.isNull(tipoDocumento)) {
tipoDocumento = documento.getClass().getSimpleName();
}
IntPratica pratica = null;
try {
pratica = IntPraticaLocalServiceUtil.getIntPratica(documento.getIntPraticaId());
} catch (PortalException e) {
}
if (Validator.isNotNull(pratica) && (documento.getFileEntryIdBase() != 0)) {
Territorio territorio = TerritorioLocalServiceUtil.getTerritorio(pratica
.getTerritorioId());
FileEntry fileEntry = null;
try {
fileEntry = DLAppServiceUtil.getFileEntry(documento.getFileEntryIdBase());
} catch (Exception e) {
_log.info(e.getClass() + ": " + e.getMessage());
}
esito.addAll(riparaPermessiFileEntry(companyId, territorio.getGroupId(), fileEntry,
"Pratica " + pratica.getNumeroProgetto() + " (" + pratica.getIntPraticaId()
+ "), " + tipoDocumento + " " + documento.getPrimaryKey()));
}
if (Validator.isNotNull(pratica) && (documento.getFileEntryIdInvio() != 0)) {
Territorio territorio = TerritorioLocalServiceUtil.getTerritorio(pratica
.getTerritorioId());
FileEntry fileEntry = null;
try {
fileEntry = DLAppServiceUtil.getFileEntry(documento.getFileEntryIdInvio());
} catch (Exception e) {
_log.info(e.getClass() + ": " + e.getMessage());
}
esito.addAll(riparaPermessiFileEntry(companyId, territorio.getGroupId(), fileEntry,
"Pratica " + pratica.getNumeroProgetto() + " (" + pratica.getIntPraticaId()
+ "), " + tipoDocumento + " " + documento.getPrimaryKey()));
}
if (Validator.isNotNull(pratica) && (documento.getFileEntryIdProtocollo() != 0)) {
Territorio territorio = TerritorioLocalServiceUtil.getTerritorio(pratica
.getTerritorioId());
FileEntry fileEntry = null;
try {
fileEntry = DLAppServiceUtil.getFileEntry(documento.getFileEntryIdProtocollo());
} catch (Exception e) {
_log.info(e.getClass() + ": " + e.getMessage());
}
esito.addAll(riparaPermessiFileEntry(companyId, territorio.getGroupId(), fileEntry,
"Pratica " + pratica.getNumeroProgetto() + " (" + pratica.getIntPraticaId()
+ "), " + tipoDocumento + " " + documento.getPrimaryKey()));
}
}
inizio += SLICE;
if (documenti.size() > 0) {
totali += documenti.size();
_log.info(totali + " " + tipoDocumento);
}
} while (documenti.size() > 0);
return esito;
}
public static List<String> riparaPermessiDocPratica(long companyId) throws SystemException,
PortalException {
List<String> esito = new ArrayList<>();
int inizio = 0;
int totali = 0;
List<DocPratica> documenti = null;
String tipoDocumento = null;
do {
documenti = DocPraticaLocalServiceUtil.getDocPraticas(inizio, inizio + SLICE);
for (DocPratica documento : documenti) {
if (Validator.isNull(tipoDocumento)) {
tipoDocumento = documento.getClass().getSimpleName();
}
IntPratica pratica = null;
try {
pratica = IntPraticaLocalServiceUtil.getIntPratica(documento.getIntPraticaId());
} catch (PortalException e) {
}
if (Validator.isNotNull(pratica) && (documento.getDlFileEntryId() != 0)) {
Territorio territorio = TerritorioLocalServiceUtil.getTerritorio(pratica
.getTerritorioId());
FileEntry fileEntry = null;
try {
fileEntry = DLAppServiceUtil.getFileEntry(documento.getDlFileEntryId());
} catch (Exception e) {
_log.info(e.getClass() + ": " + e.getMessage());
}
esito.addAll(riparaPermessiFileEntry(companyId, territorio.getGroupId(), fileEntry,
"Pratica " + pratica.getNumeroProgetto() + " (" + pratica.getIntPraticaId()
+ "), " + tipoDocumento + " " + documento.getPrimaryKey()));
}
}
inizio += SLICE;
if (asseverazioni.size() > 0) {
totali += asseverazioni.size();
_log.info(totali + " DocPratica");
if (documenti.size() > 0) {
totali += documenti.size();
_log.info(totali + " " + tipoDocumento);
}
} while (documenti.size() > 0);
return esito;
}
private static List<String> riparaPermessiFileEntry(long companyId, long groupId, FileEntry fileEntry,
String datiDocumento) throws PortalException, SystemException {
List<String> esito = new ArrayList<>();
if (Validator.isNotNull(fileEntry)) {
PermissionChecker pc = orgPc.get(groupId);
if (!fileEntry.containsPermission(pc, ActionKeys.VIEW)) {
// _log.info(datiDocumento + " non ha i permessi");
ResourcePermission resourcePermission = null;
try {
resourcePermission = ResourcePermissionLocalServiceUtil.getResourcePermission(companyId,
DLFileEntry.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(fileEntry.getPrimaryKey()), userRoleId);
} catch (NoSuchResourcePermissionException e) {
resourcePermission = ResourcePermissionLocalServiceUtil
.createResourcePermission(CounterLocalServiceUtil.increment());
resourcePermission.setCompanyId(companyId);
resourcePermission.setName(DLFileEntry.class.getName());
resourcePermission.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
resourcePermission.setPrimKey(String.valueOf(fileEntry.getPrimaryKey()));
resourcePermission.setRoleId(userRoleId);
resourcePermission.setActionIds(raFileEntry.getBitwiseValue());
ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);
}
resourcePermission.setActionIds(raFileEntry.getBitwiseValue());
ResourcePermissionLocalServiceUtil.updateResourcePermission(resourcePermission);
Folder folder = fileEntry.getFolder();
while (Validator.isNotNull(folder)) {
if (!folder.containsPermission(pc, ActionKeys.VIEW)) {
// _log.info("folder " + folder.getName() +
// " non ha i permessi");
try {
resourcePermission = ResourcePermissionLocalServiceUtil.getResourcePermission(
companyId, DLFolder.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(folder.getPrimaryKey()), userRoleId);
} catch (NoSuchResourcePermissionException e) {
resourcePermission = ResourcePermissionLocalServiceUtil
.createResourcePermission(CounterLocalServiceUtil.increment());
resourcePermission.setCompanyId(companyId);
resourcePermission.setName(DLFolder.class.getName());
resourcePermission.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
resourcePermission.setPrimKey(String.valueOf(folder.getPrimaryKey()));
resourcePermission.setRoleId(userRoleId);
resourcePermission.setActionIds(raFolder.getBitwiseValue());
ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);
}
resourcePermission.setActionIds(raFolder.getBitwiseValue());
ResourcePermissionLocalServiceUtil.updateResourcePermission(resourcePermission);
}
folder = folder.getParentFolder();
}
}
} while (asseverazioni.size() > 0);
_log.info("Mancanti " + mancanti.size());
}
return esito;
}

Caricamento…
Annulla
Salva