You are on page 1of 95

Lifecycle Management Server (LMS) Code

Jacopo Cassina Holonix D3.5 WP3 11.12.2013 286885 Public To All the Consortium D3.5 Lifecycle Management Server Code.docx 95

Person responsible / Author: Deliverable No.: Work Package No.: Date: Project No.: Classification: Distribution: File name: Number of pages:

286885 BOMA

Status of Deliverable Action Submitted (author(s)) VU (WP Leader)


Revision History

By
Jacopo Cassina Holonix

Date (dd.mm.yyyy)
Xx

Date (dd.mm.yyyy) Version (version revision) Author


02.12.2013 06.12.2013 09.12.2013 11.12.2013 16.12.2013 23.12.2013 Initial Structure Draft Version Draft Version revised Final Version Final Version revised Final Version Approved Jacopo Cassina Matteo Barone Matteo Barone Matteo Barone Fiorella Colombo Matteo Barone Alberto Alberio Michele Tibaldi Jacopo Cassina

Comments

Author(s) contact information

Name
Jacopo Cassina Alberto Alberio Michele Tibaldi Fiorella Colombo Matteo Barone

Organisation
Holonix Holonix Holonix Holonix POLIMI

E-mail
Jacopo.cassina@holonix.it Alberto.Alberio@holonix.it Michele.tibaldi@holonix.it Fiorella.Colombo@holonix.it Matteo.barone@polimi.it

Tel
+39 02 0362 1582033

286885 BOMA Table of Contents


1. 2. ABSTRACT .................................................................................................................................................. 5 INTRODUCTION.......................................................................................................................................... 6 2.1. 2.2. 3. OBJECTIVES OF THIS DOCUMENT ................................................................................................................. 6 OVERVIEW ............................................................................................................................................ 6

LIFECYCLE MANAGEMENT SERVER ............................................................................................................. 7 3.1. 3.2. 3.3. ACTIVITIES MODULE ................................................................................................................................ 7 PRODUCTION MODULE ............................................................................................................................ 8 DATA IMPORT MODULE ..........................................................................................................................11

4.

CODE .........................................................................................................................................................12 4.1. ACTIVITIES MODULE CODE .......................................................................................................................12 4.1.1. Business Logic Code.......................................................................................................................12 4.1.2. Interface Code...............................................................................................................................32 4.2. PRODUCTION CODE (SERVER SIDE) ............................................................................................................51 4.2.1. Business Logic Code.......................................................................................................................51 4.2.2. Interface Code...............................................................................................................................77 4.3. DATA IMPORT CODE ...............................................................................................................................84 4.3.1. Production sheet Code..................................................................................................................84 4.3.2. Web Service Code..........................................................................................................................85 4.3.3. Business Logic Code.......................................................................................................................87

5.

CONCLUSION ............................................................................................................................................95

Figures
Figure 1 BOMA Platform - Activities Module .......................................................................................... 8 Figure 2 BOMA Platform Production Sheet List ................................................................................... 8 Figure 3 BOMA Platform Production Sheet Detail ............................................................................... 9 Figure 4 BOMA Platform Bill of Process Input Detail ...........................................................................10 Figure 5 BOMA Platform Bill of Process Resources Detail ...................................................................10 Figure 6 Bill of Process Operator Detail .................................................................................................11

286885 BOMA

Abbreviations and Acronyms:


LMS BOW BM DSS DC PDA Lifecycle Management Server BOat web application BOMA Middleware Decision Support System Device Controller Personal Digital Assistant

286885 BOMA 1. Abstract


This deliverable describes the code that has been developed according to the specific needs and requirements of the BOMA industrial partners. The input used is related to D3.1 Concept Mock Up that describes in details all the functionalities of the Platform. To meet the requirements presented in the mock up the code described in the chapter of this document has been developed. Firstly, a brief description of the target of the code will be presented, than the java code will be fully reported.

286885 BOMA 2. Introduction


The BOMA system is thought to manage the data of each physical boat manufactured and delivered to the customer during the whole lifecycle. For this reason the infrastructure of the BOMA system contemplates several layers: The BOMA Middleware (BM) The Lifecycle Management Server (LMS) The Decision Support System (DSS) The Device Controller (DC) The BOat Web Application (BOW)

The infrastructure has been built following a web-service based approach in order to allow any enabled user to exchange data with any other. In this infrastructure it is possible to distinguish between a front-end and a back-end. The first one includes the BOat Web application (BOW) to manage the boat lifecycle. It is constituted by several modules (as described in the deliverable D3.1), with different level of access for the different kind of users (designer, producer, maintenance crew, boat owner, etc.). The back-end coincides with the server side (the lifecycle management server and the decision support system) that will take care of managing and storing all the web data, which will be needed, allowing off -line analysis and distributing the BOW. The Boat Web Application has been developed starting from the already existing extended product lifecycle management suite i-Like, owned by Holonix. However it required specific customization in order to be used in the marine industry. Moreover it needed several technical components, designed and built from scratch, which enable the above mentioned capabilities. One of these components is the Lifecycle Management Server (LMS), which allows to the BOMA system to interact with different servers, managing data and distributing web applications. In this section is presented a brief description of the main components developed in order to build the lifecycle management servers and finally the java code of each of those.

2.1.

Objectives of this document

The objective of this document is to present the LMS Code that has been developed for BOMA Platform. It is the second release of the LMS code, while the first part of the code has been already described in the Deliverable D.34 LMS Code.

2.2.

Overview

This deliverable has two main chapters: 1. Life Cycle Management Server: it contains a description of the code that will be presented in the second chapter. In particular, it describes what is the main goal of the code, the results that will be obtained. 2. Code: the code has been reported.

286885 BOMA 3. Lifecycle Management Server


The Lifecycle Management Server is the technical component of the BOMA system infrastructure that allows the interaction with multiple servers and device controllers, which store data and information, distributing also data and web application to them. The components of the Lifecycle Management Server that are going to be described in the following sections are: The Activities module of the BOMA Platform: it allows to record relevant events connected both to the boat and resource usage, for instance maintenance activities, accidents, changes in the bill of material, etc. The Production module (server-side) of the BOMA Platform: it allows the management of data and information related to the production processes The Data Import module: it allows to import data and information already managed with other systems (e.g. production sheets, items list, stock status, etc.). The data imported depend on specific requirements of each industrial partner

In the following paragraphs each module is going to be described in detail while in the next section is reported the java code developed for each module.

3.1.

Activities Module

The Activities Module (Figure 1) is the module of the BOMA platform that allows to record all the events related both to the boat and resource usage. In order to add an activity the following information must be inserted - The name of the activity - The activitys type. The following options are available: o Maintenance activity. Several types can be selected: Planned Extraordinary Corrective o Check and Control Activity o Accident event o Generic Activity - Start and end execution date - Description of the activity - Status of the Activity. The following options can be selected: o Not executed it identifies the activities planned but not already started o In progress it identifies an on-going activity o Completed it is selected when the activity has been already done o Cancelled it allows to keep track of the activities planned but not executed anymore o Suspended it identifies the temporary suspension of an activity - Operator: the responsible of the execution of the activity - Resources used for the execution of the activity - Custom attributes possibility to insert new information specific for each kind of activity

286885 BOMA
Different kind of enabled users can access to the Activities Module through the BOMA platform web interface and according to their access rights they will be able to retrieve and/or modify data.

Figure 1 BOMA Platform - Activities Module

3.2.

Production Module

The Production Module is the module of the BOMA Platform that allows to manage and monitor the production processes and to record the related data and information. It consists of two different parts: The serve side it is going to be described into details in the following paragraphs while in the second chapter of this deliverable the code developed for its implementation is going to be fully reported The PDA side it is addressed into the deliverable D3.3 Device Controller and PEID Integration Code

The Production Module consists of a main interface (see Figure 2) where all the production sheets are listed. Since all the industrial partners already use production sheets supporting the operations, it has been required to import them from the systems currently used (see Section 3.3).

Figure 2 BOMA Platform Production Sheet List

286885 BOMA

Each production sheet may consist of one or more processes (see Figure 3), which can be of four different types that have been defined after a deep analysis of the processes of each industrial partner: Merging: it identifies a process that has many inputs (which can be uniquely identified) and only one output (which can be uniquely identified) ex. Moulding Assembly: this process has in input a master uniquely identified and many other parts and components, which will be assembled on the master. The parts and components are not tracked anymore at the end of the process Action: this process comprises a set of simple activities that may require a measurement and must be flagged as done or not done ex. Test before the launch Change type: it is the process that allows to change the type to parts and components

Each process of the production sheet gathers the following information: Bill of process Input Bill of process Output Bill of process Resource Bill of process Operator

Figure 3 BOMA Platform Production Sheet Detail

The Bill of Process Input (Figure 4) reports two different sections: The planned BoM which includes the set of items that should be used during the selected process The effective BoM which is the list of the item effectively used during the selected process. This section will be automatically updated when the workers report through the PDA the tasks executed If a gap between planned and effective BoM happens, it is always indicated through a green (the quantity/number of item planned is bigger than the quantity/number of item used) or red (the quantity/number of item planned is lower than the quantity/number of item used) arrow in last raw of the table on the right side (Effective section) The Bill of Process Resource (Figure 5) reports two different sections: The planned resources which are the resources that should be involved in the selected process The effective resources which are the real resources used within the selected process. This -

286885 BOMA
section will be automatically updated when the workers report through the PDA the resources used If a gap between planned and effective resource happens, it is always indicated through a green (the number of hours planned is bigger than the number of hours required) or red (the number of hours planned is lower than the number of hours required) arrow in last raw of the table on the right side (Effective section)

Figure 4 BOMA Platform Bill of Process Input Detail

Figure 5 BOMA Platform Bill of Process Resources Detail

The Bill of Process Operator consists of the list of the operators involved in the process (Figure 6). Two different sections can be distinguished:

10

286885 BOMA
The planned operators which are the operators that should be involved in the selected process The effective operator that are the operators who effectively performed the selected process. This section will be automatically updated when the crew chief reports through the PDA the hours spent for each process by each worker involved If a gap between planned and effective working hours happens, it is always indicated through a green (the number of hours planned is bigger than the number of hours required) or red (the number of hours planned is lower than the number of hours required) arrow in last raw of the table on the right side (Effective section) -

Figure 6 Bill of Process Operator Detail

3.3.
-

Data Import Module

The Data Import Module has been developed for two main reasons: Import automatically the item code list from the system currently in use (e.g. ERP, excel, etc.). A new item, however, can be created within the BOMA Platform as well Import automatically the production sheets from the system currently in use (e.g. ERP, excel, etc.). A new production sheet cannot be created into the BOMA Platform.

In other to automatize the data exchange between the BOMA Platform and the systems adopted by the industrial partners, the development of several components has been required: The BOMA platform exposes a REST API based on Jersey 1.17, JAX-RS Java reference implementation in order to import the production sheets Data model of the web service in order to ensure the interoperability between the BOMA platform and the ERP system

Finally some custom features for the importation of the data required have been developed starting from the exportation of the ERP system adopted by the industrial partners. In the second chapter of this deliverable the code of the above mentioned components is going to be reported.

11

286885 BOMA 4. Code


In the following sections the code developed for the BOMA Platform application is going to be reported. The first two sections Activities Module Code and Production Module Code consist of two subsections: Business logic code which collects the code of the implementation logic Interface code which consists of the code developed to build the BOMA Platform Interface

The last section Data Import Module is composed by the following subsections: - Production Sheet Code the code developed for the interoperability of the BOMA Platform with other systems - Web Service Code it encloses the code developed for the implementation of the web service which will support the data exchange - Business Logic Code it collects the code of the implementation logic

4.1.

Activities Module Code

4.1.1. Business Logic Code


