Changes to EmailSending feature.

Code refactoring.
This commit is contained in:
Vova Perebykivskyi 2016-11-09 18:03:47 +02:00
parent dd06b250c3
commit acbb41cddf
33 changed files with 144 additions and 111 deletions

View file

@ -27,7 +27,7 @@ import java.util.List;
* DAO interface for the <code>Limits</code> entity. * DAO interface for the <code>Limits</code> entity.
* Contract for {@link LimitsDAO}. * Contract for {@link LimitsDAO}.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 17.12.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public interface ILimitsDAO extends IGenericDAO<Limits, Long> { public interface ILimitsDAO extends IGenericDAO<Limits, Long> {

View file

@ -27,7 +27,7 @@ import java.util.List;
/** /**
* DAO for {@link Limits}. * DAO for {@link Limits}.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 24.09.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
@Repository @Repository
@ -41,16 +41,22 @@ public class LimitsDAO extends GenericDAOHibernate<Limits, Long> implements ILim
@Override @Override
public Limits getUsersType() { public Limits getUsersType() {
List<Limits> list = list(Limits.class); List<Limits> list = list(Limits.class);
for (Limits item : list) for (Limits item : list) {
if (item.getType().equals("users")) return item; if ("users".equals(item.getType())) {
return item;
}
}
return null; return null;
} }
@Override @Override
public Limits getResourcesType() { public Limits getResourcesType() {
List<Limits> list = list(Limits.class); List<Limits> list = list(Limits.class);
for (Limits item : list) for (Limits item : list) {
if (item.getType().equals("workers+machines")) return item; if ("workers+machines".equals(item.getType())) {
return item;
}
}
return null; return null;
} }
} }

View file

@ -26,7 +26,7 @@ import org.libreplan.business.common.BaseEntity;
* This class is intended to work as a Hibernate component. * This class is intended to work as a Hibernate component.
* It represents the limit that can be modified only in database. * It represents the limit that can be modified only in database.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 17.12.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public class Limits extends BaseEntity { public class Limits extends BaseEntity {
@ -38,6 +38,7 @@ public class Limits extends BaseEntity {
public String getType() { public String getType() {
return type; return type;
} }
public void setType(String type) { public void setType(String type) {
this.type = type; this.type = type;
} }
@ -45,6 +46,7 @@ public class Limits extends BaseEntity {
public Integer getValue() { public Integer getValue() {
return value; return value;
} }
public void setValue(Integer value) { public void setValue(Integer value) {
this.value = value; this.value = value;
} }

View file

@ -28,9 +28,9 @@ import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
/** /**
* Dao for {@link EmailNotification} * DAO for {@link EmailNotification}.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 19.10.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
@Repository @Repository
public class EmailNotificationDAO public class EmailNotificationDAO
@ -58,7 +58,7 @@ public class EmailNotificationDAO
getSession().delete(item); getSession().delete(item);
} }
return list(EmailNotification.class).size() == 0; return list(EmailNotification.class).isEmpty();
} }
@Override @Override
@ -76,7 +76,7 @@ public class EmailNotificationDAO
.createCriteria(EmailNotification.class) .createCriteria(EmailNotification.class)
.add(Restrictions.eq("type", enumeration.ordinal())) .add(Restrictions.eq("type", enumeration.ordinal()))
.list() .list()
.size() == 0; .isEmpty();
} }
@Override @Override

View file

@ -33,7 +33,7 @@ import java.util.List;
/** /**
* DAO for {@link EmailTemplate} * DAO for {@link EmailTemplate}
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 24.09.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
@Repository @Repository
public class EmailTemplateDAO extends GenericDAOHibernate<EmailTemplate, Long> implements IEmailTemplateDAO { public class EmailTemplateDAO extends GenericDAOHibernate<EmailTemplate, Long> implements IEmailTemplateDAO {
@ -68,6 +68,7 @@ public class EmailTemplateDAO extends GenericDAOHibernate<EmailTemplate, Long> i
public void delete(EmailTemplate entity) { public void delete(EmailTemplate entity) {
try { try {
remove(entity.getId()); remove(entity.getId());
} catch (InstanceNotFoundException ignored) {} } catch (InstanceNotFoundException ignored) {
}
} }
} }

View file

@ -28,7 +28,7 @@ import java.util.List;
/** /**
* Contract for {@link EmailNotificationDAO} * Contract for {@link EmailNotificationDAO}
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 19.10.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public interface IEmailNotificationDAO extends IGenericDAO<EmailNotification, Long> { public interface IEmailNotificationDAO extends IGenericDAO<EmailNotification, Long> {

View file

@ -30,7 +30,7 @@ import java.util.List;
* DAO interface for the <code>EmailTemplate</code> entity. * DAO interface for the <code>EmailTemplate</code> entity.
* Contract for {@link EmailTemplateDAO}. * Contract for {@link EmailTemplateDAO}.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 29.09.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public interface IEmailTemplateDAO extends IGenericDAO<EmailTemplate, Long>{ public interface IEmailTemplateDAO extends IGenericDAO<EmailTemplate, Long>{

View file

@ -31,7 +31,7 @@ import java.util.Date;
* This class is intended to work as a Hibernate component. * This class is intended to work as a Hibernate component.
* It represents the Email notification to be send to user. * It represents the Email notification to be send to user.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 19.10.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public class EmailNotification extends BaseEntity { public class EmailNotification extends BaseEntity {
@ -49,6 +49,7 @@ public class EmailNotification extends BaseEntity {
public EmailTemplateEnum getType() { public EmailTemplateEnum getType() {
return type; return type;
} }
public void setType(EmailTemplateEnum type) { public void setType(EmailTemplateEnum type) {
this.type = type; this.type = type;
} }
@ -56,6 +57,7 @@ public class EmailNotification extends BaseEntity {
public Date getUpdated() { public Date getUpdated() {
return updated; return updated;
} }
public void setUpdated(Date updated) { public void setUpdated(Date updated) {
this.updated = updated; this.updated = updated;
} }
@ -63,6 +65,7 @@ public class EmailNotification extends BaseEntity {
public Resource getResource() { public Resource getResource() {
return resource; return resource;
} }
public void setResource(Resource resource) { public void setResource(Resource resource) {
this.resource = resource; this.resource = resource;
} }
@ -70,6 +73,7 @@ public class EmailNotification extends BaseEntity {
public TaskElement getTask() { public TaskElement getTask() {
return task; return task;
} }
public void setTask(TaskElement task) { public void setTask(TaskElement task) {
this.task = task; this.task = task;
} }
@ -77,6 +81,7 @@ public class EmailNotification extends BaseEntity {
public TaskElement getProject() { public TaskElement getProject() {
return project; return project;
} }
public void setProject(TaskElement project) { public void setProject(TaskElement project) {
this.project = project; this.project = project;
} }

View file

@ -27,7 +27,7 @@ import org.libreplan.business.settings.entities.Language;
* This class is intended to work as a Hibernate component. * This class is intended to work as a Hibernate component.
* It represents the E-mail template to be modified by admin and send to user. * It represents the E-mail template to be modified by admin and send to user.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 29.09.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public class EmailTemplate extends BaseEntity { public class EmailTemplate extends BaseEntity {
@ -42,6 +42,7 @@ public class EmailTemplate extends BaseEntity {
public EmailTemplateEnum getType() { public EmailTemplateEnum getType() {
return type; return type;
} }
public void setType(EmailTemplateEnum type) { public void setType(EmailTemplateEnum type) {
this.type = type; this.type = type;
} }
@ -49,6 +50,7 @@ public class EmailTemplate extends BaseEntity {
public Language getLanguage() { public Language getLanguage() {
return language; return language;
} }
public void setLanguage(Language language) { public void setLanguage(Language language) {
this.language = language; this.language = language;
} }
@ -56,6 +58,7 @@ public class EmailTemplate extends BaseEntity {
public String getContent() { public String getContent() {
return content != null ? content : ""; return content != null ? content : "";
} }
public void setContent(String content) { public void setContent(String content) {
this.content = content; this.content = content;
} }
@ -63,6 +66,7 @@ public class EmailTemplate extends BaseEntity {
public String getSubject() { public String getSubject() {
return subject != null ? subject : ""; return subject != null ? subject : "";
} }
public void setSubject(String subject) { public void setSubject(String subject) {
this.subject = subject; this.subject = subject;
} }

View file

@ -24,10 +24,10 @@ import static org.libreplan.business.i18n.I18nHelper._;
/** /**
* Available E-mail templates. * Available E-mail templates.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 28.09.2015.
*
* TEMPLATE_N(_("Template N")) - for i18n * TEMPLATE_N(_("Template N")) - for i18n
* TEMPLATE_A("Template A") - for general use (no internationalizing) * TEMPLATE_A("Template A") - for general use (no internationalizing)
*
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public enum EmailTemplateEnum { public enum EmailTemplateEnum {

View file

@ -26,7 +26,7 @@ import org.libreplan.business.orders.entities.OrderFile;
import java.util.List; import java.util.List;
/** /**
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 12.24.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public interface IOrderFileDAO extends IGenericDAO<OrderFile, Long> { public interface IOrderFileDAO extends IGenericDAO<OrderFile, Long> {

View file

@ -29,7 +29,9 @@ import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
/** /**
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 12.24.2015. * DAO for {@link OrderFile}.
*
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
@Repository @Repository
@ -44,7 +46,8 @@ public class OrderFileDAO extends GenericDAOHibernate<OrderFile, Long> implement
public void delete(OrderFile file) { public void delete(OrderFile file) {
try { try {
remove(file.getId()); remove(file.getId());
} catch (InstanceNotFoundException ignored) {} } catch (InstanceNotFoundException ignored) {
}
} }
@Override @Override

View file

@ -27,9 +27,9 @@ import java.util.Date;
/** /**
* OrderFile entity representing table: files. * OrderFile entity representing table: files.
* This class is intended to work as a Hibernate component. * This class is intended to work as a Hibernate component.
* It represents the LibrePlan File to be stored in customer`s HDD. * It represents the LibrePlan File to be stored in customer`s data storage.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 25.12.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public class OrderFile extends BaseEntity { public class OrderFile extends BaseEntity {

View file

@ -35,17 +35,17 @@ import org.libreplan.business.resources.entities.ResourceType;
import org.libreplan.business.resources.entities.Worker; import org.libreplan.business.resources.entities.Worker;
/** /**
* Conversation for worker search * Conversation for worker search.
* *
* @author Diego Pino Garcia <dpino@igalia.com> * @author Diego Pino Garcia <dpino@igalia.com>
*/ */
public interface IResourcesSearcher { public interface IResourcesSearcher {
public interface IResourcesQuery<T extends Resource> { interface IResourcesQuery<T extends Resource> {
/** /**
* Restrict the result to resources that have name as a substring. The * Restrict the result to resources that have name as a substring.
* match is case insensitive. * The match is case insensitive.
* *
* @param name * @param name
* @return this same object in order to cascade calls * @return this same object in order to cascade calls
@ -53,8 +53,7 @@ public interface IResourcesSearcher {
IResourcesQuery<T> byName(String name); IResourcesQuery<T> byName(String name);
/** /**
* Restrict the result to a list of {@link Resource} satisfying all * Restrict the result to a list of {@link Resource} satisfying all criteria at some point in time.
* criteria at some point in time
* *
* @param criteria * @param criteria
* @return this same object in order to cascade calls * @return this same object in order to cascade calls
@ -62,9 +61,9 @@ public interface IResourcesSearcher {
IResourcesQuery<T> byCriteria(Collection<? extends Criterion> criteria); IResourcesQuery<T> byCriteria(Collection<? extends Criterion> criteria);
/** /**
* Restrict resources to the ones having the provided type. By default * Restrict resources to the ones having the provided type.
* if this method is not called, the resources are restricted to the * By default if this method is not called, the resources are restricted to the type NON_LIMITING_RESOURCE.
* type NON_LIMITING_RESOURCE. *
* @param type * @param type
* @return this same object in order to cascade calls * @return this same object in order to cascade calls
*/ */
@ -73,48 +72,49 @@ public interface IResourcesSearcher {
/** /**
* Retrieve the list of resources that match the restrictions specified. * Retrieve the list of resources that match the restrictions specified.
* *
* @return * @return {@link List<T>}
*/ */
List<T> execute(); List<T> execute();
/** /**
* <p> * <p>
* Gets all {@link Criterion} and groups then by {@link CriterionType} * Gets all {@link Criterion} and groups then by {@link CriterionType} with the condition
* with the condition that the {@link CriterionType#getResource()} is of * that the {@link CriterionType#getResource()} is of a type compatible for this query.
* a type compatible for this query. * For example if this query has been created by {@link IResourcesSearcher#searchWorkers()}
* only the criteria with criterion type such its resource is {@link ResourceEnum#WORKER}.
* </p> * </p>
* For example if this query has been created by *
* {@link IResourcesSearcher#searchWorkers()} only the criteria with
* criterion type such its resource is {@link ResourceEnum.WORKER}
* @return HashMap<CriterionType, Set<Criterion>> * @return HashMap<CriterionType, Set<Criterion>>
*/ */
Map<CriterionType, Set<Criterion>> getCriteria(); Map<CriterionType, Set<Criterion>> getCriteria();
} }
/** /**
* Do the search limited to workers * Do the search limited to workers.
* *
* @return * @return {@link IResourcesQuery<Worker>}
*/ */
public IResourcesQuery<Worker> searchWorkers(); IResourcesQuery<Worker> searchWorkers();
/** /**
* Do the search limited to machines * Do the search limited to machines.
* @return * @return {@link IResourcesQuery<Machine>}
*/ */
public IResourcesQuery<Machine> searchMachines(); IResourcesQuery<Machine> searchMachines();
/** /**
* Search machines or workers based on the value of resourceType * Search machines or workers based on the value of resourceType.
*
* @param resourceType * @param resourceType
* @return * @return {@link IResourcesQuery<?>}
*/ */
public IResourcesQuery<?> searchBy(ResourceEnum resourceType); IResourcesQuery<?> searchBy(ResourceEnum resourceType);
/** /**
* Search both resources and machines * Search both resources and machines.
* @return *
* @return {@link IResourcesQuery<Resource>}
*/ */
public IResourcesQuery<Resource> searchBoth(); IResourcesQuery<Resource> searchBoth();
} }

View file

@ -24,7 +24,7 @@ import org.libreplan.business.email.entities.EmailNotification;
/** /**
* Sends E-mail to users with data that storing in notification_queue table. * Sends E-mail to users with data that storing in notification_queue table.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 13.10.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public interface IEmailNotificationJob { public interface IEmailNotificationJob {

View file

@ -30,7 +30,9 @@ import org.springframework.scheduling.quartz.QuartzJobBean;
* Sends E-mail to users with data that storing in notification_queue table * Sends E-mail to users with data that storing in notification_queue table
* and that are treat to {@link org.libreplan.business.email.entities.EmailTemplateEnum#TEMPLATE_MILESTONE_REACHED} * and that are treat to {@link org.libreplan.business.email.entities.EmailTemplateEnum#TEMPLATE_MILESTONE_REACHED}
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 20.01.2016. * It is used!
*
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public class SendEmailOnMilestoneReachedJob extends QuartzJobBean { public class SendEmailOnMilestoneReachedJob extends QuartzJobBean {

View file

@ -29,7 +29,9 @@ import org.springframework.scheduling.quartz.QuartzJobBean;
* Sends E-mail to users with data that storing in notification_queue table and that are treat to * Sends E-mail to users with data that storing in notification_queue table and that are treat to
* {@link org.libreplan.business.email.entities.EmailTemplateEnum#TEMPLATE_RESOURCE_REMOVED_FROM_TASK}. * {@link org.libreplan.business.email.entities.EmailTemplateEnum#TEMPLATE_RESOURCE_REMOVED_FROM_TASK}.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 20.01.2016. * It is used!
*
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public class SendEmailOnResourceRemovedFromTaskJob extends QuartzJobBean { public class SendEmailOnResourceRemovedFromTaskJob extends QuartzJobBean {

View file

@ -30,7 +30,7 @@ import org.springframework.scheduling.quartz.QuartzJobBean;
* Sends E-mail to users with data that storing in notification_queue table and that are treat to * Sends E-mail to users with data that storing in notification_queue table and that are treat to
* {@link org.libreplan.business.email.entities.EmailTemplateEnum#TEMPLATE_TASK_ASSIGNED_TO_RESOURCE}. * {@link org.libreplan.business.email.entities.EmailTemplateEnum#TEMPLATE_TASK_ASSIGNED_TO_RESOURCE}.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 13.10.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public class SendEmailOnTaskAssignedToResourceJob extends QuartzJobBean { public class SendEmailOnTaskAssignedToResourceJob extends QuartzJobBean {

View file

@ -29,7 +29,7 @@ import org.springframework.scheduling.quartz.QuartzJobBean;
* Sends E-mail to users with data that storing in notification_queue table and that are treat to * Sends E-mail to users with data that storing in notification_queue table and that are treat to
* {@link org.libreplan.business.email.entities.EmailTemplateEnum#TEMPLATE_TODAY_TASK_SHOULD_FINISH}. * {@link org.libreplan.business.email.entities.EmailTemplateEnum#TEMPLATE_TODAY_TASK_SHOULD_FINISH}.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 20.01.2016. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public class SendEmailOnTaskShouldFinishJob extends QuartzJobBean { public class SendEmailOnTaskShouldFinishJob extends QuartzJobBean {

View file

@ -30,7 +30,7 @@ import org.springframework.scheduling.quartz.QuartzJobBean;
* {@link org.libreplan.business.email.entities.EmailTemplateEnum#TEMPLATE_TODAY_TASK_SHOULD_START}. * {@link org.libreplan.business.email.entities.EmailTemplateEnum#TEMPLATE_TODAY_TASK_SHOULD_START}.
* *
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 20.01.2016 * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public class SendEmailOnTaskShouldStartJob extends QuartzJobBean { public class SendEmailOnTaskShouldStartJob extends QuartzJobBean {

View file

@ -29,7 +29,7 @@ import org.springframework.scheduling.quartz.QuartzJobBean;
* Sends E-mail to users with data that storing in notification_queue table and that are treat to * Sends E-mail to users with data that storing in notification_queue table and that are treat to
* {@link org.libreplan.business.email.entities.EmailTemplateEnum#TEMPLATE_ENTER_DATA_IN_TIMESHEET}. * {@link org.libreplan.business.email.entities.EmailTemplateEnum#TEMPLATE_ENTER_DATA_IN_TIMESHEET}.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 20.01.2016. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public class SendEmailOnTimesheetDataMissingJob extends QuartzJobBean { public class SendEmailOnTimesheetDataMissingJob extends QuartzJobBean {

View file

@ -50,7 +50,7 @@ import java.util.List;
* Date will be send on current date equals to deadline date of {@link org.zkoss.ganttz.data.Milestone}. * Date will be send on current date equals to deadline date of {@link org.zkoss.ganttz.data.Milestone}.
* But it will be only send to Manager (you can assign him in project properties). * But it will be only send to Manager (you can assign him in project properties).
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 20.01.2016. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
@Component @Component
@ -118,7 +118,10 @@ public class SendEmailOnMilestoneReached implements IEmailNotificationJob {
e.printStackTrace(); e.printStackTrace();
} }
if ( user.getWorker() != null && user.isInRole(UserRole.ROLE_EMAIL_MILESTONE_REACHED) ) { boolean userHasNeededRoles =
user.isInRole(UserRole.ROLE_SUPERUSER) || user.isInRole(UserRole.ROLE_EMAIL_MILESTONE_REACHED);
if ( user.getWorker() != null && userHasNeededRoles ) {
emailNotificationModel.setResource(user.getWorker()); emailNotificationModel.setResource(user.getWorker());
emailNotificationModel.setTask(item); emailNotificationModel.setTask(item);
emailNotificationModel.setProject(item.getParent()); emailNotificationModel.setProject(item.getParent());
@ -127,14 +130,14 @@ public class SendEmailOnMilestoneReached implements IEmailNotificationJob {
} }
public void checkMilestoneDate() { public void checkMilestoneDate() {
List<TaskElement> list = taskElementDAO.getTaskElementsWithMilestones(); List<TaskElement> milestones = taskElementDAO.getTaskElementsWithMilestones();
LocalDate date = new LocalDate(); LocalDate date = new LocalDate();
int currentYear = date.getYear(); int currentYear = date.getYear();
int currentMonth = date.getMonthOfYear(); int currentMonth = date.getMonthOfYear();
int currentDay = date.getDayOfMonth(); int currentDay = date.getDayOfMonth();
for (TaskElement item : list) { for (TaskElement item : milestones) {
if ( item.getDeadline() != null ) { if ( item.getDeadline() != null ) {
LocalDate deadline = item.getDeadline(); LocalDate deadline = item.getDeadline();

View file

@ -39,7 +39,7 @@ import java.util.List;
* and that are treat to {@link EmailTemplateEnum#TEMPLATE_RESOURCE_REMOVED_FROM_TASK}. * and that are treat to {@link EmailTemplateEnum#TEMPLATE_RESOURCE_REMOVED_FROM_TASK}.
* Data will be send if resource has been removed from task (in resource allocation) * Data will be send if resource has been removed from task (in resource allocation)
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 20.01.2016. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
@Component @Component
@ -65,12 +65,14 @@ public class SendEmailOnResourceRemovedFromTask implements IEmailNotificationJob
List<EmailNotification> notifications = List<EmailNotification> notifications =
emailNotificationModel.getAllByType(EmailTemplateEnum.TEMPLATE_RESOURCE_REMOVED_FROM_TASK); emailNotificationModel.getAllByType(EmailTemplateEnum.TEMPLATE_RESOURCE_REMOVED_FROM_TASK);
for (int i = 0; i < notifications.size(); i++) for (int i = 0; i < notifications.size(); i++) {
if ( composeMessageForUser(notifications.get(i)) ) if ( composeMessageForUser(notifications.get(i)) ) {
deleteSingleNotification(notifications.get(i)); deleteSingleNotification(notifications.get(i));
} }
} }
} }
}
}
@Override @Override
public boolean composeMessageForUser(EmailNotification notification) { public boolean composeMessageForUser(EmailNotification notification) {

View file

@ -41,7 +41,7 @@ import java.util.List;
* and that are treat to {@link EmailTemplateEnum#TEMPLATE_ENTER_DATA_IN_TIMESHEET}. * and that are treat to {@link EmailTemplateEnum#TEMPLATE_ENTER_DATA_IN_TIMESHEET}.
* Data will be send after user will be assigned to some task. * Data will be send after user will be assigned to some task.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 13.10.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
@Component @Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE) @Scope(BeanDefinition.SCOPE_PROTOTYPE)

View file

@ -98,6 +98,7 @@ public class SendEmailOnTaskShouldFinish implements IEmailNotificationJob {
@Transactional @Transactional
public void taskShouldFinish() { public void taskShouldFinish() {
// TODO resolve deprecated // TODO resolve deprecated
// Check if current date equals with item date // Check if current date equals with item date
Date date = new Date(); Date date = new Date();
int currentYear = date.getYear(); int currentYear = date.getYear();
@ -114,6 +115,7 @@ public class SendEmailOnTaskShouldFinish implements IEmailNotificationJob {
if ( currentYear == endYear && if ( currentYear == endYear &&
currentMonth == endMonth && currentMonth == endMonth &&
currentDay == endDay ) { currentDay == endDay ) {
// Get all resources for current task and send them email notification // Get all resources for current task and send them email notification
sendEmailNotificationAboutTaskShouldFinish(item); sendEmailNotificationAboutTaskShouldFinish(item);
} }

View file

@ -63,7 +63,7 @@ import java.util.List;
* and that are treat to {@link EmailTemplateEnum#TEMPLATE_ENTER_DATA_IN_TIMESHEET} * and that are treat to {@link EmailTemplateEnum#TEMPLATE_ENTER_DATA_IN_TIMESHEET}
* Data will be send for bound users with empty timesheet lines. * Data will be send for bound users with empty timesheet lines.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 20.01.2016. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
@Component @Component
@ -99,12 +99,14 @@ public class SendEmailOnTimesheetDataMissing implements IEmailNotificationJob {
List<EmailNotification> notifications = List<EmailNotification> notifications =
emailNotificationModel.getAllByType(EmailTemplateEnum.TEMPLATE_ENTER_DATA_IN_TIMESHEET); emailNotificationModel.getAllByType(EmailTemplateEnum.TEMPLATE_ENTER_DATA_IN_TIMESHEET);
for (int i = 0; i < notifications.size(); i++) for (int i = 0; i < notifications.size(); i++) {
if ( composeMessageForUser(notifications.get(i)) ) if ( composeMessageForUser(notifications.get(i)) ) {
deleteSingleNotification(notifications.get(i)); deleteSingleNotification(notifications.get(i));
} }
} }
} }
}
}
@Override @Override
public boolean composeMessageForUser(EmailNotification notification) { public boolean composeMessageForUser(EmailNotification notification) {
@ -205,8 +207,7 @@ public class SendEmailOnTimesheetDataMissing implements IEmailNotificationJob {
private PersonalTimesheetsPeriodicityEnum getPersonalTimesheetsPeriodicity() { private PersonalTimesheetsPeriodicityEnum getPersonalTimesheetsPeriodicity() {
return configurationDAO.getConfiguration().getPersonalTimesheetsPeriodicity(); return configurationDAO.getConfiguration().getPersonalTimesheetsPeriodicity();
} }
private WorkReport getWorkReport(Resource resource, LocalDate date, private WorkReport getWorkReport(Resource resource, LocalDate date, PersonalTimesheetsPeriodicityEnum periodicity) {
PersonalTimesheetsPeriodicityEnum periodicity) {
WorkReport workReport = workReportDAO.getPersonalTimesheetWorkReport(resource, date, periodicity); WorkReport workReport = workReportDAO.getPersonalTimesheetWorkReport(resource, date, periodicity);
forceLoad(workReport); forceLoad(workReport);

View file

@ -19,18 +19,13 @@
package org.libreplan.web.email; package org.libreplan.web.email;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.common.exceptions.ValidationException; import org.libreplan.business.common.exceptions.ValidationException;
import org.libreplan.business.settings.entities.Language; import org.libreplan.business.settings.entities.Language;
import org.libreplan.business.email.entities.EmailTemplateEnum; import org.libreplan.business.email.entities.EmailTemplateEnum;
import org.libreplan.business.users.daos.IUserDAO;
import org.libreplan.business.users.entities.User;
import org.libreplan.web.common.IMessagesForUser; import org.libreplan.web.common.IMessagesForUser;
import org.libreplan.web.common.Level; import org.libreplan.web.common.Level;
import org.libreplan.web.common.MessagesForUser; import org.libreplan.web.common.MessagesForUser;
import org.libreplan.web.security.SecurityUtils;
import org.springframework.transaction.annotation.Transactional;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
@ -50,15 +45,11 @@ import static org.libreplan.web.I18nHelper._;
/** /**
* Controller for page Edit email templates. * Controller for page Edit email templates.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 25.09.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public class EmailTemplateController extends GenericForwardComposer<Component> { public class EmailTemplateController extends GenericForwardComposer<Component> {
private IUserDAO userDAO;
private User user;
private IEmailTemplateModel emailTemplateModel; private IEmailTemplateModel emailTemplateModel;
private IMessagesForUser messages; private IMessagesForUser messages;
@ -77,9 +68,10 @@ public class EmailTemplateController extends GenericForwardComposer<Component> {
public EmailTemplateController() { public EmailTemplateController() {
userDAO = (IUserDAO) SpringUtil.getBean("userDAO"); if ( emailTemplateModel == null ) {
emailTemplateModel = (IEmailTemplateModel) SpringUtil.getBean("emailTemplateModel"); emailTemplateModel = (IEmailTemplateModel) SpringUtil.getBean("emailTemplateModel");
} }
}
@Override @Override
public void doAfterCompose(Component comp) throws Exception { public void doAfterCompose(Component comp) throws Exception {
@ -91,7 +83,6 @@ public class EmailTemplateController extends GenericForwardComposer<Component> {
* Set default template and language for user. * Set default template and language for user.
* And content and subject for that language & template. * And content and subject for that language & template.
*/ */
setUser();
setSelectedLanguage(Language.ENGLISH_LANGUAGE); setSelectedLanguage(Language.ENGLISH_LANGUAGE);
getContentDataBySelectedLanguage(); getContentDataBySelectedLanguage();
@ -226,12 +217,4 @@ public class EmailTemplateController extends GenericForwardComposer<Component> {
subjectTextbox.setValue(emailTemplateModel.getSubject(getSelectedLanguage(), getSelectedEmailTemplateEnum())); subjectTextbox.setValue(emailTemplateModel.getSubject(getSelectedLanguage(), getSelectedEmailTemplateEnum()));
} }
@Transactional
private void setUser() {
try {
user = userDAO.findByLoginName(SecurityUtils.getSessionUserLoginName());
} catch (InstanceNotFoundException e) {
throw new RuntimeException(e);
}
}
} }

