@ -1,9 +1,13 @@
/ * *
* Copyright ( c ) 2000 - present Liferay , Inc . All rights reserved . This library is free software ; you can redistribute it
* and / or modify it under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation ; either version 2 . 1 of the License , or ( at your option ) any later version . This library is distributed in
* the hope that it will be useful , but WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE . See the GNU Lesser General Public License for more details .
* Copyright ( c ) 2000 - present Liferay , Inc . All rights reserved .
*
* This library is free software ; you can redistribute it and / or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation ; either version
* 2 . 1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful , but WITHOUT ANY WARRANTY ; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
* /
package it.tref.portos.calendar.appointments.service.impl ;
@ -26,13 +30,11 @@ import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.Order ;
import com.liferay.portal.kernel.dao.orm.OrderFactoryUtil ;
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil ;
import com.liferay.portal.kernel.dao.orm.QueryUtil ;
import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil ;
import com.liferay.portal.kernel.exception.PortalException ;
import com.liferay.portal.kernel.exception.SystemException ;
import com.liferay.portal.kernel.log.Log ;
import com.liferay.portal.kernel.log.LogFactoryUtil ;
import com.liferay.portal.kernel.util.StringPool ;
import com.liferay.portal.model.Organization ;
import com.liferay.portal.model.Role ;
import com.liferay.portal.model.User ;
@ -40,508 +42,650 @@ import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.RoleLocalServiceUtil ;
import com.liferay.portal.service.ServiceContext ;
import com.liferay.portal.service.UserGroupRoleLocalServiceUtil ;
import com.liferay.portal.service.UserLocalServiceUtil ;
/ * *
* The implementation of the disponibilita local service .
*
* < p >
* All custom service methods should be put in this class . Whenever methods are added , rerun ServiceBuilder to copy
* their definitions into the { @link it . tref . portos . calendar . appointments . service . DisponibilitaLocalService } interface .
* All custom service methods should be put in this class . Whenever methods are added , rerun
* ServiceBuilder to copy their definitions into the
* { @link it . tref . portos . calendar . appointments . service . DisponibilitaLocalService } interface .
*
* < p >
* This is a local service . Methods of this service will not have security checks based on the propagated JAAS
* credentials because this service can only be accessed from within the same VM .
* This is a local service . Methods of this service will not have security checks based on the
* propagated JAAS credentials because this service can only be accessed from within the same VM .
* < / p >
*
* @author 3F Consulting + Manifattura Web Group s . r . l .
* @author 3F Consulting
* @see it . tref . portos . calendar . appointments . service . base . DisponibilitaLocalServiceBaseImpl
* @see it . tref . portos . calendar . appointments . service . DisponibilitaLocalServiceUtil
* /
public class DisponibilitaLocalServiceImpl extends DisponibilitaLocalServiceBaseImpl {
/ *
* NOTE FOR DEVELOPERS : Never reference this interface directly . Always use { @link
* it . tref . portos . calendar . appointments . service . DisponibilitaLocalServiceUtil } to access the disponibilita local
* service .
* NOTE FOR DEVELOPERS :
*
* Never reference this interface directly . Always use { @link
* it . tref . portos . calendar . appointments . service . DisponibilitaLocalServiceUtil } to access the
* disponibilita local service .
* /
private static Log _log = LogFactoryUtil . getLog ( DisponibilitaLocalServiceImpl . class ) ;
@Override
public long checkDisponibilitaExist ( long funzionarioId , Date startDate , Date endDate ) throws SystemException {
//Bug 32935
public long checkDisponibilitaExist ( long funzionarioId , Date startDate , Date endDate ) throws SystemException {
long exist = 0L ;
SimpleDateFormat sdf = new SimpleDateFormat ( "dd/MM/yyyy" ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "funzionarioId" , funzionarioId ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "exactDate" , sdf . format ( startDate ) ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "startDate" , startDate ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "endDate" , endDate ) ) ;
@SuppressWarnings ( "unchecked" )
//Bug 32935
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "startDate" , startDate ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "endDate" , endDate ) ) ;
List < Disponibilita > results = disponibilitaPersistence . findWithDynamicQuery ( dynamicQuery ) ;
if ( ! results . isEmpty ( ) ) {
if ( ! results . isEmpty ( ) ) {
exist = results . get ( 0 ) . getDisponibilitaId ( ) ;
}
return exist ;
}
@Override
public long checkDisponibilitaExist ( long funzionarioId , Date startDate , Date endDate , long presidio )
throws SystemException {
public long checkDisponibilitaExist ( long funzionarioId , Date startDate , Date endDate , long presidio ) throws SystemException {
long exist = 0L ;
SimpleDateFormat sdf = new SimpleDateFormat ( "dd/MM/yyyy" ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "funzionarioId" , funzionarioId ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "exactDate" , sdf . format ( startDate ) ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "presidio" , presidio ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "startDate" , startDate ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "endDate" , endDate ) ) ;
@SuppressWarnings ( "unchecked" )
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "presidio" , presidio ) ) ;
//Bug 32935
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "startDate" , startDate ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "endDate" , endDate ) ) ;
List < Disponibilita > results = disponibilitaPersistence . findWithDynamicQuery ( dynamicQuery ) ;
if ( ! results . isEmpty ( ) ) {
if ( ! results . isEmpty ( ) ) {
exist = results . get ( 0 ) . getDisponibilitaId ( ) ;
}
return exist ;
}
@Override
public Disponibilita addDisponibilita ( long userId , long funzionarioId , Date startDate , Date endDate , long presidio ,
ServiceContext serviceContext ) throws SystemException , PortalException {
Organization organization = OrganizationLocalServiceUtil . fetchOrganization ( presidio ) ;
SimpleDateFormat sdf = new SimpleDateFormat ( "dd/MM/yyyy" ) ;
Disponibilita disponibilita =
disponibilitaPersistence . create ( counterLocalService . increment ( Disponibilita . class . getName ( ) ) ) ;
User user = userPersistence . findByPrimaryKey ( userId ) ;
Date now = new Date ( ) ;
disponibilita . setCompanyId ( serviceContext . getCompanyId ( ) ) ;
disponibilita . setUserId ( user . getUserId ( ) ) ;
disponibilita . setUserName ( user . getFullName ( ) ) ;
disponibilita . setCreateDate ( serviceContext . getCreateDate ( now ) ) ;
disponibilita . setModifiedDate ( serviceContext . getModifiedDate ( now ) ) ;
disponibilita . setGroupId ( organization . getGroupId ( ) ) ;
disponibilita . setFunzionarioId ( funzionarioId ) ;
disponibilita . setStartDate ( startDate ) ;
disponibilita . setEndDate ( endDate ) ;
disponibilita . setPresidio ( presidio ) ;
disponibilita . setExactDate ( sdf . format ( startDate ) ) ;
disponibilita . setDisponibile ( true ) ;
disponibilita = updateDisponibilita ( disponibilita ) ;
disponibilita = disponibilitaLocalService . updateDisponibilita ( disponibilita ) ;
return disponibilita ;
}
@Override
public Disponibilita addIndisponibilita ( long userId , long funzionarioId , Date startDate , Date endDate ,
long presidio , ServiceContext serviceContext ) throws SystemException , PortalException {
public Disponibilita addIndisponibilita ( long userId , long funzionarioId , Date startDate , Date endDate , long presidio ,
ServiceContext serviceContext ) throws SystemException , PortalException {
Organization organization = OrganizationLocalServiceUtil . fetchOrganization ( presidio ) ;
SimpleDateFormat sdf = new SimpleDateFormat ( "dd/MM/yyyy" ) ;
Disponibilita disponibilita =
disponibilitaPersistence . create ( counterLocalService . increment ( Disponibilita . class . getName ( ) ) ) ;
User user = userPersistence . findByPrimaryKey ( userId ) ;
Date now = new Date ( ) ;
disponibilita . setCompanyId ( serviceContext . getCompanyId ( ) ) ;
disponibilita . setUserId ( user . getUserId ( ) ) ;
disponibilita . setUserName ( user . getFullName ( ) ) ;
disponibilita . setCreateDate ( serviceContext . getCreateDate ( now ) ) ;
disponibilita . setModifiedDate ( serviceContext . getModifiedDate ( now ) ) ;
disponibilita . setGroupId ( organization . getGroupId ( ) ) ;
disponibilita . setFunzionarioId ( funzionarioId ) ;
disponibilita . setStartDate ( startDate ) ;
disponibilita . setEndDate ( endDate ) ;
disponibilita . setPresidio ( presidio ) ;
disponibilita . setExactDate ( sdf . format ( startDate ) ) ;
disponibilita . setDisponibile ( false ) ;
disponibilita = updateDisponibilita ( disponibilita ) ;
disponibilita = disponibilitaLocalService . updateDisponibilita ( disponibilita ) ;
return disponibilita ;
}
@Override
public void addDisponibilitaGenerale ( long userId , Date startDate , Date endDate , long presidioId , String oraInizio ,
String oraFine , int giornoSettimana , ServiceContext serviceContext ) throws SystemException ,
PortalException , ParseException {
public void addDisponibilitaGenerale ( long userId , Date startDate , Date endDate , long presidioId ,
String oraInizio , String oraFine , int giornoSettimana , ServiceContext serviceContext ) throws SystemException , PortalException , ParseException {
Organization organization = OrganizationLocalServiceUtil . fetchOrganization ( presidioId ) ;
List < User > userDefinitivo = new ArrayList < User > ( ) ;
try {
if ( organization ! = null ) {
List < User > users = userLocalService . getOrganizationUsers ( presidioId ) ;
if ( organization ! = null ) {
List < User > users = UserLocalServiceUtil . getOrganizationUsers ( presidioId ) ;
for ( User user : users ) {
Role portosSupporto = RoleLocalServiceUtil . getRole ( organization . getCompanyId ( ) , "portos_supporto" ) ;
Role portosIstruttore =
RoleLocalServiceUtil . getRole ( organization . getCompanyId ( ) , "portos_calendario" ) ;
if ( ! userLocalService . hasRoleUser ( portosSupporto . getRoleId ( ) , user . getUserId ( ) ) ) {
boolean isIstruttore =
UserGroupRoleLocalServiceUtil . hasUserGroupRole ( user . getUserId ( ) ,
organization . getGroupId ( ) , portosIstruttore . getRoleId ( ) ) ;
if ( isIstruttore ) {
Role portosIstruttore = RoleLocalServiceUtil . getRole ( organization . getCompanyId ( ) , "portos_calendario" ) ;
if ( ! UserLocalServiceUtil . hasRoleUser ( portosSupporto . getRoleId ( ) , user . getUserId ( ) ) ) {
boolean isIstruttore = UserGroupRoleLocalServiceUtil . hasUserGroupRole (
user . getUserId ( ) , organization . getGroupId ( ) , portosIstruttore . getRoleId ( ) ) ;
if ( isIstruttore ) {
userDefinitivo . add ( user ) ;
}
}
}
}
} catch ( NumberFormatException | SystemException e ) {
_log . error ( e , e ) ;
_log . error ( e , e ) ;
} catch ( PortalException e ) {
_log . error ( e , e ) ;
_log . error ( e , e ) ;
}
Calendar calendarStartDate = Calendar . getInstance ( ) ;
calendarStartDate . setTime ( startDate ) ;
if ( calendarStartDate . get ( Calendar . DAY_OF_WEEK ) = = giornoSettimana ) {
if ( calendarStartDate . get ( Calendar . DAY_OF_WEEK ) = = giornoSettimana ) {
Date startDateToInsert = formatDateTime ( oraInizio , startDate ) ;
Date endDateToInsert = formatDateTime ( oraFine , startDate ) ;
for ( User user : userDefinitivo ) {
SimpleDateFormat sdf = new SimpleDateFormat ( "dd/MM/yyyy" ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "funzionarioId" , user . getUserId ( ) ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "exactDate" , sdf . format ( startDateToInsert ) ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "groupId" , organization . getGroupId ( ) ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "startDate" , startDateToInsert ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "endDate" , endDateToInsert ) ) ;
@SuppressWarnings ( "unchecked" )
//Bug 32935
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "startDate" , startDateToInsert ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "endDate" , endDateToInsert ) ) ;
List < Disponibilita > results = disponibilitaPersistence . findWithDynamicQuery ( dynamicQuery ) ;
if ( results . isEmpty ( ) ) {
if ( results . isEmpty ( ) ) {
addDisponibilita ( serviceContext . getUserId ( ) , user . getUserId ( ) , startDateToInsert , endDateToInsert ,
organization . getOrganizationId ( ) , serviceContext ) ;
} else {
for ( Iterator < Disponibilita > iterator = results . iterator ( ) ; iterator . hasNext ( ) ; ) {
Disponibilita disponibilita = iterator . next ( ) ;
}
//Bug 32935
else {
for ( Iterator iterator = results . iterator ( ) ; iterator . hasNext ( ) ; ) {
Disponibilita disponibilita = ( Disponibilita ) iterator . next ( ) ;
disponibilita . setDisponibile ( true ) ;
updateDisponibilita ( disponibilita ) ;
disponibilitaLocalService . updateDisponibilita ( disponibilita ) ;
}
}
}
}
addDayForDisponibilita ( startDate , endDate , oraInizio , oraFine , giornoSettimana , userDefinitivo ,
organization . getOrganizationId ( ) , serviceContext ) ;
addDayForDisponibilita ( startDate , endDate , oraInizio , oraFine , giornoSettimana ,
userDefinitivo , organization . getOrganizationId ( ) , serviceContext ) ;
}
private void addDayForDisponibilita ( Date date , Date endDate , String oraInizio , String oraFine , int giornoSettimana ,
List < User > users , long presidioId , ServiceContext serviceContext ) throws ParseException , SystemException ,
PortalException {
private void addDayForDisponibilita ( Date date , Date endDate , String oraInizio , String oraFine , int giornoSettimana , List < User > users ,
long presidioId , ServiceContext serviceContext )
throws ParseException , SystemException , PortalException {
Organization org = OrganizationLocalServiceUtil . fetchOrganization ( presidioId ) ;
Date datePlus = datePlusOneDay ( date ) ;
if ( date . before ( datePlus ) & & ( endDate . after ( datePlus ) | | isSameDate ( endDate , datePlus ) ) ) {
if ( date . before ( datePlus ) & & ( endDate . after ( datePlus ) | | isSameDate ( endDate , datePlus ) ) ) {
Calendar calendarStartDate = Calendar . getInstance ( ) ;
calendarStartDate . setTime ( datePlus ) ;
if ( calendarStartDate . get ( Calendar . DAY_OF_WEEK ) = = giornoSettimana ) {
if ( calendarStartDate . get ( Calendar . DAY_OF_WEEK ) = = giornoSettimana ) {
Date startDateToInsert = formatDateTime ( oraInizio , datePlus ) ;
Date endDateToInsert = formatDateTime ( oraFine , datePlus ) ;
for ( User user : users ) {
SimpleDateFormat sdf = new SimpleDateFormat ( "dd/MM/yyyy" ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "funzionarioId" , user . getUserId ( ) ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "exactDate" , sdf . format ( startDateToInsert ) ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "groupId" , org . getGroupId ( ) ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "startDate" , startDateToInsert ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "endDate" , endDateToInsert ) ) ;
@SuppressWarnings ( "unchecked" )
//Bug 32935
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "startDate" , startDateToInsert ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "endDate" , endDateToInsert ) ) ;
List < Disponibilita > results = disponibilitaPersistence . findWithDynamicQuery ( dynamicQuery ) ;
if ( results . isEmpty ( ) ) {
addDisponibilita ( serviceContext . getUserId ( ) , user . getUserId ( ) , startDateToInsert ,
endDateToInsert , presidioId , serviceContext ) ;
} else {
for ( Iterator < Disponibilita > iterator = results . iterator ( ) ; iterator . hasNext ( ) ; ) {
Disponibilita disponibilita = iterator . next ( ) ;
if ( results . isEmpty ( ) ) {
addDisponibilita ( serviceContext . getUserId ( ) , user . getUserId ( ) , startDateToInsert , endDateToInsert ,
presidioId , serviceContext ) ;
}
//Bug 32935
else {
for ( Iterator iterator = results . iterator ( ) ; iterator . hasNext ( ) ; ) {
Disponibilita disponibilita = ( Disponibilita ) iterator . next ( ) ;
disponibilita . setDisponibile ( true ) ;
updateDisponibilita ( disponibilita ) ;
disponibilitaLocalService . updateDisponibilita ( disponibilita ) ;
}
}
}
addDayForDisponibilita ( datePlus , endDate , oraInizio , oraFine , giornoSettimana , users , presidioId ,
serviceContext ) ;
addDayForDisponibilita ( datePlus , endDate , oraInizio , oraFine , giornoSettimana , users ,
presidioId , serviceContext ) ;
} else {
addDayForDisponibilita ( datePlus , endDate , oraInizio , oraFine , giornoSettimana , users , presidioId ,
serviceContext ) ;
addDayForDisponibilita ( datePlus , endDate , oraInizio , oraFine , giornoSettimana , users ,
presidioId , serviceContext ) ;
}
}
}
private Date datePlusOneDay ( Date date ) {
private Date datePlusOneDay ( Date date ) {
Calendar calendar = Calendar . getInstance ( ) ;
calendar . setTime ( date ) ;
calendar . add ( Calendar . DATE , 1 ) ;
return calendar . getTime ( ) ;
}
private boolean isSameDate ( Date date1 , Date date2 ) {
private boolean isSameDate ( Date date1 , Date date2 ) {
Calendar cal1 = Calendar . getInstance ( ) ;
Calendar cal2 = Calendar . getInstance ( ) ;
cal1 . setTime ( date1 ) ;
cal2 . setTime ( date2 ) ;
boolean sameDay =
cal1 . get ( Calendar . YEAR ) = = cal2 . get ( Calendar . YEAR )
& & cal1 . get ( Calendar . DAY_OF_YEAR ) = = cal2 . get ( Calendar . DAY_OF_YEAR ) ;
boolean sameDay = cal1 . get ( Calendar . YEAR ) = = cal2 . get ( Calendar . YEAR ) & &
cal1 . get ( Calendar . DAY_OF_YEAR ) = = cal2 . get ( Calendar . DAY_OF_YEAR ) ;
return sameDay ;
}
@SuppressWarnings ( "unchecked" )
@Override
public List < Disponibilita > findByStartDate ( Date date ) throws SystemException {
Date start = DateUtils . truncate ( date , Calendar . DAY_OF_MONTH ) ;
Date end = DateUtils . addDays ( start , 1 ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . between ( "startDate" , start , end ) ) ;
dynamicQuery . addOrder ( OrderFactoryUtil . desc ( "funzionarioId" ) ) ;
return disponibilitaPersistence . findWithDynamicQuery ( dynamicQuery ) ;
}
@Override
public List < Disponibilita > findByFunzionarioStartAndPresidio ( long funzionarioId , Date date , long presidio )
throws SystemException {
}
public List < Disponibilita > findByFunzionarioStartAndPresidio ( long funzionarioId , Date date , long presidio ) throws SystemException {
Date start = DateUtils . truncate ( date , Calendar . DAY_OF_MONTH ) ;
Date end = DateUtils . addHours ( start , 22 ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "funzionarioId" , funzionarioId ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . ge ( "startDate" , start ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . lt ( "endDate" , end ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "groupId" , presidio ) ) ;
@SuppressWarnings ( "unchecked" )
List < Disponibilita > results = disponibilitaPersistence . findWithDynamicQuery ( dynamicQuery ) ;
return results ;
}
@SuppressWarnings ( "unchecked" )
@Override
public List < Disponibilita > findByFunzionario_StartDate ( long funzionarioId , Date date , long presidio )
throws SystemException {
}
public List < Disponibilita > findByFunzionario_StartDate ( long funzionarioId , Date date , long presidio ) throws SystemException {
Date start = DateUtils . truncate ( date , Calendar . DAY_OF_MONTH ) ;
Date end = DateUtils . addHours ( start , 22 ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "funzionarioId" , funzionarioId ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . ge ( "startDate" , start ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . lt ( "endDate" , end ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "groupId" , presidio ) ) ;
return disponibilitaPersistence . findWithDynamicQuery ( dynamicQuery ) ;
List < Disponibilita > results = disponibilitaPersistence . findWithDynamicQuery ( dynamicQuery ) ;
return results ;
}
@SuppressWarnings ( "unchecked" )
@Override
public List < Disponibilita > findByFunzionarioStartDate ( long funzionarioId , Date date , int startRow , int endRow )
throws SystemException {
public List < Disponibilita > findByFunzionarioStartDate ( long funzionarioId , Date date , int startRow , int endRow ) throws SystemException {
Date start = DateUtils . truncate ( date , Calendar . DAY_OF_MONTH ) ;
Date end = DateUtils . addHours ( start , 22 ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "funzionarioId" , funzionarioId ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . ge ( "startDate" , start ) ) ;
Order defaultOrder = OrderFactoryUtil . asc ( "startDate" ) ;
dynamicQuery . addOrder ( defaultOrder ) ;
return dynamicQuery ( dynamicQuery , startRow , endRow ) ;
List < Disponibilita > results = disponibilitaLocalService . dynamicQuery ( dynamicQuery , startRow , endRow ) ;
return results ;
}
@Override
public int countByFunzionarioStartDate ( long funzionarioId , Date date ) throws SystemException {
Date start = DateUtils . truncate ( date , Calendar . DAY_OF_MONTH ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "funzionarioId" , funzionarioId ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . ge ( "startDate" , start ) ) ;
Order defaultOrder = OrderFactoryUtil . asc ( "startDate" ) ;
dynamicQuery . addOrder ( defaultOrder ) ;
return dynamicQuery ( dynamicQuery , QueryUtil . ALL_POS , QueryUtil . ALL_POS ) . size ( ) ;
List < Disponibilita > results = disponibilitaLocalService . dynamicQuery ( dynamicQuery , - 1 , - 1 ) ;
return results . size ( ) ;
}
@SuppressWarnings ( "unchecked" )
@Override
public List < Disponibilita > findByPOStartDateAndFilters ( long funzionarioId , Date date , int startRow , int endRow ,
String provinciaFilter , String funzionarioIdFilter ) throws SystemException {
public List < Disponibilita > findByPOStartDateAndFilters ( long funzionarioId , Date date , int startRow , int endRow , String provinciaFilter , String funzionarioIdFilter ) throws SystemException {
User user = UserLocalServiceUtil . fetchUser ( funzionarioId ) ;
User user = userLocalService . fetchUser ( funzionarioId ) ;
List < Long > orgIds = new ArrayList < Long > ( ) ;
try {
Role dirigenteGenerale = RoleLocalServiceUtil . getRole ( user . getCompanyId ( ) , "dirigente_generale" ) ;
boolean isDirigenteGenerale =
RoleLocalServiceUtil . hasUserRole ( user . getUserId ( ) , dirigenteGenerale . getRoleId ( ) ) ;
if ( isDirigenteGenerale ) {
List < Organization > orgs =
OrganizationLocalServiceUtil . getOrganizations ( QueryUtil . ALL_POS , QueryUtil . ALL_POS ) ;
boolean isDirigenteGenerale = RoleLocalServiceUtil . hasUserRole ( user . getUserId ( ) , dirigenteGenerale . getRoleId ( ) ) ;
if ( isDirigenteGenerale ) {
List < Organization > orgs = OrganizationLocalServiceUtil . getOrganizations ( - 1 , - 1 ) ;
for ( Organization organization : orgs ) {
if ( organization . getParentOrganization ( ) ! = null ) {
if ( organization . getParentOrganization ( ) ! = null ) {
orgIds . add ( organization . getOrganizationId ( ) ) ;
}
}
} else {
List < Organization > orgs = OrganizationLocalServiceUtil . getUserOrganizations ( funzionarioId ) ;
for ( Organization organization : orgs ) {
Role portosPO = RoleLocalServiceUtil . getRole ( organization . getCompanyId ( ) , "portos_po" ) ;
boolean isPO =
UserGroupRoleLocalServiceUtil . hasUserGroupRole ( funzionarioId , organization . getGroupId ( ) ,
portosPO . getRoleId ( ) ) ;
if ( isPO ) {
boolean isPO = UserGroupRoleLocalServiceUtil . hasUserGroupRole (
funzionarioId , organization . getGroupId ( ) , portosPO . getRoleId ( ) ) ;
if ( isPO ) {
orgIds . add ( organization . getOrganizationId ( ) ) ;
}
}
}
} catch ( PortalException e ) {
_log . error ( e , e ) ;
_log . error ( e , e ) ;
}
Date start = DateUtils . truncate ( date , Calendar . DAY_OF_MONTH ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
if ( provinciaFilter . equals ( "-1" ) | | provinciaFilter . equals ( StringPool . BLANK ) ) {
dynamicQuery . add ( PropertyFactoryUtil . forName ( "presidio" ) . in ( orgIds . toArray ( ) ) ) ;
} else {
if ( ! provinciaFilter . equals ( "-1" ) & & ! provinciaFilter . equals ( "" ) ) {
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "presidio" , Long . valueOf ( provinciaFilter ) ) ) ;
}
if ( funzionarioIdFilter . equals ( "-1" ) | | funzionarioIdFilter . equals ( StringPool . BLANK ) ) {
dynamicQuery . add ( RestrictionsFactoryUtil . ne ( "funzionarioId" , funzionarioId ) ) ;
} else {
dynamicQuery . add ( PropertyFactoryUtil . forName ( "presidio" ) . in ( orgIds . toArray ( ) ) ) ;
}
if ( ! funzionarioIdFilter . equals ( "-1" ) & & ! funzionarioIdFilter . equals ( "" ) ) {
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "funzionarioId" , Long . valueOf ( funzionarioIdFilter ) ) ) ;
} else {
dynamicQuery . add ( RestrictionsFactoryUtil . ne ( "funzionarioId" , funzionarioId ) ) ;
}
dynamicQuery . add ( RestrictionsFactoryUtil . ge ( "startDate" , start ) ) ;
Order defaultOrder = OrderFactoryUtil . asc ( "startDate" ) ;
dynamicQuery . addOrder ( defaultOrder ) ;
return dynamicQuery ( dynamicQuery , startRow , endRow ) ;
List < Disponibilita > results = disponibilitaLocalService . dynamicQuery ( dynamicQuery , startRow , endRow ) ;
return results ;
}
@Override
public int countByPOStartDateAndFilters ( long funzionarioId , Date date , String provinciaFilter ,
String funzionarioIdFilter ) throws SystemException {
public int countByPOStartDateAndFilters ( long funzionarioId , Date date , String provinciaFilter , String funzionarioIdFilter ) throws SystemException {
User user = UserLocalServiceUtil . fetchUser ( funzionarioId ) ;
User user = userLocalService . fetchUser ( funzionarioId ) ;
List < Long > orgIds = new ArrayList < Long > ( ) ;
try {
Role dirigenteGenerale = RoleLocalServiceUtil . getRole ( user . getCompanyId ( ) , "dirigente_generale" ) ;
boolean isDirigenteGenerale =
RoleLocalServiceUtil . hasUserRole ( user . getUserId ( ) , dirigenteGenerale . getRoleId ( ) ) ;
if ( isDirigenteGenerale ) {
List < Organization > orgs =
OrganizationLocalServiceUtil . getOrganizations ( QueryUtil . ALL_POS , QueryUtil . ALL_POS ) ;
boolean isDirigenteGenerale = RoleLocalServiceUtil . hasUserRole ( user . getUserId ( ) , dirigenteGenerale . getRoleId ( ) ) ;
if ( isDirigenteGenerale ) {
List < Organization > orgs = OrganizationLocalServiceUtil . getOrganizations ( - 1 , - 1 ) ;
for ( Organization organization : orgs ) {
if ( organization . getParentOrganization ( ) ! = null ) {
if ( organization . getParentOrganization ( ) ! = null ) {
orgIds . add ( organization . getOrganizationId ( ) ) ;
}
}
} else {
List < Organization > orgs = OrganizationLocalServiceUtil . getUserOrganizations ( funzionarioId ) ;
for ( Organization organization : orgs ) {
Role portosPO = RoleLocalServiceUtil . getRole ( organization . getCompanyId ( ) , "portos_po" ) ;
boolean isPO =
UserGroupRoleLocalServiceUtil . hasUserGroupRole ( funzionarioId , organization . getGroupId ( ) ,
portosPO . getRoleId ( ) ) ;
if ( isPO ) {
boolean isPO = UserGroupRoleLocalServiceUtil . hasUserGroupRole (
funzionarioId , organization . getGroupId ( ) , portosPO . getRoleId ( ) ) ;
if ( isPO ) {
orgIds . add ( organization . getOrganizationId ( ) ) ;
}
}
}
} catch ( PortalException e ) {
_log . error ( e , e ) ;
_log . error ( e , e ) ;
}
Date start = DateUtils . truncate ( date , Calendar . DAY_OF_MONTH ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
if ( provinciaFilter . equals ( "-1" ) | | provinciaFilter . equals ( StringPool . BLANK ) ) {
dynamicQuery . add ( PropertyFactoryUtil . forName ( "presidio" ) . in ( orgIds . toArray ( ) ) ) ;
} else {
if ( ! provinciaFilter . equals ( "-1" ) & & ! provinciaFilter . equals ( "" ) ) {
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "presidio" , Long . valueOf ( provinciaFilter ) ) ) ;
}
if ( funzionarioIdFilter . equals ( "-1" ) | | funzionarioIdFilter . equals ( StringPool . BLANK ) ) {
dynamicQuery . add ( RestrictionsFactoryUtil . ne ( "funzionarioId" , funzionarioId ) ) ;
} else {
dynamicQuery . add ( PropertyFactoryUtil . forName ( "presidio" ) . in ( orgIds . toArray ( ) ) ) ;
}
if ( ! funzionarioIdFilter . equals ( "-1" ) & & ! funzionarioIdFilter . equals ( "" ) ) {
dynamicQuery . add ( RestrictionsFactoryUtil . eq ( "funzionarioId" , Long . valueOf ( funzionarioIdFilter ) ) ) ;
} else {
dynamicQuery . add ( RestrictionsFactoryUtil . ne ( "funzionarioId" , funzionarioId ) ) ;
}
dynamicQuery . add ( RestrictionsFactoryUtil . ge ( "startDate" , start ) ) ;
Order defaultOrder = OrderFactoryUtil . asc ( "startDate" ) ;
dynamicQuery . addOrder ( defaultOrder ) ;
return dynamicQuery ( dynamicQuery , QueryUtil . ALL_POS , QueryUtil . ALL_POS ) . size ( ) ;
List < Disponibilita > results = disponibilitaLocalService . dynamicQuery ( dynamicQuery , - 1 , - 1 ) ;
return results . size ( ) ;
}
@SuppressWarnings ( "unchecked" )
@Override
public List < Disponibilita > findByPOStartDate ( long funzionarioId , Date date , int startRow , int endRow )
throws SystemException {
public List < Disponibilita > findByPOStartDate ( long funzionarioId , Date date , int startRow , int endRow ) throws SystemException {
User user = UserLocalServiceUtil . fetchUser ( funzionarioId ) ;
User user = userLocalService . fetchUser ( funzionarioId ) ;
List < Long > orgIds = new ArrayList < Long > ( ) ;
try {
Role dirigenteGenerale = RoleLocalServiceUtil . getRole ( user . getCompanyId ( ) , "dirigente_generale" ) ;
boolean isDirigenteGenerale =
RoleLocalServiceUtil . hasUserRole ( user . getUserId ( ) , dirigenteGenerale . getRoleId ( ) ) ;
if ( isDirigenteGenerale ) {
List < Organization > orgs =
OrganizationLocalServiceUtil . getOrganizations ( QueryUtil . ALL_POS , QueryUtil . ALL_POS ) ;
boolean isDirigenteGenerale = RoleLocalServiceUtil . hasUserRole ( user . getUserId ( ) , dirigenteGenerale . getRoleId ( ) ) ;
if ( isDirigenteGenerale ) {
List < Organization > orgs = OrganizationLocalServiceUtil . getOrganizations ( - 1 , - 1 ) ;
for ( Organization organization : orgs ) {
if ( organization . getParentOrganization ( ) ! = null ) {
if ( organization . getParentOrganization ( ) ! = null ) {
orgIds . add ( organization . getOrganizationId ( ) ) ;
}
}
} else {
List < Organization > orgs = OrganizationLocalServiceUtil . getUserOrganizations ( funzionarioId ) ;
for ( Organization organization : orgs ) {
Role portosPO = RoleLocalServiceUtil . getRole ( organization . getCompanyId ( ) , "portos_po" ) ;
boolean isPO =
UserGroupRoleLocalServiceUtil . hasUserGroupRole ( funzionarioId , organization . getGroupId ( ) ,
portosPO . getRoleId ( ) ) ;
if ( isPO ) {
boolean isPO = UserGroupRoleLocalServiceUtil . hasUserGroupRole (
funzionarioId , organization . getGroupId ( ) , portosPO . getRoleId ( ) ) ;
if ( isPO ) {
orgIds . add ( organization . getOrganizationId ( ) ) ;
}
}
}
} catch ( PortalException e ) {
_log . error ( e , e ) ;
_log . error ( e , e ) ;
}
Date start = DateUtils . truncate ( date , Calendar . DAY_OF_MONTH ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
dynamicQuery . add ( PropertyFactoryUtil . forName ( "presidio" ) . in ( orgIds . toArray ( ) ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . ne ( "funzionarioId" , funzionarioId ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . ge ( "startDate" , start ) ) ;
Order defaultOrder = OrderFactoryUtil . asc ( "startDate" ) ;
dynamicQuery . addOrder ( defaultOrder ) ;
return dynamicQuery ( dynamicQuery , startRow , endRow ) ;
List < Disponibilita > results = disponibilitaLocalService . dynamicQuery ( dynamicQuery , startRow , endRow ) ;
return results ;
}
@Override
public int countByPOStartDate ( long funzionarioId , Date date ) throws SystemException {
User user = userLocalService . fetchUser ( funzionarioId ) ;
User user = UserLocalServiceUtil . fetchUser ( funzionarioId ) ;
List < Long > orgIds = new ArrayList < Long > ( ) ;
try {
Role dirigenteGenerale = RoleLocalServiceUtil . getRole ( user . getCompanyId ( ) , "dirigente_generale" ) ;
boolean isDirigenteGenerale =
RoleLocalServiceUtil . hasUserRole ( user . getUserId ( ) , dirigenteGenerale . getRoleId ( ) ) ;
if ( isDirigenteGenerale ) {
List < Organization > orgs =
OrganizationLocalServiceUtil . getOrganizations ( QueryUtil . ALL_POS , QueryUtil . ALL_POS ) ;
boolean isDirigenteGenerale = RoleLocalServiceUtil . hasUserRole ( user . getUserId ( ) , dirigenteGenerale . getRoleId ( ) ) ;
if ( isDirigenteGenerale ) {
List < Organization > orgs = OrganizationLocalServiceUtil . getOrganizations ( - 1 , - 1 ) ;
for ( Organization organization : orgs ) {
if ( organization . getParentOrganization ( ) ! = null ) {
if ( organization . getParentOrganization ( ) ! = null ) {
orgIds . add ( organization . getOrganizationId ( ) ) ;
}
}
} else {
List < Organization > orgs = OrganizationLocalServiceUtil . getUserOrganizations ( funzionarioId ) ;
for ( Organization organization : orgs ) {
Role portosPO = RoleLocalServiceUtil . getRole ( organization . getCompanyId ( ) , "portos_po" ) ;
boolean isPO =
UserGroupRoleLocalServiceUtil . hasUserGroupRole ( funzionarioId , organization . getGroupId ( ) ,
portosPO . getRoleId ( ) ) ;
if ( isPO ) {
boolean isPO = UserGroupRoleLocalServiceUtil . hasUserGroupRole (
funzionarioId , organization . getGroupId ( ) , portosPO . getRoleId ( ) ) ;
if ( isPO ) {
orgIds . add ( organization . getOrganizationId ( ) ) ;
}
}
}
} catch ( PortalException e ) {
_log . error ( e , e ) ;
_log . error ( e , e ) ;
}
Date start = DateUtils . truncate ( date , Calendar . DAY_OF_MONTH ) ;
DynamicQuery dynamicQuery = dynamicQuery ( ) ;
dynamicQuery . add ( PropertyFactoryUtil . forName ( "presidio" ) . in ( orgIds . toArray ( ) ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . ne ( "funzionarioId" , funzionarioId ) ) ;
dynamicQuery . add ( RestrictionsFactoryUtil . ge ( "startDate" , start ) ) ;
Order defaultOrder = OrderFactoryUtil . asc ( "startDate" ) ;
dynamicQuery . addOrder ( defaultOrder ) ;
return dynamicQuery ( dynamicQuery , QueryUtil . ALL_POS , QueryUtil . ALL_POS ) . size ( ) ;
List < Disponibilita > results = disponibilitaLocalService . dynamicQuery ( dynamicQuery , - 1 , - 1 ) ;
return results . size ( ) ;
}
private Date formatDateTime ( String orario , Date day ) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat ( "HH:mm" ) ;
Date data = sdf . parse ( orario ) ;
Calendar calendar = GregorianCalendar . getInstance ( ) ;
calendar . setTime ( data ) ;
Date date = DateUtils . addHours ( day , calendar . get ( Calendar . HOUR_OF_DAY ) ) ;
date = DateUtils . addMinutes ( date , calendar . get ( Calendar . MINUTE ) ) ;
return date ;
}
}