public interface ActivityCategoryService { List<ActivityCategory> getAttivitaCategoriaBySearch(Search search); ActivityCategory getAttivitaCategoriaById(int id); ActivityCategory get(String code); public List<ActivityCategory> getAllAttivitaCategoria(); } @Service public class ActivityCategoryServiceImpl implements ActivityCategoryService { @Autowired private ActivityCategoryDAO dao; @Override public ActivityCategory getAttivitaCategoriaById(int id) { return dao.get(id); } @Override public ActivityCategory get(String code) { Search search = new Search(ActivityCategory.class); search.addFilter(HxFilter.equal(code, ActivityCategory._code)); List<ActivityCategory> list = getAttivitaCategoriaBySearch(search); if (list.size() > 0) return list.get(0); return null; } @Override public List<ActivityCategory> getAttivitaCategoriaBySearch(Search search) { return dao.get(search); } @Override public List<ActivityCategory> getAllAttivitaCategoria() { return dao.get(); } } public interface ActivityOperatorService { public ActivityOperator get(long id); public List<ActivityOperator> get(Search search); public List<ActivityOperator> get(Search search, int pageCurr, int pageSize);

12

286885 BOMA
public int count(Search search); public void insert(ActivityOperator activityOperator); public void delete(ActivityOperator activityOperator); public List<ActivityOperator> get(); public boolean exist(Long id); } @Service public class ActivityOperatorServiceImpl implements ActivityOperatorService { @Autowired private ActivityOperatorDAO dao; @Override public int count(Search search) { return dao.count(search); } @Override public List<ActivityOperator> get(Search search) { return dao.get(search); } @Override public List<ActivityOperator> get(Search search, int pageCurr, int pageSize) { return dao.get(search, pageCurr, pageSize); } @Override public ActivityOperator get(long id) { return dao.get(id); } @Override public void insert(ActivityOperator activityOperator) { dao.persist(activityOperator); } @Override public void delete(ActivityOperator activityOperator) { dao.remove(activityOperator); } public List<ActivityOperator> get() { return dao.get(); } @Override public boolean exist(Long id) { if (id == null) return false; Search search = new Search(ActivityOperator.class); search.addFilter(HxFilter.equal(id, ActivityOperator._id)); if (dao.count(search) == 0) return false; return true; } } public interface ActivityPhysicalProductObjectService { public ActivityPhysicalProductObject get(long id); public List<ActivityPhysicalProductObject> get(); public List<ActivityPhysicalProductObject> get(Search search); public void insert(ActivityPhysicalProductObject activityPhysicalProductObject); public List<ActivityPhysicalProductObject> get (Search search, int pageCurr, int pageSize); public int count (Search search); public boolean exist(Long id); } @Service public class ActivityPhysicalProductObjectServiceImpl implements ActivityPhysicalProductObjectService { @Autowired private ActivityPhysicalProductObjectDAO dao; @Override public ActivityPhysicalProductObject get(long id) { return dao.get(id); } @Override public List<ActivityPhysicalProductObject> get(Search search) { return dao.get(search); } @Override public void insert(ActivityPhysicalProductObject activityPhysicalProductObject) { dao.persist(activityPhysicalProductObject);

13

286885 BOMA
} @Override public List<ActivityPhysicalProductObject> get(Search search, int pageCurr, int pageSize) { return dao.get(search, pageCurr, pageSize); } @Override public int count(Search search) { return dao.count(search); } public List<ActivityPhysicalProductObject> get() { return dao.get(); } @Override public boolean exist(Long id) { if (id == null) return false; Search search = new Search(ActivityPhysicalProductObject.class); search.addFilter(HxFilter.equal(id, ActivityPhysicalProductObject._id)); if (dao.count(search) == 0) return false; return true; } } public interface ActivityService { public Activity getById(long id); public List<Activity> getAttivitaBySearch(Search search); public void insertAttivita(Activity attivita); public List<Activity> getAttivitaBySearch(Search search, int pageCurr, int pageSize); public int countAttivita(Search search); public void eliminaAttivita(Activity attivita); public void deleteSeries(Activity attivita); public abstract List<Activity> get(PhysicalProduct physicalProduct); public List<Activity> getAll(); public boolean exist(Long id); } @Service public class ActivityServiceImpl implements ActivityService { @Autowired private ActivityDAO dao; @Override public int countAttivita(Search search) { return dao.count(search); } @Override public List<Activity> getAttivitaBySearch(Search search) { return dao.get(search); } @Override public List<Activity> getAttivitaBySearch(Search search, int pageCurr, int pageSize) { return dao.get(search, pageCurr, pageSize); } @Override public Activity getById(long id) { return dao.get(id); } @Override public void insertAttivita(Activity attivita) { dao.persist(attivita); } @Override public void eliminaAttivita(Activity attivita) { dao.remove(attivita); } @Override public void deleteSeries(Activity attivita) { } public List<Activity> get(PhysicalProduct physicalProduct) { Search search = new Search(Activity.class); search.addFilter(HxFilter.equal(physicalProduct, Activity._activityPhysicalProductObjects,

14

286885 BOMA
ActivityPhysicalProductObject._physicalProduct)); return dao.get(search); } public List<Activity> getAll() { return dao.get(); } @Override public boolean exist(Long id) { if (id == null) return false; Search search = new Search(Activity.class); search.addFilter(HxFilter.equal(id, Activity._id)); if (dao.count(search) == 0) return false; return true; } } public interface ActivityStatusService { public List<ActivityStatus> get(); public ActivityStatus get(long id); public List<ActivityStatus> get(Search search); } @Service public class ActivityStatusServiceImpl implements ActivityStatusService { @Autowired private ActivityStatusDAO dao; @Override public List<ActivityStatus> get() { return dao.get() ; } @Override public ActivityStatus get(long id) { return dao.get(id); } @Override public List<ActivityStatus> get(Search search) { return dao.get(search); } } public interface ActivityTypeService { public List<ActivityType> get(); public List<ActivityType> get(boolean activeOnly); public void insertActivityType(ActivityType activityType); public ActivityType getTipoAttivitaFromId(long id); public List<ActivityType> get(ActivityCategory activityCategory); public List<ActivityType> get(ActivityCategory activityCategory, boolean activeOnly); public List<ActivityType> getTipoAttivitaBySearch(Search search); public List<ActivityType> getActivityTypeBySearch(Search search, int pageCurr, int pageSize); public int countActivityType(Search search); public ActivityType getByCode(String code); } @Service public class ActivityTypeServiceImpl implements ActivityTypeService { @Autowired private ActivityTypeDAO dao; @Override public List<ActivityType> get() { return dao.get(); } @Override public List<ActivityType> get(boolean activeOnly) { Search sTipoAtt = new Search(ActivityType.class); if (activeOnly) sTipoAtt.addFilter(HxFilter.equal(true, ActivityType._active)); return getTipoAttivitaBySearch(sTipoAtt); } @Override public ActivityType getTipoAttivitaFromId(long id) { return dao.get(id); }

15

286885 BOMA
@Override public List<ActivityType> get(ActivityCategory activityCategory) { return get(activityCategory, false); } @Override public List<ActivityType> get(ActivityCategory activityCategory, boolean activeOnly) { Search sTipoAtt = new Search(ActivityType.class); sTipoAtt.addFilter(HxFilter.equal(activityCategory.getId(), ActivityType._activityCategory, ActivityCategory._id)); if (activeOnly) sTipoAtt.addFilter(HxFilter.equal(true, ActivityType._active)); return getTipoAttivitaBySearch(sTipoAtt); } @Override public List<ActivityType> getTipoAttivitaBySearch(Search search) { return dao.get(search); } @Override public int countActivityType(Search search) { return dao.count(search); } @Override public List<ActivityType> getActivityTypeBySearch(Search search, int pageCurr, int pageSize) { return dao.get(search, pageCurr, pageSize); } @Override public void insertActivityType(ActivityType activityType) { dao.persist(activityType); } @Override public ActivityType getByCode(String code) { Search s = new Search(ActivityType.class); s.addFilter(HxFilter.ilike(code, ActivityType._code)); List<ActivityType> list = dao.get(s); if (list.size() > 0) return list.get(0); else return null; } } public interface ActivityTypeStatusService { List<ActivityTypeStatus> getTipoAttivitaStatoBySearch(Search search); public ActivityTypeStatus get(long id); } @Service public class ActivityTypeStatusServiceImpl implements ActivityTypeStatusService { @Autowired private ActivityTypeStatusDAO dao; @Override public List<ActivityTypeStatus> getTipoAttivitaStatoBySearch(Search search) { return dao.get(search); } public ActivityTypeStatus get(long id){ return dao.get(id); } } public interface ActivityUsedProductService { public abstract void insert(ActivityUsedProduct activityUsedResource); public abstract void delete(ActivityUsedProduct activityUsedResource); public abstract List<ActivityUsedProduct> get(); public abstract ActivityUsedProduct get(Long id); public abstract List<ActivityUsedProduct> get(Search search); public abstract List<ActivityUsedProduct> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); } @Service public class ActivityUsedProductServiceImpl implements ActivityUsedProductService { @Autowired ActivityUsedProductDAO dao; @Override public void insert(ActivityUsedProduct activityUsedResource) {

16

286885 BOMA
dao.persist(activityUsedResource); } @Override public void delete(ActivityUsedProduct activityUsedResource) { dao.remove(activityUsedResource); } @Override public List<ActivityUsedProduct> get() { return dao.get(); } @Override public ActivityUsedProduct get(Long id) { return dao.get(id); } @Override public List<ActivityUsedProduct> get(Search search) { return dao.get(search); } @Override public List<ActivityUsedProduct> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Override public int count() { return dao.count(); } @Override public int count(Search search) { return dao.count(search); } } public interface ActivityUsedResourceService { public abstract void insert(ActivityUsedResource activityUsedResource); public abstract void delete(ActivityUsedResource activityUsedResource); public abstract List<ActivityUsedResource> get(); public abstract ActivityUsedResource get(Long id); public abstract List<ActivityUsedResource> get(Search search); public abstract List<ActivityUsedResource> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); } @Service public class ActivityUsedResourceServiceImpl implements ActivityUsedResourceService { @Autowired private ActivityUsedResourceDAO dao; @Override public void insert(ActivityUsedResource activityUsedResource) { dao.persist(activityUsedResource); } @Override public void delete(ActivityUsedResource activityUsedResource) { dao.remove(activityUsedResource); } @Override public List<ActivityUsedResource> get() { return dao.get(); } @Override public ActivityUsedResource get(Long id) { return dao.get(id); } @Override public List<ActivityUsedResource> get(Search search) { return dao.get(search); } @Override public List<ActivityUsedResource> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Override public int count() {

17

286885 BOMA
return dao.count(); } @Override public int count(Search search) { return dao.count(search); } } public interface AttachmentActivityService { public AttachmentActivity get(long id); public List<AttachmentActivity> get(); public List<AttachmentActivity> get(Search search); List<AttachmentActivity> get(Search search, int i, int pageSize); public int count(Search search); public void insert(AttachmentActivity a); public void remove(AttachmentActivity a); public abstract void insertLink(Activity pp, String path, Operator o) throws AttachmentException; public abstract void insertFile(Activity pp, InputStream inputStream, String fileName, Operator o) throws AttachmentException; public abstract void insertFile(Activity pp, Reader reader, String fileName, Operator o) throws AttachmentException; public abstract void trash(Activity pp, Attachment a) throws AttachmentException; public abstract void trash(Attachment a) throws AttachmentException; public abstract List<Attachment> restoreFile(List<Attachment> attachments) throws AttachmentException; public abstract void deleteFile(List<Attachment> attachments) throws AttachmentException; public abstract void trash(Activity aa) throws AttachmentException; } @Service public class AttachmentActivityServiceImpl implements AttachmentActivityService { @Autowired private AttachmentActivityDAO dao; @Autowired private AttachmentService aM; private final String objectOfAttachment = "activity"; @Override public List<AttachmentActivity> get(Search search) { return dao.get(search); } public List<AttachmentActivity> get(Search search, int i, int pageSize) { return dao.get(search, i, pageSize); } public List<AttachmentActivity> get() { return dao.get(); } public AttachmentActivity get(long id){ return dao.get(id); } @Override public int count(Search search) { return dao.count(search); } @Override public void insert(AttachmentActivity a) { dao.persist(a); } @Override public void remove(AttachmentActivity a) { dao.remove(a); } private void addRealtionshipAttachmentActivity(Activity pp, Attachment a, Operator o) throws AttachmentException { Search sAttachPP = new Search(AttachmentActivity.class); sAttachPP.addFilter(HxFilter.equal(a, AttachmentActivity._attachment)); sAttachPP.addFilter(HxFilter.equal(pp, AttachmentActivity._activity)); sAttachPP.addFilter(HxFilter.equal(true, AttachmentActivity._active)); List<AttachmentActivity> listCheckAttachPP = get(sAttachPP); if (listCheckAttachPP != null && listCheckAttachPP.size() > 0) { throw new AttachmentException("This attachment already exist for this activity.", "gr"); } else { AttachmentActivity app = new AttachmentActivity(); app.setAttachment(a); app.setActivity(pp); app.setStartDate(new Date()); app.setOperator(o); app.setActive(true); insert(app);

18

286885 BOMA
} } @Override public void insertLink(Activity activity, String path, Operator operator) throws AttachmentException { Attachment attachment = aM.insertLink(path); if (attachment != null) addRealtionshipAttachmentActivity(activity, attachment, operator); } @Override public void insertFile(Activity activity, InputStream inputStream, String fileName, Operator operator) throws AttachmentException { String idObject = activity.getId().toString(); Attachment attachment = aM.insertFile(inputStream, fileName, objectOfAttachment, idObject); if (attachment != null) addRealtionshipAttachmentActivity(activity, attachment, operator); } @Override public void insertFile(Activity activity, Reader reader, String fileName, Operator operator) throws AttachmentException { ReaderInputStream ris; try { ris = new ReaderInputStream(reader, GlobalConfig.getReaderEncoding()); } catch (Exception e) { throw new AttachmentException("Unsupported encoding", "tu"); } String idObject = activity.getId().toString(); Attachment attachment = aM.insertFile(ris, fileName, objectOfAttachment, idObject); if (attachment != null) addRealtionshipAttachmentActivity(activity, attachment, operator); } @Override public void trash(Activity activity, Attachment attachment) throws AttachmentException { Search sAttachPP = new Search(AttachmentActivity.class); sAttachPP.addFilter(HxFilter.equal(attachment, AttachmentActivity._attachment)); sAttachPP.addFilter(HxFilter.equal(activity, AttachmentActivity._activity)); sAttachPP.addFilter(HxFilter.equal(true, AttachmentActivity._active)); List<AttachmentActivity> listCheckAttachPP = get(sAttachPP); if (listCheckAttachPP == null || listCheckAttachPP.size() > 1) { throw new AttachmentException("Error for this removal.","es"); } else { Date now = new Date(); AttachmentActivity app = listCheckAttachPP.get(0); app.setEndDate(now); app.setActive(false); insert(app); if (!attachment.isLink()) { aM.trashFile(attachment); } else { attachment.setActive(false); aM.insert(attachment); } } } @Override public void trash(Attachment attachment) throws AttachmentException { Search sAttachPP = new Search(AttachmentActivity.class); sAttachPP.addFilter(HxFilter.equal(attachment, AttachmentActivity._attachment)); sAttachPP.addFilter(HxFilter.equal(true, AttachmentActivity._active)); List<AttachmentActivity> listCheckAttachPP = get(sAttachPP); if (listCheckAttachPP == null || listCheckAttachPP.size() < 1) { throw new AttachmentException("Error for this removal.","es"); } else { Date now = new Date(); for (int i = 0; i < listCheckAttachPP.size(); i++) { AttachmentActivity app = listCheckAttachPP.get(i); app.setEndDate(now); app.setActive(false); insert(app); } if (!attachment.isLink()) {

19

286885 BOMA
aM.trashFile(attachment); } else { attachment.setActive(false); aM.insert(attachment); } } } @Override public List<Attachment> restoreFile(List<Attachment> attachments) throws AttachmentException { List<Attachment> attachmentsReturned = new ArrayList<Attachment>(); for (int z = 0; z < attachments.size(); z++) { Attachment a = attachments.get(z); Search sPP = new Search(AttachmentActivity.class); sPP.addFilter(HxFilter.equal(a, AttachmentActivity._attachment)); sPP.addFilter(HxFilter.equal(false, AttachmentActivity._active)); List<AttachmentActivity> listPP = get(sPP); for (int i = 0; i < listPP.size(); i++) { AttachmentActivity appMod = listPP.get(i); appMod.setActive(true); appMod.setEndDate(null); insert(appMod); } aM.restoreFile(a); } return attachmentsReturned; } @Override public void deleteFile(List<Attachment> attachments) throws AttachmentException { for (int z = 0; z < attachments.size(); z++) { Attachment a = attachments.get(z); Search sPP = new Search(AttachmentActivity.class); sPP.addFilter(HxFilter.equal(a, AttachmentActivity._attachment)); List<AttachmentActivity> listPP = get(sPP); for (int i = 0; i < listPP.size(); i++) { AttachmentActivity appMod = listPP.get(i); remove(appMod); } aM.deleteFile(a); } } @Override public void trash(Activity activity) throws AttachmentException { Search sAttachAct = new Search(AttachmentActivity.class); sAttachAct.addFilter(HxFilter.equal(activity, AttachmentActivity._activity)); List<AttachmentActivity> listAttachAct = get(sAttachAct); if (listAttachAct == null || listAttachAct.size() < 1) { throw new AttachmentException("Error for this removal.","es"); } else { for (int i = 0; i < listAttachAct.size(); i++) { AttachmentActivity app = listAttachAct.get(i); remove(app); Attachment a = aM.get(app.getAttachment().getId()); if (a.isActive()) { if (!a.isLink()) { aM.trashFile(a); } else { a.setActive(false); aM.insert(a); } } } } } } public interface AttachmentService { public abstract List<Attachment> get(Search search); public abstract List<Attachment> get(Search search, int i, int pageSize);

20

286885 BOMA
public abstract List<Attachment> get(); public abstract Attachment get(long id); public abstract int count(Search search); public abstract void insert(Attachment a); public abstract void remove(Attachment a); public abstract void editLink(Attachment a, String path, String label, String description, String note) throws AttachmentExce ption; public abstract void restoreFile(Attachment attachment) throws AttachmentException; public abstract void deleteFile(Attachment attachment) throws AttachmentException; public abstract Attachment insertFile(InputStream inputStream, String fileName, String objectOfAttachment, String idObject) t hrows AttachmentException; public Attachment insertLink(String path) throws AttachmentException; public void trashFile(Attachment a) throws AttachmentException; public abstract InputStream getFile(Attachment attachment) throws AttachmentException; } @Service public class AttachmentServiceImpl implements AttachmentService { @Autowired private AttachmentDAO dao; @Autowired private AttachmentTypeService atm; private final SecureRandom random = new SecureRandom(); private final String repositoryProtocol = "repository"; @Override public List<Attachment> get(Search search) { return dao.get(search); } @Override public List<Attachment> get(Search search, int i, int pageSize) { return dao.get(search, i, pageSize); } @Override public List<Attachment> get() { return dao.get(); } @Override public Attachment get(long id) { return dao.get(id); } @Override public int count(Search search) { return dao.count(search); } @Override public void insert(Attachment a) { dao.persist(a); } @Override public void remove(Attachment a) { dao.remove(a); } public void trashFile(Attachment attachment) throws AttachmentException { Repository repository; try { repository = Repository.getInstance(); } catch (RepositoryException e) { throw new AttachmentException(e.getMessage(), e.getTranslation()); } try { repository.trash(attachment.getPath()); } catch (RepositoryException e) { throw new AttachmentException(e.getMessage(), e.getTranslation()); } attachment.setActive(false); insert(attachment); } @Override public void editLink(Attachment a, String path, String label, String description, String note) throws AttachmentException { try { URL url = new URL(path); Search sAttach = new Search(Attachment.class); sAttach.addFilter(HxFilter.ilike(url.getProtocol(), Attachment._protocol));

21

286885 BOMA
sAttach.addFilter(HxFilter.ilike(url.getAuthority() + url.getPath(), Attachment._path)); sAttach.addFilter(HxFilter.equal(true, Attachment._active)); sAttach.addFilter(HxFilter.notEqual(a.getId(), Attachment._id)); List<Attachment> listCheckAttach = get(sAttach); if (listCheckAttach != null && listCheckAttach.size() > 0) { throw new AttachmentException("This link already exist!", "eu"); } else { a.setProtocol(url.getProtocol()); a.setPath(url.getAuthority() + url.getPath()); a.setLabel(label); a.setDescription(description); a.setLink(true); a.setNote(note); insert(a); } } catch (MalformedURLException e) { throw new AttachmentException("This isn't link!", "ex"); } } @Override public void restoreFile(Attachment attachment) throws AttachmentException { Repository repository; try { repository = Repository.getInstance(); } catch (RepositoryException e) { throw new AttachmentException(e.getMessage(), e.getTranslation()); } try { repository.restore(attachment.getPath()); } catch (RepositoryException e) { throw new AttachmentException(e.getMessage(), e.getTranslation()); } attachment.setActive(true); insert(attachment); } @Override public void deleteFile(Attachment attachment) throws AttachmentException { Repository repository; try { repository = Repository.getInstance(); } catch (RepositoryException e) { throw new AttachmentException(e.getMessage(), e.getTranslation()); } try { repository.delete(attachment.getPath()); } catch (RepositoryException e) { throw new AttachmentException(e.getMessage(), e.getTranslation()); } remove(attachment); } private String nextRandom() { String str = new BigInteger(128, random).toString(32); while (str.length() < 16) str = "0" + str; return str; } private String getExtension(String fileName) { String ext = null; int i = fileName.lastIndexOf('.'); if (i > 0 && i < fileName.length() - 1) { ext = fileName.substring(i + 1).toLowerCase(); } return ext; } @Override public Attachment insertFile(InputStream inputStream, String fileName, String objectOfAttachment, String idObject) throws

22

286885 BOMA
AttachmentException { Repository repository; try { repository = Repository.getInstance(); } catch (RepositoryException e) { throw new AttachmentException(e.getMessage(), e.getTranslation()); } String uniqueFileName = nextRandom() + "_" + fileName; String repositoryPath = null; try { while (repository.checkIfExists(uniqueFileName, objectOfAttachment, idObject)) { uniqueFileName = nextRandom() + "_" + fileName; } repositoryPath = repository.store(inputStream, uniqueFileName, objectOfAttachment, idObject); } catch (RepositoryException e) { throw new AttachmentException(e.getMessage(), e.getTranslation()); } Attachment attachment = new Attachment(); attachment.setProtocol(repositoryProtocol); attachment.setPath(repositoryPath); attachment.setActive(true); attachment.setLink(false); String extension = getExtension(fileName); List<AttachmentType> atList = atm.getByCode("." + extension); if (atList != null & atList.size() == 1) { attachment.setAttachmentType(atList.get(0)); } else { throw new AttachmentException("Check attachment type!", "f8"); } attachment.setLabel(fileName); insert(attachment); return attachment; } public Attachment insertLink(String path) throws AttachmentException { Attachment attachSave = null; try { URL url = new URL(path); Search sAttach = new Search(Attachment.class); sAttach.addFilter(HxFilter.ilike(url.getProtocol(), Attachment._protocol)); sAttach.addFilter(HxFilter.ilike(url.getAuthority() + url.getPath(), Attachment._path)); sAttach.addFilter(HxFilter.equal(true, Attachment._active)); List<Attachment> listCheckAttach = get(sAttach); if (listCheckAttach != null && listCheckAttach.size() > 0) { attachSave = listCheckAttach.get(0); } else { Attachment a = new Attachment(); a.setProtocol(url.getProtocol()); a.setPath(url.getAuthority() + url.getPath()); a.setActive(true); String label = url.getHost(); label = label + " " + new File(url.getPath()).getName(); a.setLabel(label); a.setLink(true); insert(a); attachSave = a; } } catch (MalformedURLException e) { throw new AttachmentException("This isn't link!", "ex"); } return attachSave; } @Override public InputStream getFile(Attachment attachment) throws AttachmentException { Repository repository; try { repository = Repository.getInstance(); }

23

286885 BOMA
catch (RepositoryException e) { throw new AttachmentException(e.getMessage(), e.getTranslation()); } InputStream inputStream = null; try { inputStream = repository.retrieve(attachment.getPath(), !attachment.isActive()); } catch (RepositoryException e) { throw new AttachmentException(e.getMessage(), e.getTranslation()); } return inputStream; } } public interface AttachmentTypeService { public AttachmentType getById(long id); public List<AttachmentType> getAll(); public List<AttachmentType> getBySearch(Search search); List<AttachmentType> getBySearchAndPage(Search search, int i, int pageSize); public int count(Search search); public void save(AttachmentType a); public AttachmentType findById(long id); public List<AttachmentType> getByCode(String code); } @Service public class AttachmentTypeServiceImpl implements AttachmentTypeService { @Autowired private AttachmentTypeDAO dao; @Override public List<AttachmentType> getBySearch(Search search) { return dao.get(search); } public List<AttachmentType> getBySearchAndPage(Search search, int i, int pageSize) { return dao.get(search, i, pageSize); } public List<AttachmentType> getAll() { return dao.get(); } public AttachmentType getById(long id){ return dao.get(id); } @Override public int count(Search search) { return dao.count(search); } @Override public void save(AttachmentType a) { dao.persist(a); } public AttachmentType findById(long id) { return dao.get(id); } public List<AttachmentType> getByCode(String code){ Search search=new Search(AttachmentType.class); search.addFilter(HxFilter.ilike(code, AttachmentType._code)); return dao.get(search); } } public interface CustomAttributeActivityAllowService { public CustomAttributeActivityAllow get (Long id); public void save(CustomAttributeActivityAllow ca); public List<CustomAttributeActivityAllow> getBySearch(Search search); public List<CustomAttributeActivityAllow> getBySearchAndPage(Search search, int itemStartNumber, int pageSize); public Boolean isPredefined(CustomAttribute ca); public CustomAttributeActivityAllow getByObject(CustomAttribute ca); } @Service public class CustomAttributeActivityAllowServiceImpl implements CustomAttributeActivityAllowService { @Autowired private CustomAttributeActivityAllowDAO dao;

24

286885 BOMA
public CustomAttributeActivityAllow get (Long id) { return dao.get(id); } public void save(CustomAttributeActivityAllow ca) { dao.persist(ca); } public List<CustomAttributeActivityAllow> getBySearch(Search search) { return dao.get(search); } public List<CustomAttributeActivityAllow> getBySearchAndPage(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } public Boolean isPredefined(CustomAttribute ca) { if(ca == null || ca.getId() == null) return null; Search s = new Search(CustomAttributeActivityAllow.class); s.addFilter(HxFilter.equal(ca.getId(), CustomAttributeActivityValue._customAttribute, CustomAttribute._id)); List<CustomAttributeActivityAllow> l = dao.get(s); if (l.size() > 1){ String err = "Duplicate value for custom attribute "+ca.getId(); System.err.println(err); } if (l.size() == 0) return null; return l.get(0).isPredefined(); } public CustomAttributeActivityAllow getByObject(CustomAttribute ca) { Search s = new Search(CustomAttributeActivityAllow.class); s.addFilter(HxFilter.equal(ca.getId(), CustomAttributeActivityAllow._customAttribute, CustomAttribute._id)); List<CustomAttributeActivityAllow> l = dao.get(s); if (l.size() > 1) System.err.print("\nCustomAttributeActivityAllow duplicato per CustomAttribute:"+ca.getId()); if (l.size() == 1) return l.get(0); return null; } } public interface CustomAttributeActivityValueService { public void save(CustomAttributeActivityValue ca); public List<CustomAttributeActivityValue> getBySearch(Search search); public List<CustomAttributeActivityValue> getBySearchAndPage(Search search, int itemStartNumber, int pageSize); public String getValue(Activity pp, CustomAttribute ca); public CustomAttributeActivityValue getByObject(Activity pp,CustomAttribute ca, Boolean active); public CustomAttributeActivityValue getById(Long id); } @Service public class CustomAttributeActivityValueServiceImpl implements CustomAttributeActivityValueService { @Autowired private CustomAttributeActivityValueDAO dao; public void save(CustomAttributeActivityValue ca) { dao.persist(ca); } public List<CustomAttributeActivityValue> getBySearch(Search search) { return dao.get(search); } public List<CustomAttributeActivityValue> getBySearchAndPage(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } public String getValue(Activity pp, CustomAttribute ca) { if(pp == null || ca == null || pp.getId() == null || ca.getId() == null) return null; Search s = new Search(CustomAttributeActivityValue.class); s.addFilter(HxFilter.equal(ca.getId(), CustomAttributeActivityValue._customAttribute, CustomAttribute._id)); s.addFilter(HxFilter.equal(pp.getId(), CustomAttributeActivityValue._activity, Activity._id)); s.addFilter(HxFilter.equal(true, CustomAttributeActivityValue._active)); List<CustomAttributeActivityValue> l = dao.get(s); if (l.size() > 1){ String err = "Duplicate value for physical product "+pp.getId()+" custom attribute "+ca.getId(); System.err.println(err); } if (l.size() == 0) return null;

25

286885 BOMA
return l.get(0).getValue(); } public CustomAttributeActivityValue getByObject(Activity pp, CustomAttribute ca, Boolean active) { if(pp == null || ca == null || pp.getId() == null || ca.getId() == null) return null; Search s = new Search(CustomAttributeActivityValue.class); s.addFilter(HxFilter.equal(ca.getId(), CustomAttributeActivityValue._customAttribute, CustomAttribute._id)); s.addFilter(HxFilter.equal(pp.getId(), CustomAttributeActivityValue._activity, Activity._id)); if (active != null) s.addFilter(HxFilter.equal(active.booleanValue(), CustomAttributeActivityValue._active)); List<CustomAttributeActivityValue> l = dao.get(s); if (l.size() > 1 && active != null && active.booleanValue()){ String err = "Duplicate value for physical product "+pp.getId()+" custom attribute "+ca.getId(); System.err.println(err); } if (l.size() == 0) return null; return l.get(0); } public CustomAttributeActivityValue getById(Long id) { return dao.get(id); } } public interface CustomAttributeService { public void save(CustomAttribute ca); public CustomAttribute get(String name, CustomAttributeType customAttributeType); public List<CustomAttribute> getBySearch(Search search); public List<CustomAttribute> getBySearchAndPage(Search search, int itemStartNumber, int pageSize); public int count(); public int countBySearch(Search s); public CustomAttribute getById(Long id); public void saveCustomAttributePhysicalProduct(CustomAttribute ca, CustomAttributePhysicalProductValue cappv, CustomAttributePhysicalProductAllow cappa); public void saveCustomAttributePhysicalProduct(CustomAttribute ca, CustomAttributePhysicalProductAllow cappa); public void saveCustomAttributeProductType(CustomAttribute ca, CustomAttributeProductTypeValue cappv, CustomAttributeProductTypeAllow cappa); public void saveCustomAttributeProductFamily(CustomAttribute ca, CustomAttributeProductFamilyValue cappv, CustomAttributeProductFamilyAllow cappa); public void saveCustomAttributeActivity(CustomAttribute ca, CustomAttributeActivityValue cappv, CustomAttributeActivityAllow cappa); } @Service public class CustomAttributeServiceImpl implements CustomAttributeService { @Autowired private CustomAttributeDAO dao; public void save(CustomAttribute ca) { dao.persist(ca); } @Override public CustomAttribute get(String name, CustomAttributeType customAttributeType) { Search search = new Search(CustomAttribute.class); search.addFilter(HxFilter.equal(name, CustomAttribute._name)); search.addFilter(HxFilter.equal(customAttributeType, CustomAttribute._customAttributeType)); List<CustomAttribute> list = dao.get(search); if (list.size() > 0) return list.get(0); return null; } public List<CustomAttribute> getBySearch(Search search) { return dao.get(search); } public List<CustomAttribute> getBySearchAndPage(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } public int count() { return dao.count(); } public int countBySearch(Search s) { return dao.count(s);

26

286885 BOMA
} public CustomAttribute getById(Long id){ return dao.get(id); } public static boolean newCustomAttributePhisicalProduct( PhysicalProduct pp, String name, CustomAttributeType type, boolean predefined, String value) { if (type == null) return false; if (name == null || name.equals("")) return true; Search s = new Search(CustomAttribute.class); s.addFilter(HxFilter.equal(type.getId(), CustomAttribute._customAttributeType, CustomAttributeType._id)); s.addFilter(HxFilter.equal(name, CustomAttribute._name)); List<CustomAttribute> listCA = ServiceLocator.getCustomAttributeManager().getBySearch(s); if (listCA !=null && listCA.size() > 1) System.err.printf("Duplicato custom attribute"); CustomAttribute ca; if (listCA == null || listCA.size() == 0){ ca = new CustomAttribute(); ca.setName(name); ca.setCustomAttributeType(type); } else { ca = listCA.get(0); } CustomAttributePhysicalProductValue cappv = null; CustomAttributePhysicalProductAllow cappa = null; if (ca.getId() != null) { if(pp != null) cappv = ServiceLocator.getCustomAttributePhysicalProductValueManager().getByObject(pp, ca, true); if(cappv != null) return false; cappa = ServiceLocator.getCustomAttributePhysicalProductAllowManager().getByObject(ca); } else { ServiceLocator.getCustomAttributeManager().save(ca); } if(cappa == null) { cappa = new CustomAttributePhysicalProductAllow(); cappa.setCustomAttribute(ca); } cappa.setPredefined(predefined); ServiceLocator.getCustomAttributePhysicalProductAllowManager().save(cappa); if (pp == null) return true; if(value == null || value.equals("") || pp == null) { } else { cappv = new CustomAttributePhysicalProductValue(); cappv.setPhysicalProduct(pp); cappv.setCustomAttribute(ca); cappv.setActive(true); cappv.setValue(value); cappv.setDateStart(new Date()); ServiceLocator.getCustomAttributePhysicalProductValueManager().save(cappv); } return true; } public void saveCustomAttributePhysicalProduct(CustomAttribute ca, CustomAttributePhysicalProductValue cappv, CustomAttributePhysicalProductAllow cappa) { ServiceLocator.getCustomAttributeService().save(ca); ServiceLocator.getCustomAttributePhysicalProductAllowService().save(cappa); if (cappv.getValue() == null || cappv.getValue().equals("")) cappv.setActive(false); if (!cappv.isActive()) { if (cappv.getId() != null) ServiceLocator.getCustomAttributePhysicalProductValueService().save(cappv); } else { if(cappv.getId()!=null){ CustomAttributePhysicalProductValue old = ServiceLocator.getCustomAttributePhysicalProductValueService().getById(cappv.getId()); if (old.getValue().equals(cappv.getValue())) return; old.setActive(false); old.setDateEnd(new Date());

27

286885 BOMA
ServiceLocator.getCustomAttributePhysicalProductValueService().save(old); } cappv.setDateStart(new Date()); cappv.setId(null); ServiceLocator.getCustomAttributePhysicalProductValueService().save(cappv); } } public void saveCustomAttributePhysicalProduct(CustomAttribute ca, CustomAttributePhysicalProductAllow cappa) { ServiceLocator.getCustomAttributeService().save(ca); ServiceLocator.getCustomAttributePhysicalProductAllowService().save(cappa); } public void saveCustomAttributeProductType(CustomAttribute ca, CustomAttributeProductTypeValue cappv, CustomAttributeProductTypeAllow cappa) { ServiceLocator.getCustomAttributeService().save(ca); ServiceLocator.getCustomAttributeProductTypeAllowService().save(cappa); if (cappv.getValue() == null || cappv.getValue().equals("")) cappv.setActive(false); if (!cappv.isActive()) { if (cappv.getId() != null) ServiceLocator.getCustomAttributeProductTypeValueService().save(cappv); } else { if(cappv.getId()!=null){ CustomAttributeProductTypeValue old = ServiceLocator.getCustomAttributeProductTypeValueService().getById(cappv.getId()); if (old.getValue().equals(cappv.getValue())) return; old.setActive(false); old.setDateEnd(new Date()); ServiceLocator.getCustomAttributeProductTypeValueService().save(old); } cappv.setDateStart(new Date()); cappv.setId(null); ServiceLocator.getCustomAttributeProductTypeValueService().save(cappv); } } public void saveCustomAttributeProductFamily(CustomAttribute ca, CustomAttributeProductFamilyValue cappv, CustomAttributeProductFamilyAllow cappa) { ServiceLocator.getCustomAttributeService().save(ca); ServiceLocator.getCustomAttributeProductFamilyAllowService().save(cappa); if (cappv.getValue() == null || cappv.getValue().equals("")) cappv.setActive(false); if (!cappv.isActive()) { if (cappv.getId() != null) ServiceLocator.getCustomAttributeProductFamilyValueService().save(cappv); } else { if(cappv.getId()!=null){ CustomAttributeProductFamilyValue old = ServiceLocator.getCustomAttributeProductFamilyValueService().getById(cappv.getId()); if (old.getValue().equals(cappv.getValue())) return; old.setActive(false); old.setDateEnd(new Date()); ServiceLocator.getCustomAttributeProductFamilyValueService().save(old); } cappv.setDateStart(new Date()); cappv.setId(null); ServiceLocator.getCustomAttributeProductFamilyValueService().save(cappv); } } public void saveCustomAttributeActivity(CustomAttribute ca, CustomAttributeActivityValue cappv, CustomAttributeActivityAllow cappa) { ServiceLocator.getCustomAttributeService().save(ca); ServiceLocator.getCustomAttributeActivityAllowService().save(cappa); if (cappv.getValue() == null || cappv.getValue().equals("")) cappv.setActive(false); if (!cappv.isActive()) { if (cappv.getId() != null) ServiceLocator.getCustomAttributeActivityValueService().save(cappv);

28

286885 BOMA
} else { if(cappv.getId()!=null){ CustomAttributeActivityValue old = ServiceLocator.getCustomAttributeActivityValueService().getById(cappv.getId()); if (old.getValue().equals(cappv.getValue())) return; old.setActive(false); old.setDateEnd(new Date()); ServiceLocator.getCustomAttributeActivityValueService().save(old); } cappv.setDateStart(new Date()); cappv.setId(null); ServiceLocator.getCustomAttributeActivityValueService().save(cappv); } } } @Service public class CustomAttributeServiceImpl implements CustomAttributeService { @Autowired private CustomAttributeDAO dao; public void save(CustomAttribute ca) { dao.persist(ca); } @Override public CustomAttribute get(String name, CustomAttributeType customAttributeType) { Search search = new Search(CustomAttribute.class); search.addFilter(HxFilter.equal(name, CustomAttribute._name)); search.addFilter(HxFilter.equal(customAttributeType, CustomAttribute._customAttributeType)); List<CustomAttribute> list = dao.get(search); if (list.size() > 0) return list.get(0); return null; } public List<CustomAttribute> getBySearch(Search search) { return dao.get(search); } public List<CustomAttribute> getBySearchAndPage(Search search, int currPage, int pag eSize) { return dao.get(search, currPage, pageSize); } public int count() { return dao.count(); } public int countBySearch(Search s) { return dao.count(s); } public CustomAttribute getById(Long id){ return dao.get(id); } public static boolean newCustomAttributePhisicalProduct( PhysicalProduct pp, String name, CustomAttributeType type, boolean predefined, String value) { if (type == null) return false; if (name == null || name.equals("")) return true; Search s = new Search(CustomAttribute.class); s.addFilter(HxFilter.equal(type.getId(), CustomAttribute._customAttributeType, CustomAttributeType._id)); s.addFilter(HxFilter.equal(name, CustomAttribute._name)); List<CustomAttribute> listCA = ServiceLocator.getCustomAttributeManager().getBySearch(s); if (listCA !=null && listCA.size() > 1) System.err.printf("Duplicato custom attribute"); CustomAttribute ca; if (listCA == null || listCA.size() == 0){ ca = new CustomAttribute(); ca.setName(name); ca.setCustomAttributeType(type); } else { ca = listCA.get(0); }

29

286885 BOMA
CustomAttributePhysicalProductValue cappv = null; CustomAttributePhysicalProductAllow cappa = null; if (ca.getId() != null) { if(pp != null) cappv = ServiceLocator.getCustomAttributePhysicalProductValueManager().getByObject(pp, ca, true); if(cappv != null) return false; cappa = ServiceLocator.getCustomAttributePhysicalProductAllowManager().getByObject(ca); } else { ServiceLocator.getCustomAttributeManager().save(ca); } if(cappa == null) { cappa = new CustomAttributePhysicalProductAllow(); cappa.setCustomAttribute(ca); } cappa.setPredefined(predefined); ServiceLocator.getCustomAttributePhysicalProductAllowManager().save(cappa); if (pp == null) return true; if(value == null || value.equals("") || pp == null) { } else { cappv = new CustomAttributePhysicalProductValue(); cappv.setPhysicalProduct(pp); cappv.setCustomAttribute(ca); cappv.setActive(true); cappv.setValue(value); cappv.setDateStart(new Date()); ServiceLocator.getCustomAttributePhysicalProductValueManager().save(cappv); } return true; } public void saveCustomAttributePhysicalProduct(CustomAttribute ca, CustomAttributePhysicalProductValue cappv, CustomAttributePhysicalProductAllow cappa) { ServiceLocator.getCustomAttributeService().save(ca); ServiceLocator.getCustomAttributePhysicalProductAllowService().save(cappa); if (cappv.getValue() == null || cappv.getValue().equals("")) cappv.setActive(false); if (!cappv.isActive()) { if (cappv.getId() != null) ServiceLocator.getCustomAttributePhysicalProductValueService().save(cappv); } else { if(cappv.getId()!=null){ CustomAttributePhysicalProductValue old = ServiceLocator.getCustomAttributePhysicalProductValueService().getById(cappv.getId()); if (old.getValue().equals(cappv.getValue())) return; old.setActive(false); old.setDateEnd(new Date()); ServiceLocator.getCustomAttributePhysicalProductValueService().save(old); } cappv.setDateStart(new Date()); cappv.setId(null); ServiceLocator.getCustomAttributePhysicalProductValueService().save(cappv); } } public void saveCustomAttributePhysicalProduct(CustomAttribute ca, CustomAttributePhysicalProductAllow cappa) { ServiceLocator.getCustomAttributeService().save(ca); ServiceLocator.getCustomAttributePhysicalProductAllowService().save(cappa); } public void saveCustomAttributeProductType(CustomAttribute ca, CustomAttributeProductTypeValue cappv, CustomAttributeProductTypeAllow cappa) { ServiceLocator.getCustomAttributeService().save(ca); ServiceLocator.getCustomAttributeProductTypeAllowService().save(cappa); if (cappv.getValue() == null || cappv.getValue().equals("")) cappv.setActive(false); if (!cappv.isActive()) { if (cappv.getId() != null) ServiceLocator.getCustomAttributeProductTypeValueService().save(cappv); } else { if(cappv.getId()!=null){ CustomAttributeProductTypeValue old = ServiceLocator.getCustomAttributeProductTypeValueService().getById(cappv.getId());

30

286885 BOMA
if (old.getValue().equals(cappv.getValue())) return; old.setActive(false); old.setDateEnd(new Date()); ServiceLocator.getCustomAttributeProductTypeValueService().save(old); } cappv.setDateStart(new Date()); cappv.setId(null); ServiceLocator.getCustomAttributeProductTypeValueService().save(cappv); } } public void saveCustomAttributeProductFamily(CustomAttribute ca, CustomAttributeProductFamilyValue cappv, CustomAttributeProductFamilyAllow cappa) { ServiceLocator.getCustomAttributeService().save(ca); ServiceLocator.getCustomAttributeProductFamilyAllowService().save(cappa); if (cappv.getValue() == null || cappv.getValue().equals("")) cappv.setActive(false); if (!cappv.isActive()) { if (cappv.getId() != null) ServiceLocator.getCustomAttributeProductFamilyValueService().save(cappv); } else { if(cappv.getId()!=null){ CustomAttributeProductFamilyValue old = ServiceLocator.getCustomAttributeProductFamilyValueService().getById(cappv.getId()); if (old.getValue().equals(cappv.getValue())) return; old.setActive(false); old.setDateEnd(new Date()); ServiceLocator.getCustomAttributeProductFamilyValueService().save(old); } cappv.setDateStart(new Date()); cappv.setId(null); ServiceLocator.getCustomAttributeProductFamilyValueService().save(cappv); } } public void saveCustomAttributeActivity(CustomAttribute ca,CustomAttributeActivityValue cappv,CustomAttributeActivityAllow cappa) { ServiceLocator.getCustomAttributeService().save(ca); ServiceLocator.getCustomAttributeActivityAllowService().save(cappa); if (cappv.getValue() == null || cappv.getValue().equals("")) cappv.setActive(false); if (!cappv.isActive()) { if (cappv.getId() != null) ServiceLocator.getCustomAttributeActivityValueService().save(cappv); } else { if(cappv.getId()!=null){ CustomAttributeActivityValue old = ServiceLocator.getCustomAttributeActivityValueService().getById(cappv.getId()); if (old.getValue().equals(cappv.getValue())) return; old.setActive(false); old.setDateEnd(new Date()); ServiceLocator.getCustomAttributeActivityValueService().save(old); } cappv.setDateStart(new Date()); cappv.setId(null); ServiceLocator.getCustomAttributeActivityValueService().save(cappv); } } } @Service public class CustomAttributeTypeServiceImpl implements CustomAttributeTypeService { @Autowired private CustomAttributeTypeDAO dao; public void save(CustomAttributeType ca) { dao.persist(ca); } public List<CustomAttributeType> getAll() { return dao.get(); } public CustomAttributeType getById(Long id) { return dao.get(id);

31

286885 BOMA
} public boolean isValid(String value, Long id, Long... idAttribute) { try { switch (id.intValue()) { case it.holonix.ilike.entity.persistent.id.CustomAttributeType.Text: return true; case it.holonix.ilike.entity.persistent.id.CustomAttributeType.IntegerNumber: Integer.parseInt(value); return true; case it.holonix.ilike.entity.persistent.id.CustomAttributeType.FloatingPointNumber: Float.parseFloat(value); return true; case it.holonix.ilike.entity.persistent.id.CustomAttributeType.ListofValues: return true; } } catch (NumberFormatException e) { return false; } return false; } @Override public boolean isValid(String value, CustomAttributeType customAttributeType) { return isValid(value, customAttributeType.getId()); } public List<CustomAttributeType> getBySearch(Search search) { return dao.get(search); } @Override public CustomAttributeType get(String name) { Search search = new Search(CustomAttributeType.class); search.addFilter(HxFilter.equal(name, CustomAttributeType._name)); List<CustomAttributeType> list = dao.get(search); if (list.size() > 0) return list.get(0); return null; } @Override public void insert(CustomAttributeType customAttributeType) { dao.persist(customAttributeType); } }

