Skip to content

Commit

Permalink
Merge pull request #149 from consiglionazionaledellericerche/134-espo…
Browse files Browse the repository at this point in the history
…rtare-i-codici-di-assenza-presenti-su-epas-su-un-file

Inserito nel controller administration il metodo per la creazione di un file excel con tutti i codici d'assenza e loro categorizzazione
  • Loading branch information
criluc authored Mar 4, 2024
2 parents 62c554a + d232eea commit 5e1f5fb
Show file tree
Hide file tree
Showing 2 changed files with 361 additions and 12 deletions.
56 changes: 45 additions & 11 deletions app/controllers/Administration.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
import java.util.AbstractMap.SimpleEntry;
Expand All @@ -68,6 +70,7 @@
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import manager.AbsenceManager;
import manager.CompetenceManager;
import manager.ConsistencyManager;
import manager.ContractManager;
Expand Down Expand Up @@ -96,9 +99,13 @@
import models.User;
import models.UsersRolesOffices;
import models.absences.Absence;
import models.absences.AbsenceType;
import models.absences.CategoryTab;
import models.absences.JustifiedType;
import models.absences.JustifiedType.JustifiedTypeName;
import models.enumerate.LimitType;

import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.lang.WordUtils;
import org.joda.time.LocalDate;
import org.joda.time.YearMonth;
Expand Down Expand Up @@ -176,6 +183,8 @@ public class Administration extends Controller {
static HelpdeskServiceManager helpdeskServiceManager;
@Inject
static CertificationsComunication certificationComunication;
@Inject
static AbsenceManager absenceManager;

/**
* Utilizzabile solo da developer e admin permette di prelevare un token del client
Expand Down Expand Up @@ -248,7 +257,7 @@ public static void fixPersonSituation(Person person, Office office,
Validation.addError("person", "Obbligatorio specificare un utente o un ufficio");
Validation.addError("office", "Obbligatorio specificare un utente o un ufficio");
}

if (Validation.hasErrors()) {
flash.error("Correggere gli errori evidenziati");
log.debug("Errori di validazione in fixPersonSituation, person={}, "
Expand All @@ -273,7 +282,7 @@ public static void fixPersonSituation(Person person, Office office,
personList = personDao.getActivePersonInMonth(
Sets.newHashSet(office), new YearMonth(date.getYear(), date.getMonthOfYear()));
}

consistencyManager.fixPersonSituation(personList, date, onlyRecap);

flash.success("Esecuzione avviata in background");
Expand Down Expand Up @@ -457,7 +466,7 @@ public static void saveGeneralSetting(@Required @Valid GeneralSetting generalSet
generalSetting();
}
}

/**
* Mostra tutti i parametri di configurazione del play.
*/
Expand Down Expand Up @@ -500,7 +509,7 @@ public static void runtimeData() {
"Free Memory", String.format("%s Mb", runtime.freeMemory() / mb),
"Max Memory", String.format("%s Mb", runtime.maxMemory() / mb),
"Total Memory", String.format("%s Mb", runtime.totalMemory() / mb)).entrySet();

final Set<Entry<String, String>> entries = Sets.newHashSet(entrySet);
entries.add(new SimpleEntry<String, String>("Load", String.format("%s", load)));
render("@data", entries);
Expand All @@ -514,7 +523,7 @@ public static void threadsData() {
val threadsData = threads.dumpAllThreads(true, true);
render("@threadsData", threadsData);
}

/**
* Render del modale per l'aggiunta di un nuovo parametro di configurazione.
*/
Expand Down Expand Up @@ -638,8 +647,8 @@ public static void administratorsEmails() {
List<UsersRolesOffices> uros = UsersRolesOffices.findAll();

List<String> emails = uros.stream().filter(uro ->
uro.getRole().getName().equals(Role.PERSONNEL_ADMIN)
&& uro.getUser().getPerson() != null)
uro.getRole().getName().equals(Role.PERSONNEL_ADMIN)
&& uro.getUser().getPerson() != null)
.map(uro -> uro.getUser().getPerson().getEmail())
.distinct().collect(Collectors.toList());

Expand Down Expand Up @@ -747,7 +756,7 @@ public static void applyBonusAllOffices(int year, int month) {
competenceManager.applyBonus(Optional.absent(), item, yearMonth);
});
}

/**
* Metodo che applica le competenze a presenza mensile/giornaliera.
*
Expand Down Expand Up @@ -995,7 +1004,7 @@ public static void updateAllOfficeConfigurations() {
configurationManager.updateAllOfficesConfigurations();
renderText("Aggiornati i parametri di configuratione di tutti gli uffici.");
}

public static void updatePeopleConfigurations() {
configurationManager.updatePeopleConfigurations();
renderText("Aggiornati i parametri di configurazione di tutte le persone.");
Expand Down Expand Up @@ -1053,11 +1062,11 @@ private static void changeSeatLocation(Office office, Institute institute,
institute.save();

}

public static void emergency(Boolean confirm) {
render(confirm);
}

/**
* Il peggior hack di sempre per uccidere il play.
* È da utilizzare in casi disperati come quando sta finendo la
Expand Down Expand Up @@ -1149,4 +1158,29 @@ public void deleteExpiredJwtTokens() {
log.debug("Cancellati {} expired tokens", expiredTokens.size());
renderText(String.format("Cancellati %s expired tokens", expiredTokens.size()));
}

/**
* Genero l'alberatura dei gruppi dei codici d'assenza con limiti di fruizione e completamento
* @throws ArchiveException
*/
public void generateAbsencesFile() throws ArchiveException {
List<CategoryTab> categoryTabs = absenceComponentDao.tabsByPriority();
InputStream file = absenceManager.buildFile(categoryTabs);

renderBinary(file, "export.zip", false);
}

public void generateAbsenceCodeList() {
List<AbsenceType> list = absenceTypeDao
.list(java.util.Optional.empty(), java.util.Optional.of(LocalDate.now()), java.util.Optional.empty());
list = list.stream().filter(abt -> !abt.isInternalUse()).collect(Collectors.toList());
InputStream file = null;
try {
file = absenceManager.buildAbsenceTypeListFile(list);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
renderBinary(file, "codici.zip", false);
}
}
Loading

0 comments on commit 5e1f5fb

Please sign in to comment.