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

Caricamento…
Annulla
Salva