4.1.2. Interface Code


<?page title="Lista attivita" contentType="text/html;charset=UTF-8"?> <zk> <window id="wndListaAttivita" border="none" use="it.holonix.ilike.view.attivita.ViewActivityList" style="overflow:auto;"> <style src="./stili/stile_extra.css"/> <div id="divButtonsBar" sclass="buttonsBar" /> <panel sclass="pnlWindowContainer"> <panelchildren> <div sclass="lbTitoloPagina"> <label value="Activities list"> <custom-attributes translation="4y"/> </label> </div> <space spacing="10px" /> <groupbox> <caption label="Search" style="font-weight:bold;"> <custom-attributes translation="j"/> </caption> <vbox> <hbox> <vbox> <hbox> <label value="Name"> <custom-attributes translation="8"/> </label>

32

286885 BOMA
<label value="Type"> <custom-attributes translation="1p"/> </label> <label value="Status"> <custom-attributes translation="1e"/> </label> <label value="Operator"> <custom-attributes translation="1w"/> </label> <label value="Description"> <custom-attributes translation="3i"/> </label> </hbox> <textbox id="tbCodiceRicerca" width="250px" /> </vbox> <space spacing="10px" /> <vbox> <label value="Activity category"> <custom-attributes translation="8g"/> </label> <combobox id="cmbCategoriaAttivita" readonly="true" width="150px" /> </vbox> <space spacing="10px" /> <vbox> <label value="Planning date"> <custom-attributes translation="51"/> </label> <hbox> <div width="50px"> <label value="From"> <custom-attributes translation="2k" /> </label> </div> <datebox id="dbDalStart" width="100px"> </datebox> </hbox> <hbox> <div width="50px"> <label value="To"> <custom-attributes translation="2l" /> </label> </div> <datebox id="dbAlStart" width="100px"> </datebox> </hbox> </vbox> <space spacing="10px" /> <vbox> <label value="Exedcution date"> <custom-attributes translation="53"/> </label> <hbox> <div width="50px"> <label value="From"> <custom-attributes translation="2k" /> </label> </div> <datebox id="dbDalEnd" width="100px"> </datebox> </hbox> <hbox> <div width="50px"> <label value="To"> <custom-attributes translation="2l" /> </label>

33

286885 BOMA
</div> <datebox id="dbAlEnd" width="100px"> </datebox> </hbox> </vbox> </hbox> <button label="Find" id="btnSearch"> <custom-attributes translation="1"/> </button> </vbox> </groupbox> <separator spacing="10px"/> <listbox id="listElencoAttivita" sizedByContent="true" span="true"> <listhead> <listheader label="Type" sort="auto"> <custom-attributes translation="1p"/> </listheader> <listheader label="Name" sort="auto"> <custom-attributes translation="8"/> </listheader> <listheader label="Activity type" sort="auto"> <custom-attributes translation="32"/> </listheader> <listheader label="Status"> <custom-attributes translation="1e"/> </listheader> <listheader label="Planning start date" sort="auto"> <custom-attributes translation="34"/> </listheader> <listheader label="Planning deadline" sort="auto"> <custom-attributes translation="33"/> </listheader> <listheader label="Start exec. date" sort="auto"> <custom-attributes translation="35"/> </listheader> <listheader label="End exec. date" sort="auto"> <custom-attributes translation="36"/> </listheader> <listheader label="Operator" sort="auto"> <custom-attributes translation="1w" /> </listheader> <listheader label="Object resource" sort="auto"> <custom-attributes translation="37"/> </listheader> <listheader label="Description" sort="auto"> <custom-attributes translation="3i"/> </listheader> <listheader label="Detail" sort="auto" align="center"> <custom-attributes translation="p"/> </listheader> </listhead> </listbox> <paging id="pageListElencoAttivita" onPaging="wndListaAttivita.onPagingListAttivita(event)"/> </panelchildren> </panel> </window> </zk> public class ViewActivityList extends HxWindow { private static final long serialVersionUID = 1693967111711157796L; ActivityCategoryService acm=ServiceLocator.getActivityCategoryService(); @Wire Textbox tbCodiceRicerca; @Wire Datebox dbDalStart; @Wire Datebox dbAlStart; @Wire Datebox dbDalEnd; @Wire Datebox dbAlEnd; @Wire Combobox cmbCategoriaAttivita; Search searchAttivita; private final int _pageSizeAttivita = GlobalConfig.getListItemCountLarge(); private int _startPageNumberAttivita = 0; private int _totalSizeAttivita = 0;

34

286885 BOMA
private boolean _needsTotalSizeUpdateAttivita = true; @Wire Listbox listElencoAttivita; @Wire Paging pageListElencoAttivita; PagingListModelAttivita modelList=null; int idRisorsaCorrente; public void onCreate(){ super.onCreate(); HtmlMacroComponent compCenter = (HtmlMacroComponent)this.getRoot().getFellow("idCpCenter"); this.setHeight(compCenter.getHeight()); Div divHeader=(Div)this.getFellow("divButtonsBar"); Executions.getCurrent().createComponents("./headers/headerElencoAttivitaLista.zul", divHeader, null); Selectors.wireComponents(this, this, false); Selectors.wireEventListeners(this, this); List<ActivityCategory> acList=acm.getAllAttivitaCategoria(); Comboitem tuttiItem = cmbCategoriaAttivita.appendItem("All"); tuttiItem.setValue(null); tuttiItem.setAttribute("translation", "4f"); cmbCategoriaAttivita.setSelectedItem(tuttiItem); for(ActivityCategory ac:acList) { Comboitem comboitem = new Comboitem(ac.getLabel()); comboitem.setValue(ac); comboitem.setAttribute("translation", ac.getTranslation()); cmbCategoriaAttivita.appendChild(comboitem); } ZK.translate(cmbCategoriaAttivita); listElencoAttivita.setItemRenderer(new ListitemActivityRenderer(this)); this.searchAttivita=new Search(Activity.class); this.searchAttivita.addSortAsc(Activity._plannedStartDate); if(DetectSystem.detectOS()==2){ this.searchAttivita.addFilter(HxFilter.equal(it.holonix.ilike.entity.persistent.id.ActivityStatus.nonEseguito, Activity._activityStatus, ActivityStatus._id)); } if(this.getAttribute("idRisorsa")!=null){ this.idRisorsaCorrente=Integer.parseInt(this.getAttribute("idRisorsa").toString()); this.searchAttivita.addFilter(HxFilter.equal(this.idRisorsaCorrente, Activity._resource, Resource._id)); } refreshModelAttivita(_startPageNumberAttivita); } private void refreshModelAttivita(int activePage){ this.pageListElencoAttivita.setPageSize(_pageSizeAttivita); modelList = new PagingListModelAttivita(this.searchAttivita,activePage, _pageSizeAttivita); if(_needsTotalSizeUpdateAttivita) { _totalSizeAttivita = modelList.getTotalSize(this.searchAttivita); _needsTotalSizeUpdateAttivita = false; } this.pageListElencoAttivita.setTotalSize(_totalSizeAttivita); listElencoAttivita.setModel(modelList); } @Listen("onPaging = #pageListElencoAttivita") public void onPagingListAttivita(Event event){ _startPageNumberAttivita = ((Paging)(event.getTarget())).getActivePage(); refreshModelAttivita(_startPageNumberAttivita); } @Listen("onClick = #listElencoAttivita .btnDetail") public void onClickDettaglio(Event event) { Activity activity = ((Listcell) event.getTarget()).getValue(); Window w=(Window)Executions.createComponents(PagePath.activityDetail, this, null); w.setAttribute("activity", activity); w.setClosable(true); w.setWidth(GlobalConfig.getModalWindowWidthMedium()); w.setFocus(true); w.doOverlapped(); w.doModal(); } @Listen("onClick = #linkBtnNew") public void onClickNuovaAttivita() { Window w=(Window)Executions.createComponents(PagePath.activityDetail, this, null); w.setWidth(GlobalConfig.getModalWindowWidthMedium()); w.setClosable(true); w.setFocus(true); w.doOverlapped(); w.doModal();

35

286885 BOMA
} @Listen("onClick = #btnSearch; onOK = #tbCodiceRicerca") public void onClickRicercaRapida(){ this.searchAttivita.clearFilters(); String codice = this.tbCodiceRicerca.getText(); if (codice.length() > 0) { String testo = "%" + codice +"%"; this.searchAttivita.addFilterOr(HxFilter.ilike(testo, Activity._name), HxFilter.ilike(testo, Activity._activityType, ActivityType._label), HxFilter.ilike(testo, Activity._activityOperators, ActivityOperator._operator, Operator._label), HxFilter.ilike(testo, Activity._activityStatus, ActivityStatus._code), HxFilter.ilike(testo, Activity._activityPhysicalProductObjects, ActivityPhysicalProductObject._description)); } else { this.searchAttivita.clearFilters(); } if(this.dbDalStart.getValue()!=null) { this.searchAttivita.addFilter(HxFilter.greaterOrEqual(this.dbDalStart.getValue(), Activity._plannedStartDate)); } if(this.dbAlStart.getValue()!=null) { Calendar c=Calendar.getInstance(); c.setTime(this.dbAlStart.getValue()); c.add(Calendar.DATE, 1); this.searchAttivita.addFilter(HxFilter.lessOrEqual(c.getTime(), Activity._plannedEndDate)); } if(this.dbDalEnd.getValue()!=null){ this.searchAttivita.addFilter(HxFilter.greaterOrEqual(this.dbDalEnd.getValue(), Activity._executionStartDate)); } if(this.dbAlEnd.getValue()!=null){ Calendar c=Calendar.getInstance(); c.setTime(this.dbAlEnd.getValue()); c.add(Calendar.DATE, 1); this.searchAttivita.addFilter(HxFilter.lessOrEqual(c.getTime(), Activity._executionEndDate)); } if (this.cmbCategoriaAttivita.getSelectedItem().getValue() != null) { ActivityCategory activityCategory = cmbCategoriaAttivita.getSelectedItem().getValue(); this.searchAttivita.addFilter(HxFilter.equal(activityCategory.getId(), Activity._activityType, ActivityType._activityCategory, ActivityCategory._id)); } this._needsTotalSizeUpdateAttivita=true; refreshModelAttivita(0); } public void aggiornaListaAttivita() { this._needsTotalSizeUpdateAttivita=true; refreshModelAttivita(0); } } public class WndActivityDetail extends HxWindow { private static final long serialVersionUID = 8330556562061928255L; private Activity attivitaCorrente; private ActivityService am = ServiceLocator.getActivityService(); private ActivityTypeService tam = ServiceLocator.getActivityTypeService(); private ActivityStatusService sam = ServiceLocator.getActivityStatusService(); private ResourceService rm = ServiceLocator.getResourceService(); private OperatorService om = ServiceLocator.getOperatorService(); private ActivityOperatorService aoM = ServiceLocator.getActivityOperatorService(); private AttachmentActivityService achaM = ServiceLocator.getAttachmentActivityService(); private OperationService opm = ServiceLocator.getOperationService(); private TextService tm=ServiceLocator.getTextService(); private ActivityCategoryService acM = ServiceLocator.getActivityCategoryService(); private CustomAttributeService caM = ServiceLocator.getCustomAttributeService(); private CustomAttributeTypeService catM = ServiceLocator.getCustomAttributeTypeService(); private CustomAttributeActivityAllowService caaaM = ServiceLocator.getCustomAttributeActivityAllowService(); private CustomAttributeActivityValueService caavM = ServiceLocator.getCustomAttributeActivityValueService(); private ActivityPhysicalProductObjectService apfoM = ServiceLocator.getActivityPhysicalProductObjectService(); private ActivityUsedResourceService aruM = ServiceLocator.getActivityUsedResourceService(); private ActivityLogisticService alM = ServiceLocator.getActivityLogisticService(); private ActivityUsedProductService aupM = ServiceLocator.getActivityUsedProductService(); @Wire Textbox tbAttivitaNome; @Wire Combobox cbCategoriaAttivita;

36

286885 BOMA
@Wire Combobox cbTipoAttivita; @Wire Combobox cbStatoAttivita; @Wire Datebox dbDataInizioPianAttivita; @Wire Datebox dbDataFinePianAttivita; @Wire Datebox dbDataInizioEsecAttivita; @Wire Datebox dbDataFineEsecAttivita; @Wire Textbox tbDescrAttivita; @Wire Combobox cbRisorsaOggettoAttivita; @Wire Checkbox ckPianificataAttivita; @Wire Textbox tbDescrIntervento; @Wire Combobox cbOperatorActivity; @Wire Tabbox tb; @Wire Tab tabPlanning; @Wire Tab tabExecution; @Wire Listbox lbUsedResource; List<ActivityUsedResource> aurNew = new ArrayList<ActivityUsedResource>(); List<ActivityUsedResource> aurTotal = new ArrayList<ActivityUsedResource>(); ListModel<ActivityUsedResource> lmUsedResource; @Wire Listbox lbUsedPhysicalProduct; List<ActivityUsedProduct> aupNew = new ArrayList<ActivityUsedProduct>(); List<ActivityUsedProduct> aupTotal = new ArrayList<ActivityUsedProduct>(); ListModel<ActivityUsedProduct> lmUsedPhysicalProduct; @Wire Tab tabPhysicalPhysicalProductObject; @Wire Tabpanel panelPhysicalProductObject; @Wire Listbox lbPhysicalProductObject; List<ActivityPhysicalProductObject> appoNew = new ArrayList<ActivityPhysicalProductObject>(); List<ActivityPhysicalProductObject> appoTotal = new ArrayList<ActivityPhysicalProductObject>(); ListModel<ActivityPhysicalProductObject> lmPhysicalProductObject; @Wire Listbox lbLogistic; List<ActivityLogistic> alNew = new ArrayList<ActivityLogistic>(); List<ActivityLogistic> alTotal = new ArrayList<ActivityLogistic>(); ListModel<ActivityLogistic> lmLogistic; @Wire Tab tabAttachment; @Wire Tabpanel panelAttach; @Wire Div divAttach; @Wire Radio rdbTypeFile; @Wire Button btnAttachFile; @Wire Radio rdbTypeLink; @Wire Button btnAttachLink; @Wire Textbox tbPathLink; @Wire Listbox lbAttachemntList; @Wire Paging pageListAttachment; Search sAttachment; private final int _pageSizeAttachment = 5; private int _startPageNumberAttachment = 0; private int _totalSizeAttachment = 0; private boolean _needsTotalSizeAttachment = true; @Wire Tab tabCustomAttribute; @Wire Tabpanel panelAttributes; @Wire Div addCustomAttribute; @Wire Combobox cbType; @Wire Checkbox cbPredefinedeCA; @Wire Textbox tbValueCA; @Wire Bandbox bbNameCA; @Wire Listbox lbCustomAttributeSearch; @Wire Listbox lbCustomAttribute; @Wire Paging pageListCustomAttribute; List<CustomAttribute> listCA; List<EditableCustomAttributeActivity> listEca = new ArrayList<EditableCustomAttributeActivity>(); List<CustomAttributeType> listCustomAttributeType; Search sCA; private final int _pageSizeCA = 5; private int _startPageCA = 0; private int _totalSizeCA = 0; private boolean _needsTotalSizeCA = true; public void onCreate(){ super.onCreate(); Selectors.wireComponents(this, this, false); Selectors.wireEventListeners(this, this); btnAttachFile.setUpload("true, maxsize=" + GlobalConfig.getAttachmentMaxFileSize()); lbUsedResource.setItemRenderer(new ListitemResourceByActivityUsedResourceRenderer(this));

37

286885 BOMA
lbUsedPhysicalProduct.setItemRenderer(new ListitemPhysicalProductByActivityUsedProductRenderer(this)); lbPhysicalProductObject.setItemRenderer(new ListitemPhysicalProductByActivityPhysicalProductObjectRenderer(this)); lbLogistic.setItemRenderer(new ListitemActivityLogisticRenderer(this)); attivitaCorrente = (Activity) this.getAttribute("activity"); List<Operator> operators = om.get(); List<ActivityStatus> activityStates = sam.get(); List<ActivityCategory> activityCategories = acM.getAllAttivitaCategoria(); if (attivitaCorrente != null) { this.tbAttivitaNome.setValue(attivitaCorrente.getName()); this.dbDataInizioPianAttivita.setValue(attivitaCorrente.getPlannedStartDate()); this.dbDataFinePianAttivita.setValue(attivitaCorrente.getPlannedEndDate()); this.dbDataInizioEsecAttivita.setValue(attivitaCorrente.getExecutionStartDate()); this.dbDataFineEsecAttivita.setValue(attivitaCorrente.getExecutionEndDate()); this.tbDescrAttivita.setValue(attivitaCorrente.getDescription()); this.ckPianificataAttivita.setChecked(attivitaCorrente.getIsPlanned()); if(attivitaCorrente.getText() != null) { Text t = tm.getTestoById(attivitaCorrente.getText().getId()); this.tbDescrIntervento.setText(t.getText()); } Search aurS = new Search(ActivityUsedResource.class); aurS.addFilter(HxFilter.equal(attivitaCorrente.getId(), ActivityUsedResource._activity, Activity._id)); aurTotal = aruM.get(aurS); refreshUsedResourceListmodel(aurTotal); Search aupS = new Search(ActivityUsedProduct.class); aupS.addFilter(HxFilter.equal(attivitaCorrente.getId(), ActivityUsedProduct._activity, Activity._id)); aupTotal = aupM.get(aupS); refreshUsedProductListmodel(aupTotal); Search appoS = new Search(ActivityPhysicalProductObject.class); appoS.addFilter(HxFilter.equal(attivitaCorrente.getId(), ActivityPhysicalProductObject._activity, Activity._id)); appoTotal = apfoM.get(appoS); refreshPhysicalProductObjectListmodel(appoTotal); Search alS = new Search(ActivityLogistic.class); alS.addFilter(HxFilter.equal(attivitaCorrente.getId(), ActivityLogistic._activityPhysicalProductObject, ActivityPhysicalProductObject._activity, Activity._id)); alTotal = alM.get(alS); refreshLogisticListmodel(alTotal); cbCategoriaAttivita.setDisabled(true); } else { attivitaCorrente = new Activity(); this.dbDataInizioPianAttivita.setDisabled(true); this.dbDataFinePianAttivita.setDisabled(true); this.tbDescrAttivita.setDisabled(true); this.ckPianificataAttivita.setChecked(false); PhysicalProduct physicalProductObject = (PhysicalProduct) this.getAttribute("physicalProductObject"); if (physicalProductObject != null) { ActivityPhysicalProductObject appo = new ActivityPhysicalProductObject(); appo.setActivity(attivitaCorrente); appo.setPhysicalProduct(physicalProductObject); appo.setNumberOfItems(1); appo.setQuantity(physicalProductObject.getEffectiveQuantity()); appoNew.add(appo); appoTotal.add(appo); refreshPhysicalProductObjectListmodel(appoTotal); activityCategories = new ArrayList<ActivityCategory>(); activityCategories.add(acM.get("Attivita_prodotto")); cbCategoriaAttivita.setDisabled(true); tb.setSelectedTab(tabPhysicalPhysicalProductObject); } } onCheckPianificato(); fillActivityCategoryCombo(activityCategories); ActivityCategory activityCategory = cbCategoriaAttivita.getSelectedItem().getValue(); List<ActivityType> activityTypes = tam.get(activityCategory, true); fillActivityTypeCombo(activityTypes); fillActivityStateCombo(activityStates); fillMasterOperatorCombo(operators); onChangingCategoriaAttivita(); if (!opm.isAllowed("ADD_ATTACHMENTS")) { tabAttachment.setVisible(false); } else{

38

286885 BOMA
tabAttachment.setVisible(false); if(this.getAttribute("idAttivita")!=null){ tabAttachment.setVisible(true); this.btnAttachFile.setUpload("true, maxsize=" + GlobalConfig.getAttachmentMaxFileSize()); fillAttachmentList(); } } if (opm.isAllowed("CUSTOM_ATTRIBUTE_FOR_ELEMENTS")) { tabCustomAttribute.setVisible(true); panelAttributes.setVisible(true); fillCustomAttribute(); } if (opm.isAllowed("VIEW_ATTACHMENTS") || opm.isAllowed("ADD_ATTACHMENTS")) { if (attivitaCorrente.getId() != null) { tabAttachment.setVisible(true); panelAttach.setVisible(true); fillAttachmentList(); } if (opm.isAllowed("ADD_ATTACHMENTS")) { divAttach.setVisible(true); } } if (opm.isAllowed("CUSTOM_ATTRIBUTE_FOR_ELEMENTS")) { tabCustomAttribute.setVisible(true); panelAttributes.setVisible(true); List<CustomAttributeType> listCustomAttributeType = catM.getAll(); fillCustomAttributeType(listCustomAttributeType); fillCustomAttribute(); } } private void refreshUsedResourceListmodel(List<ActivityUsedResource> list) { lmUsedResource = new ListModelActivityUsedResource(list); lbUsedResource.setModel(lmUsedResource); } private void refreshUsedProductListmodel(List<ActivityUsedProduct> list) { lmUsedPhysicalProduct = new ListModelActivityUsedProduct(list); lbUsedPhysicalProduct.setModel(lmUsedPhysicalProduct); } private void refreshPhysicalProductObjectListmodel(List<ActivityPhysicalProductObject> list) { lmPhysicalProductObject = new ListModelActivityPhysicalProductObject(list); lbPhysicalProductObject.setModel(lmPhysicalProductObject); } private void refreshLogisticListmodel(List<ActivityLogistic> list) { lmLogistic = new ListModelActivityLogistic(list); lbLogistic.setModel(lmLogistic); } private void fillActivityCategoryCombo(List<ActivityCategory> activityCategories) { ActivityCategory currentActivityCategory = null; if (attivitaCorrente.getId() != null) { if (attivitaCorrente.getActivityType() != null) { ActivityType activityType = tam.getTipoAttivitaFromId(attivitaCorrente.getActivityType().getId()); currentActivityCategory = acM.getAttivitaCategoriaById(activityType.getActivityCategory().getId()); } } cbCategoriaAttivita.getChildren().clear(); for (int i = 0; i < activityCategories.size(); i++) { ActivityCategory activityCategory = activityCategories.get(i); Comboitem ci = new Comboitem(activityCategory.getLabel()); ci.setValue(activityCategory); cbCategoriaAttivita.appendChild(ci); if (i == 0) cbCategoriaAttivita.setSelectedItem(ci); if (currentActivityCategory != null && currentActivityCategory.getId().equals(activityCategory.getId())) cbCategoriaAttivita.setSelectedItem(ci); } } private void fillActivityTypeCombo(List<ActivityType> activityTypes) { ActivityType currentActivityType = null; if (attivitaCorrente.getId() != null) { if (attivitaCorrente.getActivityType() != null) { currentActivityType = tam.getTipoAttivitaFromId(attivitaCorrente.getActivityType().getId()); }

39

286885 BOMA
} cbTipoAttivita.getChildren().clear(); for (int i = 0; i < activityTypes.size(); i++) { ActivityType activityType = activityTypes.get(i); Comboitem ci = new Comboitem(activityType.getLabel()); ci.setValue(activityType); ci.setAttribute("translation", activityType.getTranslation()); cbTipoAttivita.appendChild(ci); if (i == 0) cbTipoAttivita.setSelectedItem(ci); if (currentActivityType != null && currentActivityType.getId().equals(activityType.getId())) cbTipoAttivita.setSelectedItem(ci); } ZK.translate(cbTipoAttivita); } private void fillActivityStateCombo(List<ActivityStatus> activityStates) { ActivityStatus currentActivityState = null; if (attivitaCorrente.getId() != null) { if (attivitaCorrente.getActivityStatus() != null) { currentActivityState = sam.get(attivitaCorrente.getActivityStatus().getId()); } } int selectedIndex = 0; cbStatoAttivita.getChildren().clear(); for (int i = 0; i < activityStates.size(); i++) { ActivityStatus activityState = activityStates.get(i); Comboitem ci = new Comboitem(activityState.getLabel()); ci.setValue(activityState); ci.setAttribute("translation", activityState.getTranslation()); cbStatoAttivita.appendChild(ci); if (currentActivityState != null && currentActivityState.getId().equals(activityState.getId())) selectedIndex = i; } ZK.translate(cbStatoAttivita); cbStatoAttivita.setSelectedIndex(selectedIndex); } private void fillMasterOperatorCombo(List<Operator> operators) { Operator currentOperator = null; if (attivitaCorrente.getId() != null) { Search oS = new Search(Operator.class); oS.addFilter(HxFilter.equal(attivitaCorrente.getId(), Operator._activityOperators, ActivityOperator._activity, Activity._id)); oS.addFilter(HxFilter.equal(true, Operator._activityOperators, ActivityOperator._master)); List<Operator> list = om.get(oS); if(list.size() > 0) { currentOperator = list.get(0); } } cbOperatorActivity.getChildren().clear(); for (int i = 0; i < operators.size(); i++) { Operator operator = operators.get(i); Comboitem ci = new Comboitem(operator.getLabel()); ci.setValue(operator); cbOperatorActivity.appendChild(ci); if (i == 0) cbOperatorActivity.setSelectedItem(ci); if (currentOperator != null && currentOperator.getId().equals(operator.getId())) cbOperatorActivity.setSelectedItem(ci); } } private void fillResourceObjectCombo(List<Resource> resources) { Resource currentResource = null; if (attivitaCorrente.getId() != null) { if (attivitaCorrente.getResource() != null) { currentResource = rm.getById(attivitaCorrente.getResource().getId()); } } cbRisorsaOggettoAttivita.getChildren().clear(); if (resources == null || resources.size() == 0) { Comboitem ci = new Comboitem("-"); cbRisorsaOggettoAttivita.appendChild(ci);

40

286885 BOMA
cbRisorsaOggettoAttivita.setSelectedItem(ci); return; } for (int i = 0; i < resources.size(); i++) { Resource resource = resources.get(i); Comboitem ci = new Comboitem(resource.getName()); ci.setValue(resource); cbRisorsaOggettoAttivita.appendChild(ci); if (i == 0) cbRisorsaOggettoAttivita.setSelectedItem(ci); if (currentResource != null && currentResource.getId().equals(resource.getId())) cbRisorsaOggettoAttivita.setSelectedItem(ci); } } private void fillCustomAttributeType(List<CustomAttributeType> listCustomAttributeType) { cbType.getChildren().clear(); Iterator<CustomAttributeType> itCAT = listCustomAttributeType.iterator(); while (itCAT.hasNext()) { Comboitem ci = new Comboitem(); CustomAttributeType cat = (CustomAttributeType) itCAT.next(); ci.setAttribute("translation", cat.getTranslation()); ci.setLabel(cat.getName()); ci.setValue(cat); cbType.appendChild(ci); } ZK.translate(cbType); } private void validateSave() { ActivityCategory activityCategory = cbCategoriaAttivita.getSelectedItem().getValue(); ActivityStatus activityState = cbStatoAttivita.getSelectedItem().getValue(); if (tbAttivitaNome.getValue().length() == 0) { String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(tbAttivitaNome, error); } if (activityCategory.getCode().equals("Attivita_risorsa")) { if (cbRisorsaOggettoAttivita.getSelectedItem().getValue() == null) { String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(cbRisorsaOggettoAttivita, error); } } else if (activityCategory.getCode().equals("Attivita_prodotto")) { } if (ckPianificataAttivita.isChecked()) { if (dbDataInizioPianAttivita.getValue() == null) { tb.setSelectedTab(tabPlanning); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataInizioPianAttivita, error); } if (dbDataFinePianAttivita.getValue() == null) { tb.setSelectedTab(tabPlanning); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataFinePianAttivita, error); } if (activityState.getCode().equals("Non eseguito")) { if (dbDataInizioEsecAttivita.getValue() != null) { tb.setSelectedTab(tabExecution); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataInizioEsecAttivita, error); } if (dbDataFineEsecAttivita.getValue() != null) { tb.setSelectedTab(tabExecution); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataFineEsecAttivita, error); } } else if (activityState.getCode().equals("In corso")) { if (dbDataInizioEsecAttivita.getValue() == null) { tb.setSelectedTab(tabExecution); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataInizioEsecAttivita, error); } if (dbDataFineEsecAttivita.getValue() != null) {

41

286885 BOMA
tb.setSelectedTab(tabExecution); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataFineEsecAttivita, error); } } else { if (dbDataInizioEsecAttivita.getValue() == null) { tb.setSelectedTab(tabExecution); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataInizioEsecAttivita, error); } if (dbDataFineEsecAttivita.getValue() == null) { tb.setSelectedTab(tabExecution); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataFineEsecAttivita, error); } } } else { if (activityState.getCode().equals("In corso")) { if (dbDataInizioEsecAttivita.getValue() == null) { tb.setSelectedTab(tabExecution); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataInizioEsecAttivita, error); } if (dbDataFineEsecAttivita.getValue() != null) { tb.setSelectedTab(tabExecution); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataFineEsecAttivita, error); } } else { if (dbDataInizioEsecAttivita.getValue() == null) { tb.setSelectedTab(tabExecution); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataInizioEsecAttivita, error); } if (dbDataFineEsecAttivita.getValue() == null) { tb.setSelectedTab(tabExecution); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataFineEsecAttivita, error); } } } if (dbDataInizioPianAttivita.getValue() != null && dbDataFinePianAttivita.getValue() != null) { if (dbDataFinePianAttivita.getValue().compareTo(dbDataInizioPianAttivita.getValue()) <= 0) { tb.setSelectedTab(tabPlanning); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataFinePianAttivita, error); } } if (dbDataInizioEsecAttivita.getValue() != null && dbDataFineEsecAttivita.getValue() != null) { if (dbDataFineEsecAttivita.getValue().compareTo(dbDataInizioEsecAttivita.getValue()) <= 0) { tb.setSelectedTab(tabExecution); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(dbDataFineEsecAttivita, error); } } List<Listitem> listitems = lbCustomAttribute.getItems(); for (int i = 0; i < listitems.size(); i++) { Listitem listitem = listitems.get(i); EditableCustomAttributeActivity eca = listitem.getValue(); String val = eca.getCustomAttributeActivityValue().getValue(); CustomAttributeType customAttributeType = eca.getCustomAttribute().getCustomAttributeType(); List<Textbox> textboxes = ZK.getChildren(listitem, Textbox.class); if(!catM.isValid(val, customAttributeType.getId())) { tb.setSelectedTab(tabCustomAttribute); String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(textboxes.get(0), error); } } }

