Adds the generated code sequence to work report types.
Replaces the generated code by the code sequence for work report type and changes the configuration interface to add the property generateCodeForWorkReportType. FEA :ItEr61S04NavalPlanEntities
This commit is contained in:
parent
b1385d0a49
commit
f2d8a36465
15 changed files with 123 additions and 60 deletions
|
|
@ -65,6 +65,8 @@ public class Configuration extends BaseEntity {
|
|||
|
||||
private Boolean monteCarloMethodTabVisible = false;
|
||||
|
||||
private Boolean generateCodeForWorkReportType = true;
|
||||
|
||||
public void setDefaultCalendar(BaseCalendar defaultCalendar) {
|
||||
this.defaultCalendar = defaultCalendar;
|
||||
}
|
||||
|
|
@ -197,4 +199,13 @@ public class Configuration extends BaseEntity {
|
|||
return generateCodeForBaseCalendars;
|
||||
}
|
||||
|
||||
public void setGenerateCodeForWorkReportType(
|
||||
Boolean generateCodeForWorkReportType) {
|
||||
this.generateCodeForWorkReportType = generateCodeForWorkReportType;
|
||||
}
|
||||
|
||||
public Boolean getGenerateCodeForWorkReportType() {
|
||||
return generateCodeForWorkReportType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ import org.navalplanner.business.resources.entities.CriterionType;
|
|||
import org.navalplanner.business.resources.entities.Machine;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.navalplanner.business.workreports.entities.WorkReport;
|
||||
import org.navalplanner.business.workreports.entities.WorkReportType;
|
||||
|
||||
/**
|
||||
* It represents the entities which use code generation
|
||||
|
|
@ -43,7 +44,8 @@ public enum EntityNameEnum {
|
|||
ORDER("Order"), CRITERION("Criterion"), LABEL("Label"), MACHINE("Machine"), WORKER(
|
||||
"Worker"), UNIT_TYPE("Unit type"), CALENDAR("Calendar"), WORK_HOURS_TYPE(
|
||||
"Type of work hours"), MATERIAL_CATEGORY("Material category"), WORK_REPORT(
|
||||
"Work report"), RESOURCE_CALENDAR("Resource calendar");
|
||||
"Work report"), WORK_REPORT_TYPE("Work report type"), RESOURCE_CALENDAR(
|
||||
"Resource calendar");
|
||||
|
||||
private String description;
|
||||
|
||||
|
|
@ -84,6 +86,9 @@ public enum EntityNameEnum {
|
|||
case WORK_REPORT:
|
||||
return (IIntegrationEntityDAO<WorkReport>) Registry
|
||||
.getWorkReportDAO();
|
||||
case WORK_REPORT_TYPE:
|
||||
return (IIntegrationEntityDAO<WorkReportType>) Registry
|
||||
.getWorkReportTypeDAO();
|
||||
default:
|
||||
throw new RuntimeException("can't handle the code sequence of the "
|
||||
+ description);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ package org.navalplanner.business.workreports.daos;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
import org.navalplanner.business.common.daos.IGenericDAO;
|
||||
import org.navalplanner.business.common.daos.IIntegrationEntityDAO;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.workreports.entities.WorkReportType;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
|
@ -37,7 +37,8 @@ import org.springframework.stereotype.Repository;
|
|||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public interface IWorkReportTypeDAO extends IGenericDAO<WorkReportType, Long> {
|
||||
public interface IWorkReportTypeDAO extends
|
||||
IIntegrationEntityDAO<WorkReportType> {
|
||||
|
||||
public WorkReportType findUniqueByName(WorkReportType workReportType)
|
||||
throws InstanceNotFoundException, NonUniqueResultException;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import org.apache.commons.lang.Validate;
|
|||
import org.hibernate.Criteria;
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
import org.navalplanner.business.common.daos.IntegrationEntityDAO;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.workreports.entities.WorkReportType;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
|
@ -42,8 +42,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class WorkReportTypeDAO extends
|
||||
GenericDAOHibernate<WorkReportType, Long> implements IWorkReportTypeDAO {
|
||||
public class WorkReportTypeDAO extends IntegrationEntityDAO<WorkReportType>
|
||||
implements IWorkReportTypeDAO {
|
||||
|
||||
@Override
|
||||
public WorkReportType findUniqueByName(WorkReportType workReportType)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import org.hibernate.NonUniqueResultException;
|
|||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.hibernate.validator.Valid;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
import org.navalplanner.business.common.IntegrationEntity;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.labels.entities.LabelType;
|
||||
|
|
@ -40,24 +40,18 @@ import org.navalplanner.business.workreports.valueobjects.DescriptionField;
|
|||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
public class WorkReportType extends BaseEntity {
|
||||
public class WorkReportType extends IntegrationEntity {
|
||||
|
||||
public static WorkReportType create() {
|
||||
WorkReportType workReportType = new WorkReportType();
|
||||
workReportType.setNewObject(true);
|
||||
return workReportType;
|
||||
return create(new WorkReportType());
|
||||
}
|
||||
|
||||
public static WorkReportType create(String name, String code) {
|
||||
WorkReportType workReportType = new WorkReportType(name, code);
|
||||
workReportType.setNewObject(true);
|
||||
return workReportType;
|
||||
return create(new WorkReportType(name), code);
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
private String code;
|
||||
|
||||
private Boolean dateIsSharedByLines = false;
|
||||
|
||||
private Boolean resourceIsSharedInLines = false;
|
||||
|
|
@ -80,18 +74,8 @@ public class WorkReportType extends BaseEntity {
|
|||
|
||||
}
|
||||
|
||||
private WorkReportType(String name, String code) {
|
||||
private WorkReportType(String name) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@NotEmpty(message = "code not specified or empty")
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@NotEmpty(message = "name not specified or empty")
|
||||
|
|
@ -169,7 +153,7 @@ public class WorkReportType extends BaseEntity {
|
|||
@SuppressWarnings("unused")
|
||||
@AssertTrue(message = "Value is not valid.\n Code cannot contain chars like '_'.")
|
||||
public boolean checkConstraintWorkReportTypeCodeWithoutIncorrectCharacter() {
|
||||
if ((code == null) || (code.contains("_"))) {
|
||||
if ((getCode() == null) || (getCode().contains("_"))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -193,27 +177,6 @@ public class WorkReportType extends BaseEntity {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AssertTrue(message = "work report type code is already being used")
|
||||
public boolean checkConstraintUniqueWorkReportTypeCode() {
|
||||
|
||||
IWorkReportTypeDAO workReportTypeDAO = Registry.getWorkReportTypeDAO();
|
||||
|
||||
if (isNewObject()) {
|
||||
return !workReportTypeDAO.existsByCodeAnotherTransaction(this);
|
||||
} else {
|
||||
try {
|
||||
WorkReportType c = workReportTypeDAO.findUniqueByCode(code);
|
||||
return c.getId().equals(getId());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return true;
|
||||
} catch (NonUniqueResultException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AssertTrue(message = "The field name must be unique.")
|
||||
public boolean checkConstraintUniqueNamesDescriptionFields() {
|
||||
|
|
@ -545,4 +508,9 @@ public class WorkReportType extends BaseEntity {
|
|||
.compareTo(list.size()) <= 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IWorkReportTypeDAO getIntegrationEntityDAO() {
|
||||
return Registry.getWorkReportTypeDAO();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
<property name="companyCode" />
|
||||
|
||||
<property name="generateCodeForWorkReportType" not-null="true" />
|
||||
<property name="generateCodeForCriterion" not-null="true" />
|
||||
<property name="generateCodeForLabel" not-null="true" />
|
||||
<property name="generateCodeForWorkReport" not-null="true" />
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
<property name="dateIsSharedByLines" access="field" />
|
||||
<property name="resourceIsSharedInLines" access="field" />
|
||||
<property name="orderElementIsSharedInLines" access="field" />
|
||||
<property name="codeAutogenerated" access="field" not-null="true"/>
|
||||
|
||||
<property name="hoursManagement">
|
||||
<type name="org.hibernate.type.EnumType">
|
||||
|
|
|
|||
|
|
@ -145,13 +145,6 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
}
|
||||
}
|
||||
|
||||
// private void addSeparatorComponent(Component component){
|
||||
// Separator separator = new Separator();
|
||||
// separator.setHeight("10px");
|
||||
// separator.setBar(true);
|
||||
// component.appendChild(separator);
|
||||
// }
|
||||
|
||||
public List<BaseCalendar> getCalendars() {
|
||||
return configurationModel.getCalendars();
|
||||
}
|
||||
|
|
@ -210,6 +203,16 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
configurationModel.setGenerateCodeForCriterion(generateCodeForCriterion);
|
||||
}
|
||||
|
||||
public Boolean getGenerateCodeForWorkReportType() {
|
||||
return configurationModel.getGenerateCodeForWorkReportType();
|
||||
}
|
||||
|
||||
public void setGenerateCodeForWorkReportType(
|
||||
Boolean generateCodeForWorkReportType) {
|
||||
configurationModel
|
||||
.setGenerateCodeForWorkReportType(generateCodeForWorkReportType);
|
||||
}
|
||||
|
||||
public Boolean getGenerateCodeForLabel() {
|
||||
return configurationModel.getGenerateCodeForLabel();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,6 +266,23 @@ public class ConfigurationModel implements IConfigurationModel {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getGenerateCodeForWorkReportType() {
|
||||
if (configuration == null) {
|
||||
return null;
|
||||
}
|
||||
return configuration.getGenerateCodeForWorkReportType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenerateCodeForWorkReportType(
|
||||
Boolean generateCodeForWorkReportType) {
|
||||
if (configuration != null) {
|
||||
configuration
|
||||
.setGenerateCodeForWorkReportType(generateCodeForWorkReportType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getGenerateCodeForLabel() {
|
||||
if (configuration == null) {
|
||||
|
|
|
|||
|
|
@ -52,6 +52,10 @@ public interface IConfigurationModel {
|
|||
String getCompanyCode();
|
||||
void setCompanyCode(String companyCode);
|
||||
|
||||
Boolean getGenerateCodeForWorkReportType();
|
||||
|
||||
void setGenerateCodeForWorkReportType(Boolean generateCodeForWorkReportType);
|
||||
|
||||
Boolean getGenerateCodeForCriterion();
|
||||
void setGenerateCodeForCriterion(Boolean generateCodeForCriterion);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,13 +33,14 @@ import org.navalplanner.business.workreports.entities.WorkReport;
|
|||
import org.navalplanner.business.workreports.entities.WorkReportLabelTypeAssigment;
|
||||
import org.navalplanner.business.workreports.entities.WorkReportType;
|
||||
import org.navalplanner.business.workreports.valueobjects.DescriptionField;
|
||||
import org.navalplanner.web.common.IIntegrationEntityModel;
|
||||
|
||||
/**
|
||||
* Contract for {@link WorkRerportType}
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public interface IWorkReportTypeModel {
|
||||
public interface IWorkReportTypeModel extends IIntegrationEntityModel {
|
||||
|
||||
/**
|
||||
* Gets the current {@link WorkReportType}.
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package org.navalplanner.web.workreports;
|
|||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
|
@ -46,6 +47,7 @@ import org.navalplanner.web.common.entrypoints.IURLHandlerRegistry;
|
|||
import org.navalplanner.web.common.entrypoints.URLHandler;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.event.CheckEvent;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
|
|
@ -1014,4 +1016,16 @@ public class WorkReportTypeCRUDController extends GenericForwardComposer
|
|||
}
|
||||
}
|
||||
|
||||
public void onCheckGenerateCode(Event e) {
|
||||
CheckEvent ce = (CheckEvent) e;
|
||||
if (ce.isChecked()) {
|
||||
// we have to auto-generate the code for new objects
|
||||
try {
|
||||
workReportTypeModel.setCodeAutogenerated(ce.isChecked());
|
||||
} catch (ConcurrentModificationException err) {
|
||||
messagesForUser.showMessage(Level.ERROR, err.getMessage());
|
||||
}
|
||||
}
|
||||
Util.reloadBindings(code);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.navalplanner.business.common.IntegrationEntity;
|
||||
import org.navalplanner.business.common.daos.IConfigurationDAO;
|
||||
import org.navalplanner.business.common.entities.EntityNameEnum;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.labels.daos.ILabelTypeDAO;
|
||||
|
|
@ -42,6 +45,7 @@ import org.navalplanner.business.workreports.entities.WorkReport;
|
|||
import org.navalplanner.business.workreports.entities.WorkReportLabelTypeAssigment;
|
||||
import org.navalplanner.business.workreports.entities.WorkReportType;
|
||||
import org.navalplanner.business.workreports.valueobjects.DescriptionField;
|
||||
import org.navalplanner.web.common.IntegrationEntityModel;
|
||||
import org.navalplanner.web.common.concurrentdetection.OnConcurrentModification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
|
@ -58,7 +62,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
@Service
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
@OnConcurrentModification(goToPage = "/workreports/workReportTypes.zul")
|
||||
public class WorkReportTypeModel implements IWorkReportTypeModel {
|
||||
public class WorkReportTypeModel extends IntegrationEntityModel implements
|
||||
IWorkReportTypeModel {
|
||||
|
||||
@Autowired
|
||||
private IWorkReportTypeDAO workReportTypeDAO;
|
||||
|
|
@ -69,6 +74,9 @@ public class WorkReportTypeModel implements IWorkReportTypeModel {
|
|||
@Autowired
|
||||
private ILabelTypeDAO labelTypeDAO;
|
||||
|
||||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
private WorkReportType workReportType;
|
||||
|
||||
private boolean editing = false;
|
||||
|
|
@ -117,7 +125,14 @@ public class WorkReportTypeModel implements IWorkReportTypeModel {
|
|||
loadLabels();
|
||||
setListing(false);
|
||||
editing = false;
|
||||
this.workReportType = WorkReportType.create();
|
||||
|
||||
Boolean generateCode = configurationDAO.getConfiguration()
|
||||
.getGenerateCodeForWorkReportType();
|
||||
this.workReportType = WorkReportType.create("", "");
|
||||
if (generateCode) {
|
||||
setDefaultCode();
|
||||
}
|
||||
this.workReportType.setCodeAutogenerated(generateCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -130,6 +145,7 @@ public class WorkReportTypeModel implements IWorkReportTypeModel {
|
|||
|
||||
this.workReportType = getFromDB(workReportType);
|
||||
loadCollections(this.workReportType);
|
||||
initOldCodes();
|
||||
}
|
||||
|
||||
private WorkReportType getFromDB(WorkReportType workReportType) {
|
||||
|
|
@ -378,7 +394,7 @@ public class WorkReportTypeModel implements IWorkReportTypeModel {
|
|||
}
|
||||
|
||||
getWorkReportType().setCode(code);
|
||||
if (!getWorkReportType().checkConstraintUniqueWorkReportTypeCode()) {
|
||||
if (!getWorkReportType().checkConstraintUniqueCode()) {
|
||||
throw new IllegalArgumentException(
|
||||
_("Exist other workReportType with the same code."));
|
||||
}
|
||||
|
|
@ -515,4 +531,15 @@ public class WorkReportTypeModel implements IWorkReportTypeModel {
|
|||
}
|
||||
}
|
||||
|
||||
public EntityNameEnum getEntityName() {
|
||||
return EntityNameEnum.WORK_REPORT_TYPE;
|
||||
}
|
||||
|
||||
public Set<IntegrationEntity> getChildren() {
|
||||
return new HashSet<IntegrationEntity>();
|
||||
}
|
||||
|
||||
public IntegrationEntity getCurrentEntity() {
|
||||
return this.workReportType;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,6 +101,11 @@
|
|||
checked="@{configurationController.generateCodeForBaseCalendars}"
|
||||
onCheck="configurationController.reloadGeneralConfiguration();" />
|
||||
</row>
|
||||
<row>
|
||||
<checkbox label="${i18n:_('Work report types')}"
|
||||
checked="@{configurationController.generateCodeForWorkReportType}"
|
||||
onCheck="configurationController.reloadGeneralConfiguration();" />
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</row>
|
||||
|
|
|
|||
|
|
@ -51,8 +51,13 @@
|
|||
<label value="${i18n:_('Code')}:" />
|
||||
<hbox>
|
||||
<textbox visible = "@{controller.editable}"
|
||||
disabled="@{controller.workReportType.codeAutogenerated}"
|
||||
id="code" value="@{controller.workReportType.code}" width="300px"
|
||||
constraint = "@{controller.validateWorkReportTypeCode}"/>
|
||||
<checkbox id="generateCode" label="${i18n:_('Generate code')}"
|
||||
visible = "@{controller.editable}"
|
||||
onCheck="controller.onCheckGenerateCode(event)"
|
||||
checked="@{controller.workReportType.codeAutogenerated}" />
|
||||
<label visible = "@{controller.readOnly}"
|
||||
value="@{controller.workReportType.code}" width="300px"/>
|
||||
</hbox>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue