|
|
|
@ -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<>(); |
|
|
|
|
|
|
|
|
|
int inizio = 0; |
|
|
|
|
int totali = 0; |
|
|
|
|
List<Asseverazione> documenti = null; |
|
|
|
|
String tipoDocumento = null; |
|
|
|
|
do { |
|
|
|
|
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(documento.getIntPraticaId()); |
|
|
|
|
} catch (PortalException e) { |
|
|
|
|
} |
|
|
|
|
if (Validator.isNotNull(pratica) && (documento.getFileEntryId() != 0)) { |
|
|
|
|
Territorio territorio = TerritorioLocalServiceUtil.getTerritorio(pratica |
|
|
|
|
.getTerritorioId()); |
|
|
|
|
FileEntry fileEntry = null; |
|
|
|
|
try { |
|
|
|
|
fileEntry = DLAppServiceUtil.getFileEntry(documento.getFileEntryId()); |
|
|
|
|
} 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> 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<>(); |
|
|
|
|
|
|
|
|
|
List<Long> mancanti = new ArrayList<>(); |
|
|
|
|
int inizio = 0; |
|
|
|
|
int totali = 0; |
|
|
|
|
List<Asseverazione> asseverazioni = null; |
|
|
|
|
List<DocPratica> documenti = null; |
|
|
|
|
String tipoDocumento = null; |
|
|
|
|
do { |
|
|
|
|
asseverazioni = AsseverazioneLocalServiceUtil.getAsseveraziones(inizio, inizio + SLICE); |
|
|
|
|
for (Asseverazione asseverazione : asseverazioni) { |
|
|
|
|
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(asseverazione.getIntPraticaId()); |
|
|
|
|
pratica = IntPraticaLocalServiceUtil.getIntPratica(documento.getIntPraticaId()); |
|
|
|
|
} catch (PortalException e) { |
|
|
|
|
} |
|
|
|
|
if (Validator.isNotNull(pratica)) { |
|
|
|
|
if (Validator.isNotNull(pratica) && (documento.getDlFileEntryId() != 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.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 (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("Pratica " + pratica.getNumeroProgetto() + " (" |
|
|
|
|
+ pratica.getIntPraticaId() + "), asseverazione " |
|
|
|
|
+ asseverazione.getAsseverazioneId() + " non ha i permessi"); |
|
|
|
|
// _log.info(datiDocumento + " non ha i permessi");
|
|
|
|
|
ResourcePermission resourcePermission = null; |
|
|
|
|
try { |
|
|
|
|
resourcePermission = ResourcePermissionLocalServiceUtil |
|
|
|
|
.getResourcePermission(companyId, DLFileEntry.class.getName(), |
|
|
|
|
ResourceConstants.SCOPE_INDIVIDUAL, |
|
|
|
|
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()); |
|
|
|
|
} 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"); |
|
|
|
|
resourcePermission = ResourcePermissionLocalServiceUtil |
|
|
|
|
.getResourcePermission(companyId, DLFolder.class.getName(), |
|
|
|
|
ResourceConstants.SCOPE_INDIVIDUAL, |
|
|
|
|
// _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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
inizio += SLICE; |
|
|
|
|
if (asseverazioni.size() > 0) { |
|
|
|
|
totali += asseverazioni.size(); |
|
|
|
|
_log.info(totali + " DocPratica"); |
|
|
|
|
} |
|
|
|
|
} while (asseverazioni.size() > 0); |
|
|
|
|
_log.info("Mancanti " + mancanti.size()); |
|
|
|
|
return esito; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|