42

286885 BOMA
@Listen("onClick = #btnSave") public void onSalvaAttivita() { validateSave(); ActivityCategory activityCategory = cbCategoriaAttivita.getSelectedItem().getValue(); ActivityStatus activityState = cbStatoAttivita.getSelectedItem().getValue(); ActivityType activityType = cbTipoAttivita.getSelectedItem().getValue(); Resource objectResource = cbRisorsaOggettoAttivita.getSelectedItem().getValue(); Operator operator = cbOperatorActivity.getSelectedItem().getValue(); attivitaCorrente.setName(tbAttivitaNome.getText()); attivitaCorrente.setDescription(tbDescrAttivita.getText()); if (ckPianificataAttivita.isChecked()) { attivitaCorrente.setPlannedStartDate(dbDataInizioPianAttivita.getValue()); attivitaCorrente.setPlannedEndDate(dbDataFinePianAttivita.getValue()); } else { attivitaCorrente.setPlannedStartDate(null); attivitaCorrente.setPlannedEndDate(null); } attivitaCorrente.setExecutionStartDate(dbDataInizioEsecAttivita.getValue()); attivitaCorrente.setExecutionEndDate(dbDataFineEsecAttivita.getValue()); attivitaCorrente.setIsPlanned(ckPianificataAttivita.isChecked()); attivitaCorrente.setActivityStatus(activityState); attivitaCorrente.setActivityType(activityType); attivitaCorrente.setResource(objectResource); if(tbDescrIntervento.getText().length() > 0) { if(attivitaCorrente.getText() != null) { Text t=tm.getTestoById(this.attivitaCorrente.getText().getId()); t.setText(this.tbDescrIntervento.getText()); tm.insertTesto(t); this.attivitaCorrente.setText(t); } else{ Text t=new Text(); t.setText(this.tbDescrIntervento.getText()); tm.insertTesto(t); this.attivitaCorrente.setText(t); } } List<ActivityOperator> activityOperators = null; if (attivitaCorrente.getId() != null){ Search aoS = new Search(ActivityOperator.class); aoS.addFilter(HxFilter.equal(attivitaCorrente.getId(), ActivityOperator._activity, Activity._id)); aoS.addFilter(HxFilter.equal(true, ActivityOperator._master)); activityOperators = aoM.get(aoS); } ActivityOperator activityOperator; if (activityOperators != null && activityOperators.size() > 0) { activityOperator = activityOperators.get(0); activityOperator.setOperator(operator); } else { activityOperator = new ActivityOperator(); activityOperator.setActivity(attivitaCorrente); activityOperator.setOperator(operator); activityOperator.setMaster(true); } am.insertAttivita(attivitaCorrente); if (activityCategory.getCode().equals("Attivita_prodotto")) { for (int i = 0; i < appoNew.size(); i++) { ActivityPhysicalProductObject appo = appoNew.get(i); apfoM.insert(appo); } } for (int i = 0; i < aupNew.size(); i++) { ActivityUsedProduct aup = aupNew.get(i); aupM.insert(aup); } aoM.insert(activityOperator); for (int i = 0; i < listEca.size(); i++) { EditableCustomAttributeActivity eca = listEca.get(i); if (eca.isEdit()) { CustomAttribute ca = eca.getCustomAttribute();

43

286885 BOMA
CustomAttributeActivityValue cappv = eca.getCustomAttributeActivityValue(); CustomAttributeActivityAllow cappa = eca.getCustomAttributeActivityAllow(); cappv.setActivity(attivitaCorrente); caM.saveCustomAttributeActivity(ca,cappv, cappa); } } if (this.getParent() instanceof ViewActivityList) { ViewActivityList window = (ViewActivityList) this.getParent(); window.aggiornaListaAttivita(); } else if (this.getParent() instanceof WndPhysicalProductDetail) { WndPhysicalProductDetail window = (WndPhysicalProductDetail) this.getParent(); window.refreshModelActivityProductObject(0); } this.detach(); } @Listen("onClick = #btnCancel") public void onClickCancel() { this.detach(); } @Listen("onClick = #btnDelete") public void onClickEliminaAttivita(){ int resultMs = HxMessageBox.show("Are you sure to delete this activity?", "Attention", HxMessageBox.YES | HxMessageBox.NO, HxMessageBox.QUESTION, "ao", "9s"); if (resultMs == HxMessageBox.YES) { am.eliminaAttivita(attivitaCorrente); } } @Listen("onClick = #btnDeleteSeries") public void onClickDeleteSerie() { int resultMs = HxMessageBox.show("Are you sure to delete the set of activities?", "Attention", HxMessageBox.YES | HxMessageBox.NO, HxMessageBox.QUESTION, "an", "9s"); if (resultMs == HxMessageBox.YES) { am.deleteSeries(attivitaCorrente); } } @Listen("onCheck = #ckPianificataAttivita") public void onCheckPianificato() { if(this.ckPianificataAttivita.isChecked()) { tabPlanning.setDisabled(false); this.dbDataInizioPianAttivita.setDisabled(false); this.dbDataFinePianAttivita.setDisabled(false); this.tbDescrAttivita.setDisabled(false); } else { tabPlanning.setDisabled(true); this.dbDataInizioPianAttivita.setDisabled(true); this.dbDataFinePianAttivita.setDisabled(true); this.tbDescrAttivita.setDisabled(true); this.dbDataInizioPianAttivita.setValue(null); this.dbDataFinePianAttivita.setValue(null); } switchToEnabledTab(); } @Listen("onBlur = #cbCategoriaAttivita") public void onChangingCategoriaAttivita() { ActivityCategory activityCategory = cbCategoriaAttivita.getSelectedItem().getValue(); if (activityCategory == null) return; List<ActivityType> activityTypes = tam.get(activityCategory, true); fillActivityTypeCombo(activityTypes); if (activityCategory.getCode().equals("Attivita_risorsa")) { tabPhysicalPhysicalProductObject.setDisabled(true); cbRisorsaOggettoAttivita.setDisabled(false); List<Resource> resources = rm.get(); fillResourceObjectCombo(resources); } else if (activityCategory.getCode().equals("Attivita_prodotto")) { tabPhysicalPhysicalProductObject.setDisabled(false); cbRisorsaOggettoAttivita.setDisabled(true); fillResourceObjectCombo(null); }

44

286885 BOMA
switchToEnabledTab(); } public void fillAttachmentList(){ _needsTotalSizeAttachment = true; sAttachment = new Search(Attachment.class); sAttachment.addFilter(HxFilter.equal(true, Attachment._active)); sAttachment.addFilter(HxFilter.equal(this.attivitaCorrente.getId(), Attachment._attachmentActivities, AttachmentActivity._activity, Activity._id)); sAttachment.addFilter(HxFilter.equal(true, Attachment._attachmentActivities, AttachmentActivity._active)); lbAttachemntList.setItemRenderer(new ListitemAttachmentRenderer(this)); refreshModelAttachment(_startPageNumberAttachment); } public void refreshModelAttachment(int activePage) { pageListAttachment.setPageSize(_pageSizeAttachment); PagingListModelAttachment modelAttach = new PagingListModelAttachment(sAttachment, activePage, _pageSizeAttachment); if(_needsTotalSizeAttachment) { _totalSizeAttachment = modelAttach.getTotalSize(sAttachment); _needsTotalSizeAttachment = false; } pageListAttachment.setActivePage(activePage); pageListAttachment.setTotalSize(_totalSizeAttachment); lbAttachemntList.setModel(modelAttach); } @Listen("onPaging = #pageListAttachment") public void onPagingAttachment(Event e) { _startPageNumberAttachment = ((Paging)(e.getTarget())).getActivePage(); refreshModelAttachment(_startPageNumberAttachment); } @Listen("onClick = #lbAttachemntList .btnEdit") public void onClickAttachmentEdit(Event event){ Listcell lc = (Listcell) event.getTarget(); Attachment a = ZK.getListItemParent(lc).getValue(); Window w = (Window) Executions.getCurrent().createComponents("./pagine/attachment/attachmentDetail.zul", this, null); w.setAttribute("attachment", a); w.setClosable(true); w.setWidth("75%"); w.setFocus(true); w.doOverlapped(); w.doModal(); } @Listen("onClick = #lbAttachemntList .btnGoToAttach") public void onClickGoToAttachment(Event event){ Listcell lc = (Listcell) event.getTarget(); Attachment a = ZK.getListItemParent(lc).getValue(); if (a.isLink()){ ZK.openLink(a); } else{ try { ZK.downloadFile(a); } catch (AttachmentException e) { HxMessageBox.show(e.getMessage(), "Attention", HxMessageBox.OK, HxMessageBox.EXCLAMATION, null, e.getTranslation(), "9s"); } } } @Listen("onClick = #lbAttachemntList .btnRemoveAttach") public void onClickRemoveAttachmentFromProduct(Event event){ if (HxMessageBox.show("Are you sure to remove attachment from this activity?", "Attention", HxMessageBox.YES | HxMessageBox.NO, HxMessageBox.QUESTION, "gs", "9s") == HxMessageBox.NO) return; Listcell lc = (Listcell) event.getTarget(); Attachment a = ZK.getListItemParent(lc).getValue(); try { achaM.trash(this.attivitaCorrente, a); } catch (AttachmentException e) { HxMessageBox.show(e.getMessage(), "Attention", HxMessageBox.OK, HxMessageBox.EXCLAMATION, null, e.getTranslation(), "9s"); } fillAttachmentList(); }

45

286885 BOMA
@Listen("onCheck = #rdgAttachmentType") public void onCheckAttachmentType(){ if (rdbTypeFile.isChecked()){ btnAttachFile.setVisible(true); tbPathLink.setVisible(false); btnAttachLink.setVisible(false); } if (rdbTypeLink.isChecked()){ tbPathLink.setVisible(true); btnAttachLink.setVisible(true); btnAttachFile.setVisible(false); } } @Listen("onUpload = #btnAttachFile") public void onClickAttachFile(UploadEvent event) { Operator o = ZK.getCurrentZKOperator(); Media media = event.getMedia(); try { if (media.isBinary()) { InputStream inputStream = media.getStreamData(); achaM.insertFile(attivitaCorrente, inputStream, media.getName(), o); } else { Reader reader = media.getReaderData(); achaM.insertFile(attivitaCorrente, reader, media.getName(), o); } } catch (AttachmentException e) { HxMessageBox.show(e.getMessage(), "Attention", HxMessageBox.OK, HxMessageBox.EXCLAMATION, null, e.getTranslation(), "9s"); } fillAttachmentList(); } @Listen("onClick = #btnAttachLink") public void onClickAttachLink(Event event){ if (tbPathLink.getText() == "" || tbPathLink.getText() == null){ HxMessageBox.show("Specify link in text box.", "Attention", HxMessageBox.OK, HxMessageBox.EXCLAMATION, null, "el", "9s"); } else{ Operator o = ZK.getCurrentZKOperator(); try { achaM.insertLink(this.attivitaCorrente, tbPathLink.getText(), o); } catch (WrongValueException e) { e.printStackTrace(); } catch (AttachmentException e) { HxMessageBox.show(e.getMessage(), "Attention", HxMessageBox.OK, HxMessageBox.EXCLAMATION, null, e.getTranslation(), "9s"); } fillAttachmentList(); tbPathLink.setText(""); } } public void fillCustomAttribute () { Search sCA = new Search(CustomAttribute.class); if (attivitaCorrente.getId() != null) { Filter f1 = HxFilter.equal(attivitaCorrente.getId(), CustomAttribute._customAttributeActivityValues, CustomAttributeActivityValue._activity, Activity._id); Filter f2 = HxFilter.equal(true, CustomAttribute._customAttributeActivityValues, CustomAttributeActivityValue._active); sCA.addFilterOr(HxFilter.equal(true, CustomAttribute._customAttributeActivityAllows, CustomAttributeActivityAllow._predefined), Filter.and(f1,f2)); sCA.setDistinct(true); } else { sCA.addFilter(HxFilter.equal(true, CustomAttribute._customAttributeActivityAllows, CustomAttributeActivityAllow._predefined)); } listCA = caM.getBySearch(sCA); Iterator<CustomAttribute> itCA = listCA.iterator();

46

286885 BOMA
listEca = new ArrayList<EditableCustomAttributeActivity>(); while (itCA.hasNext()) { CustomAttribute ca = itCA.next(); CustomAttributeActivityAllow cappa = caaaM.getByObject(ca); CustomAttributeActivityValue cappv = caavM.getByObject(attivitaCorrente, ca, true); if (cappv == null) { cappv = new CustomAttributeActivityValue(); cappv.setActivity(attivitaCorrente); cappv.setCustomAttribute(ca); cappv.setActive(true); } EditableCustomAttributeActivity eca = new EditableCustomAttributeActivity(ca, cappv, cappa); listEca.add(eca); } lbCustomAttribute.setItemRenderer(new ListitemEditableCustomAttributeRenderer(this)); lbCustomAttributeSearch.setItemRenderer(new ListitemCustomAttributeRenderer(this)); refreshModelCustomAttributeActivity(_startPageCA); } @Listen("onOpen = #bbNameCA") public void fillBandbox(){ refreshModelCustomAttribute(bbNameCA.getValue()); } @Listen("onChanging = #bbNameCA") public void changeBandbox(InputEvent event){ bbNameCA.setValue(event.getValue()); refreshModelCustomAttribute(bbNameCA.getValue()); if(!bbNameCA.isOpen()) bbNameCA.open(); } public void refreshModelCustomAttribute(String value) { Search s = new Search(CustomAttribute.class); s.addFilter(HxFilter.like(value + "%", CustomAttribute._name)); s.addFilter(HxFilter.isNotEmpty(CustomAttribute._customAttributeActivityAllows)); s.addFilter(HxFilter.notIn(listCA, HxFilter.ROOT_ENTITY)); List<CustomAttribute> lca = ServiceLocator.getCustomAttributeService().getBySearch(s); ListModel<CustomAttribute> modelCA = new ListModelCustomAttribute(lca); lbCustomAttributeSearch.setModel(modelCA); } public void refreshModelCustomAttributeActivity(int activePage) { pageListCustomAttribute.setPageSize(_pageSizeCA); PagingListModelCustomAttribute<EditableCustomAttributeActivity> modelCA = new PagingListModelCustomAttribute<EditableCustomAttributeActivity>(listEca, activePage, _pageSizeCA); if(_needsTotalSizeCA) { _totalSizeCA = modelCA.getTotalSize(); _needsTotalSizeCA = false; } pageListCustomAttribute.setActivePage(activePage); pageListCustomAttribute.setTotalSize(_totalSizeCA); lbCustomAttribute.setModel(modelCA); } private void validateNewCustomAttribute() { if (bbNameCA.getValue().length() == 0) { String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(bbNameCA, error); } for (int i = 0; i < listEca.size(); i++) { EditableCustomAttribute eca = listEca.get(i); CustomAttribute customAttribute = eca.getCustomAttribute(); if (customAttribute.getName().equals(bbNameCA.getValue()) ) { String error = ZK.translateInLanguageSelected("Name already exists", "tj"); throw new WrongValueException(bbNameCA, error); } } if (cbType.getSelectedItem() == null) { String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(cbType, error); } if (cbType.getSelectedItem().getValue() == null) { String error = ZK.translateInLanguageSelected("Invalid value", "ti");

47

286885 BOMA
throw new WrongValueException(cbType, error); } CustomAttributeType customAttributeType = cbType.getSelectedItem().getValue(); if(!catM.isValid(tbValueCA.getValue(), customAttributeType)) { String error = ZK.translateInLanguageSelected("Invalid value", "ti"); throw new WrongValueException(tbValueCA, error); } } @Listen("onChanging = #lbCustomAttribute textbox") public void onChangingValue (Event event) { Textbox tb = (Textbox) event.getTarget(); Listitem li = ZK.getListItemParent(tb); EditableCustomAttributeActivity eca = li.getValue(); CustomAttributeActivityValue cappv = eca.getCustomAttributeActivityValue(); cappv.setValue(((InputEvent)event).getValue()); if(ServiceLocator.getCustomAttributeTypeService().isValid(cappv.getValue(), eca.getCustomAttribute().getCustomAttributeType().getId())){ tb.setStyle("border:1px solid #E6E6E6; border-top-color: #B2B2B"); } else tb.setStyle("border:1px solid red"); eca.setCustomAttributeActivityValue(cappv); } @Listen("onCheck = #lbCustomAttribute checkbox.cbPredefinite") public void onChangingPredefinite (Event event) { Checkbox cb = (Checkbox) event.getTarget(); Listitem li = ZK.getListItemParent(cb); EditableCustomAttributeActivity eca = li.getValue(); CustomAttributeActivityAllow cappa = eca.getCustomAttributeActivityAllow(); cappa.setPredefined(cb.isChecked()); eca.setCustomAttributeActivityAllow(cappa); } @Listen("onClick = #lbCustomAttribute .btnDelete") public void onChangingActive (Event event) { Listcell lc = (Listcell) event.getTarget(); Listitem li = ZK.getListItemParent(lc); EditableCustomAttributeActivity eca = li.getValue(); CustomAttributeActivityValue cappv = eca.getCustomAttributeActivityValue(); cappv.setActive(!cappv.isActive()); if(!cappv.isActive() && cappv.getDateEnd() == null) cappv.setDateEnd(new Date()); if(cappv.isActive()) cappv.setDateEnd(null); List<Component> child = lc.getChildren(); Image i = (Image) child.get(0); if (cappv.isActive()) i.setSrc(Icon24Path.delete); else i.setSrc(Icon16Path.X); eca.setCustomAttributeActivityValue(cappv); } @Listen("onClick = #addCustomAttribute button") public void onClickAddNewAttribute (Event event) { validateNewCustomAttribute(); Search search = new Search(CustomAttribute.class); search.addFilter(HxFilter.equal(bbNameCA.getValue(), CustomAttribute._name)); search.addFilter(HxFilter.equal(((CustomAttributeType)cbType.getSelectedItem().getValue()).getId(), CustomAttribute._customAttributeType, CustomAttributeType._id)); List<CustomAttribute> lca = caM.getBySearch(search); CustomAttribute ca; CustomAttributeActivityAllow cappa; if (lca == null || lca.size() > 0) { ca = lca.get(0); cappa = caaaM.getByObject(ca); if (cappa == null) cappa = new CustomAttributeActivityAllow(); } else { ca = new CustomAttribute(); ca.setName(bbNameCA.getValue()); ca.setCustomAttributeType((CustomAttributeType)cbType.getSelectedItem().getValue());

48

286885 BOMA
cappa = new CustomAttributeActivityAllow(); cappa.setCustomAttribute(ca); } CustomAttributeActivityValue cappv = new CustomAttributeActivityValue(); cappv.setCustomAttribute(ca); cappv.setActivity(attivitaCorrente); cappv.setActive(true); cappv.setDateStart(new Date()); cappv.setValue(tbValueCA.getValue()); cappv.setAccount(ZK.getCurrentZKAccount()); cappa.setCustomAttribute(ca); cappa.setPredefined(cbPredefinedeCA.isChecked()); EditableCustomAttributeActivity eca = new EditableCustomAttributeActivity(ca, cappv, cappa, true); if (listEca.contains(eca)) return; listEca.add(eca); _needsTotalSizeCA = true; refreshModelCustomAttributeActivity(_startPageCA); if(ca != null) if (ca.getId() != null) listCA.add(ca); resetNewCustomAttributeForm(); } private void resetNewCustomAttributeForm() { bbNameCA.setValue(""); bbNameCA.clearErrorMessage(); tbValueCA.setValue(""); tbValueCA.clearErrorMessage(); cbType.setSelectedItem(null); cbType.clearErrorMessage(); cbPredefinedeCA.setChecked(false); } @Listen("onSelect = #lbCustomAttributeSearch") public void onSelectName(Event event) { CustomAttribute ca = (CustomAttribute) (((Listbox) event.getTarget()).getSelectedItem()).getValue(); int i = ca.getCustomAttributeType().getId().intValue(); cbType.setSelectedIndex(i-1); bbNameCA.setValue(ca.getName()); bbNameCA.close(); } @Listen("onPaging = #pageListCustomAttribute") public void onPagingCA(Event e) { _startPageCA = ((Paging)(e.getTarget())).getActivePage(); refreshModelCustomAttributeActivity(_startPageCA); } @Listen("onClick = #btnAddPhysicalProductObject") public void onClickBtnAddPhysicalProductObject() { Window w=(Window)Executions.createComponents(PagePath.physicalProductSearch, this, null); w.setAttribute("target", WndPhysicalProductSearch.Target.physicalProductObject); w.setClosable(true); w.setWidth(GlobalConfig.getModalWindowWidthLarge()); w.setFocus(true); w.doOverlapped(); w.doModal(); } public void addPhysicalProductObject(PhysicalProduct physicalProductObject) { ActivityPhysicalProductObject appo = new ActivityPhysicalProductObject(); appo.setActivity(attivitaCorrente); appo.setPhysicalProduct(physicalProductObject); appo.setNumberOfItems(1); appo.setQuantity(physicalProductObject.getEffectiveQuantity()); appoNew.add(appo); appoTotal.add(appo); refreshPhysicalProductObjectListmodel(appoTotal); } public void addPhysicalProductObjects(List<PhysicalProduct> physicalProductObjects) { for (int i = 0; i < physicalProductObjects.size(); i++) { PhysicalProduct physicalProductObject = physicalProductObjects.get(i); ActivityPhysicalProductObject appo = new ActivityPhysicalProductObject(); appo.setActivity(attivitaCorrente);

49

286885 BOMA
appo.setPhysicalProduct(physicalProductObject); appo.setNumberOfItems(1); appo.setQuantity(physicalProductObject.getEffectiveQuantity()); appoNew.add(appo); appoTotal.add(appo); } refreshPhysicalProductObjectListmodel(appoTotal); } @Listen("onClick = #btnAddUsedProduct") public void onClickBtnAddUsedProduct() { Window w=(Window)Executions.createComponents(PagePath.physicalProductSearch, this, null); w.setAttribute("target", WndPhysicalProductSearch.Target.usedPhysicalProduct); w.setClosable(true); w.setWidth(GlobalConfig.getModalWindowWidthLarge()); w.setFocus(true); w.doOverlapped(); w.doModal(); } public void addUsedProduct(PhysicalProduct usedProduct) { ActivityUsedProduct aup = new ActivityUsedProduct(); aup.setActivity(attivitaCorrente); aup.setPhysicalProduct(usedProduct); aupNew.add(aup); aupTotal.add(aup); refreshUsedProductListmodel(aupTotal); } public void addUsedProducts(List<PhysicalProduct> usedProducts) { for (int i = 0; i < usedProducts.size(); i++) { PhysicalProduct usedProduct = usedProducts.get(i); ActivityUsedProduct aup = new ActivityUsedProduct(); aup.setActivity(attivitaCorrente); aup.setPhysicalProduct(usedProduct); aupNew.add(aup); aupTotal.add(aup); } refreshUsedProductListmodel(aupTotal); } @Listen("onClick = #lbPhysicalProductObject .btnDetail; onClick = #lbUsedPhysicalProduct .btnDetail") public void onClickPhysicalProductDetail(Event event) { Listcell listcell = (Listcell) event.getTarget(); PhysicalProduct pp = listcell.getValue(); if (pp.getIsWip() == null) return; Window w=(Window)Executions.createComponents(PagePath.physicalProductDetail, this, null); w.setAttribute("physical_product", pp); w.setClosable(true); w.setWidth(GlobalConfig.getModalWindowWidthLarge()); w.setFocus(true); w.doOverlapped(); w.doModal(); } private void switchToEnabledTab() { Tab selectedTab = tb.getSelectedTab(); try { for (int i = 0; selectedTab.isDisabled(); i++) { tb.setSelectedIndex(i); selectedTab = tb.getSelectedTab(); } } catch (Exception e) { return; } } }

50

286885 BOMA 4.2. Production Code (Server Side)

4.2.1. Business Logic Code


public interface BatchService { public abstract void insert(Batch batch); public abstract void delete(Batch batch); public abstract List<Batch> get(); public abstract Batch get(Long id); public abstract Batch get(String code, Integer idProductType); public abstract Batch getByPhysicalProduct(Long idPhysicalProduct); public abstract List<Batch> get(Search search); public abstract List<Batch> get(Search search, int currPage, int pageSize); public abstract List<Batch> get(String code); public abstract List<Batch> get(Integer idProductType); public abstract int count(); public abstract int count(Search search); } @Service public class BatchServiceImpl implements BatchService { @Autowired private BatchDAO dao; @Autowired private PhysicalProductService ppS; @Transactional public void insert(Batch batch) { dao.persist(batch); } @Transactional public void delete(Batch batch) { dao.remove(batch); } @Transactional public List<Batch> get() { return dao.get(); } @Transactional public Batch get(Long id) { return dao.get(id); } @Transactional public List<Batch> get(Search search) { return dao.get(search); } @Transactional public List<Batch> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } @Override public List<Batch> get(String code) { Search s = new Search(Batch.class); s.addFilter(HxFilter.equal(code, Batch._code)); List<Batch> list = dao.get(s); return list; } @Override public List<Batch> get(Integer idProductType) { Search s = new Search(Batch.class); s.addFilter(HxFilter.equal(idProductType, Batch._productType, ProductType._id)); List<Batch> list = dao.get(s); return list; }

51

286885 BOMA
@Override public Batch get(String code, Integer idProductType) { Search s = new Search(Batch.class); s.addFilter(HxFilter.equal(code, Batch._code)); s.addFilter(HxFilter.equal(idProductType, Batch._productType, ProductType._id)); List<Batch> list = dao.get(s); if (list.size() > 0) return list.get(0); else return null; } @Override public Batch getByPhysicalProduct(Long idPhysicalProduct) { Batch b = null; PhysicalProduct p = ppS.getProdottoFisicoById(idPhysicalProduct); if (p != null) b = dao.get(p.getBatch().getId()); return b; } } public interface BillOfProcessInputService { public abstract void insert(BillOfProcessInput sensor); public abstract void delete(BillOfProcessInput sensor); public abstract List<BillOfProcessInput> get(); public abstract BillOfProcessInput get(Long id); public abstract List<BillOfProcessInput> get(Search search); public abstract List<BillOfProcessInput> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); public abstract List<BillOfProcessInputSummary> getBillOfProcessInputSummaries(Process process, BillOfProcess billOfProcess); public abstract BigDecimal getTotalPlannedQuantity(List<BillOfProcessInputSummary> billOfProcessInputSummaries); public abstract BigDecimal getTotalEffectiveQuantity(List<BillOfProcessInputSummary> billOfProcessInputSummaries); public abstract Integer getTotalPlannedNumberOfItems(List<BillOfProcessInputSummary> billOfProcessInputSummaries); public abstract Integer getTotalEffectiveNumberOfItems(List<BillOfProcessInputSummary> billOfProcessInputSummaries); } @Service public class BillOfProcessInputServiceImpl implements BillOfProcessInputService{ @Autowired private BillOfProcessInputDAO dao; @Autowired private ProcessPhysicalProductInputService pppiS; @Autowired private PhysicalProductService pfM; @Autowired private ProductTypeService tpM; @Autowired private ProductFamilyService fpM; @Override @Transactional public void insert(BillOfProcessInput sensor) { dao.persist(sensor); } @Override @Transactional public void delete(BillOfProcessInput sensor) { dao.remove(sensor); } @Override @Transactional public List<BillOfProcessInput> get() { return dao.get(); } @Override @Transactional public BillOfProcessInput get(Long id) { return dao.get(id); } @Override @Transactional public List<BillOfProcessInput> get(Search search) { return dao.get(search); } @Override @Transactional public List<BillOfProcessInput> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize);

52

286885 BOMA
} @Override @Transactional public int count() { return dao.count(); } @Override @Transactional public int count(Search search) { return dao.count(search); } @Override @Transactional public List<BillOfProcessInputSummary> getBillOfProcessInputSummaries(Process process, BillOfProcess billOfProcess) { List<BillOfProcessInputSummary> listWip = new ArrayList<BillOfProcessInputSummary>(); Search searchInput = new Search(BillOfProcessInput.class); searchInput.addFilter(HxFilter.equal(billOfProcess.getId(), BillOfProcessInput._billOfProcess, BillOfProcess._id)); searchInput.addSort(HxSort.asc(BillOfProcessInput._sequence)); searchInput.addSort(HxSort.desc(BillOfProcessInput._master)); List<BillOfProcessInput> listPlanned = dao.get(searchInput); for (int i = 0; i < listPlanned.size(); i++) { BillOfProcessInput planned = listPlanned.get(i); BillOfProcessInputSummary b = new BillOfProcessInputSummary(); b.setProcess(process); b.setBillOfProcessInput(planned); b.setProcessPhysicalProductInput(new ArrayList<ProcessPhysicalProductInput>()); listWip.add(b); } Search searchProduct = new Search(ProcessPhysicalProductInput.class); searchProduct.addFilter(HxFilter.equal(billOfProcess.getId(), ProcessPhysicalProductInput._billOfProcess, BillOfProcess._id)); searchProduct.addFilter(HxFilter.equal(process.getId(), ProcessPhysicalProductInput._process, Process._id)); List<ProcessPhysicalProductInput> listEffective = pppiS.get(searchProduct); List<ProcessPhysicalProductInput> listToRemove = new ArrayList<ProcessPhysicalProductInput>(); if (listEffective != null && listEffective.size() > 0) { effective: for (int j = 0; j < listEffective.size(); j++) { ProcessPhysicalProductInput effective = listEffective.get(j); PhysicalProduct product = pfM.getProdottoFisicoById(effective.getPhysicalProduct().getId()); for (int i = 0; i < listWip.size(); i++) { BillOfProcessInputSummary bomWip = listWip.get(i); BillOfProcessInput planned = bomWip.getBillOfProcessInput(); if (planned.getPhysicalProduct() != null) { PhysicalProduct planProd = pfM.getProdottoFisicoById(planned.getPhysicalProduct().getId()); if (planProd.getId().equals(product.getId())) { List<ProcessPhysicalProductInput> list = bomWip.getProcessPhysicalProductInput(); list.add(effective); bomWip.setProcessPhysicalProductInput(list); listToRemove.add(effective); continue effective; } } } for (int i = 0; i < listWip.size(); i++) { BillOfProcessInputSummary bomWip = listWip.get(i); BillOfProcessInput planned = bomWip.getBillOfProcessInput(); if (planned.getProductType() != null) { if (product.getProductType() != null) { ProductType planType = tpM.findById(planned.getProductType().getId()); ProductType pt = tpM.findById(product.getProductType().getId()); if (planType.getId().equals(pt.getId())) { List<ProcessPhysicalProductInput> list = bomWip.getProcessPhysicalProductInput(); list.add(effective); bomWip.setProcessPhysicalProductInput(list); listToRemove.add(effective); continue effective; } } }

53

286885 BOMA
} for (int i = 0; i < listWip.size(); i++) { BillOfProcessInputSummary bomWip = listWip.get(i); BillOfProcessInput planned = bomWip.getBillOfProcessInput(); if (planned.getProductFamily() != null) { if (product.getProductType() != null) { ProductType pt = tpM.findById(product.getProductType().getId()); if (pt.getProductFamily() != null) { ProductFamily planFam = fpM.getById(planned.getProductFamily().getId()); ProductFamily pf = fpM.getById(pt.getProductFamily().getId()); if (planFam.getId().equals(pf.getId())) { List<ProcessPhysicalProductInput> list = bomWip.getProcessPhysicalProductInput(); list.add(effective); bomWip.setProcessPhysicalProductInput(list); listToRemove.add(effective); continue effective; } } } } } } listEffective.removeAll(listToRemove); if (listEffective.size() > 0) { for (int j = 0; j < listEffective.size(); j++) { BillOfProcessInputSummary b = new BillOfProcessInputSummary(); b.setProcess(process); b.setBillOfProcessInput(null); List<ProcessPhysicalProductInput> listProduct = new ArrayList<ProcessPhysicalProductInput>(); listProduct.add(listEffective.get(j)); b.setProcessPhysicalProductInput(listProduct); listWip.add(b); } } } return listWip; } @Override public BigDecimal getTotalPlannedQuantity(List<BillOfProcessInputSummary> bomInputWorkInProgresses) { BigDecimal totQuantityPlanned = new BigDecimal("0"); for (int i = 0; i < bomInputWorkInProgresses.size(); i++) { BillOfProcessInputSummary bomInputWorkInProgress = bomInputWorkInProgresses.get(i); BillOfProcessInput billOfProcessInput = bomInputWorkInProgress.getBillOfProcessInput(); if (billOfProcessInput == null) continue; if (billOfProcessInput.getQuantity() != null) totQuantityPlanned = totQuantityPlanned.add(billOfProcessInput.getQuantity()); } return totQuantityPlanned; } @Override public BigDecimal getTotalEffectiveQuantity(List<BillOfProcessInputSummary> bomInputWorkInProgresses) { BigDecimal totQuantityEffective = new BigDecimal("0"); for (int i = 0; i < bomInputWorkInProgresses.size(); i++) { BillOfProcessInputSummary bomInputWorkInProgress = bomInputWorkInProgresses.get(i); List<ProcessPhysicalProductInput> processPhysicalProductInputs = bomInputWorkInProgress.getProcessPhysicalProductInput(); for (int j = 0; j < processPhysicalProductInputs.size(); j++) { ProcessPhysicalProductInput processPhysicalProductInput = processPhysicalProductInputs.get(j); if (processPhysicalProductInput.getQuantity() != null) totQuantityEffective = totQuantityEffective.add(processPhysicalProductInput.getQuantity()); } } return totQuantityEffective; } @Override

54

286885 BOMA
public Integer getTotalPlannedNumberOfItems(List<BillOfProcessInputSummary> bomInputWorkInProgresses) { Integer totItemPlanned = 0; for (int i = 0; i < bomInputWorkInProgresses.size(); i++) { BillOfProcessInputSummary bomInputWorkInProgress = bomInputWorkInProgresses.get(i); BillOfProcessInput billOfProcessInput = bomInputWorkInProgress.getBillOfProcessInput(); if (billOfProcessInput == null) continue; if (billOfProcessInput.getNumberOfItems() != null) totItemPlanned = totItemPlanned + billOfProcessInput.getNumberOfItems(); } return totItemPlanned; } @Override public Integer getTotalEffectiveNumberOfItems(List<BillOfProcessInputSummary> bomInputWorkInProgresses) { Integer totItemEffective = 0; for (int i = 0; i < bomInputWorkInProgresses.size(); i++) { BillOfProcessInputSummary bomInputWorkInProgress = bomInputWorkInProgresses.get(i); List<ProcessPhysicalProductInput> processPhysicalProductInputs = bomInputWorkInProgress.getProcessPhysicalProductInput(); for (int j = 0; j < processPhysicalProductInputs.size(); j++) { ProcessPhysicalProductInput processPhysicalProductInput = processPhysicalProductInputs.get(j); if (processPhysicalProductInput.getNumberOfItems() != null) totItemEffective = totItemEffective + processPhysicalProductInput.getNumberOfItems(); } } return totItemEffective; } } public interface BillOfProcessOperatorService { public abstract void insert(BillOfProcessOperator sensor); public abstract void delete(BillOfProcessOperator sensor); public abstract List<BillOfProcessOperator> get(); public abstract BillOfProcessOperator get(Long id); public abstract List<BillOfProcessOperator> get(Search search); public abstract List<BillOfProcessOperator> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); public abstract List<BillOfProcessOperatorSummary> getBillOfProcessOperatorSummaries(Process process, BillOfProcess billOfProcess); public abstract Integer getTotalPlannedHours(List<BillOfProcessOperatorSummary> billOfProcessOperatorSummaries); public abstract Integer getTotalEffectiveHours(List<BillOfProcessOperatorSummary> billOfProcessOperatorSummaries); } @Service public class BillOfProcessOperatorServiceImpl implements BillOfProcessOperatorService { @Autowired private BillOfProcessOperatorDAO dao; @Autowired private ProcessOperatorService loM; @Autowired private OperatorService oM; @Autowired private OperatorTypeService otM; @Transactional public void insert(BillOfProcessOperator sensor) { dao.persist(sensor); } @Transactional public void delete(BillOfProcessOperator sensor) { dao.remove(sensor); } @Transactional public List<BillOfProcessOperator> get() { return dao.get(); } @Transactional public BillOfProcessOperator get(Long id) { return dao.get(id); } @Transactional public List<BillOfProcessOperator> get(Search search) { return dao.get(search); } @Transactional public List<BillOfProcessOperator> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); }

55

286885 BOMA
@Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } @Override public List<BillOfProcessOperatorSummary> getBillOfProcessOperatorSummaries(Process process, BillOfProcess billOfProcess) { List<BillOfProcessOperatorSummary> listWip = new ArrayList<BillOfProcessOperatorSummary>(); Search searchPlan = new Search(BillOfProcessOperator.class); searchPlan.addFilter(HxFilter.equal(billOfProcess.getId(), BillOfProcessOperator._billOfProcess, BillOfProcess._id)); List<BillOfProcessOperator> listPlanned = dao.get(searchPlan); for (int i = 0; i < listPlanned.size(); i++) { BillOfProcessOperator planned = listPlanned.get(i); BillOfProcessOperatorSummary b = new BillOfProcessOperatorSummary(); b.setProcess(process); b.setBillOfProcessOperator(planned); b.setProcessOperator(new ArrayList<ProcessOperator>()); listWip.add(b); } Search searchEff = new Search(ProcessOperator.class); searchEff.addFilter(HxFilter.equal(billOfProcess.getId(), ProcessOperator._billOfProcess, BillOfProcess._id)); searchEff.addFilter(HxFilter.equal(process.getId(), ProcessOperator._process, Process._id)); List<ProcessOperator> listEffective = loM.getLavorazioneOperatoreBySearch(searchEff); List<ProcessOperator> listToRemove = new ArrayList<ProcessOperator>(); if (listEffective != null && listEffective.size() > 0) { effective: for (int j = 0; j < listEffective.size(); j++) { ProcessOperator effective = listEffective.get(j); for (int i = 0; i < listWip.size(); i++) { BillOfProcessOperatorSummary bomWip = listWip.get(i); BillOfProcessOperator planned = bomWip.getBillOfProcessOperator(); if (planned.getOperatorType() != null) { OperatorType planOperType = otM.getById(planned.getOperatorType().getId()); if (planOperType.getId().equals(effective.getOperatorType().getId())) { List<ProcessOperator> list = bomWip.getProcessOperator(); list.add(effective); bomWip.setProcessOperator(list); listToRemove.add(effective); continue effective; } } } for (int i = 0; i < listWip.size(); i++) { BillOfProcessOperatorSummary bomWip = listWip.get(i); BillOfProcessOperator planned = bomWip.getBillOfProcessOperator(); if (planned.getOperator() != null) { Operator planOper = oM.get(planned.getOperator().getId()); if (planOper.getId().equals(effective.getOperator().getId())) { List<ProcessOperator> list = bomWip.getProcessOperator(); list.add(effective); bomWip.setProcessOperator(list); listToRemove.add(effective); continue effective; } } } } listEffective.removeAll(listToRemove); if (listEffective.size() > 0) { for (int j = 0; j < listEffective.size(); j++) { BillOfProcessOperatorSummary b = new BillOfProcessOperatorSummary(); b.setProcess(process); b.setBillOfProcessOperator(null); List<ProcessOperator> list = new ArrayList<ProcessOperator>(); list.add(listEffective.get(j)); b.setProcessOperator(list); listWip.add(b); } }

56

286885 BOMA
} return listWip; } @Override public Integer getTotalPlannedHours(List<BillOfProcessOperatorSummary> bomOperatorWorkInProgresses) { Integer totHourPlanned = 0; for (int i = 0; i < bomOperatorWorkInProgresses.size(); i++) { BillOfProcessOperatorSummary bomOperatorWorkInProgress = bomOperatorWorkInProgresses.get(i); BillOfProcessOperator billOfProcessOperator = bomOperatorWorkInProgress.getBillOfProcessOperator(); if (billOfProcessOperator == null) continue; if (billOfProcessOperator.getHours() != null) totHourPlanned = totHourPlanned + billOfProcessOperator.getHours(); } return totHourPlanned; } @Override public Integer getTotalEffectiveHours(List<BillOfProcessOperatorSummary> bomOperatorWorkInProgresses) { Integer totHourEffective = 0; for (int i = 0; i < bomOperatorWorkInProgresses.size(); i++) { BillOfProcessOperatorSummary bomOperatorWorkInProgress = bomOperatorWorkInProgresses.get(i); List<ProcessOperator> processOperator = bomOperatorWorkInProgress.getProcessOperator(); if (processOperator == null) continue; if (processOperator != null) for (int j = 0; j < processOperator.size(); j++) if (processOperator.get(j).getHours() != null) totHourEffective = totHourEffective + processOperator.get(j).getHours(); } return totHourEffective; } } public interface BillOfProcessOutputService { public abstract void insert(BillOfProcessOutput sensor); public abstract void delete(BillOfProcessOutput sensor); public abstract List<BillOfProcessOutput> get(); public abstract BillOfProcessOutput get(Long id); public abstract List<BillOfProcessOutput> get(Search search); public abstract List<BillOfProcessOutput> get(Search search, int currPage, int pageSize); public abstract List<BillOfProcessOutput> getByBillOfProcess(Long idBillOfProcess); public abstract List<BillOfProcessOutput> getByBillOfProcess(BillOfProcess billOfProcess); public abstract int count(); public abstract int count(Search search); public abstract List<BillOfProcessOutputSummary> getBillOfProcessOutputSummaries(Process process, BillOfProcess billOfProcess); public abstract BigDecimal getTotalPlannedQuantity(List<BillOfProcessOutputSummary> billOfProcessOutputSummaries); public abstract BigDecimal getTotalEffectiveQuantity(List<BillOfProcessOutputSummary> billOfProcessOutputSummaries); public abstract Integer getTotalPlannedNumberOfItems(List<BillOfProcessOutputSummary> billOfProcessOutputSummaries); public abstract Integer getTotalEffectiveNumberOfItems(List<BillOfProcessOutputSummary> billOfProcessOutputSummaries); } @Service public class BillOfProcessOutputServiceImpl implements BillOfProcessOutputService{ @Autowired private BillOfProcessOutputDAO dao; @Autowired private ProcessPhysicalProductOutputService pppoS; @Autowired private PhysicalProductService pfM; @Autowired private ProductTypeService tpM; @Autowired private ProductFamilyService fpM; @Transactional public void insert(BillOfProcessOutput sensor) { dao.persist(sensor); } @Transactional public void delete(BillOfProcessOutput sensor) { dao.remove(sensor); } @Transactional public List<BillOfProcessOutput> get() { return dao.get(); } @Transactional public BillOfProcessOutput get(Long id) {

57

286885 BOMA
return dao.get(id); } @Transactional public List<BillOfProcessOutput> get(Search search) { return dao.get(search); } @Transactional public List<BillOfProcessOutput> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } @Override public List<BillOfProcessOutput> getByBillOfProcess(BillOfProcess billOfProcess) { return getByBillOfProcess(billOfProcess.getId()); } @Override public List<BillOfProcessOutput> getByBillOfProcess(Long idBillOfProcess) { Search search = new Search(BillOfProcessOutput.class); search.addFilter(HxFilter.equal(idBillOfProcess, BillOfProcessOutput._billOfProcess, BillOfProcess._id)); List<BillOfProcessOutput> list = dao.get(search); return list; } @Override public List<BillOfProcessOutputSummary> getBillOfProcessOutputSummaries(Process process, BillOfProcess billOfProcess) { List<BillOfProcessOutputSummary> listWip = new ArrayList<BillOfProcessOutputSummary>(); Search searchOutput = new Search(BillOfProcessOutput.class); searchOutput.addFilter(HxFilter.equal(billOfProcess.getId(), BillOfProcessOutput._billOfProcess, BillOfProcess._id)); List<BillOfProcessOutput> listPlanned = dao.get(searchOutput); for (int i = 0; i < listPlanned.size(); i++) { BillOfProcessOutput planned = listPlanned.get(i); BillOfProcessOutputSummary b = new BillOfProcessOutputSummary(); b.setProcess(process); b.setBillOfProcessOutput(planned); b.setProcessPhysicalProductOutput(new ArrayList<ProcessPhysicalProductOutput>()); listWip.add(b); } Search searchProduct = new Search(ProcessPhysicalProductOutput.class); searchProduct.addFilter(HxFilter.equal(billOfProcess.getId(), ProcessPhysicalProductOutput._billOfProcess, BillOfProcess._id)); searchProduct.addFilter(HxFilter.equal(process.getId(), ProcessPhysicalProductOutput._process, Process._id)); List<ProcessPhysicalProductOutput> listEffective = pppoS.get(searchProduct); List<ProcessPhysicalProductOutput> listToRemove = new ArrayList<ProcessPhysicalProductOutput>(); if (listEffective != null && listEffective.size() > 0) { for (int j = 0; j < listEffective.size(); j++) { ProcessPhysicalProductOutput effective = listEffective.get(j); PhysicalProduct product = pfM.getProdottoFisicoById(effective.getPhysicalProduct().getId()); Boolean find = false; for (int i = 0; i < listWip.size(); i++) { BillOfProcessOutputSummary bomWip = listWip.get(i); BillOfProcessOutput planned = bomWip.getBillOfProcessOutput(); if (planned.getPhysicalProduct() != null) { PhysicalProduct planProd = pfM.getProdottoFisicoById(planned.getPhysicalProduct().getId()); if (planProd.getId().equals(product.getId())) { List<ProcessPhysicalProductOutput> list = bomWip.getProcessPhysicalProductOutput(); list.add(effective); bomWip.setProcessPhysicalProductOutput(list); listToRemove.add(effective); find = true; break; } }

58

286885 BOMA
} if (find) continue; for (int i = 0; i < listWip.size(); i++) { BillOfProcessOutputSummary bomWip = listWip.get(i); BillOfProcessOutput planned = bomWip.getBillOfProcessOutput(); if (planned.getProductType() != null) { if (product.getProductType() != null) { ProductType planType = tpM.findById(planned.getProductType().getId()); ProductType pt = tpM.findById(product.getProductType().getId()); if (planType.getId().equals(pt.getId())) { List<ProcessPhysicalProductOutput> list = bomWip.getProcessPhysicalProductOutput(); list.add(effective); bomWip.setProcessPhysicalProductOutput(list); listToRemove.add(effective); find = true; break; } } } } if (find) continue; for (int i = 0; i < listWip.size(); i++) { BillOfProcessOutputSummary bomWip = listWip.get(i); BillOfProcessOutput planned = bomWip.getBillOfProcessOutput(); if (planned.getProductFamily() != null) { if (product.getProductType() != null) { ProductType pt = tpM.findById(product.getProductType().getId()); if (pt.getProductFamily() != null) { ProductFamily planFam = fpM.getById(planned.getProductFamily().getId()); ProductFamily pf = fpM.getById(pt.getProductFamily().getId()); if (planFam.getId().equals(pf.getId())) { List<ProcessPhysicalProductOutput> list = bomWip.getProcessPhysicalProductOutput(); list.add(effective); bomWip.setProcessPhysicalProductOutput(list); listToRemove.add(effective); find = true; break; } } } } } if (find) continue; } listEffective.removeAll(listToRemove); if (listEffective.size() > 0) { for (int j = 0; j < listEffective.size(); j++) { BillOfProcessOutputSummary b = new BillOfProcessOutputSummary(); b.setProcess(process); b.setBillOfProcessOutput(null); List<ProcessPhysicalProductOutput> listProduct = new ArrayList<ProcessPhysicalProductOutput>(); listProduct.add(listEffective.get(j)); b.setProcessPhysicalProductOutput(listProduct); listWip.add(b); } } } return listWip; } @Override public BigDecimal getTotalPlannedQuantity(List<BillOfProcessOutputSummary> bomOutputWorkInProgresses) { BigDecimal totQuantityPlanned = new BigDecimal("0"); for (int i = 0; i < bomOutputWorkInProgresses.size(); i++) { BillOfProcessOutputSummary bomOutputWorkInProgress = bomOutputWorkInProgresses.get(i);

59

286885 BOMA
BillOfProcessOutput billOfProcessOutput = bomOutputWorkInProgress.getBillOfProcessOutput(); if (billOfProcessOutput == null) continue; if (billOfProcessOutput.getQuantity() != null) totQuantityPlanned = totQuantityPlanned.add(billOfProcessOutput.getQuantity()); } return totQuantityPlanned; } @Override public BigDecimal getTotalEffectiveQuantity(List<BillOfProcessOutputSummary> bomOutputWorkInProgresses) { BigDecimal totQuantityEffective = new BigDecimal("0"); for (int i = 0; i < bomOutputWorkInProgresses.size(); i++) { BillOfProcessOutputSummary bomOutputWorkInProgress = bomOutputWorkInProgresses.get(i); List<ProcessPhysicalProductOutput> processPhysicalProductOutputs = bomOutputWorkInProgress.getProcessPhysicalProductOutput(); for (int j = 0; j < processPhysicalProductOutputs.size(); j++) { ProcessPhysicalProductOutput processPhysicalProductOutput = processPhysicalProductOutputs.get(j); if (processPhysicalProductOutput.getQuantity() != null) totQuantityEffective = totQuantityEffective.add(processPhysicalProductOutput.getQuantity()); } } return totQuantityEffective; } @Override public Integer getTotalPlannedNumberOfItems(List<BillOfProcessOutputSummary> bomOutputWorkInProgresses) { Integer totItemPlanned = 0; for (int i = 0; i < bomOutputWorkInProgresses.size(); i++) { BillOfProcessOutputSummary bomOutputWorkInProgress = bomOutputWorkInProgresses.get(i); BillOfProcessOutput billOfProcessOutput = bomOutputWorkInProgress.getBillOfProcessOutput(); if (billOfProcessOutput == null) continue; if (billOfProcessOutput.getNumberOfItems() != null) totItemPlanned = totItemPlanned + billOfProcessOutput.getNumberOfItems(); } return totItemPlanned; } @Override public Integer getTotalEffectiveNumberOfItems(List<BillOfProcessOutputSummary> bomOutputWorkInProgresses) { Integer totItemEffective = 0; for (int i = 0; i < bomOutputWorkInProgresses.size(); i++) { BillOfProcessOutputSummary bomOutputWorkInProgress = bomOutputWorkInProgresses.get(i); List<ProcessPhysicalProductOutput> processPhysicalProductOutputs = bomOutputWorkInProgress.getProcessPhysicalProductOutput(); for (int j = 0; j < processPhysicalProductOutputs.size(); j++) { ProcessPhysicalProductOutput processPhysicalProductOutput = processPhysicalProductOutputs.get(j); if (processPhysicalProductOutput.getNumberOfItems() != null) totItemEffective = totItemEffective + processPhysicalProductOutput.getNumberOfItems(); } } return totItemEffective; } } public interface BillOfProcessPackagingTypeService { public abstract void insert(BillOfProcessPackagingType session); public abstract void delete(BillOfProcessPackagingType session); public abstract List<BillOfProcessPackagingType> get(); public abstract BillOfProcessPackagingType get(Long id); public abstract List<BillOfProcessPackagingType> get(Search search); public abstract List<BillOfProcessPackagingType> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); } @Service public class BillOfProcessPackagingTypeServiceImpl implements BillOfProcessPackagingTypeService { @Autowired private BillOfProcessPackagingTypeDAO dao; @Transactional public void insert(BillOfProcessPackagingType billOfProcessPackagingType) { dao.persist(billOfProcessPackagingType);

60

286885 BOMA
} @Transactional public void delete(BillOfProcessPackagingType billOfProcessPackagingType) { dao.remove(billOfProcessPackagingType); } @Transactional public List<BillOfProcessPackagingType> get() { return dao.get(); } @Transactional public BillOfProcessPackagingType get(Long id) { return dao.get(id); } @Transactional public List<BillOfProcessPackagingType> get(Search search) { return dao.get(search); } @Transactional public List<BillOfProcessPackagingType> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } } public interface BillOfProcessResourceService { public abstract void insert(BillOfProcessResource billOfProcessResource); public abstract void delete(BillOfProcessResource billOfProcessResource); public abstract List<BillOfProcessResource> get(); public abstract BillOfProcessResource get(Long id); public abstract List<BillOfProcessResource> get(Search search); public abstract List<BillOfProcessResource> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); public abstract List<BillOfProcessResourceSummary> getBillOfProcessResourceSummaries(Process process, BillOfProcess billOfProcess); public abstract Integer getTotalPlannedHours(List<BillOfProcessResourceSummary> billOfProcessResourceSummaries); public abstract Integer getTotalEffectiveHours(List<BillOfProcessResourceSummary> billOfProcessResourceSummaries); } @Service public class BillOfProcessResourceServiceImpl implements BillOfProcessResourceService { @Autowired private BillOfProcessResourceDAO dao; @Autowired private ProcessResourceService lrM; @Autowired private ResourceService rM; @Transactional public void insert(BillOfProcessResource billOfProcessResource) { dao.persist(billOfProcessResource); } @Transactional public void delete(BillOfProcessResource billOfProcessResource) { dao.remove(billOfProcessResource); } @Transactional public List<BillOfProcessResource> get() { return dao.get(); } @Transactional public BillOfProcessResource get(Long id) { return dao.get(id); } @Transactional public List<BillOfProcessResource> get(Search search) { return dao.get(search); } @Transactional public List<BillOfProcessResource> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize);