View file

@ -36,7 +36,7 @@ import java.util.List;
/** /**
* Model for operations related to {@link EmailTemplate}. * Model for operations related to {@link EmailTemplate}.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 25.09.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
@Service @Service
@Scope(BeanDefinition.SCOPE_PROTOTYPE) @Scope(BeanDefinition.SCOPE_PROTOTYPE)
@ -142,6 +142,7 @@ public class EmailTemplateModel implements IEmailTemplateModel {
return template != null ? template.getSubject() : ""; return template != null ? template.getSubject() : "";
} }
@Override
public EmailTemplate getEmailTemplateByTypeAndLanguage(EmailTemplateEnum type, Language language) { public EmailTemplate getEmailTemplateByTypeAndLanguage(EmailTemplateEnum type, Language language) {
return emailTemplateDAO.findByTypeAndLanguage(type, language); return emailTemplateDAO.findByTypeAndLanguage(type, language);
} }

View file

@ -28,7 +28,7 @@ import java.util.List;
/** /**
* Contract for {@link EmailTemplate}. * Contract for {@link EmailTemplate}.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 28.09.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public interface IEmailTemplateModel { public interface IEmailTemplateModel {

View file

@ -14,7 +14,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
/** /**
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 12.24.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
@Service @Service
@ -80,6 +80,7 @@ public class OrderFileModel implements IOrderFileModel {
return fileDAO.findByParent(parent); return fileDAO.findByParent(parent);
} }
@Override
public OrderFile getOrderFile() { public OrderFile getOrderFile() {
return orderFile; return orderFile;
} }

View file

@ -62,7 +62,7 @@ import static org.libreplan.web.I18nHelper._;
/** /**
* Controller for managing Order files. * Controller for managing Order files.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 12.24.2015. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
public class OrderFilesController extends GenericForwardComposer { public class OrderFilesController extends GenericForwardComposer {
@ -82,11 +82,22 @@ public class OrderFilesController extends GenericForwardComposer {
private Listbox filesList; private Listbox filesList;
public OrderFilesController() { public OrderFilesController() {
if ( configurationModel == null ) {
configurationModel = (IConfigurationModel) SpringUtil.getBean("configurationModel"); configurationModel = (IConfigurationModel) SpringUtil.getBean("configurationModel");
}
if ( userDAO == null ) {
userDAO = (IUserDAO) SpringUtil.getBean("userDAO"); userDAO = (IUserDAO) SpringUtil.getBean("userDAO");
}
if ( orderElementModel == null ) {
orderElementModel = (IOrderElementModel) SpringUtil.getBean("orderElementModel"); orderElementModel = (IOrderElementModel) SpringUtil.getBean("orderElementModel");
}
if ( orderFileModel == null ) {
orderFileModel = (IOrderFileModel) SpringUtil.getBean("orderFileModel"); orderFileModel = (IOrderFileModel) SpringUtil.getBean("orderFileModel");
} }
}
@Override @Override
public void doAfterCompose(Component comp) throws Exception { public void doAfterCompose(Component comp) throws Exception {
@ -99,8 +110,10 @@ public class OrderFilesController extends GenericForwardComposer {
configurationModel.init(); configurationModel.init();
File repositoryDirectory = null; File repositoryDirectory = null;
if ( configurationModel.getRepositoryLocation() != null )
if ( configurationModel.getRepositoryLocation() != null ) {
repositoryDirectory = new File(configurationModel.getRepositoryLocation()); repositoryDirectory = new File(configurationModel.getRepositoryLocation());
}
return repositoryDirectory != null && repositoryDirectory.exists(); return repositoryDirectory != null && repositoryDirectory.exists();
} }
@ -239,9 +252,10 @@ public class OrderFilesController extends GenericForwardComposer {
if ( inputStream != null ) { if ( inputStream != null ) {
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
for ( int count; (count = inputStream.read(buffer)) != -1; ) for ( int count; (count = inputStream.read(buffer)) != -1; ) {
outputStream.write(buffer, 0, count); outputStream.write(buffer, 0, count);
} }
}
outputStream.flush(); outputStream.flush();
outputStream.close(); outputStream.close();
@ -283,9 +297,10 @@ public class OrderFilesController extends GenericForwardComposer {
public void openWindow(IOrderElementModel orderElementModel) { public void openWindow(IOrderElementModel orderElementModel) {
setOrderElementModel(orderElementModel); setOrderElementModel(orderElementModel);
if ( isRepositoryExists() ) if ( isRepositoryExists() ) {
updateListbox(); updateListbox();
} }
}
/** /**
* Listbox is updating after re set the model for it. * Listbox is updating after re set the model for it.

View file

@ -17,7 +17,7 @@
<http auto-config="false" realm="LibrePlan Web Application" > <http auto-config="false" realm="LibrePlan Web Application" >
<!-- In Spring 4.1.0 it is useless to use hasRole() for single role because Spring calling hasAnyRole() anyway --> <!-- In Spring Security 4.1.0 it is useless to use hasRole() for single role because Spring calling hasAnyRole() anyway -->
<!-- Web services --> <!-- Web services -->
<intercept-url pattern="/ws/rest/bounduser/**" access="hasAnyRole('ROLE_BOUND_USER')" method="GET" /> <intercept-url pattern="/ws/rest/bounduser/**" access="hasAnyRole('ROLE_BOUND_USER')" method="GET" />

View file

@ -53,7 +53,7 @@ import java.util.Date;
/** /**
* Tests for {@link OrderFile}. * Tests for {@link OrderFile}.
* *
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 11.01.2016. * @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)