use of com.autentia.tnt.businessobject.Holiday in project TNTConcept by autentia.
the class DynMenuBean method generateMenu.
/**
* Generates a list of navigation items, representating entries of the dynamic menu bar
*
* @return
*/
private List<NavigationMenuItem> generateMenu() {
if (navItems == null || !locale.equals(FacesUtils.getViewLocale())) {
locale = FacesUtils.getViewLocale();
if (log.isDebugEnabled()) {
log.debug("generating dynamic menu");
}
Principal creds = null;
boolean isAnonymous = true;
try {
creds = SpringUtils.getPrincipal();
isAnonymous = false;
} catch (ClassCastException e) {
// veamos si es un usuario anonimo
if ("anonymousUser".equals(SpringUtils.getPrincipalAsObject())) {
isAnonymous = true;
} else {
throw new RuntimeException(e);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
navItems = new ArrayList<NavigationMenuItem>();
NavigationMenuItem item = null;
if (!isAnonymous) {
if (log.isDebugEnabled()) {
log.debug("user is NOT anonymous");
}
// file menu
if ((item = createMenuItem(creds, null, "file", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Setting.class), "settings", "/img/configure.png")));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(User.class), "#{dynMenuBean.exit}", "/img/exit.png")));
addItem2Items(navItems, item);
}
// administration menu
if ((item = createMenuItem(creds, null, "admin", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(User.class), "users", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(UserCategory.class), "userCategorys", null)));
addItem2Item(item, (createMenuItem(creds, null, "changePassword", "/img/key.png")));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Department.class), "departments", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(WorkingAgreement.class), "workingAgreements", null)));
addItem2Items(navItems, item);
}
// master tables menu
if ((item = createMenuItem(creds, null, "masterTables", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(AccountEntryType.class), "accountEntryTypes", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(OrganizationType.class), "organizationTypes", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(InteractionType.class), "interactionTypes", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(OrganizationISOCategory.class), "organizationISOCategorys", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(ContractType.class), "contractTypes", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Magazine.class), "magazines", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(OfferRejectReason.class), "offerRejectReasons", null)));
addItem2Items(navItems, item);
}
// billing
if ((item = createMenuItem(creds, null, "billing", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Bill.class), "sii", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Bill.class), "bills", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(CreditTitle.class), "creditTitles", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(AccountEntryType.class), "accounts", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(AccountEntry.class), "accountEntrys", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(PeriodicalAccountEntry.class), "periodicalAccountEntrys", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_NOF, "nof", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(FinancialRatio.class), "financialRatios", null)));
addItem2Items(navItems, item);
}
// contacts
if ((item = createMenuItem(creds, null, "contacts", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Organization.class), "organizations", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Position.class), "positions", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Interaction.class), "interactions", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Contact.class), "contacts", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Offer.class), "offers", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Project.class), "projects", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Tag.class), "tags", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Collaborator.class), "collaborators", null)));
addItem2Items(navItems, item);
}
// commissionings
if ((item = createMenuItem(creds, null, "commissionings", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Commissioning.class), "commissionings", null)));
addItem2Items(navItems, item);
}
// quality
if ((item = createMenuItem(creds, null, "quality", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Action_ListQualityDocuments, "qualityDocuments", null)));
addItem2Items(navItems, item);
}
// bulletin
if ((item = createMenuItem(creds, null, "bulletin", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(BulletinBoard.class), "bulletinBoards", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(CompanyState.class), "companyStates", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(BulletinBoardCategory.class), "bulletinBoardCategorys", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Idea.class), "ideas", null)));
addItem2Items(navItems, item);
}
// activity
if ((item = createMenuItem(creds, null, "activity", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Activity.class), "activitys", null)));
// addItem2Item(item,(createMenuItem(creds, Permission.Entity_Menu(ExternalActivity.class),
// "externalActivities", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Objective.class), "objectives", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_GlobalHoursReport, "globalHoursReport", null)));
// addItem2Item(item,(createMenuItem(creds, Permission.Entity_Menu(Occupation.class), "jpivotTest", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Occupation.class), "availabilitys", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Occupation.class), "occupations", null)));
addItem2Items(navItems, item);
}
// reports tables menu
if ((item = createMenuItem(creds, null, "reports", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Action_GeneralReports, "generalReports", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_BitacoreReports, "bitacoreReports", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_BillReports, "billReports", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_ProjectReports, "projectReports", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_InteractionReports, "interactionReports", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_OrganizationReports, "organizationReports", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_OfferReports, "offerReports", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_CommissioningReports, "commissioningReports", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_OwnReports, "ownReports", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_PersonalReports, "personalReports", null)));
addItem2Items(navItems, item);
}
// publish
if ((item = createMenuItem(creds, null, "publish", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Tutorial.class), "tutorials", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Publication.class), "publications", null)));
addItem2Items(navItems, item);
}
// holiday
if ((item = createMenuItem(creds, null, "holiday", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Holiday.class), "holidays", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(RequestHoliday.class), "requestHolidays", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(AdminHoliday.class), "adminHolidays", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_UserHolidaysState, "userHolidayState", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Action_MyHolidays, "#{userHolidaysStateBean.myHolidays}", null)));
addItem2Items(navItems, item);
}
// utils
if ((item = createMenuItem(creds, null, "utils", null)) != null) {
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Book.class), "books", null)));
addItem2Item(item, (createMenuItem(creds, Permission.Entity_Menu(Inventary.class), "inventarys", null)));
addItem2Items(navItems, item);
}
} else {
// menu items for anonymous users
if (log.isDebugEnabled()) {
log.debug("user is NOT anonymous");
}
}
}
return navItems;
}
use of com.autentia.tnt.businessobject.Holiday in project TNTConcept by autentia.
the class UserHolidaysStateManager method calculateUserHolidaysState.
public UserHolidaysState calculateUserHolidaysState(User usuario, Date year) {
UserHolidaysState uhs = new UserHolidaysState();
uhs.setUser(usuario);
// WorkingAgreement attribute is an HB proxy not initialized, we need to get it
// from DB
WorkingAgreementDAO workingAgreementDao = WorkingAgreementDAO.getDefault();
WorkingAgreement agreement = workingAgreementDao.loadById(usuario.getAgreement().getId());
// and refresh the user instance agreement attribute
usuario.setAgreement(agreement);
uhs.setTotalYear(agreement.getHolidays());
int acceptedHolidays = 0;
if (year != null) {
HolidayManager fiestasManager = HolidayManager.getDefault();
// We must take in account previous year holidays and next year holidays
Date firstDayOfYear = com.autentia.tnt.util.DateUtils.getFirstDayOfYear(year);
Date lastDayOfYear = com.autentia.tnt.util.DateUtils.getLastDayOfYear(year);
Calendar calendarFirstDayOfYear = Calendar.getInstance();
calendarFirstDayOfYear.setTime(firstDayOfYear);
calendarFirstDayOfYear.add(Calendar.YEAR, -1);
Calendar calendarLastDayOfYear = Calendar.getInstance();
calendarLastDayOfYear.setTime(lastDayOfYear);
calendarLastDayOfYear.add(Calendar.YEAR, 1);
HolidaySearch fiestaSearch = new HolidaySearch();
fiestaSearch.setStartDate(calendarFirstDayOfYear.getTime());
fiestaSearch.setEndDate(calendarLastDayOfYear.getTime());
List<Holiday> allFiestas = fiestasManager.getAllEntities(fiestaSearch, null);
firstDayOfYear = com.autentia.tnt.util.DateUtils.getFirstDayOfYear(year);
calendarFirstDayOfYear.setTime(firstDayOfYear);
lastDayOfYear = com.autentia.tnt.util.DateUtils.getLastDayOfYear(year);
calendarLastDayOfYear.setTime(lastDayOfYear);
RequestHolidayManager holyManager = RequestHolidayManager.getDefault();
RequestHolidaySearch holSearch = new RequestHolidaySearch();
holSearch.setUserRequest(uhs.getUser());
holSearch.setState(HolidayState.ACCEPT);
holSearch.setStartChargeYear(calendarFirstDayOfYear.getTime());
holSearch.setEndChargeYear(calendarLastDayOfYear.getTime());
List<RequestHoliday> listH = holyManager.getAllEntities(holSearch, null);
for (RequestHoliday rH : listH) {
Calendar cActual = Calendar.getInstance();
cActual.setTime(rH.getBeginDate());
while (!cActual.getTime().after(rH.getFinalDate())) {
if (cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
boolean isFiesta = false;
for (Holiday fiest : allFiestas) {
Calendar cFiesta = Calendar.getInstance();
cFiesta.setTime(fiest.getDate());
if (cFiesta.get(Calendar.YEAR) == cActual.get(Calendar.YEAR) && cFiesta.get(Calendar.MONTH) == cActual.get(Calendar.MONTH) && cFiesta.get(Calendar.DAY_OF_MONTH) == cActual.get(Calendar.DAY_OF_MONTH)) {
isFiesta = true;
}
}
if (!isFiesta) {
acceptedHolidays++;
}
}
cActual.add(Calendar.DAY_OF_MONTH, 1);
}
}
uhs.setTotalAccepted(acceptedHolidays);
Calendar calAuxCont = Calendar.getInstance();
calAuxCont.setTime(uhs.getUser().getStartDate());
Calendar calAux = Calendar.getInstance();
calAux.setTime(year);
int yearCharge = calAux.get(Calendar.YEAR);
int yearContract = calAuxCont.get(Calendar.YEAR);
if (yearCharge == yearContract) {
// Dividimos los días de cada usuario entre los dias del año.
double ratio = uhs.getUser().getAgreement().getHolidays() / 360.0;
int dayContract = calAuxCont.get(Calendar.DAY_OF_YEAR);
int workedDays = (360 - dayContract);
double holidayDays = workedDays * ratio;
double aux = Math.round(holidayDays);
uhs.setTotalYear((int) aux);
}
}
return uhs;
}
use of com.autentia.tnt.businessobject.Holiday in project TNTConcept by autentia.
the class UserHolidaysStateManager method getWorkingDays.
/**
* @return Devuelve el número de días laborables que hay entre dos fechas
*/
public int getWorkingDays(Date fromDate, Date toDate) {
int total = 0;
// Evitamos un bucle infinito en el bucle que viene a continuación
if (fromDate.before(toDate) || DateUtils.isSameDay(fromDate, toDate)) {
HolidaySearch fiestaSearch = new HolidaySearch();
Date current = (Date) fromDate.clone();
fiestaSearch.setStartDate(fromDate);
fiestaSearch.setEndDate(toDate);
List<Holiday> allFiestas = HolidayManager.getDefault().getAllEntities(fiestaSearch, null);
Calendar fromYear = Calendar.getInstance();
Calendar toYear = Calendar.getInstance();
fromYear.setTime(fromDate);
toYear.setTime(toDate);
while (current.before(toDate) || DateUtils.isSameDay(current, toDate)) {
if (!this.isHoliday(allFiestas, current)) {
total++;
}
current = DateUtils.addDays(current, 1);
}
}
return total;
}
use of com.autentia.tnt.businessobject.Holiday in project TNTConcept by autentia.
the class AvailabilityBean method fillModelHolidays.
/**
* Fill holidays in listOccupations for that user.
*
* @param user
* @param model
*/
private void fillModelHolidays(User user, OcupationModel model) {
Calendar calendarFirstDayOfMonth = Calendar.getInstance();
Calendar calendarLastDayOfMonth = Calendar.getInstance();
Date firstDayOfMonth = DateUtils.getFirstDayOfMonth(selectedDate);
Date lastDayOfMonth = DateUtils.getLastDayOfMonth(selectedDate);
calendarFirstDayOfMonth.setTime(firstDayOfMonth);
calendarLastDayOfMonth.setTime(lastDayOfMonth);
calendarFirstDayOfMonth.add(Calendar.MONTH, -1);
calendarLastDayOfMonth.add(Calendar.MONTH, 1);
RequestHolidayManager rhManager = RequestHolidayManager.getDefault();
RequestHolidaySearch rhSearch = new RequestHolidaySearch();
rhSearch.setUserRequest(user);
rhSearch.setState(HolidayState.ACCEPT);
rhSearch.setStartBeginDate(calendarFirstDayOfMonth.getTime());
rhSearch.setEndBeginDate(calendarLastDayOfMonth.getTime());
rhSearch.setStartFinalDate(calendarFirstDayOfMonth.getTime());
rhSearch.setEndFinalDate(calendarLastDayOfMonth.getTime());
List<RequestHoliday> listH = rhManager.getAllEntities(rhSearch, null);
for (RequestHoliday rH : listH) {
OcupationEntryImpl oc = new OcupationEntryImpl();
oc.setStart(DateUtils.minHourInDate(rH.getBeginDate()));
oc.setEnd(DateUtils.maxHourInDate(rH.getFinalDate()));
oc.setVacances(true);
oc.setHoliday(false);
oc.setDescription(FacesUtils.getMessage("activity.acceptedHolidays"));
model.addOcupationEntry(oc);
}
HolidaySearch monthSearch = new HolidaySearch();
HolidayManager holidayManager = HolidayManager.getDefault();
monthSearch.setStartDate(calendarFirstDayOfMonth.getTime());
monthSearch.setEndDate(calendarLastDayOfMonth.getTime());
List<Holiday> allHolidays = holidayManager.getAllEntities(monthSearch, null);
for (Holiday holiday : allHolidays) {
OcupationEntryImpl oc = new OcupationEntryImpl();
oc.setStart(DateUtils.minHourInDate(holiday.getDate()));
oc.setEnd(DateUtils.maxHourInDate(holiday.getDate()));
oc.setVacances(false);
oc.setHoliday(true);
oc.setDescription(holiday.getDescription());
model.addOcupationEntry(oc);
}
}
use of com.autentia.tnt.businessobject.Holiday in project TNTConcept by autentia.
the class ActivityBean_IT method getMonthTotalHours_GeneralHolidaysInWorkingDays.
@Test
public void getMonthTotalHours_GeneralHolidaysInWorkingDays() {
// create a general holiday day
HolidayManager holidayManager = HolidayManager.getDefault();
Holiday holiday = new Holiday();
LocalDate holidayDay = LocalDate.of(2017, 8, 15);
Date holidayDate = Date.from(holidayDay.atStartOfDay(ZoneId.systemDefault()).toInstant());
holiday.setDate(holidayDate);
holiday.setDescription("Test Holiday");
holidayManager.insertEntity(holiday);
// verify total hours for the month where the holiday day is in
ActivityBeanNoJSF sut = new ActivityBeanNoJSF();
LocalDate august = LocalDate.of(2017, 8, 1);
Date augustDate = Date.from(august.atStartOfDay(ZoneId.systemDefault()).toInstant());
sut.setSelectedDate(augustDate);
double augustHours = sut.getMonthTotalHours();
assertThat(augustHours, closeTo(176.0, 0.1));
}
Aggregations