61

286885 BOMA
} @Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } @Override public List<BillOfProcessResourceSummary> getBillOfProcessResourceSummaries(Process process, BillOfProcess billOfProcess) { List<BillOfProcessResourceSummary> listWip = new ArrayList<BillOfProcessResourceSummary>(); Search searchPlan = new Search(BillOfProcessResource.class); searchPlan.addFilter(HxFilter.equal(billOfProcess.getId(), BillOfProcessResource._billOfProcess, BillOfProcess._id)); List<BillOfProcessResource> listPlanned = dao.get(searchPlan); for (int i = 0; i < listPlanned.size(); i++) { BillOfProcessResource planned = listPlanned.get(i); BillOfProcessResourceSummary b = new BillOfProcessResourceSummary(); b.setProcess(process); b.setBillOfProcessResource(planned); b.setProcessResource(new ArrayList<ProcessResource>()); listWip.add(b); } Search searchEff = new Search(ProcessResource.class); searchEff.addFilter(HxFilter.equal(billOfProcess.getId(), ProcessResource._billOfProcess, BillOfProcess._id)); searchEff.addFilter(HxFilter.equal(process.getId(), ProcessResource._process, Process._id)); List<ProcessResource> listEffective = lrM.getLavorazioneRisorsaBySearch(searchEff); List<ProcessResource> listToRemove = new ArrayList<ProcessResource>(); if (listEffective != null && listEffective.size() > 0) { for (int j = 0; j < listEffective.size(); j++) { ProcessResource effective = listEffective.get(j); Resource resource = rM.getById(effective.getResource().getId()); for (int i = 0; i < listWip.size(); i++) { BillOfProcessResourceSummary bomWip = listWip.get(i); BillOfProcessResource planned = bomWip.getBillOfProcessResource(); Resource planRersource = rM.getById(planned.getResource().getId()); if (planRersource.getId().equals(resource.getId())) { List<ProcessResource> list = bomWip.getProcessResource(); list.add(effective); bomWip.setProcessResource(list); listToRemove.add(effective); break; } } } listEffective.removeAll(listToRemove); if (listEffective.size() > 0) { for (int j = 0; j < listEffective.size(); j++) { BillOfProcessResourceSummary b = new BillOfProcessResourceSummary(); b.setProcess(process); b.setBillOfProcessResource(null); List<ProcessResource> list = new ArrayList<ProcessResource>(); list.add(listEffective.get(j)); b.setProcessResource(list); listWip.add(b); } } } return listWip; } @Override public Integer getTotalPlannedHours(List<BillOfProcessResourceSummary> bomResourceWorkInProgresses) { Integer totHourPlanned = 0; for (int i = 0; i < bomResourceWorkInProgresses.size(); i++) { BillOfProcessResourceSummary bomResourceWorkInProgress = bomResourceWorkInProgresses.get(i); BillOfProcessResource billOfProcessResource = bomResourceWorkInProgress.getBillOfProcessResource(); if (billOfProcessResource == null) continue; if (billOfProcessResource.getHours() != null) totHourPlanned = totHourPlanned + billOfProcessResource.getHours(); } return totHourPlanned;

62

286885 BOMA
} @Override public Integer getTotalEffectiveHours(List<BillOfProcessResourceSummary> bomResourceWorkInProgresses) { Integer totHourEffective = 0; for (int i = 0; i < bomResourceWorkInProgresses.size(); i++) { BillOfProcessResourceSummary bomResourceWorkInProgress = bomResourceWorkInProgresses.get(i); List<ProcessResource> processResource = bomResourceWorkInProgress.getProcessResource(); if (processResource == null) continue; if (processResource != null) for (int j = 0; j < processResource.size(); j++) if (processResource.get(j).getHours() != null) totHourEffective = totHourEffective + processResource.get(j).getHours(); } return totHourEffective; } } public interface BillOfProcessService { public abstract void insert(BillOfProcess sensor); public abstract void delete(BillOfProcess sensor); public abstract List<BillOfProcess> get(); public abstract BillOfProcess get(Long id); public abstract List<BillOfProcess> get(Search search); public abstract List<BillOfProcess> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); public abstract BillOfProcess getByProcess(Long idProcess); } @Service public class BillOfProcessServiceImpl implements BillOfProcessService { @Autowired private BillOfProcessDAO dao; @Transactional public void insert(BillOfProcess sensor) { dao.persist(sensor); } @Transactional public void delete(BillOfProcess sensor) { dao.remove(sensor); } @Transactional public List<BillOfProcess> get() { return dao.get(); } @Transactional public BillOfProcess get(Long id) { return dao.get(id); } @Transactional public List<BillOfProcess> get(Search search) { return dao.get(search); } @Transactional public List<BillOfProcess> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } @Override public BillOfProcess getByProcess(Long idProcess) { BillOfProcess billOfProcess = null; Search searchBillOfProcess = new Search(BillOfProcess.class); searchBillOfProcess.addFilter(HxFilter.equal(idProcess, BillOfProcess._processBillOfProcesses, ProcessBillOfProcess._process, Process._id)); searchBillOfProcess.addSort(HxSort.desc(BillOfProcess._date));

63

286885 BOMA
List<BillOfProcess> listBillOfProcess = dao.get(searchBillOfProcess); if (listBillOfProcess.size() > 0) billOfProcess = listBillOfProcess.get(0); return billOfProcess; } } public interface BomAsProducedService { public abstract void insert(BomAsProduced bomAsProduced); public abstract void delete(BomAsProduced bomAsProduced); public abstract List<BomAsProduced> get(); public abstract BomAsProduced get(Long id); public abstract List<BomAsProduced> get(Search search); public abstract List<BomAsProduced> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); public abstract List<BomAsProduced> get(Process process); } @Service public class BomAsProducedServiceImpl implements BomAsProducedService { @Autowired private BomAsProducedDAO dao; @Transactional public void insert(BomAsProduced bomAsProduced) { dao.persist(bomAsProduced); } @Transactional public void delete(BomAsProduced bomAsProduced) { dao.remove(bomAsProduced); } @Transactional public List<BomAsProduced> get() { return dao.get(); } @Transactional public BomAsProduced get(Long id) { return dao.get(id); } @Transactional public List<BomAsProduced> get(Search search) { return dao.get(search); } @Transactional public List<BomAsProduced> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } @Transactional public List<BomAsProduced> get(Process process) { Search search = new Search(BomAsProduced.class); search.addFilter(HxFilter.equal(process.getId(), BomAsProduced._process, Process._id)); return get(search); } } public interface ProcessBillOfProcessService { public abstract void insert(ProcessBillOfProcess session); public abstract void delete(ProcessBillOfProcess session); public abstract List<ProcessBillOfProcess> get(); public abstract ProcessBillOfProcess get(Long id); public abstract List<ProcessBillOfProcess> get(Search search); public abstract List<ProcessBillOfProcess> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); }

64

286885 BOMA
@Service public class ProcessBillOfProcessServiceImpl implements ProcessBillOfProcessService { @Autowired private ProcessBillOfProcessDAO dao; @Transactional public void insert(ProcessBillOfProcess processBillOfProcess) { dao.persist(processBillOfProcess); } @Transactional public void delete(ProcessBillOfProcess processBillOfProcess) { dao.remove(processBillOfProcess); } @Transactional public List<ProcessBillOfProcess> get() { return dao.get(); } @Transactional public ProcessBillOfProcess get(Long id) { return dao.get(id); } @Transactional public List<ProcessBillOfProcess> get(Search search) { return dao.get(search); } @Transactional public List<ProcessBillOfProcess> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } } public interface ProcessOperatorService { public ProcessOperator get(Long id); public List<ProcessOperator> get(); public void insertLavorazioneOperatore(ProcessOperator lavorazioneOperatore); public List<ProcessOperator> getLavorazioneOperatoreBySearch(Search search); public int count(Search search); public List<ProcessOperator> get(Search search, int pageCurr, int pageSize); } @Service public class ProcessOperatorServiceImpl implements ProcessOperatorService { @Autowired private ProcessOperatorDAO dao; @Override public List<ProcessOperator> getLavorazioneOperatoreBySearch(Search search) { return this.dao.get(search); } @Override public void insertLavorazioneOperatore(ProcessOperator lavorazioneOperatore) { this.dao.persist(lavorazioneOperatore); } @Override public ProcessOperator get(Long id) { return dao.get(id); } @Override public List<ProcessOperator> get() { return dao.get(); } public int count(Search search) { return dao.count(search); } public List<ProcessOperator> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); }

65

286885 BOMA
} public interface ProcessPhysicalProductInputService { public abstract void insert(ProcessPhysicalProductInput sensor); public abstract void delete(ProcessPhysicalProductInput sensor); public abstract List<ProcessPhysicalProductInput> get(); public abstract ProcessPhysicalProductInput get(Long id); public abstract List<ProcessPhysicalProductInput> get(Search search); public abstract List<ProcessPhysicalProductInput> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); public abstract List<ProcessPhysicalProductInput> get(Process process); } @Service public class ProcessPhysicalProductInputServiceImpl implements ProcessPhysicalProductInputService{ @Autowired private ProcessPhysicalProductInputDAO dao; @Transactional public void insert(ProcessPhysicalProductInput sensor) { dao.persist(sensor); } @Transactional public void delete(ProcessPhysicalProductInput sensor) { dao.remove(sensor); } @Transactional public List<ProcessPhysicalProductInput> get() { return dao.get(); } @Transactional public ProcessPhysicalProductInput get(Long id) { return dao.get(id); } @Transactional public List<ProcessPhysicalProductInput> get(Search search) { return dao.get(search); } @Transactional public List<ProcessPhysicalProductInput> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } @Transactional public List<ProcessPhysicalProductInput> get(Process process) { Search search = new Search(ProcessPhysicalProductInput.class); search.addFilter(HxFilter.equal(process.getId(), ProcessPhysicalProductInput._process, Process._id )); return get(search); } } public interface ProcessPhysicalProductOutputService { public abstract void insert(ProcessPhysicalProductOutput sensor); public abstract void delete(ProcessPhysicalProductOutput sensor); public abstract List<ProcessPhysicalProductOutput> get(); public abstract ProcessPhysicalProductOutput get(Long id); public abstract List<ProcessPhysicalProductOutput> get(Search search); public abstract List<ProcessPhysicalProductOutput> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); public abstract List<ProcessPhysicalProductOutput> get(Process process); } @Service public class ProcessPhysicalProductOutputServiceImpl implements ProcessPhysicalProductOutputService{ @Autowired private ProcessPhysicalProductOutputDAO dao;

66

286885 BOMA
@Transactional public void insert(ProcessPhysicalProductOutput sensor) { dao.persist(sensor); } @Transactional public void delete(ProcessPhysicalProductOutput sensor) { dao.remove(sensor); } @Transactional public List<ProcessPhysicalProductOutput> get() { return dao.get(); } @Transactional public ProcessPhysicalProductOutput get(Long id) { return dao.get(id); } @Transactional public List<ProcessPhysicalProductOutput> get(Search search) { return dao.get(search); } @Transactional public List<ProcessPhysicalProductOutput> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } @Transactional public List<ProcessPhysicalProductOutput> get(Process process) { Search search = new Search(ProcessPhysicalProductOutput.class); search.addFilter(HxFilter.equal(process.getId(), ProcessPhysicalProductOutput._process, Process._id)); return get(search); } } public interface ProcessPreemptionService { public abstract void insert(ProcessPreemption processPreemption); public abstract void delete(ProcessPreemption processPreemption); public abstract List<ProcessPreemption> get(); public abstract ProcessPreemption get(Long id); public abstract List<ProcessPreemption> get(Search search); public abstract List<ProcessPreemption> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); } @Service public class ProcessPreemptionServiceImpl implements ProcessPreemptionService { @Autowired private ProcessPreemptionDAO dao; @Transactional public void insert(ProcessPreemption processPreemption) { dao.persist(processPreemption); } @Transactional public void delete(ProcessPreemption processPreemption) { dao.remove(processPreemption); } @Transactional public List<ProcessPreemption> get() { return dao.get(); } @Transactional public ProcessPreemption get(Long id) { return dao.get(id); } @Transactional

67

286885 BOMA
public List<ProcessPreemption> get(Search search) { return dao.get(search); } @Transactional public List<ProcessPreemption> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } } public interface ProcessResourceService { public ProcessResource get(Long id); public List<ProcessResource> get(); public void insertLavorazioneRisorsa(ProcessResource lavorazioneRisorsa); public List<ProcessResource> getLavorazioneRisorsaBySearch(Search search); } @Service public class ProcessResourceServiceImpl implements ProcessResourceService { @Autowired private ProcessResourceDAO dao; @Override public List<ProcessResource> getLavorazioneRisorsaBySearch(Search search) { return this.dao.get(search); } @Override public void insertLavorazioneRisorsa(ProcessResource lavorazioneRisorsa) { this.dao.persist(lavorazioneRisorsa); } @Override public ProcessResource get(Long id) { return dao.get(id); } @Override public List<ProcessResource> get() { return dao.get(); } } public interface ProcessService { public void insertLavorazione(Process lavorazione); public Process getLavorazioneById(Long idLavorazione); public List<Process> getLavorazioneBySearch(Search search); public int countLavorazione(Search search); public List<Process> get(Search search, int i, int pageSize); public List<Process> get(); public abstract List<ProcessSummary> getSummary(Long idProductionSheet); public abstract List<ProcessSummary> getSummary(ProductionSheet productionSheet); public List<Process> get(ProductionSheet ps); public List<Process> get(ProductionSheet productionSheet, String processTypeCode); } @Service public class ProcessServiceImpl implements ProcessService { @Autowired private ProcessDAO dao; @Autowired private ProcessPreemptionService ppS; @Override public List<Process> getLavorazioneBySearch(Search search) { return this.dao.get(search); } @Override public int countLavorazione(Search search) { return this.dao.count(search); } @Override public Process getLavorazioneById(Long idLavorazione) {

68

286885 BOMA
return this.dao.get(idLavorazione); } @Override public void insertLavorazione(Process lavorazione) { this.dao.persist(lavorazione); } @Override public List<Process> get(Search search, int i, int pageSize) { return dao.get(search, i, pageSize); } public List<Process> get() { return dao.get(); } @Override @Transactional public List<ProcessSummary> getSummary(Long idProductionSheet) { List<ProcessSummary> processSummaries = new ArrayList<ProcessSummary>(); Search pS = new Search(Process.class); pS.addFilter(HxFilter.equal(idProductionSheet, Process._productionSheet, ProductionSheet._id)); pS.addFetch(HxSearch.mergeNames(Process._processType)); List<Process> processes = dao.get(pS); for (int i = 0; i < processes.size(); i++) { ProcessType processType = processes.get(i).getProcessType(); processSummaries.add(new ProcessSummary(processes.get(i), processType)); } boolean sorted = true; do { sorted = true; for (int i = 0; i < processSummaries.size(); i++) { ProcessSummary processSummary = processSummaries.get(i); if (processSummary.getLevel() != null && processSummary.isReachable() != null) continue; Search ppSearch = new Search(ProcessPreemption.class); ppSearch.addFilter(HxFilter.equal(processSummary.getProcess(), ProcessPreemption._processByProcess)); List<ProcessPreemption> processPreemptions = ppS.get(ppSearch); if (processPreemptions.size() == 0) { processSummary.setLevel(0); processSummary.setReachable(true); continue; } List<Integer> parentLevel = new ArrayList<Integer>(processPreemptions.size()); processSummary.setReachable(true); for (int j = 0; j < processPreemptions.size(); j++) { ProcessPreemption processPreemption = processPreemptions.get(j); for (int k = 0; k < processSummaries.size(); k++) { ProcessSummary matchingProcess = processSummaries.get(k); if (processPreemption.getProcessByParentProcess().equals(matchingProcess.getProcess())) { if (matchingProcess.getLevel() != null) parentLevel.add(matchingProcess.getLevel()); if (processSummary.isReachable() != null) { if (matchingProcess.isReachable() == null) processSummary.setReachable(null); else if (matchingProcess.isReachable() == false) processSummary.setReachable(false); else if (matchingProcess.isReachable() == true) if (matchingProcess.getProcess().getEndDate() == null) processSummary.setReachable(false); } } } } if (parentLevel.size() > 0) processSummary.setLevel(Collections.max(parentLevel) + 1); if (processSummary.getLevel() == null) sorted = false; if (processSummary.isReachable() == null) sorted = false; } } while (!sorted);

69

286885 BOMA
Collections.sort(processSummaries); return processSummaries; } @Override public List<ProcessSummary> getSummary(ProductionSheet productionSheet) { return getSummary(productionSheet.getId()); } public List<Process> get(ProductionSheet ps) { Search search = new Search(Process.class); search.addFilter(HxFilter.equal(ps.getId(), Process._productionSheet, ProductionSheet._id)); return getLavorazioneBySearch(search); } @Override public Process get(ProductionSheet ps, String name, String externalId) { Search search = new Search(Process.class); search.addFilter(HxFilter.equal(ps.getId(), Process._productionSheet, ProductionSheet._id)); search.addFilter(HxFilter.equal(name, Process._name)); search.addFilter(HxFilter.equal(externalId, Process._externalId)); List<Process> p = getLavorazioneBySearch(search); if (p == null || p.size() == 0) return null; return p.get(0); } @Override public List<Process> get(ProductionSheet productionSheet, String code) { Search search = new Search(Process.class); search.addFilter(HxFilter.equal(code, Process._processType, ProcessType._code)); search.addFilter(HxFilter.equal(productionSheet.getId(), Process._productionSheet, ProductionSheet._id)); return getLavorazioneBySearch(search); } } public interface ProcessTypeCategoryService { public abstract void insert(ProcessTypeCategory processTypeCategory); public abstract void delete(ProcessTypeCategory processTypeCategory); public abstract List<ProcessTypeCategory> get(); public abstract ProcessTypeCategory get(String code); public abstract ProcessTypeCategory get(Long id); public abstract List<ProcessTypeCategory> get(Search search); public abstract List<ProcessTypeCategory> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); public abstract ProcessTypeCategory getDefault(); } @Service public class ProcessTypeCategoryServiceImpl implements ProcessTypeCategoryService { @Autowired private ProcessTypeCategoryDAO dao; @Transactional public void insert(ProcessTypeCategory processTypeCategory) { dao.persist(processTypeCategory); } @Transactional public void delete(ProcessTypeCategory processTypeCategory) { dao.remove(processTypeCategory); } @Transactional public List<ProcessTypeCategory> get() { return dao.get(); } @Transactional public ProcessTypeCategory get(Long id) { return dao.get(id); } @Transactional public List<ProcessTypeCategory> get(Search search) { return dao.get(search); } @Transactional public List<ProcessTypeCategory> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); }

70

286885 BOMA
@Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } public ProcessTypeCategory getDefault() { return get("PRODUCTION"); } public ProcessTypeCategory get(String code) { Search search = new Search(ProcessTypeCategory.class); search.addFilter(HxFilter.equal(code, ProcessTypeCategory._code)); List<ProcessTypeCategory> l = get(search); if (l!=null && l.size()>0) return l.get(0); return null; } } public interface ProcessTypeService { public ProcessType get(Long id); public List<ProcessType> get(); public ProcessType get(String code); public ProcessType getOrCreate(String code); public void insert(ProcessType processType); public List<ProcessType> get( ProcessTypeCategory processTypeCategory); public List<ProcessType> get(Search search); } @Service public class ProcessTypeServiceImpl implements ProcessTypeService { @Autowired private ProcessTypeDAO dao; @Autowired private ProcessTypeCategoryService processTypeCategoryS; @Override public ProcessType get(Long id) { return this.dao.get(id); } public List<ProcessType> get() { return dao.get(); } public ProcessType get(String code) { Search s = new Search(ProcessType.class); s.addFilter(HxFilter.equal(code, ProcessType._code)); List<ProcessType> lpt = dao.get(s); if(lpt == null || lpt.size() == 0) return null; else return lpt.get(0); } public void insert(ProcessType processType) { dao.persist(processType); } @Override public ProcessType getOrCreate(String code) { ProcessType el = get(code); if (el != null) return el; el = new ProcessType(); el.setCode(code); el.setLabel(code); el.setProcessTypeCategory(processTypeCategoryS.getDefault()); insert(el); return el; } public List<ProcessType> get(ProcessTypeCategory processTypeCategory) { Search search = new Search(ProcessType.class); search.addFilter(HxFilter.equal(processTypeCategory.getId(), ProcessType._processTypeCategory, ProcessTypeCategory._id)); return get(search);

71

286885 BOMA
} public List<ProcessType> get(Search search) { return dao.get(search); } } public interface ProductionSheetService { public void insertSchedaProduzione(ProductionSheet schedaProduzione); public ProductionSheet getSchedaProduzione(Long id); public List<ProductionSheet> getSchedaProduzione(Search search, int pageCurr, int pageSize); public int countSchedaProduzione(Search search); public List<ProductionSheet> getSchedaProduzione(Search search); public PhysicalProduct getWip(long idSchedaProduzione); public List<ProductionSheet> get(); public ProductionSheet get(String code); public ProductionSheet getByBatch(String batch); public ProductionSheet get(String code, String batch); public List<ProductionSheet> getProductionSheetsToExport(); public List<ProductionSheet> get(Project project); } @Service public class ProductionSheetServiceImpl implements ProductionSheetService { @Autowired private ProductionSheetDAO dao; @Autowired private ProductFamilyDAO productFamilyDAO; @Autowired private ProductTypeDAO productTypeDAO; @Autowired private BatchDAO batchDAO; @Autowired private PhysicalProductDAO physicalProductDAO; @Autowired private BillOfProcessService billOfProcessS; @Autowired private ProcessService processS; @Autowired private BillOfProcessOutputService billOfProcessOutputS; @Override public ProductionSheet getSchedaProduzione(Long id) { ProductionSheet productionSheet = dao.get(id); return dao.unproxy(productionSheet); } @Override public int countSchedaProduzione(Search search) { return dao.count(search); } @Override public List<ProductionSheet> getSchedaProduzione(Search search, int pageCurr, int pageSize) { List<ProductionSheet> productionSheets = dao.get(search, pageCurr, pageSize); return dao.unproxy(productionSheets); } @Override public List<ProductionSheet> getSchedaProduzione(Search search) { List<ProductionSheet> productionSheets = dao.get(search); return dao.unproxy(productionSheets); } @Override public PhysicalProduct getWip(long idSchedaProduzione) { PhysicalProductService pfM = ServiceLocator.getPhysicalProductService(); Search spf=new Search(PhysicalProduct.class); spf.addFilter(HxFilter.equal(idSchedaProduzione, PhysicalProduct._productionSheet, ProductionSheet._id)); spf.addFilter(HxFilter.equal(true, PhysicalProduct._isWip)); List<PhysicalProduct> listpf = pfM.getProdottoFisicoBySearch(spf); if(listpf==null || listpf.size()==0) return null; else if((listpf.size()==1)) return listpf.get(0); else return null; } @Override public void insertSchedaProduzione(ProductionSheet schedaProduzione) { this.dao.persist(schedaProduzione); } @Override public List<ProductionSheet> get() { return dao.get(); } @Override

72

286885 BOMA
public ProductionSheet get(String code) { Search psS = new Search(ProductionSheet.class); psS.addFilter(HxFilter.equal(code, ProductionSheet._code)); List<ProductionSheet> list = dao.get(psS); if (list.size() == 0) return null; else return list.get(0); } @Override public ProductionSheet getByBatch(String batch) { Search psS = new Search(ProductionSheet.class); psS.addFilter(HxFilter.equal(batch, ProductionSheet._batchCode)); List<ProductionSheet> list = dao.get(psS); if (list.size() == 0) return null; else return list.get(0); } @Override public ProductionSheet get(String code, String batch) { Search psS = new Search(ProductionSheet.class); psS.addFilter(HxFilter.equal(code, ProductionSheet._code)); psS.addFilter(HxFilter.equal(batch, ProductionSheet._batchCode)); List<ProductionSheet> list = dao.get(psS); if (list.size() == 0) return null; else return list.get(0); } @Override public List<ProductionSheet> getProductionSheetsToExport() { Search search = new Search(ProductionSheet.class); search.addFilter(HxFilter.equal(true, ProductionSheet._export)); return getSchedaProduzione(search); } public List<ProductionSheet> get(Project project) { Search search = new Search(ProductionSheet.class); search.addFilter(HxFilter.equal(project, ProductionSheet._project)); return getSchedaProduzione(search); } @Transactional public ProductionSheetOutputCommonData getOutputCommonData(ProductionSheet productionSheet) { List<Process> processes = processS.get(productionSheet); List<BillOfProcess> billOfProcesses = new ArrayList<BillOfProcess>(); for (Process process : processes) { BillOfProcess billOfProcess = billOfProcessS.getByProcess(process.getId()); billOfProcesses.add(billOfProcess); } List<BillOfProcessOutput> billOfProcessOutputs = new ArrayList<BillOfProcessOutput>(); for (BillOfProcess billOfProcess : billOfProcesses) { Search s = new Search(BillOfProcessOutput.class); s.addFilter(HxFilter.equal(billOfProcess, BillOfProcessOutput._billOfProcess)); s.addFilter(HxFilter.isEmpty(BillOfProcessOutput._billOfProcessInputs)); List<BillOfProcessOutput> list = billOfProcessOutputS.get(s); billOfProcessOutputs.addAll(list); } ProductFamily productFamily = null; ProductType productType = null; ProductFamily productFamilyByProductType = null; PhysicalProduct physicalProduct = null; ProductType productTypeByPhysicalProduct = null; ProductFamily productFamilyByPhysicalProduct = null; BigDecimal quantity = new BigDecimal(0); Integer numberOfItems = 0; boolean firstRun = true; for (BillOfProcessOutput billOfProcessOutput : billOfProcessOutputs) { if (quantity != null) { if (billOfProcessOutput.getQuantity() != null) quantity = quantity.add(billOfProcessOutput.getQuantity()); else quantity = null;

73

286885 BOMA
} if (numberOfItems != null) { if (billOfProcessOutput.getNumberOfItems() != null) numberOfItems += billOfProcessOutput.getNumberOfItems(); else numberOfItems = null; } if (firstRun) { firstRun = false; productFamily = billOfProcessOutput.getProductFamily(); productType = billOfProcessOutput.getProductType(); if (productType != null) productFamilyByProductType = productType.getProductFamily(); physicalProduct = billOfProcessOutput.getPhysicalProduct(); if (physicalProduct != null) { productTypeByPhysicalProduct = physicalProduct.getProductType(); if (productTypeByPhysicalProduct != null) productFamilyByPhysicalProduct = productTypeByPhysicalProduct.getProductFamily(); } continue; } if (productFamily != null) { if (!productFamily.equals(billOfProcessOutput.getProductFamily())) productFamily = null; } if (productType != null) { if (!productType.equals(billOfProcessOutput.getProductType())) productType = null; } if (productFamilyByProductType != null) { if (billOfProcessOutput.getProductType() != null) if (!productFamilyByProductType.equals(billOfProcessOutput.getProductType().getProductFamily())) productFamilyByProductType = null; } if (physicalProduct != null) { if (!physicalProduct.equals(billOfProcessOutput.getPhysicalProduct())) physicalProduct = null; } if (productTypeByPhysicalProduct != null) { if (billOfProcessOutput.getPhysicalProduct() != null) if (!productTypeByPhysicalProduct.equals(billOfProcessOutput.getPhysicalProduct().getProductType())) productTypeByPhysicalProduct = null; } if (productFamilyByPhysicalProduct != null) { if (billOfProcessOutput.getPhysicalProduct() != null) if (billOfProcessOutput.getPhysicalProduct().getProductType() != null) if (!productFamilyByPhysicalProduct.equals(billOfProcessOutput.getPhysicalProduct().getProductType().getProductFamily())) productFamilyByPhysicalProduct = null; } } ProductionSheetOutputCommonData commonData = new ProductionSheetOutputCommonData(); if (productFamily != null) { productFamily = productFamilyDAO.unproxy(productFamily); commonData.setProductFamily(productFamily); } else if (productFamilyByProductType != null) { productFamilyByProductType = productFamilyDAO.unproxy(productFamilyByProductType); commonData.setProductFamily(productFamilyByProductType); } else if (productFamilyByPhysicalProduct != null) { productFamilyByPhysicalProduct = productFamilyDAO.unproxy(productFamilyByPhysicalProduct); commonData.setProductFamily(productFamilyByPhysicalProduct); } if (productType != null) { productType = productTypeDAO.unproxy(productType); commonData.setProductType(productType); } else if (productTypeByPhysicalProduct != null) {

74

286885 BOMA
productType = productTypeDAO.unproxy(productTypeByPhysicalProduct); commonData.setProductType(productTypeByPhysicalProduct); } if (physicalProduct != null) { physicalProduct = physicalProductDAO.unproxy(physicalProduct); commonData.setPhysicalProduct(physicalProduct); } commonData.setQuantity(quantity); commonData.setNumberOfItems(numberOfItems); return commonData; } } public interface ProductionSheetStatusService { public abstract void insert(ProductionSheetStatus productionSheetStatus); public abstract void delete(ProductionSheetStatus productionSheetStatus); public abstract List<ProductionSheetStatus> get(); public abstract ProductionSheetStatus get(Long id); public abstract ProductionSheetStatus get(String code); public abstract List<ProductionSheetStatus> get(Search search); public abstract List<ProductionSheetStatus> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); } @Service public class ProductionSheetStatusServiceImpl implements ProductionSheetStatusService { @Autowired private ProductionSheetStatusDAO dao; @Transactional public void insert(ProductionSheetStatus productionSheetStatus) { dao.persist(productionSheetStatus); } @Transactional public void delete(ProductionSheetStatus productionSheetStatus) { dao.remove(productionSheetStatus); } @Transactional public List<ProductionSheetStatus> get() { return dao.get(); } @Transactional public ProductionSheetStatus get(Long id) { return dao.get(id); } @Transactional public ProductionSheetStatus get(String code) { Search search = new Search(); search.addFilter(HxFilter.equal(code, ProductionSheetStatus._code)); List<ProductionSheetStatus> list = dao.get(search); if (list.size() > 0) return list.get(0); return null; } @Transactional public List<ProductionSheetStatus> get(Search search) { return dao.get(search); } @Transactional public List<ProductionSheetStatus> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } } public interface ProductionTypeService {

75

286885 BOMA
public abstract void insert(ProductionType productionType); public abstract void delete(ProductionType productionType); public abstract List<ProductionType> get(); public abstract ProductionType get(Long id); public abstract ProductionType get(String code); public abstract ProductionType getOrCreate(String code); public abstract List<ProductionType> get(Search search); public abstract List<ProductionType> get(Search search, int currPage, int pageSize); public abstract int count(); public abstract int count(Search search); } @Service public class ProductionTypeServiceImpl implements ProductionTypeService { @Autowired private ProductionTypeDAO dao; @Transactional public void insert(ProductionType productionType) { dao.persist(productionType); } @Transactional public void delete(ProductionType productionType) { dao.remove(productionType); } @Transactional public List<ProductionType> get() { return dao.get(); } @Transactional public ProductionType get(Long id) { return dao.get(id); } @Transactional public List<ProductionType> get(Search search) { return dao.get(search); } @Transactional public List<ProductionType> get(Search search, int currPage, int pageSize) { return dao.get(search, currPage, pageSize); } @Transactional public int count() { return dao.count(); } @Transactional public int count(Search search) { return dao.count(search); } @Transactional public ProductionType get(String code) { Search s = new Search(ProductionType.class); s.addFilter(HxFilter.equal(code, ProductionType._code)); List<ProductionType> lpt = dao.get(s); if(lpt == null || lpt.size() == 0) return null; else return lpt.get(0); } public ProductionType getOrCreate(String code) { ProductionType el = get(code); if (el != null) return el; el = new ProductionType(); el.setCode(code); el.setLabel(code); insert(el); return el; } }

76

286885 BOMA 4.2.2. Interface Code


<?page title="Stato produzione" contentType="text/html;charset=UTF-8"?> <zk> <window id="wndStatoProduzione" use="it.holonix.ilike.view.production.WndProductionSheetList" title="" border="none" width="100%" height="100%" style="overflow:auto;"> <style src="./stili/stile.css" /> <style src="./stili/stile_extra.css" /> <div id="divButtonsBar" sclass="buttonsBar"></div> <panel sclass="pnlWindowContainer" border="none" width="100%"> <panelchildren> <div sclass="lbTitoloPagina"> <label value="Production sheets"> <custom-attributes translation="1h" /> </label> </div> <space spacing="10px" /> <groupbox> <caption label="Search" style="font-weight:bold;"> <custom-attributes translation="j" /> </caption> <hbox> <vbox> <hbox> <label value="Code"> <custom-attributes translation="1r" /> </label> <label value="Product family"> <custom-attributes translation="19" /> </label> <label value="Batch"> <custom-attributes translation="1a" /> </label> </hbox> <textbox id="tbCodiceRicerca" width="250px"> </textbox> </vbox> <separator spacing="10px" /> <vbox> <label value="Machine used"> <custom-attributes translation="sh" /> </label> <combobox id="cbMachine" /> </vbox> </hbox> <separator spacing="5px" /> <button id="btnSearch" label="Find" > <custom-attributes translation="1" /> </button> </groupbox> <separator spacing="10px" /> <listbox id="listElencoSchedaProduzione" sizedByContent="true" span="true"> <auxhead> <auxheader label="Production sheets" colspan="11"> <custom-attributes translation="1h" /> </auxheader> </auxhead> <listhead sizable="true"> <listheader width="22px" visible="false" /> <listheader label="Code" sort="auto"> <custom-attributes translation="1r" /> </listheader> <listheader label="Product family" sort="auto"> <custom-attributes translation="19" /> </listheader> <listheader label="Batch" sort="auto">

77

286885 BOMA
<custom-attributes translation="1a" /> </listheader> <listheader label="Quantity" sort="auto"> <custom-attributes translation="12" /> </listheader> <listheader label="Creation date"> <custom-attributes translation="1b" /> </listheader> <listheader label="Start date"> <custom-attributes translation="1c" /> </listheader> <listheader label="End date"> <custom-attributes translation="1d" /> </listheader> <listheader label="Status" sort="auto"> <custom-attributes translation="1e" /> </listheader> <listheader label="Exported" sort="auto" align="center"> <custom-attributes translation="ug" /> </listheader> <listheader label="Active" sort="auto" align="center"> <custom-attributes translation="o" /> </listheader> <listheader label="Detail" sort="auto" align="center"> <custom-attributes translation="p" /> </listheader> </listhead> </listbox> <paging id="pageListSchedaProduzione" /> </panelchildren> </panel> </window> </zk> public class WndNewProductionSheet extends HxWindow { private static final long serialVersionUID = -4884649211278853769L; private ProductionSheetService spM = ServiceLocator.getProductionSheetService(); private ProductionTypeService ptS = ServiceLocator.getProductionTypeService(); private ProjectService projectS = ServiceLocator.getProjectService(); private ProductionSheetStatusService pssS = ServiceLocator.getProductionSheetStatusService(); private ProductFamilyService fpM = ServiceLocator.getProductFamilyService(); private CustomerService customerService = ServiceLocator.getCustomerService(); private ProcessTypeCategoryService processTypeCategoryS = ServiceLocator.getProcessTypeCategoryService(); private ProcessTypeService processTypeS = ServiceLocator.getProcessTypeService(); private ProcessService processS = ServiceLocator.getProcessService(); private BillOfProcessService billOfProcessS = ServiceLocator.getBillOfProcessService(); private ProcessBillOfProcessService processBillOfProcessS = ServiceLocator.getProcessBillOfProcessService(); private ProductionSheet productionSheet; private List<Process> processes; @Wire Div divButtonsBar; @Wire Textbox tbCodeProductionSheet; @Wire Combobox cbProductionType; @Wire Combobox cbProject; @Wire Combobox cbCustomer; @Wire Combobox cbProductionSheetstatus; @Wire Checkbox ckActive; @Wire Textbox tbBatch; @Wire Combobox cbProductFamily; @Wire Decimalbox tbQuantity; @Wire Checkbox ckExport; @Wire Checkbox ckExported; @Wire Combobox cbCategoryProcessType; @Wire Combobox cbProcessType; @Wire Textbox tbProcessName; @Wire Textbox tbDescription; @Wire Checkbox ckProcessActive; @Wire Button btnAddProcess; @Wire Button btnUpdateProcess; @Wire Button btnUpdateCancel; @Wire Listbox lbProcesses; @Wire Div divTitleNew; @Wire Div divTitleEdit;

78

286885 BOMA
@Wire Panel pOperation; private Process processCurrent; public void onCreate(){ super.onCreate(); Selectors.wireComponents(this, this, false); Selectors.wireEventListeners(this, this); Executions.getCurrent().createComponents(HeaderPath.productionSheetDetailHeader, divButtonsBar, null); processes = new ArrayList<Process>(); productionSheet = new ProductionSheet(); fillAllComboProductionSheet(); resetAndFillAllComboNewProcess(); lbProcesses.setItemRenderer(new ListitemNewProcessRenderer(this)); Selectors.wireComponents(this, this, false); Selectors.wireEventListeners(this, this); } @Listen("onClick = #btnCancel") public void onClickCancel() { this.detach(); } private void fillAllComboProductionSheet() { List<ProductionType> listProductionTypes = ptS.get(); List<ProductionSheetStatus> listProductionSheetStatus = pssS.get(); Search searchFamily = new Search(ProductFamily.class); searchFamily.addFilter(HxFilter.equal(true, ProductFamily._active)); fpM.getBySearch(searchFamily); cbProductionType.getChildren().clear(); if (listProductionTypes != null) { for (int i = 0; i < listProductionTypes.size(); i++){ ProductionType p = listProductionTypes.get(i); Comboitem ci = new Comboitem(ZK.translateInLanguageSelected(p.getLabel(), p.getTranslation())); ci.setValue(p); cbProductionType.appendChild(ci); } } cbProcessType.setSelectedItem(null); List<Customer> customers = customerService.getAll(); cbCustomer.getChildren().clear(); if (customers != null) { for (Customer customer : customers){ Comboitem ci = new Comboitem(customer.getCode()); ci.setValue(customer); cbCustomer.appendChild(ci); } } cbProductionSheetstatus.setSelectedItem(null); cbProductionSheetstatus.getChildren().clear(); if (listProductionSheetStatus != null) { for (int i = 0; i < listProductionSheetStatus.size(); i++){ ProductionSheetStatus p = listProductionSheetStatus.get(i); Comboitem ci = new Comboitem(ZK.translateInLanguageSelected(p.getLabel(), p.getTranslation())); ci.setValue(p); cbProductionSheetstatus.appendChild(ci); } } } private void resetAndFillAllComboNewProcess() { List<ProcessTypeCategory> processTypeCategories = processTypeCategoryS.get(); cbCategoryProcessType.getChildren().clear(); if (processTypeCategories != null) { for (ProcessTypeCategory processTypeCategory : processTypeCategories ) { Comboitem ci = new Comboitem(ZK.translateInLanguageSelected(processTypeCategory.getLabel(), processTypeCategory.getTranslation())); ci.setValue(processTypeCategory); cbCategoryProcessType.appendChild(ci); } } cbCategoryProcessType.setSelectedItem(null); cbCategoryProcessType.setValue(""); cbProcessType.setSelectedItem(null); cbProcessType.getChildren().clear(); tbProcessName.setValue(""); tbDescription.setValue("");

79

286885 BOMA
ckProcessActive.setChecked(false); } @Listen("onSelect = #cbCategoryProcessType") public void onSelectProcessTypeCategory (Event e) { Combobox cb = (Combobox) e.getTarget(); ProcessTypeCategory processTypeCategory = (ProcessTypeCategory) cb.getSelectedItem().getValue() ; List<ProcessType> processTypes = processTypeS.get(processTypeCategory); cbProcessType.setSelectedItem(null); cbProcessType.getChildren().clear(); if (processTypes != null) { for (ProcessType processType : processTypes) { Comboitem ci = new Comboitem(ZK.translateInLanguageSelected(processType.getLabel(), processType.getTranslation())); ci.setValue(processType); cbProcessType.appendChild(ci); } } } @Listen("onSelect = #cbCustomer") public void onSelectCustomer(Event e) { Combobox cb = (Combobox) e.getTarget(); Customer customer = cb.getSelectedItem().getValue(); List<Project> listProjects = projectS.get(customer); cbProject.getChildren().clear(); if (listProjects != null) { for (int i = 0; i < listProjects.size(); i++){ Project p = listProjects.get(i); Comboitem ci = new Comboitem(p.getName()); ci.setValue(p); cbProject.appendChild(ci); if (i == 0) cbProject.setSelectedIndex(0); } } } @Listen("onClick = #btnSave") public void onClickSave() { if (tbCodeProductionSheet.getValue().length() > 0) productionSheet.setCode(tbCodeProductionSheet.getText()); else productionSheet.setCode(null); if (cbProductionType.getSelectedItem() == null) { HxMessageBox.show("Please select a production type", null); return; } ProductionType pt = cbProductionType.getSelectedItem().getValue(); if (pt != null) productionSheet.setProductionType(pt); else productionSheet.setProductionType(null); if (cbProject.getSelectedItem() != null) productionSheet.setProject((Project) cbProject.getSelectedItem().getValue()); else productionSheet.setProject(null); ProductionSheetStatus pss = cbProductionSheetstatus.getSelectedItem().getValue(); if (pss != null) productionSheet.setProductionSheetStatus(pss); else { HxMessageBox.show("Please select a status", "000"); return; } productionSheet.setActive(ckActive.isChecked()); productionSheet.setEntryDate(new Date()); if (tbBatch.getValue().length() > 0) productionSheet.setBatchCode(tbBatch.getText()); else productionSheet.setBatchCode(null); spM.insertSchedaProduzione(productionSheet); for (Process process : processes) { process.setProductionSheet(productionSheet); BillOfProcess billOfProcess = new BillOfProcess(); billOfProcess.setVersion("1");

80

286885 BOMA
billOfProcess.setDate(new Date()); billOfProcessS.insert(billOfProcess); processS.insertLavorazione(process); ProcessBillOfProcess processBillOfProcess = new ProcessBillOfProcess(); processBillOfProcess.setBillOfProcess(billOfProcess); processBillOfProcess.setProcess(process); processBillOfProcessS.insert(processBillOfProcess); } this.detach(); } @Listen("onClick = #btnAddProcess") public void onClickAddProcess() { Process process = new Process(); process.setActive(true); process.setDescription(tbDescription.getText()); process.setName(tbProcessName.getText()); process.setProcessType((ProcessType) cbProcessType.getSelectedItem().getValue()); processes.add(process); lbProcesses.setModel(new ListModelProcess(processes)); resetAndFillAllComboNewProcess(); } @Listen("onClick = .btnRemove") public void onRemoveProcess(Event e) { Listcell li = (Listcell) e.getTarget(); Process process = li.getValue(); processes.remove(process); lbProcesses.setModel(new ListModelProcess(processes)); } @Listen("onClick = .btnEdit") public void onEditProcess(Event e) { Listcell li = (Listcell) e.getTarget(); Process process = li.getValue(); divTitleNew.setVisible(false); divTitleEdit.setVisible(true); pOperation.setVisible(false); btnAddProcess.setVisible(false); btnUpdateProcess.setVisible(true); btnUpdateCancel.setVisible(true); processCurrent = process; fillUpdateProcess(process); } @Listen("onClick = #btnUpdateProcess") public void onUpdateProcess(Event e) { processCurrent.setProcessType((ProcessType) cbProcessType.getSelectedItem().getValue()); processCurrent.setName(tbProcessName.getText()); processCurrent.setActive(ckActive.isChecked()); processCurrent.setDescription(tbDescription.getText()); lbProcesses.setModel(new ListModelProcess(processes)); viewInsertLayout(); } @Listen("onClick = #btnUpdateCancel") public void viewInsertLayout(){ divTitleNew.setVisible(true); divTitleEdit.setVisible(false); pOperation.setVisible(true); btnAddProcess.setVisible(true); btnUpdateProcess.setVisible(false); btnUpdateCancel.setVisible(false); resetAndFillAllComboNewProcess(); } private void fillUpdateProcess(Process process) { List<ProcessTypeCategory> processTypeCategories = processTypeCategoryS.get(); ProcessType processTypeCurrent = processTypeS.get(process.getProcessType().getId()); ProcessTypeCategory processTypeCategoryCurrent = processTypeCategoryS.get(processTypeCurrent.getProcessTypeCategory().getId()); cbCategoryProcessType.getChildren().clear(); if (processTypeCategories != null) { for (ProcessTypeCategory processTypeCategory : processTypeCategories ) { Comboitem ci = new Comboitem(ZK.translateInLanguageSelected(processTypeCategory.getLabel(), processTypeCategory.getTranslation())); ci.setValue(processTypeCategory); cbCategoryProcessType.appendChild(ci);

81

286885 BOMA
if (processTypeCategory.getId().equals(processTypeCategoryCurrent.getId())) cbCategoryProcessType.setSelectedItem(ci); } } List<ProcessType> processTypes = processTypeS.get(processTypeCategoryCurrent); cbProcessType.getChildren().clear(); if (processTypes != null) { for (ProcessType processType : processTypes ) { Comboitem ci = new Comboitem(ZK.translateInLanguageSelected(processType.getLabel(), processType.getTranslation())); ci.setValue(processType); cbProcessType.appendChild(ci); if (processType.getId().equals(processTypeCurrent.getId())) cbProcessType.setSelectedItem(ci); } } tbProcessName.setValue(process.getName()); tbDescription.setValue(process.getDescription()); ckProcessActive.setChecked(process.getActive()); } } public class WndProductionSheetList extends HxWindow { private static final long serialVersionUID = 5147904544478198284L; ProcessResourceService lM = ServiceLocator.getProcessResourceService(); ResourceService rM = ServiceLocator.getResourceService(); Search searchSchedaProduzione; private final int _pageSizeSchedaProduzione = GlobalConfig.getListItemCountLarge(); private int _startPageNumberSchedaProduzione = 0; private int _totalSizeSchedaProduzione = 0; private boolean _needsTotalSizeUpdateSchedaProduzione = true; @Wire Listbox listElencoSchedaProduzione; @Wire Paging pageListSchedaProduzione; PagingListModelSchedaProduzione model; @Wire Textbox tbCodiceRicerca; @Wire Div divMenuDxImportProductionSheet; @Wire Div divMenuDxNewProductionSheet; @Wire Combobox cbMachine; public void onCreate(){ super.onCreate(); this.tbCodiceRicerca=(Textbox) this.getFellow("tbCodiceRicerca"); Div divHeader=(Div)this.getFellow("divButtonsBar"); Executions.getCurrent().createComponents(HeaderPath.productionSheetListHeader, divHeader, null); Selectors.wireComponents(this, this, false); Selectors.wireEventListeners(this, this); switch(GlobalConfig.getInstallation()) { default: break; case nearchimica: case demoProduzione: divMenuDxImportProductionSheet.setVisible(true); break; case sirapCastelbelforte: case sirapCastiglionFiorentino: case sirapVerolanuova: case sirapSanVito: case inlinePoland: case demoLogistica: break; } fillComboBoxMachine(); searchSchedaProduzione = new Search(ProductionSheet.class); searchSchedaProduzione.addSortDesc(ProductionSheet._date); listElencoSchedaProduzione.setItemRenderer(new ListitemSchedaProduzioneRenderer(this)); refreshModelSchedaProduzione(_startPageNumberSchedaProduzione); } private void fillComboBoxMachine() { cbMachine.getChildren().clear(); Search search = new Search(Resource.class); search.addFilter(HxFilter.ilike("Macchina", Resource._resourceType, ResourceType._code)); List<Resource> listResource = rM.getRisorsaBySearch(search); Comboitem ci = new Comboitem("All");

82

286885 BOMA
ci.setValue(null); ci.setAttribute("translation", "4f"); cbMachine.appendChild(ci); for (int i = 0; i < listResource.size(); i++) { Resource resource = listResource.get(i); Search s = new Search(ProcessResource.class); s.addFilter(HxFilter.equal(resource.getId(), ProcessResource._resource, Resource._id)); List<ProcessResource> listProcess = lM.getLavorazioneRisorsaBySearch(s); if (listProcess != null && listProcess.size() > 0){ ci = new Comboitem(resource.getName()); ci.setValue(resource); cbMachine.appendChild(ci); } } ZK.translate(cbMachine); cbMachine.setSelectedIndex(0); } private void refreshModelSchedaProduzione(int activePage) { this.pageListSchedaProduzione.setPageSize(_pageSizeSchedaProduzione); model = new PagingListModelSchedaProduzione(this.searchSchedaProduzione,activePage, _pageSizeSchedaProduzione); if(_needsTotalSizeUpdateSchedaProduzione) { _totalSizeSchedaProduzione = model.getTotalSize(this.searchSchedaProduzione); _needsTotalSizeUpdateSchedaProduzione = false; } this.pageListSchedaProduzione.setTotalSize(_totalSizeSchedaProduzione); listElencoSchedaProduzione.setModel(model); } @Listen("onPaging = #pageListSchedaProduzione") public void onPagingListSchedaProduzione(PagingEvent event) { _startPageNumberSchedaProduzione = event.getActivePage(); refreshModelSchedaProduzione(_startPageNumberSchedaProduzione); } @Listen("onClick = #listElencoSchedaProduzione .btnEdit") public void onDoubleClickCellNumeroSchedaProduzione(Event event) { Listcell target = (Listcell) event.getTarget(); ProductionSheet productionSheet = target.getValue(); Window w=(Window)Executions.createComponents(PagePath.productionSheetDetail, this, null); w.setAttribute("productionSheet", productionSheet); w.setWidth(GlobalConfig.getModalWindowWidthLarge()); w.setClosable(true); w.setFocus(true); w.doOverlapped(); w.doModal(); } @Listen("onClick = #btnSearch; onOK = tbCodiceRicerca") public void onClickRicercaRapida() { searchSchedaProduzione.clearFilters(); if(tbCodiceRicerca.getText().length() > 0) { String testo = "%" + tbCodiceRicerca.getText() + "%"; searchSchedaProduzione.addFilterOr( HxFilter.ilike(testo, ProductionSheet._code), HxFilter.ilike(testo, ProductionSheet._batchCode), HxFilter.ilike(testo, ProductionSheet._processes, Process._processBillOfProcesses, ProcessBillOfProcess._billOfProcess, BillOfProcess._billOfProcessOutputs, BillOfProcessOutput._productFamily, ProductFamily._code)); } if (cbMachine.getSelectedItem() != null){ Resource r = cbMachine.getSelectedItem().getValue(); if (r != null) { searchSchedaProduzione.addFilter(HxFilter.equal(r.getId(), ProductionSheet._processes, Process._processResources, ProcessResource._resource, Resource._id)); searchSchedaProduzione.setDistinct(true); } } _needsTotalSizeUpdateSchedaProduzione = true; refreshModelSchedaProduzione(_startPageNumberSchedaProduzione); } @Listen("onClick = #linkBtnImportProductionSheet") public void onClickImportProductionSheet() { if (HxMessageBox.show("Production sheets manual import?", "Attention", HxMessageBox.YES | HxMessageBox.NO, HxMessageBox.QUESTION, "gw", "9s") == HxMessageBox.NO) return;

83

286885 BOMA
Window w=(Window)Executions.createComponents("./pagine/importazione/importNearchimicaSchedeProduzione.zul", this, null); w.setClosable(true); w.setWidth("80%"); w.setFocus(true); w.doOverlapped(); w.doModal(); this._needsTotalSizeUpdateSchedaProduzione=true; refreshModelSchedaProduzione(this._startPageNumberSchedaProduzione); } @Listen("onClick = #linkBtnDxNewProductionSheet") public void onClickNewProductionSheet() { Window w=(Window)Executions.createComponents(PagePath.newProductionSheetDetail, this, null); w.setWidth(GlobalConfig.getModalWindowWidthLarge()); w.setClosable(true); w.setFocus(true); w.doOverlapped(); w.doModal(); } }

4.3.

Data Import Code

4.3.1. Production sheet Code


@XmlRootElement public class ProcessExternal { private Long id; private String processType; private String externalId; private List<ParentProcessExternal> preemption; private List<InputExternal> inputs; private List<OutputExternal> outputs; private List<OperatorExternal> operators; private List<ResourceExternal> resources; private String name; private Process process; private BillOfProcess billOfProcess; @XmlAttribute public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } public String getExternalId() { return this.externalId; } public void setExternalId(String externalId) { this.externalId = externalId; } public String getProcessType() { return this.processType; } public void setProcessType(String processType) { this.processType = processType; } @XmlElement(name="parentProcess") @XmlElementWrapper(name="preemption") public List<ParentProcessExternal> getPreemption() { return preemption; } public void setPreemption(List<ParentProcessExternal> preemption) { this.preemption = preemption;

84

286885 BOMA
} @XmlElement(name="input") @XmlElementWrapper(name="inputs") public List<InputExternal> getInputs() { return this.inputs; } public void setInputs(List<InputExternal> inputs) { this.inputs = inputs; } @XmlElement(name="output") @XmlElementWrapper(name="outputs") public List<OutputExternal> getOutputs() { return this.outputs; } public void setOutputs(List<OutputExternal> outputs) { this.outputs = outputs; } @XmlElement(name="operator") @XmlElementWrapper(name="operators") public List<OperatorExternal> getOperators() { return this.operators; } public void setOperators(List<OperatorExternal> operators) { this.operators = operators; } @XmlElement(name="resource") @XmlElementWrapper(name="resources") public List<ResourceExternal> getResources() { return this.resources; } public void setResources(List<ResourceExternal> resources) { this.resources = resources; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } @XmlTransient public Process getProcess() { return process; } public void setProcess(Process process) { this.process = process; } @XmlTransient public BillOfProcess getBillOfProcess() { return billOfProcess; } public void setBillOfProcess(BillOfProcess billOfProcess) { this.billOfProcess = billOfProcess; } }

4.3.2. Web Service Code


@Path("external/productionSheet") public class ProductionSheetREST extends TransactionalResource<ProductionSheetExternal>{ ProductionSheetExternalService psM = ServiceLocatorExternal.getProductionSheetService(); private static HashMap<Long, ProductionSheetExternal> transactions = new HashMap<Long, ProductionSheetExternal>(); protected HashMap<Long, ProductionSheetExternal> getTransactions() { return transactions; } @GET @Path("example") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public ProductionSheetExternal getExample(@PathParam("id") Long id) throws Exception { ProductionSheetExternal ps = new ProductionSheetExternal();

85

286885 BOMA
ps.setDate(new Date()); List<InputExternal> inputList = new ArrayList<InputExternal>(); InputExternal input1 = new InputExternal(); input1.setNumberOfItems(1); input1.setWip(false); input1.setPhysicalProduct("physicalProductTag1"); InputExternal input2 = new InputExternal(); input2.setNumberOfItems(1); input2.setWip(false); input2.setProductFamily("productFamily"); inputList.add(input1); inputList.add(input2); List<OutputExternal> outputList = new ArrayList<OutputExternal>(); OutputExternal output1 = new OutputExternal(); output1.setId(1); output1.setNumberOfItems(2); output1.setProductType("productTypeOUTPUT"); output1.setWip(true); outputList.add(output1); List<OperatorExternal> operatorList = new ArrayList<OperatorExternal>(); OperatorExternal o = new OperatorExternal(); o.setCodeOperator("operatorcode"); o.setDate(new Date()); o.setHours("hours"); o.setMaster(true); operatorList.add(o); List<ResourceExternal> resourceList = new ArrayList<ResourceExternal>(); ResourceExternal r = new ResourceExternal(); r.setCode("codeResource"); r.setHours("12"); resourceList.add(r); List<ParentProcessExternal> ppList = new ArrayList<ParentProcessExternal>(); ParentProcessExternal pp = new ParentProcessExternal(); pp.setId((long) 5); ppList.add(pp); ProcessExternal p = new ProcessExternal(); p.setExternalId("externalId"); p.setId((long) 1); p.setProcessType("processType"); p.setInputs(inputList); List<ProcessExternal> lp = new ArrayList<ProcessExternal>(); lp.add(p); p.setInputs(inputList); p.setOutputs(outputList); p.setOperators(operatorList); p.setResources(resourceList); p.setPreemption(ppList); p = new ProcessExternal(); p.setExternalId("externalId2"); p.setId((long) 2); lp.add(p); p = new ProcessExternal(); p.setId((long) 3); InputExternal input3 = new InputExternal(); input3.setId((long) 1); OutputInInputExternal oii = new OutputInInputExternal(); oii.setOutput((long) 1); oii.setProcess((long) 1); input3.setOutput(oii); inputList = new ArrayList<InputExternal>(); inputList.add(input3); p.setInputs(inputList); lp.add(p); OutputExternal output2 = new OutputExternal(); InputInOutputExternal inputInOutputExternal = new InputInOutputExternal(); output2.setInput(inputInOutputExternal); inputInOutputExternal.setId((long) 1); List<OutputExternal> loe = new ArrayList<OutputExternal>(); loe.add(output2); p.setOutputs(loe); ps.setCode("code"); ps.setProductionType("productionType");

86

286885 BOMA
ps.setQuantity("0"); ps.setProductFamily("productFamily"); ps.setProcesses(lp); ps.setBatch("batch"); return ps; } @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public ProductionSheetExternal create(ProductionSheetExternal ps) throws Exception { ps.setState(TransactionState.active); try { storeTransaction(ps); } catch (TransactionIdConflictException e) { throw new ConflictException(); } if (ps.isAutoCommit()) commit(ps.getId()); return ps; } @PUT @Path("/{id}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public ProductionSheetExternal commit(@PathParam("id") Long id) { if (id == null) throw new BadRequestException(); ProductionSheetExternal ps = getTransaction(id); if (ps == null) throw new NotFoundException(); if (ps.getState() != TransactionState.active) return ps; ps.setState(TransactionState.partiallyCommitted); try { psM.save(ps); } catch (IllegalArgumentException e) { ps.setState(TransactionState.failed); throw new BadRequestException(e.getMessage()); } catch (RuntimeException e) { ps.setState(TransactionState.failed); throw e; } ps.setState(TransactionState.committed); return ps; } }

4.3.3. Business Logic Code


@Service public class ProductionSheetExternalServiceImpl implements ProductionSheetExternalService { @Autowired ProductionSheetService productionSheetS; @Autowired PhysicalProductService physicalProductS; @Autowired ProductTypeService productTypeS; @Autowired ProductFamilyService productfamilyS; @Autowired ProcessTypeService processTypeS; @Autowired ProductionTypeService productionTypeS; @Autowired ProcessService processS; @Autowired

87

286885 BOMA
BillOfProcessService billOfProcessS; @Autowired BillOfProcessOutputService billOfProcessOutputS; @Autowired ProcessBillOfProcessService processBillOfProcessS; @Autowired TagService tagS; @Autowired PhysicalProductTagService physicalProductTagS; @Autowired ResourceService resourceS; @Autowired BillOfProcessResourceService billOfProcessResourceS; @Autowired OperatorService operatorS; @Autowired BillOfProcessOperatorService billOfProcessOperatorS; @Autowired ProcessPreemptionService processPreemptionS; @Autowired BillOfProcessInputService billOfProcessInputS; @Autowired OperatorTypeService operatorTypeS; private int processNumber; private int lap; boolean update = false; @Transactional(rollbackFor={Exception.class, RuntimeException.class}) public void save(ProductionSheetExternal psExt) throws IllegalArgumentException { ProductionSheet ps; if (psExt.getCode() == null || psExt.getCode().equals("")) throw new IllegalArgumentException("Code production sheet is required."); ps = productionSheetS.get(psExt.getCode()); if (ps != null) { update = true; } else { ps = new ProductionSheet(); ps.setCode(psExt.getCode()); } if (!update) { if (psExt.getProductionType() == null || psExt.getProductionType().equals("") ) throw new IllegalArgumentException("ProductionType is required in productionsheet (code ="+ psExt.getCode()+")"); ProductionType pt; if (psExt.getParamCreateProductionType()) pt = productionTypeS.getOrCreate(psExt.getProductionType()); else pt = productionTypeS.get(psExt.getProductionType()); if (pt == null) throw new IllegalArgumentException("ProductionType not found and not create in productionsheet (code ="+ psExt.getCode()+")"); ps.setProductionType(pt); if((psExt.getProductFamily()== null || psExt.getProductFamily().equals("")) && (psExt.getProductType()== null || psExt.getProductType().equals("")) ) { throw new IllegalArgumentException("Family code or Product Type code in productionsheet missing (code ="+ psExt.getCode()+")"); } if (psExt.getProductFamily()!= null && !psExt.getProductFamily().equals("")){ ProductFamily pf = productfamilyS.getByCodiceFamiglia(psExt.getProductFamily()); if (pf == null) { throw new IllegalArgumentException("Family code in productionsheet (code ="+ psExt.getCode()+") not found "); } ps.setProductFamily(pf); } if (psExt.getProductType()!= null && !psExt.getProductType().equals("")){ ProductType productType = productTypeS.get(psExt.getProductType()); if (productType == null) { throw new IllegalArgumentException("Product Type code in productionsheet (code ="+ psExt.getCode()+") not found "); } ps.setProductFamily(productfamilyS.getById(productType.getProductFamily().getId()));

88

286885 BOMA
} } ps.setExport(false); ps.setExported(false); ps.setProductionSheetStatus(new ProductionSheetStatus()); ps.getProductionSheetStatus().setId((long) 1); ps.setActive(true); ps.setDate(psExt.getDate()); ps.setEntryDate(new Date()); productionSheetS.insertSchedaProduzione(ps); Iterator<ProcessExternal> itExternalProcess = null; if (psExt.getProcesses()!=null) itExternalProcess = psExt.getProcesses().iterator(); Map<Long, ProcessExternal> processExternalMap = new HashMap<Long, ProcessExternal>(); Map<Long, Map<Long, BillOfProcessOutput>> processOutputMap = new HashMap<Long, Map<Long, BillOfProcessOutput>>(); while (itExternalProcess != null && itExternalProcess.hasNext()) { ProcessExternal processExternal = itExternalProcess.next(); if (processExternal.getName() == null || processExternal.getName().equals("")) throw new IllegalArgumentException("Name is required in process (id ="+ processExternal.getId()+", production sheet code = "+ ps.getCode()+")"); Process p = null; BillOfProcess oldBillOfProcess = null; if (update) { p = processS.get(ps, processExternal.getName(), processExternal.getExternalId()); oldBillOfProcess = billOfProcessS.getByProcess(p.getId()); } if (p == null) { p = new Process(); p.setName(processExternal.getName()); p.setExternalId(processExternal.getExternalId()); p.setProductionSheet(ps); p.setActive(true); if (processExternal.getProcessType() == null || processExternal.getProcessType().equals("")) throw new IllegalArgumentException("ProcessType is required in process (id ="+ processExternal.getId()+", production sheet code = "+ ps.getCode()+")"); ProcessType processType; if (psExt.getParamCreateProcessType()) processType = processTypeS.getOrCreate(processExternal.getProcessType()); else processType = processTypeS.get(processExternal.getProcessType()); if (processType == null) throw new IllegalArgumentException("ProcessType not found and not create in process (name="+processExternal.getName()+", extId="+processExternal.getExternalId()+", production sheet code="+ psExt.getCode()+")"); p.setProcessType(processType); processS.insertLavorazione(p); } BillOfProcess billOfProcess = new BillOfProcess(new Date()); if (oldBillOfProcess == null) billOfProcess.setVersion("0"); else { Integer version = Integer.valueOf(oldBillOfProcess.getVersion()) + 1; billOfProcess.setVersion(version.toString()); } billOfProcessS.insert(billOfProcess); processExternal.setProcess(p); processExternal.setBillOfProcess(billOfProcess); ProcessBillOfProcess processBillOfProcess = new ProcessBillOfProcess(); processBillOfProcess.setBillOfProcess(billOfProcess); processBillOfProcess.setProcess(p); processBillOfProcessS.insert(processBillOfProcess); Map<Long, BillOfProcessOutput> outputMap = extractOutput(processExternal.getOutputs(), billOfProcess); extractResources(processExternal.getResources(), billOfProcess, psExt.getParamCreateResources()); extractOperator(processExternal.getOperators(), billOfProcess); if(processExternal.getId()!=null) { processOutputMap.put(processExternal.getId(),outputMap); processExternalMap.put(processExternal.getId(), processExternal); } } if (psExt.getProcesses() == null) return; itExternalProcess = psExt.getProcesses().iterator();

89

286885 BOMA
while (itExternalProcess != null && itExternalProcess.hasNext() ) { ProcessExternal processExternal = itExternalProcess.next(); if (processExternal.getPreemption() != null) { Iterator<ParentProcessExternal> itPreemption = processExternal.getPreemption().iterator(); while (itPreemption.hasNext()) { ParentProcessExternal parentProcessExternal = itPreemption.next(); processMap.get(parentProcessExternal.getId()); Process parent = processExternalMap.get(parentProcessExternal.getId()).getProcess(); if (parent == null) throw new IllegalArgumentException("Invalid parent in process (id ="+ processExternal.getId()+")"); ProcessPreemption processPreemption = new ProcessPreemption(); processPreemption.setProcessByProcess(processExternal.getProcess()); processPreemption.setProcessByParentProcess(parent); processPreemptionS.insert(processPreemption); } } extractInput(processExternal.getInputs(), processExternal.getBillOfProcess(), processOutputMap); } itExternalProcess = psExt.getProcesses().iterator(); while (itExternalProcess != null && itExternalProcess.hasNext()) { ProcessExternal processExternal = itExternalProcess.next(); extractInputInOutput(processExternal); } itExternalProcess = psExt.getProcesses().iterator(); processNumber = psExt.getProcesses().size(); lap = 0; while (itExternalProcess != null && itExternalProcess.hasNext()) { ProcessExternal processExternal = itExternalProcess.next(); Iterator<OutputExternal> itOutput = null; if (processExternal.getOutputs() != null) { itOutput = processExternal.getOutputs().iterator(); } while (itOutput!=null && itOutput.hasNext()) { OutputExternal outputExternal = itOutput.next(); if (outputExternal.getInput() != null) { BillOfProcessOutput billOfProcessOutput = outputExternal.getBillOfProcessOutput(); esplicitProductInformation(billOfProcessOutput); } } Iterator<InputExternal> itInput = null; if (processExternal.getInputs() != null) { itInput = processExternal.getInputs().iterator(); } while (itInput!=null && itInput.hasNext()) { InputExternal inputExternal = itInput.next(); if (inputExternal.getOutput() != null) { BillOfProcessInput billOfProcessInput = inputExternal.getBillOfProcessInput(); lap = 0; esplicitProductInformation(billOfProcessInput); } } } } private void esplicitProductInformation(BillOfProcessOutput billOfProcessOutput) { if (billOfProcessOutput.getProductType() == null && billOfProcessOutput.getProductFamily() == null && billOfProcessOutput.getPhysicalProduct() == null) { BillOfProcessInput billOfProcessInput = billOfProcessInputS.get(billOfProcessOutput.getBillOfProcessInput().getId()); esplicitProductInformation(billOfProcessInput); billOfProcessOutput.setPhysicalProduct(billOfProcessInput.getPhysicalProduct()); billOfProcessOutput.setProductType(billOfProcessInput.getProductType()); billOfProcessOutput.setProductFamily(billOfProcessInput.getProductFamily()); } } private void esplicitProductInformation(BillOfProcessInput billOfProcessInput) { if (lap++ > processNumber) throw new IllegalArgumentException("There is a loop in the references between process"); if (billOfProcessInput.getProductType() == null && billOfProcessInput.getProductFamily() == null

90

286885 BOMA
&& billOfProcessInput.getPhysicalProduct() == null) { BillOfProcessOutput billOfProcessOutput = billOfProcessOutputS.get(billOfProcessInput.getBillOfProcessOutput().getId()); esplicitProductInformation(billOfProcessOutput); billOfProcessInput.setPhysicalProduct(billOfProcessOutput.getPhysicalProduct()); billOfProcessInput.setProductType(billOfProcessOutput.getProductType()); billOfProcessInput.setProductFamily(billOfProcessOutput.getProductFamily()); } } private void extractInputInOutput (ProcessExternal processExternal) { Iterator<OutputExternal> itOutputExternals = processExternal.getOutputs().iterator(); while (itOutputExternals.hasNext()) { OutputExternal outputExternal = itOutputExternals.next(); if (outputExternal.getInput() != null) { if (outputExternal.getProductType()!=null || outputExternal.getProductFamily() != null || outputExternal.getPhysicalProduct()!=null ) throw new IllegalArgumentException("Output must be one between PhysicalProduct, product type, product family, input in " + "process (id ="+ processExternal.getId()+")"); Iterator<InputExternal> itInputExternals = processExternal.getInputs().iterator(); BillOfProcessInput billOfProcessInputTEMP = null; while (itInputExternals.hasNext()) { InputExternal inputExternal = itInputExternals.next(); if (inputExternal.getId()!=null && inputExternal.getId().equals(outputExternal.getInput().getId()) ) { if (billOfProcessInputTEMP != null) throw new IllegalArgumentException("Duplicate input id in process (id ="+ processExternal.getId()+")"); billOfProcessInputTEMP = inputExternal.getBillOfProcessInput(); } } if (billOfProcessInputTEMP != null) outputExternal.getBillOfProcessOutput().setBillOfProcessInput(billOfProcessInputTEMP); } } } private void extractOperator(List<OperatorExternal> operators, BillOfProcess billOfProcess) { Iterator<OperatorExternal> operatorIt = null; if (operators!=null) operatorIt = operators.iterator(); while (operatorIt!=null && operatorIt.hasNext()) { int set = 0; OperatorExternal operatorExternal = operatorIt.next(); Operator operator = null; OperatorType operatorType = null; if ( operatorExternal.getCodeOperator() != null && !operatorExternal.getCodeOperator().equals("")) { operator = operatorS.get(operatorExternal.getCodeOperator()); if (operator == null) { operator = new Operator(); operator.setCode(operatorExternal.getCodeOperator()); operator.setLabel(operatorExternal.getCodeOperator()); operator.setName(operatorExternal.getCodeOperator()); operator.setSurname(operatorExternal.getCodeOperator()); operatorS.insert(operator); } set++; } if (operatorExternal.getCodeOperatorType() != null && !operatorExternal.getCodeOperatorType().equals("")){ operatorType = operatorTypeS.get(operatorExternal.getCodeOperatorType()); if (operatorType == null) { operatorType = new OperatorType(); operatorType.setCode(operatorExternal.getCodeOperatorType()); operatorType.setLabel(operatorExternal.getCodeOperatorType()); operatorType.setName(operatorExternal.getCodeOperatorType()); operatorTypeS.insert(operatorType); } set++; } if (set == 0) throw new IllegalArgumentException("Operator Code or Type Operator code required in process "); BillOfProcessOperator billOfProcessOperator = new BillOfProcessOperator(); billOfProcessOperator.setBillOfProcess(billOfProcess);

91

286885 BOMA
billOfProcessOperator.setOperator(operator); billOfProcessOperator.setOperatorType(operatorType); if (operatorExternal.getHours()!=null) billOfProcessOperator.setHours(Integer.valueOf(operatorExternal.getHours())); if (operatorExternal.getMaster()!=null) billOfProcessOperator.setMaster(operatorExternal.getMaster().booleanValue()); billOfProcessOperator.setDate(operatorExternal.getDate()); billOfProcessOperatorS.insert(billOfProcessOperator); } } private Map<Long,BillOfProcessOutput> extractOutput(List<OutputExternal> outputs, BillOfProcess billOfProcess) { Iterator<OutputExternal> outputIt = null; Map<Long,BillOfProcessOutput> outputMap = new HashMap<Long,BillOfProcessOutput>(); if (outputs!=null) { outputIt = outputs.iterator(); } while (outputIt != null && outputIt.hasNext()) { OutputExternal output = outputIt.next(); BillOfProcessOutput billOfProcessOutput = new BillOfProcessOutput(); billOfProcessOutput.setBillOfProcess(billOfProcess); billOfProcessOutput.setNumberOfItems(output.getNumberOfItems()); if (output.getQuantity()!=null) billOfProcessOutput.setQuantity(new BigDecimal(output.getQuantity())); if (output.getWip()!=null) billOfProcessOutput.setWip(output.getWip()); int set = 0; if (output.getProductFamily() != null && !output.getProductFamily().equals("")){ set++; ProductFamily productFamily = productfamilyS.getByCodiceFamiglia(output.getProductFamily()); if (productFamily == null) { throw new IllegalArgumentException("Family code "+output.getProductFamily()+" not found"); } billOfProcessOutput.setProductFamily(productFamily); } if (output.getProductType() != null && !output.getProductType().equals("")) { set++; ProductType productType = productTypeS.get(output.getProductType()); if (productType == null) { throw new IllegalArgumentException("Product type code "+ output.getProductType()+ " not found" ); } billOfProcessOutput.setProductType(productType); } if (output.getPhysicalProduct() != null && !output.getPhysicalProduct().equals("")) { set++; Tag tag = tagS.getByCodeProduct(output.getPhysicalProduct()); PhysicalProduct pp = null; if (tag!=null) pp = physicalProductS.getProdottoFisicoByTag(tag); if (pp == null) { throw new IllegalArgumentException("Physical Product code"); } } if (output.getInput() != null && output.getInput().getId() != null) { set++; } if (set!=1) throw new IllegalArgumentException("Output must be one between PhysicalProduct, product type, product family, input"); billOfProcessOutputS.insert(billOfProcessOutput); output.setBillOfProcessOutput(billOfProcessOutput); if (output.getId()!=null) outputMap.put(output.getId().longValue(),billOfProcessOutput); } return outputMap; } private void extractInput(List<InputExternal> inputs, BillOfProcess billOfProcess, Map<Long, Map<Long, BillOfProcessOutput>> processOutputMap) { Iterator<InputExternal> inputIt = null; if (inputs!=null) inputIt = inputs.iterator();

92

286885 BOMA
while (inputIt != null && inputIt.hasNext()) { InputExternal input = inputIt.next(); BillOfProcessInput billOfProcessInput = new BillOfProcessInput(); billOfProcessInput.setBillOfProcess(billOfProcess); billOfProcessInput.setNumberOfItems(input.getNumberOfItems()); if(input.getSequence()!=null) billOfProcessInput.setSequence(input.getSequence()); if(input.getMaster() != null) billOfProcessInput.setMaster(input.getMaster()); if (input.getQuantity()!=null) billOfProcessInput.setQuantity(new BigDecimal(input.getQuantity())); if (input.getWip()!=null) billOfProcessInput.setWip(input.getWip()); int set = 0; if (input.getProductFamily() != null && !input.getProductFamily().equals("")){ set++; ProductFamily productFamily = productfamilyS.getByCodiceFamiglia(input.getProductFamily()); if (productFamily == null) { throw new IllegalArgumentException("Family code required"); } billOfProcessInput.setProductFamily(productFamily); } if (input.getProductType() != null && !input.getProductType().equals("")) { set++; ProductType productType = productTypeS.get(input.getProductType()); if (productType == null) { throw new IllegalArgumentException("Product type code unknown"); } billOfProcessInput.setProductType(productType); } if (input.getPhysicalProduct() != null && !input.getPhysicalProduct().equals("")) { set++; Tag tag = tagS.getByCodeProduct(input.getPhysicalProduct()); PhysicalProduct pp = null; if (tag!=null) pp = physicalProductS.getProdottoFisicoByTag(tag); if (pp == null) { throw new IllegalArgumentException("Physical Product code"); } billOfProcessInput.setPhysicalProduct(pp); } if (input.getOutput()!=null) { set++; Map<Long, BillOfProcessOutput> outputMap = processOutputMap.get(input.getOutput().getProcess()); if (outputMap == null) throw new IllegalArgumentException("Input process references dont found "); BillOfProcessOutput billOfProcessOutput = outputMap.get(input.getOutput().getOutput()); if (billOfProcessOutput == null) throw new IllegalArgumentException("Input process output references dont found "); billOfProcessInput.setBillOfProcessOutput(billOfProcessOutput); } if (set!=1) throw new IllegalArgumentException("Output must be one between PhysicalProduct, product type, product family, output"); billOfProcessInputS.insert(billOfProcessInput); input.setBillOfProcessInput(billOfProcessInput); } } private void extractResources(List<ResourceExternal> resources, BillOfProcess billOfProcess, Boolean create) { Iterator<ResourceExternal> resourceIt = null; if (resources!=null) resourceIt = resources.iterator(); while (resourceIt != null && resourceIt.hasNext()) { ResourceExternal resourceEx = resourceIt.next(); if (resourceEx.getCode() == null || resourceEx.getCode().equals("")) throw new IllegalArgumentException("Resource Code"); Resource resource; if (create) resource = resourceS.getAndCreate(resourceEx.getCode()); else resource = resourceS.get(resourceEx.getCode()); if (resource == null)

93

286885 BOMA
throw new IllegalArgumentException("Resource not found and not create in process (code="+resourceEx.getCode()+")"); BillOfProcessResource billOfProcessResource = new BillOfProcessResource(); billOfProcessResource.setBillOfProcess(billOfProcess); billOfProcessResource.setResource(resource); billOfProcessResource.setDate(resourceEx.getDate()); if(resourceEx.getHours()!=null) billOfProcessResource.setHours(Integer.valueOf(resourceEx.getHours())); billOfProcessResourceS.insert(billOfProcessResource); } } @Override public boolean isStarted(String code, String batch) { Date now = new Date(); Search searchProcess = new Search(Process.class); searchProcess.addFilter(HxFilter.equal(code, Process._productionSheet, ProductionSheet._code)); searchProcess.addFilter(HxFilter.lessOrEqual(now, Process._startDate)); if (processS.countLavorazione(searchProcess) > 0 ) return true; return false; } }

94

286885 BOMA 5. Conclusion


This deliverable aims to show how the alredy existent extended product lifecycle management suite iLike has been customized for its adoption in the marine industry by different kind of users as well as enriched with specific capabilities that fit and satisfy several technical requirements (as reported in the deliverable D1.2). In particular in this deliverable has been presented the description and the java code of the lifecycle management server, required in order to enable BOMA system to interact with multiple server, managing data and distributing web application. This layer of the BOMA infrastructure support the management of the production processes and maintenance activities while the data import module has been developed in order to ensure the integration of the BOMA system with the systems currently in use.

95

You might also like