diff --git a/DB/Validation Master.mwb b/DB/Validation Master.mwb index 333dd93e..739c74ad 100644 Binary files a/DB/Validation Master.mwb and b/DB/Validation Master.mwb differ diff --git a/DB/Validation Master.mwb.bak b/DB/Validation Master.mwb.bak index 53d7d31b..fbe34983 100644 Binary files a/DB/Validation Master.mwb.bak and b/DB/Validation Master.mwb.bak differ diff --git a/VM-Core/nbactions.xml b/VM-Core/nbactions.xml index 98e195af..d27d733c 100644 --- a/VM-Core/nbactions.xml +++ b/VM-Core/nbactions.xml @@ -43,4 +43,41 @@ java + + test + + * + + + test + + + true + + + + test.single + + * + + + test-compile + surefire:test + + + ${packageClassName} + true + + + + CUSTOM-Coverage Report + Coverage Report + + verify + + + true + false + + diff --git a/VM-Core/pom.xml b/VM-Core/pom.xml index ee661c95..04419742 100644 --- a/VM-Core/pom.xml +++ b/VM-Core/pom.xml @@ -4,7 +4,7 @@ net.sourceforge.javydreamercsw Validation-Manager - 0.3.2 + 0.3.3 VM-Core @@ -141,6 +141,25 @@ jacoco-maven-plugin test + + + javax.mail + javax.mail-api + 1.5.6 + + + com.sun.mail + javax.mail + 1.5.6 + + + + de.saly + javamail-mock2-fullmock + 0.5-beta4 + test + + @@ -158,52 +177,53 @@ + + maven-surefire-plugin + + ${cobertura.test} + + + + unit-test + test + + test + + + ${maven.test.skip} + ${argLine} + + **/*IT.java + + + + + org.jacoco jacoco-maven-plugin 0.7.9 + + ${skipTests} + file + true + - - pre-unit-test + jacoco-initialize prepare-agent - - - jacocoArgLine - - - post-unit-test - test + jacoco-site + verify report - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.20 - - - - ${jacocoArgLine} - - diff --git a/VM-Core/src/main/java/com/validation/manager/core/ContentProvider.java b/VM-Core/src/main/java/com/validation/manager/core/ContentProvider.java index e3a5d1e2..d3d2dae9 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/ContentProvider.java +++ b/VM-Core/src/main/java/com/validation/manager/core/ContentProvider.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,39 +13,44 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core; - -import com.vaadin.ui.Component; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public interface ContentProvider { - - /** - * Return the component caption. This will be attempted to be translated. - * - * @return component caption - */ - String getComponentCaption(); - - /** - * The Content of the provider - * - * @return content. - */ - Component getContent(); - - /** - * This is the unique id of the provider - * - * @return unique id for the provider. - */ - String getId(); - - /** - * Refresh the contents. - */ - void update(); -} +package com.validation.manager.core; + +import com.vaadin.ui.Component; +import com.validation.manager.core.api.internationalization.InternationalizationProvider; +import org.openide.util.Lookup; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public interface ContentProvider { + + static final InternationalizationProvider TRANSLATOR + = Lookup.getDefault().lookup(InternationalizationProvider.class); + + /** + * Return the component caption. This will be attempted to be translated. + * + * @return component caption + */ + String getComponentCaption(); + + /** + * The Content of the provider + * + * @return content. + */ + Component getContent(); + + /** + * This is the unique id of the provider + * + * @return unique id for the provider. + */ + String getId(); + + /** + * Refresh the contents. + */ + void update(); +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/DataBaseManager.java b/VM-Core/src/main/java/com/validation/manager/core/DataBaseManager.java index e1ac70bb..fdd87224 100755 --- a/VM-Core/src/main/java/com/validation/manager/core/DataBaseManager.java +++ b/VM-Core/src/main/java/com/validation/manager/core/DataBaseManager.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,636 +13,636 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core; - -import com.googlecode.flyway.core.Flyway; -import com.googlecode.flyway.core.api.FlywayException; -import com.googlecode.flyway.core.api.MigrationInfo; -import com.googlecode.flyway.core.api.MigrationState; -import com.validation.manager.core.db.controller.VmIdJpaController; -import com.validation.manager.core.server.core.VMIdServer; -import com.validation.manager.core.server.core.VMSettingServer; -import static java.lang.Class.forName; -import static java.lang.Integer.parseInt; -import static java.lang.Long.valueOf; -import static java.lang.Thread.sleep; -import java.lang.reflect.Field; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.StringTokenizer; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import static java.util.logging.Logger.getLogger; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityTransaction; -import static javax.persistence.Persistence.createEntityManagerFactory; -import javax.persistence.Query; -import javax.persistence.TableGenerator; -import javax.sql.DataSource; -import org.h2.jdbcx.JdbcDataSource; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class DataBaseManager { - - private static EntityManagerFactory emf; - private static Map properties; - //Default. Can be overwritten using setPersistenceUnitName(String aPU) - private static String PU = "VMPU"; - private static EntityManager em; - private static boolean dbError = false; - private static final Logger LOG - = getLogger(DataBaseManager.class.getSimpleName()); - private static DBState state = DBState.START_UP; - private static boolean locked = false; - private static boolean usingContext; - private static boolean demo; - private static Long demoResetPeriod; - private static DataBaseManager instance; - private static boolean versioning_enabled = true; - - /** - * @return the versioning enabled - */ - public static boolean isVersioningEnabled() { - return versioning_enabled; - } - - /** - * @param aVersioning_enabled the versioning_enabled to set - */ - public static void setVersioningEnabled(boolean aVersioning_enabled) { - versioning_enabled = aVersioning_enabled; - } - - /** - * @return the demoResetPeriod - */ - public static Long getDemoResetPeriod() { - return demoResetPeriod; - } - - private DataBaseManager() { - } - - public static DataBaseManager get() throws Exception { - if (instance == null) { - instance = new DataBaseManager(); - } - return instance; - } - - @SuppressWarnings("unchecked") - private static void processFields(Field[] fields) { - try { - for (Field field : fields) { - if (field.isAnnotationPresent(TableGenerator.class)) { - field.setAccessible(true); - TableGenerator annotation = field.getAnnotation(TableGenerator.class); - field.setAccessible(false); - Map parameters = new HashMap<>(); - String tableName = annotation.pkColumnValue(); - parameters.put("tableName", tableName); - if (namedQuery("VmId.findByTableName", parameters, false).isEmpty()) { - LOG.log(Level.FINE, "Adding: {0}: {1}", - new Object[]{tableName, annotation.initialValue() - 1}); - VMIdServer temp = new VMIdServer(tableName, annotation.initialValue() - 1); - temp.write2DB(); - LOG.log(Level.FINE, "Added: {0}: {1}", - new Object[]{tableName, annotation.initialValue() - 1}); - } - } - } - } - catch (VMException ex1) { - LOG.log(Level.SEVERE, null, ex1); - } - finally { - if (LOG.isLoggable(Level.CONFIG)) { - VmIdJpaController controller = new VmIdJpaController( - getEntityManagerFactory()); - controller.findVmIdEntities().stream().forEach((next) -> { - LOG.log(Level.CONFIG, "{0}, {1}, {2}", new Object[]{next.getId(), - next.getTableName(), next.getLastId()}); - }); - } - } - } - - private static void generateIDs() { - if (!dbError) { - LOG.log(Level.FINE, - "Creating ids to work around eclipse issue " - + "(https://bugs.eclipse.org/bugs/show_bug.cgi?id=366852)..."); - getEntityManager().getMetamodel().getEmbeddables().forEach((et) -> { - processFields(et.getJavaType().getDeclaredFields()); - }); - getEntityManager().getMetamodel().getEntities().forEach((et) -> { - processFields(et.getBindableJavaType().getDeclaredFields()); - }); - LOG.log(Level.FINE, "Done!"); - } - } - - /** - * @return the properties - */ - public static Map getProperties() { - return properties; - } - - /** - * Get the current persistence unit name - * - * @return current persistence unit name - */ - public static String getPersistenceUnitName() { - return PU; - } - - /** - * @param aPU the PU to set - */ - public static void setPersistenceUnitName(String aPU) { - PU = aPU; - LOG.log(Level.FINE, "Changed persistence unit name to: {0}", PU); - //Set it to null so it's recreated with new Persistence Unit next time is requested. - emf = null; - em = null; - try { - reload(); - } - catch (VMException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - - public static void setEntityManagerFactory(EntityManagerFactory newEMF) { - emf = newEMF; - } - - /** - * @return the emf - */ - public static EntityManagerFactory getEntityManagerFactory() { - if (emf == null && !dbError) { - try { - InitialContext ctx = new InitialContext(); - //Use the context defined Database connection - PU = (String) ctx.lookup("java:comp/env/validation-manager/JNDIDB"); - try { - demo = (Boolean) ctx.lookup("java:comp/env/validation-manager/demo"); - } - catch (NamingException e) { - LOG.log(Level.SEVERE, null, e); - demo = false; - } - if (isDemo()) { - try { - demoResetPeriod = (Long) ctx - .lookup("java:comp/env/validation-manager/demo-period"); - } - catch (NamingException e) { - LOG.log(Level.SEVERE, null, e); - demoResetPeriod = valueOf(0); - } - if (getDemoResetPeriod() > 0) { - Long millis = getDemoResetPeriod(); - String format = String.format("%02d min, %02d sec", - TimeUnit.MILLISECONDS.toMinutes(millis), - TimeUnit.MILLISECONDS.toSeconds(millis) - - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)) - ); - LOG.log(Level.WARNING, - "Instance configured as demo, database will reset" - + " each {0}", format); - } - } - final String JNDIDB = (String) ctx.lookup("java:comp/env/validation-manager/JNDIDB"); - emf = createEntityManagerFactory(JNDIDB); - LOG.log(Level.FINE, "Using context defined database connection: {0}", JNDIDB); - usingContext = true; - } - catch (NamingException e) { - LOG.log(Level.FINE, null, e); - if (!usingContext) { - LOG.log(Level.WARNING, - "Manually specified connection parameters. " - + "Using pre-defined persistence unit: {0}", PU); - emf = createEntityManagerFactory(PU); - } else { - LOG.log(Level.SEVERE, - "Context doesn't exist. Check your configuration.", e); - dbError = true; - } - } - } - return emf; - } - - /** - * @return the demo - */ - public static boolean isDemo() { - return demo; - } - - public static EntityManager getEntityManager() { - if (em == null) { - em = getEntityManagerFactory().createEntityManager(); - LOG.log(Level.FINE, - "Creating EntityManager from: {0}", PU); - properties = em.getProperties(); - } - return em; - } - - public static List createdQuery(String query) { - return createdQuery(query, null); - } - - @SuppressWarnings("unchecked") - public static List createdQuery(String query, Map parameters) { - Query q = getEntityManager().createQuery(query); - if (parameters != null) { - Iterator> entries = parameters.entrySet().iterator(); - while (entries.hasNext()) { - Entry e = entries.next(); - q.setParameter(e.getKey(), e.getValue()); - } - } - return q.getResultList(); - } - - /** - * Named query that will modify the database - * - * @param query query to execute - */ - public static void namedUpdateQuery(String query) { - namedQuery(query, null, true); - } - - public static List nativeQuery(String query) { - List resultList - = getEntityManager().createNativeQuery(query).getResultList(); - return resultList; - } - - public static List createdQuery(String query, T result) { - List resultList - = getEntityManager().createQuery(query).getResultList(); - return resultList; - } - - public static void nativeUpdateQuery(String query) { - getEntityManager().createNativeQuery(query).executeUpdate(); - } - - /** - * Named query (not for updates) - * - * @param query query to execute - * @return query result - */ - public static List namedQuery(String query) { - return namedQuery(query, null, false); - } - - /** - * Named query that will modify the database - * - * @param query query to execute - * @param parameters query parameters - */ - public static void namedUpdateQuery(String query, Map parameters) { - namedQuery(query, parameters, true); - } - - /** - * Named query (not for updates) - * - * @param query query to execute - * @param parameters query parameters - * @return query result - */ - public static List namedQuery(String query, - Map parameters) { - return namedQuery(query, parameters, false); - } - - @SuppressWarnings("unchecked") - private static List namedQuery(String query, - Map parameters, boolean change) { - EntityTransaction transaction = getEntityManager().getTransaction(); - if (change) { - transaction.begin(); - } - Query q = getEntityManager().createNamedQuery(query); - if (parameters != null) { - Iterator> entries - = parameters.entrySet().iterator(); - while (entries.hasNext()) { - Entry e = entries.next(); - q.setParameter(e.getKey(), e.getValue()); - } - } - if (change) { - transaction.commit(); - } - return q.getResultList(); - } - - public static void close() { - getEntityManager().close(); - getEntityManagerFactory().close(); - emf = null; - em = null; - } - - public static EntityTransaction getTransaction() { - return getEntityManager().getTransaction(); - } - - public static void reload() throws VMException { - reload(false); - } - - public static void reload(boolean close) throws VMException { - if (close) { - close(); - } - updateDBState(); - getEntityManager(); - generateIDs(); - } - - public static void updateDBState() { - DataSource ds = null; - Connection conn = null; - PreparedStatement stmt = null; - ResultSet rs = null; - try { - ds = (javax.sql.DataSource) new InitialContext().lookup("java:comp/env/jdbc/VMDB"); - conn = ds.getConnection(); - } - catch (NamingException ne) { - LOG.log(Level.FINE, null, ne); - if (emf == null) { - try { - //It might be the tests, use an H2 Database - ds = new JdbcDataSource(); - ((JdbcDataSource) ds).setPassword(""); - ((JdbcDataSource) ds).setUser("vm_user"); - ((JdbcDataSource) ds).setURL( - "jdbc:h2:file:./target/data/test/validation-manager-test;AUTO_SERVER=TRUE"); - //Load the H2 driver - forName("org.h2.Driver"); - conn = ds.getConnection(); - } - catch (ClassNotFoundException | SQLException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } else { - EntityTransaction transaction = getEntityManager().getTransaction(); - transaction.begin(); - conn = getEntityManager().unwrap(java.sql.Connection.class); - transaction.commit(); - } - } - catch (SQLException ex) { - LOG.log(Level.SEVERE, null, ex); - } - if (conn != null) { - try { - stmt = conn.prepareStatement("select * from vm_setting"); - rs = stmt.executeQuery(); - if (!rs.next()) { - //Tables there but empty? Not safe to proceed - setState(DBState.NEED_MANUAL_UPDATE); - } - } - catch (SQLException ex) { - LOG.log(Level.FINE, null, ex); - //Need INIT, probably nothing there - setState(DBState.NEED_INIT); - //Create the database - getEntityManager(); - } - finally { - try { - conn.close(); - } - catch (SQLException ex) { - LOG.log(Level.SEVERE, null, ex); - } - try { - if (stmt != null) { - stmt.close(); - } - } - catch (SQLException ex) { - LOG.log(Level.SEVERE, null, ex); - } - try { - if (rs != null) { - rs.close(); - } - } - catch (SQLException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - } - if (ds != null) { - //Initialize flyway - initializeFlyway(ds); - updateDatabase(ds); - } else { - state = DBState.ERROR; - } - - if (state != DBState.VALID) { - waitForDB(); - } - } - - private static void updateDatabase(DataSource dataSource) { - Flyway flyway = new Flyway(); - try { - flyway.setDataSource(dataSource); - flyway.setLocations("db.migration"); - LOG.fine("Starting migration..."); - flyway.migrate(); - LOG.fine("Done!"); - } - catch (FlywayException fe) { - LOG.log(Level.SEVERE, "Unable to migrate data", fe); - setState(DBState.ERROR); - } - try { - LOG.fine("Validating migration..."); - flyway.validate(); - LOG.fine("Done!"); - setState(flyway.info().current().getState() - == MigrationState.SUCCESS ? DBState.VALID : DBState.ERROR); - } - catch (FlywayException fe) { - LOG.log(Level.SEVERE, "Unable to validate", fe); - setState(DBState.ERROR); - } - } - - protected static void setState(DBState newState) { - state = newState; - } - - public static void waitForDB() { - while (getState() != DBState.VALID - && getState() != DBState.UPDATED - && getState() != DBState.ERROR) { - LOG.log(Level.FINE, - "Waiting for DB initialization. Current state: {0}", - (getState() != null ? getState().name() : null)); - try { - sleep(100); - } - catch (InterruptedException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - LOG.log(Level.FINE, "DB ready, resuming..."); - } - - /** - * @return the state - */ - public static DBState getState() { - return state; - } - - /** - * @param lock the lock to set - */ - public static void setLocked(boolean lock) { - LOG.log(Level.WARNING, "{0} the database.", - (lock ? "Locking" : "Unlocking")); - locked = lock; - } - - public static String getVersion() { - return getVersionNumber() - + ((VMSettingServer.getSetting("version.postfix") - .getStringVal().isEmpty() - ? "" : " " - + VMSettingServer.getSetting("version.postfix") - .getStringVal())); - } - - public static String getVersionNumber() { - StringBuilder version = new StringBuilder(); - version.append(VMSettingServer.getSetting("version.high").getIntVal()); - version.append("."); - version.append(VMSettingServer.getSetting("version.mid").getIntVal()); - version.append("."); - version.append(VMSettingServer.getSetting("version.low").getIntVal()); - return version.toString(); - } - - /** - * Compare two number strings. For example: 2.1.0 == 2.01.00 - * - * @param first first string to compare - * @param second second string to compare - * @return true if same, false otherwise - */ - public static boolean compareNumberStrings(String first, String second) { - return compareNumberStrings(first, second, "."); - } - - /** - * Compare two number strings. For example: 2.1.0 == 2.01.00 - * - * @param first first string to compare - * @param second second string to compare - * @param separator separator of fields (i.e. for 2.1.0 is '.') - * @return true if same, false otherwise - */ - public static boolean compareNumberStrings(String first, String second, - String separator) { - boolean result = true; - StringTokenizer firstST = new StringTokenizer(first, separator); - StringTokenizer secondST = new StringTokenizer(second, separator); - if (firstST.countTokens() != secondST.countTokens()) { - //Different amount of fields, not equal. (i.e. 2.1 and 2.1.1 - result = false; - } else { - try { - while (firstST.hasMoreTokens()) { - int firstInt = parseInt(firstST.nextToken()); - int secondInt = parseInt(secondST.nextToken()); - //Both numbers let's continue - if (firstInt != secondInt) { - result = false; - break; - } - } - //Everything the same - } - catch (java.lang.NumberFormatException e) { - LOG.log(Level.WARNING, null, e); - //Is not a number - result = false; - } - } - return result; - } - - /** - * @return the locked - */ - public static boolean isLocked() { - return locked; - } - - private static void initializeFlyway(DataSource dataSource) { - assert dataSource != null; - setState(DBState.START_UP); - Flyway flyway = new Flyway(); - flyway.setDataSource(dataSource); - MigrationInfo status = flyway.info().current(); - if (status == null) { - setState(DBState.NEED_INIT); - LOG.fine("Initialize the metadata..."); - try { - flyway.init(); - LOG.fine("Done!"); - } - catch (FlywayException fe) { - LOG.log(Level.SEVERE, "Unable to initialize database", fe); - setState(DBState.ERROR); - } - } else { - LOG.fine("Database has Flyway metadata already..."); - displayDBStatus(status); - } - } - - private static void displayDBStatus(MigrationInfo status) { - LOG.log(Level.FINE, "Description: {0}\nState: {1}\nVersion: {2}", - new Object[]{status.getDescription(), status.getState(), status.getVersion()}); - } -} +package com.validation.manager.core; + +import com.googlecode.flyway.core.Flyway; +import com.googlecode.flyway.core.api.FlywayException; +import com.googlecode.flyway.core.api.MigrationInfo; +import com.googlecode.flyway.core.api.MigrationState; +import com.validation.manager.core.db.controller.VmIdJpaController; +import com.validation.manager.core.server.core.VMIdServer; +import com.validation.manager.core.server.core.VMSettingServer; +import static java.lang.Class.forName; +import static java.lang.Integer.parseInt; +import static java.lang.Long.valueOf; +import static java.lang.Thread.sleep; +import java.lang.reflect.Field; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.StringTokenizer; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; +import static java.util.logging.Logger.getLogger; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import static javax.persistence.Persistence.createEntityManagerFactory; +import javax.persistence.Query; +import javax.persistence.TableGenerator; +import javax.sql.DataSource; +import org.h2.jdbcx.JdbcDataSource; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class DataBaseManager { + + private static EntityManagerFactory emf; + private static Map properties; + //Default. Can be overwritten using setPersistenceUnitName(String aPU) + private static String PU = "VMPU"; + private static EntityManager em; + private static boolean dbError = false; + private static final Logger LOG + = getLogger(DataBaseManager.class.getSimpleName()); + private static DBState state = DBState.START_UP; + private static boolean locked = false; + private static boolean usingContext; + private static boolean demo; + private static Long demoResetPeriod; + private static DataBaseManager instance; + private static boolean versioning_enabled = true; + + /** + * @return the versioning enabled + */ + public static boolean isVersioningEnabled() { + return versioning_enabled; + } + + /** + * @param aVersioning_enabled the versioning_enabled to set + */ + public static void setVersioningEnabled(boolean aVersioning_enabled) { + versioning_enabled = aVersioning_enabled; + } + + /** + * @return the demoResetPeriod + */ + public static Long getDemoResetPeriod() { + return demoResetPeriod; + } + + private DataBaseManager() { + } + + public static DataBaseManager get() throws Exception { + if (instance == null) { + instance = new DataBaseManager(); + } + return instance; + } + + @SuppressWarnings("unchecked") + private static void processFields(Field[] fields) { + try { + for (Field field : fields) { + if (field.isAnnotationPresent(TableGenerator.class)) { + field.setAccessible(true); + TableGenerator annotation = field.getAnnotation(TableGenerator.class); + field.setAccessible(false); + Map parameters = new HashMap<>(); + String tableName = annotation.pkColumnValue(); + parameters.put("tableName", tableName); + if (namedQuery("VmId.findByTableName", parameters, false).isEmpty()) { + LOG.log(Level.FINE, "Adding: {0}: {1}", + new Object[]{tableName, annotation.initialValue() - 1}); + VMIdServer temp = new VMIdServer(tableName, annotation.initialValue() - 1); + temp.write2DB(); + LOG.log(Level.FINE, "Added: {0}: {1}", + new Object[]{tableName, annotation.initialValue() - 1}); + } + } + } + } + catch (VMException ex1) { + LOG.log(Level.SEVERE, null, ex1); + } + finally { + if (LOG.isLoggable(Level.CONFIG)) { + VmIdJpaController controller = new VmIdJpaController( + getEntityManagerFactory()); + controller.findVmIdEntities().stream().forEach((next) -> { + LOG.log(Level.CONFIG, "{0}, {1}, {2}", new Object[]{next.getId(), + next.getTableName(), next.getLastId()}); + }); + } + } + } + + private static void generateIDs() { + if (!dbError) { + LOG.log(Level.FINE, + "Creating ids to work around eclipse issue " + + "(https://bugs.eclipse.org/bugs/show_bug.cgi?id=366852)..."); + getEntityManager().getMetamodel().getEmbeddables().forEach((et) -> { + processFields(et.getJavaType().getDeclaredFields()); + }); + getEntityManager().getMetamodel().getEntities().forEach((et) -> { + processFields(et.getBindableJavaType().getDeclaredFields()); + }); + LOG.log(Level.FINE, "Done!"); + } + } + + /** + * @return the properties + */ + public static Map getProperties() { + return properties; + } + + /** + * Get the current persistence unit name + * + * @return current persistence unit name + */ + public static String getPersistenceUnitName() { + return PU; + } + + /** + * @param aPU the PU to set + */ + public static void setPersistenceUnitName(String aPU) { + PU = aPU; + LOG.log(Level.FINE, "Changed persistence unit name to: {0}", PU); + //Set it to null so it's recreated with new Persistence Unit next time is requested. + emf = null; + em = null; + try { + reload(); + } + catch (VMException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + + public static void setEntityManagerFactory(EntityManagerFactory newEMF) { + emf = newEMF; + } + + /** + * @return the emf + */ + public static EntityManagerFactory getEntityManagerFactory() { + if (emf == null && !dbError) { + try { + InitialContext ctx = new InitialContext(); + //Use the context defined Database connection + PU = (String) ctx.lookup("java:comp/env/validation-manager/JNDIDB"); + try { + demo = (Boolean) ctx.lookup("java:comp/env/validation-manager/demo"); + } + catch (NamingException e) { + LOG.log(Level.SEVERE, null, e); + demo = false; + } + if (isDemo()) { + try { + demoResetPeriod = (Long) ctx + .lookup("java:comp/env/validation-manager/demo-period"); + } + catch (NamingException e) { + LOG.log(Level.SEVERE, null, e); + demoResetPeriod = valueOf(0); + } + if (getDemoResetPeriod() > 0) { + Long millis = getDemoResetPeriod(); + String format = String.format("%02d min, %02d sec", + TimeUnit.MILLISECONDS.toMinutes(millis), + TimeUnit.MILLISECONDS.toSeconds(millis) + - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)) + ); + LOG.log(Level.WARNING, + "Instance configured as demo, database will reset" + + " each {0}", format); + } + } + final String JNDIDB = (String) ctx.lookup("java:comp/env/validation-manager/JNDIDB"); + emf = createEntityManagerFactory(JNDIDB); + LOG.log(Level.FINE, "Using context defined database connection: {0}", JNDIDB); + usingContext = true; + } + catch (NamingException e) { + LOG.log(Level.FINE, null, e); + if (!usingContext) { + LOG.log(Level.WARNING, + "Manually specified connection parameters. " + + "Using pre-defined persistence unit: {0}", PU); + emf = createEntityManagerFactory(PU); + } else { + LOG.log(Level.SEVERE, + "Context doesn't exist. Check your configuration.", e); + dbError = true; + } + } + } + return emf; + } + + /** + * @return the demo + */ + public static boolean isDemo() { + return demo; + } + + public static EntityManager getEntityManager() { + if (em == null) { + em = getEntityManagerFactory().createEntityManager(); + LOG.log(Level.FINE, + "Creating EntityManager from: {0}", PU); + properties = em.getProperties(); + } + return em; + } + + public static List createdQuery(String query) { + return createdQuery(query, null); + } + + @SuppressWarnings("unchecked") + public static List createdQuery(String query, Map parameters) { + Query q = getEntityManager().createQuery(query); + if (parameters != null) { + Iterator> entries = parameters.entrySet().iterator(); + while (entries.hasNext()) { + Entry e = entries.next(); + q.setParameter(e.getKey(), e.getValue()); + } + } + return q.getResultList(); + } + + /** + * Named query that will modify the database + * + * @param query query to execute + */ + public static void namedUpdateQuery(String query) { + namedQuery(query, null, true); + } + + public static List nativeQuery(String query) { + List resultList + = getEntityManager().createNativeQuery(query).getResultList(); + return resultList; + } + + public static List createdQuery(String query, T result) { + List resultList + = getEntityManager().createQuery(query).getResultList(); + return resultList; + } + + public static void nativeUpdateQuery(String query) { + getEntityManager().createNativeQuery(query).executeUpdate(); + } + + /** + * Named query (not for updates) + * + * @param query query to execute + * @return query result + */ + public static List namedQuery(String query) { + return namedQuery(query, null, false); + } + + /** + * Named query that will modify the database + * + * @param query query to execute + * @param parameters query parameters + */ + public static void namedUpdateQuery(String query, Map parameters) { + namedQuery(query, parameters, true); + } + + /** + * Named query (not for updates) + * + * @param query query to execute + * @param parameters query parameters + * @return query result + */ + public static List namedQuery(String query, + Map parameters) { + return namedQuery(query, parameters, false); + } + + @SuppressWarnings("unchecked") + private static List namedQuery(String query, + Map parameters, boolean change) { + EntityTransaction transaction = getEntityManager().getTransaction(); + if (change) { + transaction.begin(); + } + Query q = getEntityManager().createNamedQuery(query); + if (parameters != null) { + Iterator> entries + = parameters.entrySet().iterator(); + while (entries.hasNext()) { + Entry e = entries.next(); + q.setParameter(e.getKey(), e.getValue()); + } + } + if (change) { + transaction.commit(); + } + return q.getResultList(); + } + + public static void close() { + getEntityManager().close(); + getEntityManagerFactory().close(); + emf = null; + em = null; + } + + public static EntityTransaction getTransaction() { + return getEntityManager().getTransaction(); + } + + public static void reload() throws VMException { + reload(false); + } + + public static void reload(boolean close) throws VMException { + if (close) { + close(); + } + updateDBState(); + getEntityManager(); + generateIDs(); + } + + public static void updateDBState() { + DataSource ds = null; + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + try { + ds = (javax.sql.DataSource) new InitialContext().lookup("java:comp/env/jdbc/VMDB"); + conn = ds.getConnection(); + } + catch (NamingException ne) { + LOG.log(Level.FINE, null, ne); + if (emf == null) { + try { + //It might be the tests, use an H2 Database + ds = new JdbcDataSource(); + ((JdbcDataSource) ds).setPassword(""); + ((JdbcDataSource) ds).setUser("vm_user"); + ((JdbcDataSource) ds).setURL( + "jdbc:h2:file:./target/data/test/validation-manager-test;AUTO_SERVER=TRUE"); + //Load the H2 driver + forName("org.h2.Driver"); + conn = ds.getConnection(); + } + catch (ClassNotFoundException | SQLException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } else { + EntityTransaction transaction = getEntityManager().getTransaction(); + transaction.begin(); + conn = getEntityManager().unwrap(java.sql.Connection.class); + transaction.commit(); + } + } + catch (SQLException ex) { + LOG.log(Level.SEVERE, null, ex); + } + if (conn != null) { + try { + stmt = conn.prepareStatement("select * from vm_setting"); + rs = stmt.executeQuery(); + if (!rs.next()) { + //Tables there but empty? Not safe to proceed + setState(DBState.NEED_MANUAL_UPDATE); + } + } + catch (SQLException ex) { + LOG.log(Level.FINE, null, ex); + //Need INIT, probably nothing there + setState(DBState.NEED_INIT); + //Create the database + getEntityManager(); + } + finally { + try { + conn.close(); + } + catch (SQLException ex) { + LOG.log(Level.SEVERE, null, ex); + } + try { + if (stmt != null) { + stmt.close(); + } + } + catch (SQLException ex) { + LOG.log(Level.SEVERE, null, ex); + } + try { + if (rs != null) { + rs.close(); + } + } + catch (SQLException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + } + if (ds != null) { + //Initialize flyway + initializeFlyway(ds); + updateDatabase(ds); + } else { + state = DBState.ERROR; + } + + if (state != DBState.VALID) { + waitForDB(); + } + } + + private static void updateDatabase(DataSource dataSource) { + Flyway flyway = new Flyway(); + try { + flyway.setDataSource(dataSource); + flyway.setLocations("db.migration"); + LOG.fine("Starting migration..."); + flyway.migrate(); + LOG.fine("Done!"); + } + catch (FlywayException fe) { + LOG.log(Level.SEVERE, "Unable to migrate data", fe); + setState(DBState.ERROR); + } + try { + LOG.fine("Validating migration..."); + flyway.validate(); + LOG.fine("Done!"); + setState(flyway.info().current().getState() + == MigrationState.SUCCESS ? DBState.VALID : DBState.ERROR); + } + catch (FlywayException fe) { + LOG.log(Level.SEVERE, "Unable to validate", fe); + setState(DBState.ERROR); + } + } + + protected static void setState(DBState newState) { + state = newState; + } + + public static void waitForDB() { + while (getState() != DBState.VALID + && getState() != DBState.UPDATED + && getState() != DBState.ERROR) { + LOG.log(Level.FINE, + "Waiting for DB initialization. Current state: {0}", + (getState() != null ? getState().name() : null)); + try { + sleep(100); + } + catch (InterruptedException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + LOG.log(Level.FINE, "DB ready, resuming..."); + } + + /** + * @return the state + */ + public static DBState getState() { + return state; + } + + /** + * @param lock the lock to set + */ + public static void setLocked(boolean lock) { + LOG.log(Level.WARNING, "{0} the database.", + (lock ? "Locking" : "Unlocking")); + locked = lock; + } + + public static String getVersion() { + return getVersionNumber() + + ((VMSettingServer.getSetting("version.postfix") + .getStringVal().isEmpty() + ? "" : " " + + VMSettingServer.getSetting("version.postfix") + .getStringVal())); + } + + public static String getVersionNumber() { + StringBuilder version = new StringBuilder(); + version.append(VMSettingServer.getSetting("version.high").getIntVal()); + version.append("."); + version.append(VMSettingServer.getSetting("version.mid").getIntVal()); + version.append("."); + version.append(VMSettingServer.getSetting("version.low").getIntVal()); + return version.toString(); + } + + /** + * Compare two number strings. For example: 2.1.0 == 2.01.00 + * + * @param first first string to compare + * @param second second string to compare + * @return true if same, false otherwise + */ + public static boolean compareNumberStrings(String first, String second) { + return compareNumberStrings(first, second, "."); + } + + /** + * Compare two number strings. For example: 2.1.0 == 2.01.00 + * + * @param first first string to compare + * @param second second string to compare + * @param separator separator of fields (i.e. for 2.1.0 is '.') + * @return true if same, false otherwise + */ + public static boolean compareNumberStrings(String first, String second, + String separator) { + boolean result = true; + StringTokenizer firstST = new StringTokenizer(first, separator); + StringTokenizer secondST = new StringTokenizer(second, separator); + if (firstST.countTokens() != secondST.countTokens()) { + //Different amount of fields, not equal. (i.e. 2.1 and 2.1.1 + result = false; + } else { + try { + while (firstST.hasMoreTokens()) { + int firstInt = parseInt(firstST.nextToken()); + int secondInt = parseInt(secondST.nextToken()); + //Both numbers let's continue + if (firstInt != secondInt) { + result = false; + break; + } + } + //Everything the same + } + catch (java.lang.NumberFormatException e) { + LOG.log(Level.WARNING, null, e); + //Is not a number + result = false; + } + } + return result; + } + + /** + * @return the locked + */ + public static boolean isLocked() { + return locked; + } + + private static void initializeFlyway(DataSource dataSource) { + assert dataSource != null; + setState(DBState.START_UP); + Flyway flyway = new Flyway(); + flyway.setDataSource(dataSource); + MigrationInfo status = flyway.info().current(); + if (status == null) { + setState(DBState.NEED_INIT); + LOG.fine("Initialize the metadata..."); + try { + flyway.init(); + LOG.fine("Done!"); + } + catch (FlywayException fe) { + LOG.log(Level.SEVERE, "Unable to initialize database", fe); + setState(DBState.ERROR); + } + } else { + LOG.fine("Database has Flyway metadata already..."); + displayDBStatus(status); + } + } + + private static void displayDBStatus(MigrationInfo status) { + LOG.log(Level.FINE, "Description: {0}\nState: {1}\nVersion: {2}", + new Object[]{status.getDescription(), status.getState(), status.getVersion()}); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/DemoBuilder.java b/VM-Core/src/main/java/com/validation/manager/core/DemoBuilder.java index 9e561abf..107bb18d 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/DemoBuilder.java +++ b/VM-Core/src/main/java/com/validation/manager/core/DemoBuilder.java @@ -13,254 +13,254 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core; - -import com.validation.manager.core.db.Project; -import com.validation.manager.core.db.Requirement; -import com.validation.manager.core.db.Step; -import com.validation.manager.core.db.TestCase; -import com.validation.manager.core.db.controller.ProjectJpaController; -import com.validation.manager.core.db.controller.RequirementJpaController; -import com.validation.manager.core.db.controller.TestCaseJpaController; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.server.core.ExecutionStepServer; -import com.validation.manager.core.server.core.ProjectServer; -import com.validation.manager.core.server.core.RequirementServer; -import com.validation.manager.core.server.core.RequirementSpecNodeServer; -import com.validation.manager.core.server.core.RequirementSpecServer; -import com.validation.manager.core.server.core.StepServer; -import com.validation.manager.core.server.core.TestCaseExecutionServer; -import com.validation.manager.core.server.core.TestCaseServer; -import com.validation.manager.core.server.core.TestPlanServer; -import com.validation.manager.core.server.core.TestProjectServer; -import com.validation.manager.core.server.core.VMUserServer; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Random; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author Javier Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class DemoBuilder { - - private static final Logger LOG - = Logger.getLogger(DemoBuilder.class.getSimpleName()); - private static int tcCounter = 1, tpCounter, reqCounter; - - public static void buildDemoProject() throws Exception { - LOG.info("Creating demo projects..."); - ProjectJpaController controller - = new ProjectJpaController(DataBaseManager - .getEntityManagerFactory()); - Project rootProject = new Project("Demo"); - controller.create(rootProject); - for (int i = 0; i < 2; i++) { - Project temp = new Project("Sub " + (i + 1)); - temp.setParentProjectId(rootProject); - controller.create(temp); - ProjectServer ps = new ProjectServer(temp); - addDemoProjectRequirements(ps.getEntity()); - addDemoProjectTestProject(ps.getEntity()); - rootProject.getProjectList().add(ps.getEntity()); - } - addDemoProjectRequirements(rootProject); - controller.edit(rootProject); - //Link requirements with steps - List requirements - = new RequirementJpaController(DataBaseManager - .getEntityManagerFactory()) - .findRequirementEntities(); - LOG.log(Level.INFO, "Total: {0}", requirements.size()); - List tcs = new TestCaseJpaController(DataBaseManager - .getEntityManagerFactory()).findTestCaseEntities(); - int amount = tcs.size(); - int size = requirements.size() / amount; - int i = 0; - for (TestCase tc : tcs) { - for (Step step : tc.getStepList()) { - try { - StepServer ss = new StepServer(step); - ss.getRequirementList().addAll(requirements - .subList(i * size, i * size + size)); - ss.write2DB(); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - i++; - } - for (Project p : controller.findProjectEntities()) { - addDemoExecution(p); - } - LOG.info("Done!"); - } - - private static void addDemoProjectRequirements(Project p) - throws Exception { - tpCounter = 1; - reqCounter = 1; - //Create User Needs spec - RequirementSpecServer un = createRequirementSpec(p, 1, 1, 5, - "User Need", "User Need Desc"); - List subSpecs = new ArrayList<>(); - for (int i = 0; i < 5; i++) { - //Create a spec - subSpecs.add(createRequirementSpec(p, 5, 1, 5, "Spec " + i, - "Desc " + i)); - } - //Now link UN requirement to lower level requirements - un.getRequirementSpecNodeList().forEach(rsn -> { - int count = 0; - for (Requirement r : rsn.getRequirementList()) { - subSpecs.get(count).getRequirementSpecNodeList().forEach(nl -> { - nl.getRequirementList().forEach(sr -> { - try { - new RequirementServer(r) - .addChildRequirement(sr); - } - catch (VMException ex) { - LOG.log(Level.SEVERE, null, ex); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - }); - }); - count++; - } - }); - new ProjectJpaController(DataBaseManager - .getEntityManagerFactory()).edit(p); - } - - /** - * Create a requirement spec for the provided project on the specified - * requirement level. - * - * @param p Project to add the spec to. - * @param level Spec level - * @param nodeAmount Amount of nodes to create - * @param reqAmount Amount of requirements to add to each node of this spec. - * @param specName Spec desired name - * @param specDesc Spec description - * @return Created Requirement Spec - * @throws Exception - */ - private static RequirementSpecServer createRequirementSpec(Project p, - int level, int nodeAmount, int reqAmount, String specName, - String specDesc) throws Exception { - RequirementSpecServer temp - = new RequirementSpecServer(specName, - specDesc, - p.getId(), level); - temp.write2DB(); - if (nodeAmount > 0) { - for (int i = 0; i < nodeAmount; i++) { - RequirementSpecNodeServer node - = temp.addSpecNode("Node " + (i + 1), - "Description " + (i + 1), "Scope " + (i + 1)); - if (reqAmount > 0) { - for (int y = 0; y < reqAmount; y++) { - String header = ""; - switch (level) { - case 1: - header = "PS"; - break; - case 5: - header = "SRS"; - break; - default: - header = "SRS"; - break; - } - RequirementServer req - = new RequirementServer(header - + String.format("%05d", reqCounter), - "Description " + reqCounter, - node.getRequirementSpecNodePK(), - "Notes", 1, 1); - req.write2DB(); - node.getRequirementList().add(req.getEntity()); - reqCounter++; - } - } - node.write2DB(); - } - p.getRequirementSpecList().add(temp.getEntity()); - temp.update(); - } - return temp; - } - - private static void addDemoProjectTestProject(Project p) throws - NonexistentEntityException, Exception { - TestProjectServer tp - = new TestProjectServer("Test Project", true); - tp.setName("Test Project"); - tp.setNotes("Notes"); - tp.setActive(true); - tp.write2DB(); - //Add the test structure - TestPlanServer tps = new TestPlanServer(tp.getEntity(), - true, true); - tps.setName("Test Plan #" + (tpCounter++)); - tps.setNotes("Notes"); - tps.write2DB(); - int amount = 5; - for (int i = 0; i < 5; i++) { - //Add steps - TestCaseServer tcs - = new TestCaseServer("Test Case #" - + (tcCounter++), - new Date()); - tcs.write2DB(); - for (int j = 0; j < amount; j++) { - tcs.addStep((j + 1), "Step #" + (j + 1), "Note", - "Criteria", - new ArrayList<>()); - } - tcs.write2DB(); - tps.addTestCase(tcs.getEntity()); - } - ProjectServer ps = new ProjectServer(p); - if (ps.getTestProjectList() == null) { - ps.setTestProjectList(new ArrayList<>()); - } - ps.getTestProjectList().add(tp.getEntity()); - //Save it - ps.write2DB(); - } - - private static void addDemoExecution(Project p) - throws NonexistentEntityException, Exception { - int i = 1; - TestCaseExecutionServer tces - = new TestCaseExecutionServer("Execution " + i, - "Test Scope " + i); - tces.setConclusion("Conclusion!"); - tces.write2DB(); - p.getTestProjectList().forEach((tp) -> { - tces.addTestProject(tp); - }); - tces.write2DB(); - VMUserServer tester1 = new VMUserServer(2);//Tester - VMUserServer tester2 = new VMUserServer(3);//Tester - VMUserServer assigner = new VMUserServer(6);//Tester - Random r = new Random(); - tces.getExecutionStepList().stream().map((es) - -> new ExecutionStepServer(es)).forEachOrdered((ess) - -> { - ess.getStep().getRequirementList().forEach(req -> { - ess.getHistoryList().add(req.getHistoryList().get(0)); - }); - ess.setStepHistory(ess.getStep().getHistoryList().get(0)); - ess.assignUser(r.nextBoolean() ? tester1.getEntity() - : tester2.getEntity(), assigner.getEntity()); - }); - } -} +package com.validation.manager.core; + +import com.validation.manager.core.db.Project; +import com.validation.manager.core.db.Requirement; +import com.validation.manager.core.db.Step; +import com.validation.manager.core.db.TestCase; +import com.validation.manager.core.db.controller.ProjectJpaController; +import com.validation.manager.core.db.controller.RequirementJpaController; +import com.validation.manager.core.db.controller.TestCaseJpaController; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.server.core.ExecutionStepServer; +import com.validation.manager.core.server.core.ProjectServer; +import com.validation.manager.core.server.core.RequirementServer; +import com.validation.manager.core.server.core.RequirementSpecNodeServer; +import com.validation.manager.core.server.core.RequirementSpecServer; +import com.validation.manager.core.server.core.StepServer; +import com.validation.manager.core.server.core.TestCaseExecutionServer; +import com.validation.manager.core.server.core.TestCaseServer; +import com.validation.manager.core.server.core.TestPlanServer; +import com.validation.manager.core.server.core.TestProjectServer; +import com.validation.manager.core.server.core.VMUserServer; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Random; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Javier Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class DemoBuilder { + + private static final Logger LOG + = Logger.getLogger(DemoBuilder.class.getSimpleName()); + private static int tcCounter = 1, tpCounter, reqCounter; + + public static void buildDemoProject() throws Exception { + LOG.info("Creating demo projects..."); + ProjectJpaController controller + = new ProjectJpaController(DataBaseManager + .getEntityManagerFactory()); + Project rootProject = new Project("Demo"); + controller.create(rootProject); + for (int i = 0; i < 2; i++) { + Project temp = new Project("Sub " + (i + 1)); + temp.setParentProjectId(rootProject); + controller.create(temp); + ProjectServer ps = new ProjectServer(temp); + addDemoProjectRequirements(ps.getEntity()); + addDemoProjectTestProject(ps.getEntity()); + rootProject.getProjectList().add(ps.getEntity()); + } + addDemoProjectRequirements(rootProject); + controller.edit(rootProject); + //Link requirements with steps + List requirements + = new RequirementJpaController(DataBaseManager + .getEntityManagerFactory()) + .findRequirementEntities(); + LOG.log(Level.FINE, "Total Requirements: {0}", requirements.size()); + List tcs = new TestCaseJpaController(DataBaseManager + .getEntityManagerFactory()).findTestCaseEntities(); + int amount = tcs.size(); + int size = requirements.size() / amount; + int i = 0; + for (TestCase tc : tcs) { + for (Step step : tc.getStepList()) { + try { + StepServer ss = new StepServer(step); + ss.getRequirementList().addAll(requirements + .subList(i * size, i * size + size)); + ss.write2DB(); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + i++; + } + for (Project p : controller.findProjectEntities()) { + addDemoExecution(p); + } + LOG.info("Done!"); + } + + private static void addDemoProjectRequirements(Project p) + throws Exception { + tpCounter = 1; + reqCounter = 1; + //Create User Needs spec + RequirementSpecServer un = createRequirementSpec(p, 1, 1, 5, + "User Need", "User Need Desc"); + List subSpecs = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + //Create a spec + subSpecs.add(createRequirementSpec(p, 5, 1, 5, "Spec " + i, + "Desc " + i)); + } + //Now link UN requirement to lower level requirements + un.getRequirementSpecNodeList().forEach(rsn -> { + int count = 0; + for (Requirement r : rsn.getRequirementList()) { + subSpecs.get(count).getRequirementSpecNodeList().forEach(nl -> { + nl.getRequirementList().forEach(sr -> { + try { + new RequirementServer(r) + .addChildRequirement(sr); + } + catch (VMException ex) { + LOG.log(Level.SEVERE, null, ex); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + } + }); + }); + count++; + } + }); + new ProjectJpaController(DataBaseManager + .getEntityManagerFactory()).edit(p); + } + + /** + * Create a requirement spec for the provided project on the specified + * requirement level. + * + * @param p Project to add the spec to. + * @param level Spec level + * @param nodeAmount Amount of nodes to create + * @param reqAmount Amount of requirements to add to each node of this spec. + * @param specName Spec desired name + * @param specDesc Spec description + * @return Created Requirement Spec + * @throws Exception + */ + private static RequirementSpecServer createRequirementSpec(Project p, + int level, int nodeAmount, int reqAmount, String specName, + String specDesc) throws Exception { + RequirementSpecServer temp + = new RequirementSpecServer(specName, + specDesc, + p.getId(), level); + temp.write2DB(); + if (nodeAmount > 0) { + for (int i = 0; i < nodeAmount; i++) { + RequirementSpecNodeServer node + = temp.addSpecNode("Node " + (i + 1), + "Description " + (i + 1), "Scope " + (i + 1)); + if (reqAmount > 0) { + for (int y = 0; y < reqAmount; y++) { + String header = ""; + switch (level) { + case 1: + header = "PS"; + break; + case 5: + header = "SRS"; + break; + default: + header = "SRS"; + break; + } + RequirementServer req + = new RequirementServer(header + + String.format("%05d", reqCounter), + "Description " + reqCounter, + node.getRequirementSpecNodePK(), + "Notes", 1, 1); + req.write2DB(); + node.getRequirementList().add(req.getEntity()); + reqCounter++; + } + } + node.write2DB(); + } + p.getRequirementSpecList().add(temp.getEntity()); + temp.update(); + } + return temp; + } + + private static void addDemoProjectTestProject(Project p) throws + NonexistentEntityException, Exception { + TestProjectServer tp + = new TestProjectServer("Test Project", true); + tp.setName("Test Project"); + tp.setNotes("Notes"); + tp.setActive(true); + tp.write2DB(); + //Add the test structure + TestPlanServer tps = new TestPlanServer(tp.getEntity(), + true, true); + tps.setName("Test Plan #" + (tpCounter++)); + tps.setNotes("Notes"); + tps.write2DB(); + int amount = 5; + for (int i = 0; i < 5; i++) { + //Add steps + TestCaseServer tcs + = new TestCaseServer("Test Case #" + + (tcCounter++), + new Date()); + tcs.write2DB(); + for (int j = 0; j < amount; j++) { + tcs.addStep((j + 1), "Step #" + (j + 1), "Note", + "Criteria", + new ArrayList<>()); + } + tcs.write2DB(); + tps.addTestCase(tcs.getEntity()); + } + ProjectServer ps = new ProjectServer(p); + if (ps.getTestProjectList() == null) { + ps.setTestProjectList(new ArrayList<>()); + } + ps.getTestProjectList().add(tp.getEntity()); + //Save it + ps.write2DB(); + } + + private static void addDemoExecution(Project p) + throws NonexistentEntityException, Exception { + int i = 1; + TestCaseExecutionServer tces + = new TestCaseExecutionServer("Execution " + i, + "Test Scope " + i); + tces.setConclusion("Conclusion!"); + tces.write2DB(); + p.getTestProjectList().forEach((tp) -> { + tces.addTestProject(tp); + }); + tces.write2DB(); + VMUserServer tester1 = new VMUserServer(2);//Tester + VMUserServer tester2 = new VMUserServer(3);//Tester + VMUserServer assigner = new VMUserServer(6);//Tester + Random r = new Random(); + tces.getExecutionStepList().stream().map((es) + -> new ExecutionStepServer(es)).forEachOrdered((ess) + -> { + ess.getStep().getRequirementList().forEach(req -> { + ess.getHistoryList().add(req.getHistoryList().get(0)); + }); + ess.setStepHistory(ess.getStep().getHistoryList().get(0)); + ess.assignUser(r.nextBoolean() ? tester1.getEntity() + : tester2.getEntity(), assigner.getEntity()); + }); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/EntityServer.java b/VM-Core/src/main/java/com/validation/manager/core/EntityServer.java index 9b82bb85..818a26ef 100755 --- a/VM-Core/src/main/java/com/validation/manager/core/EntityServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/EntityServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,46 +13,46 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core; - -import java.util.HashMap; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - * @param Entity - */ -public interface EntityServer { - - static HashMap PARAMETERS = new HashMap(); - - /** - * Write Entity to database - * - * @return Id for entity (new if just created) - * @throws Exception if there was an issue updating the database. - */ - public int write2DB() throws Exception; - - /** - * Gets the entity represented by this EntityServer. Easy method to access - * underlying entity for use with controllers and such. - * - * @return The entity. - */ - public T getEntity(); - - /** - * Update the target with the source object. - * - * @param target object to update. - * @param source object to update from. - */ - public void update(T target, T source); - - /** - * Update the enclosed entity. - * - */ - public void update(); -} +package com.validation.manager.core; + +import java.util.HashMap; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + * @param Entity + */ +public interface EntityServer { + + static HashMap PARAMETERS = new HashMap(); + + /** + * Write Entity to database + * + * @return Id for entity (new if just created) + * @throws Exception if there was an issue updating the database. + */ + public int write2DB() throws Exception; + + /** + * Gets the entity represented by this EntityServer. Easy method to access + * underlying entity for use with controllers and such. + * + * @return The entity. + */ + public T getEntity(); + + /** + * Update the target with the source object. + * + * @param target object to update. + * @param source object to update from. + */ + public void update(T target, T source); + + /** + * Update the enclosed entity. + * + */ + public void update(); +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/ImportException.java b/VM-Core/src/main/java/com/validation/manager/core/ImportException.java deleted file mode 100644 index 2f8ac722..00000000 --- a/VM-Core/src/main/java/com/validation/manager/core/ImportException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.validation.manager.core; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class ImportException extends VMException { - -} diff --git a/VM-Core/src/main/java/com/validation/manager/core/ImporterInterface.java b/VM-Core/src/main/java/com/validation/manager/core/ImporterInterface.java index 6be248cd..29072572 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/ImporterInterface.java +++ b/VM-Core/src/main/java/com/validation/manager/core/ImporterInterface.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,39 +13,39 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core; - -import java.util.List; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - * @param Class type for template. - */ -public interface ImporterInterface { - - /** - * Import the file. - * - * @return List of imported entities - * @throws ImportException If something goes wrong in the importing process. - */ - List importFile() throws VMException; - - /** - * Import the file. - * - * @param header File has header row. - * @return List of imported entities - * @throws ImportException If something goes wrong in the importing process. - */ - List importFile(boolean header) throws VMException; - - /** - * Process the imported data. - * - * @return true if processed successfully, false otherwise. - * @throws VMException if there was an issue during import. - */ - boolean processImport() throws VMException; -} +package com.validation.manager.core; + +import java.util.List; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + * @param Class type for template. + */ +public interface ImporterInterface { + + /** + * Import the file. + * + * @return List of imported entities + * @throws VMException If something goes wrong in the importing process. + */ + List importFile() throws VMException; + + /** + * Import the file. + * + * @param header File has header row. + * @return List of imported entities + * @throws VMException If something goes wrong in the importing process. + */ + List importFile(boolean header) throws VMException; + + /** + * Process the imported data. + * + * @return true if processed successfully, false otherwise. + * @throws VMException if there was an issue during import. + */ + boolean processImport() throws VMException; +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/VMIdGenerator.java b/VM-Core/src/main/java/com/validation/manager/core/VMIdGenerator.java deleted file mode 100755 index 76f263b4..00000000 --- a/VM-Core/src/main/java/com/validation/manager/core/VMIdGenerator.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.validation.manager.core; - -import static com.validation.manager.core.DataBaseManager.namedQuery; -import com.validation.manager.core.db.VmId; -import java.util.HashMap; -import java.util.logging.Level; -import java.util.logging.Logger; -import static java.util.logging.Logger.getLogger; -import javax.persistence.PrePersist; - -/** - * Work around issue with sequencing on H2 databases on Linux - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class VMIdGenerator { - - private static final Logger LOG - = getLogger(VMIdGenerator.class.getSimpleName()); - - /** - * Just before persisting an entity. - * - * @param o object to be persisted - * @throws Exception if something goes wrong - */ - @PrePersist - public void persistEntity(Object o) throws Exception { - LOG.log(Level.FINE, "Pre-persist: {0}", o); - if (o instanceof VmId) { - VmId vmId = (VmId) o; - if (vmId.getId() == null || vmId.getId() <= 0) { - LOG.log(Level.FINE, "Detected: {0}, fixing id...", vmId); - HashMap parameters = new HashMap<>(); - int id = namedQuery("VmId.findAll").size() + 1; - while (vmId.getId() <= 0) { - parameters.put("id", id); - if (namedQuery("VmId.findById", parameters).isEmpty()) { - vmId.setId(id); - LOG.log(Level.FINE, "Assigned id: {0} to {1}", - new Object[]{id, vmId.getTableName()}); - } else { - id++; - } - } - } - } - } -} diff --git a/VM-Core/src/main/java/com/validation/manager/core/VaadinUtils.java b/VM-Core/src/main/java/com/validation/manager/core/VaadinUtils.java index 5d177b4a..41c4a185 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/VaadinUtils.java +++ b/VM-Core/src/main/java/com/validation/manager/core/VaadinUtils.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,162 +13,162 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core; - -import com.vaadin.data.Property; -import com.vaadin.ui.Component; -import com.vaadin.ui.HasComponents; -import com.vaadin.ui.UI; -import java.io.UnsupportedEncodingException; -import java.util.Collections; -import java.util.Enumeration; -import java.util.Locale; -import java.util.ResourceBundle; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * {@code VaadinUtils} offers some utility functions for the - * Vaadin UI Framework. - * - * @author Javier Ortiz Bultron - * Based on code from: Ronald K. Muller - * https://gist.github.com/rmuller/10980706 - */ -public final class VaadinUtils { - - private static final Logger LOG - = Logger.getLogger(VaadinUtils.class.getSimpleName()); - - // Utility class - private VaadinUtils() { - } - - /** - * Change all {@code Locale} dependant properties of the - * {@code com.vaadin.ui.Component}s within of the given component container - * (typically an {@link UI} or other top level layout component). If the - * specified {@code Locale} is the same as the current {@code Locale} of the - * component container, this method does nothing. Otherwise it'll go thru - * the components searching for it's component id. If it is in the resource - * bundle, it'll set it's caption to the right translated string. - * - *

- * To use this method, do something like: - *

-     * public class MyUI extends UI {
-     *
-     *     {@literal @}Override
-     *     public void init(final VaadinRequest request) {
-     *         // ... usual code
-     *         // somewhere in the UI the user can change the "Form Locale". This code must
-     *         // call myUI#setLocale(newLocale);
-     *     }
-     *
-     *     // ...
-     *
-     * }
-     *
-     *      String key = "demo.tab.message";
-     *      VerticalLayout vl = new VerticalLayout();
-     *      Button b = new Button(key);
-     *      vl.addComponent(b);
-     *      ResourceBundle rb = ResourceBundle.getBundle(
-     *              "resource.bundle",
-     *              new Locale("es"));
-     *      VaadinUtils.updateLocale(vl, new Locale("es"), rb);
-     *
-     *      It also works with components implementing Property:
-     *
-     *      VerticalLayout vl = new VerticalLayout();
-     *      Label l = new Label(key);
-     *      vl.addComponent(l);
-     *      ResourceBundle rb = ResourceBundle.getBundle(
-     *              "resource.bundle",
-     *              new Locale("es"));
-     *      VaadinUtils.updateLocale(vl, new Locale("es"), rb);
-     * 
- * - * @param ui The component container for which the {@code Locale} dependent - * component properties must be changed, never {@code null} - * @param locale The new {@code Locale}, never {@code null} - * @param rb The {@code ResourceBundle} for the specified {@code Locale}, - * never {@code null} - */ - public static void updateLocale(final HasComponents ui, final Locale locale, - final ResourceBundle rb) { - - // locale may not be null, however the current UI Locale may be null! - if (locale.equals(ui.getLocale())) { - return; - } - final long time = System.currentTimeMillis(); - walkComponentTree(ui, (Component c) -> { - String id = c.getId(); - String caption; - if (c instanceof Property - && ((Property) c).getValue() instanceof String) { - caption = (String) ((Property) c).getValue(); - } else { - caption = c.getCaption(); - } - if (id != null && !id.trim().isEmpty()) { - if (rb.containsKey(id)) { - try { - c.setCaption(new String(rb.getString(id) - .getBytes("ISO-8859-1"), "UTF-8")); - } - catch (UnsupportedEncodingException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - } else if (caption != null && !caption.trim().isEmpty()) { - /** - * This is a more complex scenario where the caption uses more - * than one key for translation. Sort the keys in reverse so - * substitutions are correct. - */ - final SortedSet ss = new TreeSet<>(Collections.reverseOrder()); - for (Enumeration e = rb.getKeys(); e.hasMoreElements();) { - try { - String key = e.nextElement(); - ss.add(key); - caption = caption.replaceAll(key, new String(rb.getString(key) - .getBytes("ISO-8859-1"), "UTF-8")); - } - catch (UnsupportedEncodingException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - if (c instanceof Property) { - ((Property) c).setValue(caption); - } else { - c.setCaption(caption); - } - } - }); - LOG.log(Level.INFO, "Locale updated: {0} -> {1} in {2} ms.", - new Object[]{ui.getLocale(), locale, - System.currentTimeMillis() - time}); - } - - // private - // if switching to Java 8, remove this and replace by java.util.funtion.Consumer - // (and make to code more functional) - interface Consumer { - - void accept(T t); - } - - // recursively walk the Component true - private static void walkComponentTree(Component c, Consumer visitor) { - visitor.accept(c); - if (c instanceof HasComponents) { - for (Component child : ((HasComponents) c)) { - walkComponentTree(child, visitor); - } - } - } -} +package com.validation.manager.core; + +import com.vaadin.data.Property; +import com.vaadin.ui.Component; +import com.vaadin.ui.HasComponents; +import com.vaadin.ui.UI; +import java.io.UnsupportedEncodingException; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * {@code VaadinUtils} offers some utility functions for the + * Vaadin UI Framework. + * + * @author Javier Ortiz Bultron + * Based on code from: Ronald K. Muller + * https://gist.github.com/rmuller/10980706 + */ +public final class VaadinUtils { + + private static final Logger LOG + = Logger.getLogger(VaadinUtils.class.getSimpleName()); + + // Utility class + private VaadinUtils() { + } + + /** + * Change all {@code Locale} dependant properties of the + * {@code com.vaadin.ui.Component}s within of the given component container + * (typically an {@link UI} or other top level layout component). If the + * specified {@code Locale} is the same as the current {@code Locale} of the + * component container, this method does nothing. Otherwise it'll go thru + * the components searching for it's component id. If it is in the resource + * bundle, it'll set it's caption to the right translated string. + * + *

+ * To use this method, do something like: + *

+     * public class MyUI extends UI {
+     *
+     *     {@literal @}Override
+     *     public void init(final VaadinRequest request) {
+     *         // ... usual code
+     *         // somewhere in the UI the user can change the "Form Locale". This code must
+     *         // call myUI#setLocale(newLocale);
+     *     }
+     *
+     *     // ...
+     *
+     * }
+     *
+     *      String key = "demo.tab.message";
+     *      VerticalLayout vl = new VerticalLayout();
+     *      Button b = new Button(key);
+     *      vl.addComponent(b);
+     *      ResourceBundle rb = ResourceBundle.getBundle(
+     *              "resource.bundle",
+     *              new Locale("es"));
+     *      VaadinUtils.updateLocale(vl, new Locale("es"), rb);
+     *
+     *      It also works with components implementing Property:
+     *
+     *      VerticalLayout vl = new VerticalLayout();
+     *      Label l = new Label(key);
+     *      vl.addComponent(l);
+     *      ResourceBundle rb = ResourceBundle.getBundle(
+     *              "resource.bundle",
+     *              new Locale("es"));
+     *      VaadinUtils.updateLocale(vl, new Locale("es"), rb);
+     * 
+ * + * @param ui The component container for which the {@code Locale} dependent + * component properties must be changed, never {@code null} + * @param locale The new {@code Locale}, never {@code null} + * @param rb The {@code ResourceBundle} for the specified {@code Locale}, + * never {@code null} + */ + public static void updateLocale(final HasComponents ui, final Locale locale, + final ResourceBundle rb) { + + // locale may not be null, however the current UI Locale may be null! + if (locale.equals(ui.getLocale())) { + return; + } + final long time = System.currentTimeMillis(); + walkComponentTree(ui, (Component c) -> { + String id = c.getId(); + String caption; + if (c instanceof Property + && ((Property) c).getValue() instanceof String) { + caption = (String) ((Property) c).getValue(); + } else { + caption = c.getCaption(); + } + if (id != null && !id.trim().isEmpty()) { + if (rb.containsKey(id)) { + try { + c.setCaption(new String(rb.getString(id) + .getBytes("ISO-8859-1"), "UTF-8")); + } + catch (UnsupportedEncodingException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + } else if (caption != null && !caption.trim().isEmpty()) { + /** + * This is a more complex scenario where the caption uses more + * than one key for translation. Sort the keys in reverse so + * substitutions are correct. + */ + final SortedSet ss = new TreeSet<>(Collections.reverseOrder()); + for (Enumeration e = rb.getKeys(); e.hasMoreElements();) { + try { + String key = e.nextElement(); + ss.add(key); + caption = caption.replaceAll(key, new String(rb.getString(key) + .getBytes("ISO-8859-1"), "UTF-8")); + } + catch (UnsupportedEncodingException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + if (c instanceof Property) { + ((Property) c).setValue(caption); + } else { + c.setCaption(caption); + } + } + }); + LOG.log(Level.FINE, "Locale updated: {0} -> {1} in {2} ms.", + new Object[]{ui.getLocale(), locale, + System.currentTimeMillis() - time}); + } + + // private + // if switching to Java 8, remove this and replace by java.util.funtion.Consumer + // (and make to code more functional) + interface Consumer { + + void accept(T t); + } + + // recursively walk the Component true + private static void walkComponentTree(Component c, Consumer visitor) { + visitor.accept(c); + if (c instanceof HasComponents) { + for (Component child : ((HasComponents) c)) { + walkComponentTree(child, visitor); + } + } + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/adapter/TimestampAdapter.java b/VM-Core/src/main/java/com/validation/manager/core/adapter/TimestampAdapter.java deleted file mode 100644 index 63edb98b..00000000 --- a/VM-Core/src/main/java/com/validation/manager/core/adapter/TimestampAdapter.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.validation.manager.core.adapter; - -import java.sql.Timestamp; -import java.util.Date; -import javax.xml.bind.annotation.adapters.XmlAdapter; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class TimestampAdapter extends XmlAdapter { - - @Override - public Timestamp unmarshal(Date v) throws Exception { - if (v == null) { - return null; - } else { - return new Timestamp(v.getTime()); - } - } - - @Override - public Date marshal(Timestamp v) throws Exception { - if (v == null) { - return null; - } else { - return new Date(v.getTime()); - } - } -} diff --git a/VM-Core/src/main/java/com/validation/manager/core/tool/step/importer/StepImportException.java b/VM-Core/src/main/java/com/validation/manager/core/api/email/IEmailManager.java similarity index 55% rename from VM-Core/src/main/java/com/validation/manager/core/tool/step/importer/StepImportException.java rename to VM-Core/src/main/java/com/validation/manager/core/api/email/IEmailManager.java index 26091df3..8be830e8 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/tool/step/importer/StepImportException.java +++ b/VM-Core/src/main/java/com/validation/manager/core/api/email/IEmailManager.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,23 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.tool.step.importer; - -import static java.util.Locale.getDefault; -import java.util.ResourceBundle; -import static java.util.ResourceBundle.getBundle; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class StepImportException extends Exception { - - private static final ResourceBundle RB - = getBundle("com.validation.manager.resources.VMMessages", - getDefault()); - - public StepImportException(String message) { - super(RB.containsKey(message) ? RB.getString(message) : message); - } -} +package com.validation.manager.core.api.email; + +import javax.mail.MessagingException; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public interface IEmailManager { + + /** + * Create an email message. + * + * @param to Recipient email + * @param cc Email to copy to + * @param from Sender email + * @param subject Subject + * @param bodyText Message + * @throws MessagingException If there's an error sending the message + */ + void sendEmail(String to, String cc, String from, + String subject, String bodyText) throws MessagingException; +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/api/internationalization/InternationalizationProvider.java b/VM-Core/src/main/java/com/validation/manager/core/api/internationalization/InternationalizationProvider.java index d9b47f8d..d4f48fc5 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/api/internationalization/InternationalizationProvider.java +++ b/VM-Core/src/main/java/com/validation/manager/core/api/internationalization/InternationalizationProvider.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,28 +13,38 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.api.internationalization; - -import java.util.ResourceBundle; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public interface InternationalizationProvider extends LocaleListener { - - /** - * Translate a string. - * - * @param mess String to translate - * @return Translated string or the same string if no translation found. - */ - public String translate(String mess); - - /** - * Get the ResourceBundle. - * - * @return The resource bundle. - */ - public ResourceBundle getResourceBundle(); -} +package com.validation.manager.core.api.internationalization; + +import java.util.Locale; +import java.util.ResourceBundle; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public interface InternationalizationProvider { + + /** + * Translate a string. + * + * @param mess String to translate + * @return Translated string or the same string if no translation found. + */ + public String translate(String mess); + + /** + * Translate a string. + * + * @param mess String to translate + * @param l Locale to translate into. + * @return Translated string or the same string if no translation found. + */ + public String translate(String mess, Locale l); + + /** + * Get the ResourceBundle. + * + * @return The resource bundle. + */ + public ResourceBundle getResourceBundle(); +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/AssigmentType.java b/VM-Core/src/main/java/com/validation/manager/core/db/AssigmentType.java index cb095ed2..9be79510 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/AssigmentType.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/AssigmentType.java @@ -13,131 +13,131 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "assigment_type") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "AssigmentType.findAll", - query = "SELECT a FROM AssigmentType a") - , @NamedQuery(name = "AssigmentType.findById", - query = "SELECT a FROM AssigmentType a WHERE a.id = :id") - , @NamedQuery(name = "AssigmentType.findByFkTable", - query = "SELECT a FROM AssigmentType a WHERE a.fkTable = :fkTable")}) -public class AssigmentType implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "Assignment_Type_IDGEN") - @TableGenerator(name = "Assignment_Type_IDGEN", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "assigment_type", - initialValue = 1000, - allocationSize = 1) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "fk_table") - private String fkTable; - @Lob - @Size(max = 2147483647) - @Column(name = "description") - private String description; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "assigmentType") - private List userAssigmentList; - - public AssigmentType() { - } - - public AssigmentType(String fkTable) { - this.fkTable = fkTable; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getFkTable() { - return fkTable; - } - - public void setFkTable(String fkTable) { - this.fkTable = fkTable; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getUserAssigmentList() { - return userAssigmentList; - } - - public void setUserAssigmentList(List userAssigmentList) { - this.userAssigmentList = userAssigmentList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof AssigmentType)) { - return false; - } - AssigmentType other = (AssigmentType) object; - return (this.id.equals(other.id)); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.AssigmentType[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "assigment_type") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "AssigmentType.findAll", + query = "SELECT a FROM AssigmentType a") + , @NamedQuery(name = "AssigmentType.findById", + query = "SELECT a FROM AssigmentType a WHERE a.id = :id") + , @NamedQuery(name = "AssigmentType.findByFkTable", + query = "SELECT a FROM AssigmentType a WHERE a.fkTable = :fkTable")}) +public class AssigmentType implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "Assignment_Type_IDGEN") + @TableGenerator(name = "Assignment_Type_IDGEN", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "assigment_type", + initialValue = 1_000, + allocationSize = 1) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "fk_table") + private String fkTable; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "description") + private String description; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "assigmentType") + private List userAssigmentList; + + public AssigmentType() { + } + + public AssigmentType(String fkTable) { + this.fkTable = fkTable; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getFkTable() { + return fkTable; + } + + public void setFkTable(String fkTable) { + this.fkTable = fkTable; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getUserAssigmentList() { + return userAssigmentList; + } + + public void setUserAssigmentList(List userAssigmentList) { + this.userAssigmentList = userAssigmentList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof AssigmentType)) { + return false; + } + AssigmentType other = (AssigmentType) object; + return (this.id.equals(other.id)); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.AssigmentType[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/AssignmentStatus.java b/VM-Core/src/main/java/com/validation/manager/core/db/AssignmentStatus.java index 3dc1809c..3db70fa0 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/AssignmentStatus.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/AssignmentStatus.java @@ -13,134 +13,134 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "assignment_status") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "AssignmentStatus.findAll", - query = "SELECT a FROM AssignmentStatus a") - , @NamedQuery(name = "AssignmentStatus.findById", - query = "SELECT a FROM AssignmentStatus a WHERE a.id = :id") - , @NamedQuery(name = "AssignmentStatus.findByName", - query = "SELECT a FROM AssignmentStatus a WHERE a.name = :name")}) -public class AssignmentStatus implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "Assignment_Status_IDGEN") - @TableGenerator(name = "Assignment_Status_IDGEN", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "assigment_status", - initialValue = 1000, - allocationSize = 1) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Basic(optional = false) - @NotNull - @Lob - @Size(max = 2147483647) - @Column(name = "description") - private String description; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "assignmentStatus") - private List userAssigmentList; - - public AssignmentStatus() { - } - - public AssignmentStatus(String name, String description) { - this.name = name; - this.description = description; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getUserAssigmentList() { - return userAssigmentList; - } - - public void setUserAssigmentList(List userAssigmentList) { - this.userAssigmentList = userAssigmentList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof AssignmentStatus)) { - return false; - } - AssignmentStatus other = (AssignmentStatus) object; - return (this.id.equals(other.id)); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.AssignmentStatus[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "assignment_status") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "AssignmentStatus.findAll", + query = "SELECT a FROM AssignmentStatus a") + , @NamedQuery(name = "AssignmentStatus.findById", + query = "SELECT a FROM AssignmentStatus a WHERE a.id = :id") + , @NamedQuery(name = "AssignmentStatus.findByName", + query = "SELECT a FROM AssignmentStatus a WHERE a.name = :name")}) +public class AssignmentStatus implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "Assignment_Status_IDGEN") + @TableGenerator(name = "Assignment_Status_IDGEN", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "assigment_status", + initialValue = 1_000, + allocationSize = 1) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Basic(optional = false) + @NotNull + @Lob + @Size(max = 2_147_483_647) + @Column(name = "description") + private String description; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "assignmentStatus") + private List userAssigmentList; + + public AssignmentStatus() { + } + + public AssignmentStatus(String name, String description) { + this.name = name; + this.description = description; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getUserAssigmentList() { + return userAssigmentList; + } + + public void setUserAssigmentList(List userAssigmentList) { + this.userAssigmentList = userAssigmentList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof AssignmentStatus)) { + return false; + } + AssignmentStatus other = (AssignmentStatus) object; + return (this.id.equals(other.id)); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.AssignmentStatus[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/Attachment.java b/VM-Core/src/main/java/com/validation/manager/core/db/Attachment.java index 781a7810..cace5615 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/Attachment.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/Attachment.java @@ -13,160 +13,160 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "attachment") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Attachment.findAll", - query = "SELECT a FROM Attachment a") - , @NamedQuery(name = "Attachment.findById", - query = "SELECT a FROM Attachment a WHERE a.attachmentPK.id = :id") - , @NamedQuery(name = "Attachment.findByAttachmentTypeId", - query = "SELECT a FROM Attachment a WHERE a.attachmentPK.attachmentTypeId = :attachmentTypeId") - , @NamedQuery(name = "Attachment.findByStringValue", - query = "SELECT a FROM Attachment a WHERE a.stringValue = :stringValue") - , @NamedQuery(name = "Attachment.findByFileName", - query = "SELECT a FROM Attachment a WHERE a.fileName = :fileName")}) -public class Attachment implements Serializable { - - private static final long serialVersionUID = 1L; - @EmbeddedId - protected AttachmentPK attachmentPK; - @Size(max = 255) - @Column(name = "string_value") - private String stringValue; - @Lob - @Column(name = "file") - private byte[] file; - @Lob - @Size(max = 2147483647) - @Column(name = "TEXT_VALUE") - private String textValue; - @Size(max = 255) - @Column(name = "file_name") - private String fileName; - @JoinColumn(name = "attachment_type_id", referencedColumnName = "id", - insertable = false, updatable = false) - @ManyToOne(optional = false) - private AttachmentType attachmentType; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "attachment") - private List executionStepHasAttachmentList; - - public Attachment() { - } - - public Attachment(AttachmentPK attachmentPK) { - this.attachmentPK = attachmentPK; - } - - public Attachment(int id, int attachmentTypeId) { - this.attachmentPK = new AttachmentPK(id, attachmentTypeId); - } - - public AttachmentPK getAttachmentPK() { - return attachmentPK; - } - - public void setAttachmentPK(AttachmentPK attachmentPK) { - this.attachmentPK = attachmentPK; - } - - public String getStringValue() { - return stringValue; - } - - public void setStringValue(String stringValue) { - this.stringValue = stringValue; - } - - public String getTextValue() { - return textValue; - } - - public void setTextValue(String textValue) { - this.textValue = textValue; - } - - public String getFileName() { - return fileName; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - - public AttachmentType getAttachmentType() { - return attachmentType; - } - - public void setAttachmentType(AttachmentType attachmentType) { - this.attachmentType = attachmentType; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepHasAttachmentList() { - return executionStepHasAttachmentList; - } - - public void setExecutionStepHasAttachmentList(List executionStepHasAttachmentList) { - this.executionStepHasAttachmentList = executionStepHasAttachmentList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (attachmentPK != null ? attachmentPK.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof Attachment)) { - return false; - } - Attachment other = (Attachment) object; - return !((this.attachmentPK == null && other.attachmentPK != null) - || (this.attachmentPK != null - && !this.attachmentPK.equals(other.attachmentPK))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.Attachment[ attachmentPK=" - + attachmentPK + " ]"; - } - - public byte[] getFile() { - return file; - } - - public void setFile(byte[] file) { - this.file = file; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "attachment") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Attachment.findAll", + query = "SELECT a FROM Attachment a") + , @NamedQuery(name = "Attachment.findById", + query = "SELECT a FROM Attachment a WHERE a.attachmentPK.id = :id") + , @NamedQuery(name = "Attachment.findByAttachmentTypeId", + query = "SELECT a FROM Attachment a WHERE a.attachmentPK.attachmentTypeId = :attachmentTypeId") + , @NamedQuery(name = "Attachment.findByStringValue", + query = "SELECT a FROM Attachment a WHERE a.stringValue = :stringValue") + , @NamedQuery(name = "Attachment.findByFileName", + query = "SELECT a FROM Attachment a WHERE a.fileName = :fileName")}) +public class Attachment implements Serializable { + + private static final long serialVersionUID = 1L; + @EmbeddedId + protected AttachmentPK attachmentPK; + @Size(max = 255) + @Column(name = "string_value") + private String stringValue; + @Lob + @Column(name = "file") + private byte[] file; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "TEXT_VALUE") + private String textValue; + @Size(max = 255) + @Column(name = "file_name") + private String fileName; + @JoinColumn(name = "attachment_type_id", referencedColumnName = "id", + insertable = false, updatable = false) + @ManyToOne(optional = false) + private AttachmentType attachmentType; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "attachment") + private List executionStepHasAttachmentList; + + public Attachment() { + } + + public Attachment(AttachmentPK attachmentPK) { + this.attachmentPK = attachmentPK; + } + + public Attachment(int id, int attachmentTypeId) { + this.attachmentPK = new AttachmentPK(id, attachmentTypeId); + } + + public AttachmentPK getAttachmentPK() { + return attachmentPK; + } + + public void setAttachmentPK(AttachmentPK attachmentPK) { + this.attachmentPK = attachmentPK; + } + + public String getStringValue() { + return stringValue; + } + + public void setStringValue(String stringValue) { + this.stringValue = stringValue; + } + + public String getTextValue() { + return textValue; + } + + public void setTextValue(String textValue) { + this.textValue = textValue; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public AttachmentType getAttachmentType() { + return attachmentType; + } + + public void setAttachmentType(AttachmentType attachmentType) { + this.attachmentType = attachmentType; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepHasAttachmentList() { + return executionStepHasAttachmentList; + } + + public void setExecutionStepHasAttachmentList(List executionStepHasAttachmentList) { + this.executionStepHasAttachmentList = executionStepHasAttachmentList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (attachmentPK != null ? attachmentPK.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof Attachment)) { + return false; + } + Attachment other = (Attachment) object; + return !((this.attachmentPK == null && other.attachmentPK != null) + || (this.attachmentPK != null + && !this.attachmentPK.equals(other.attachmentPK))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.Attachment[ attachmentPK=" + + attachmentPK + " ]"; + } + + public byte[] getFile() { + return file; + } + + public void setFile(byte[] file) { + this.file = file; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/AttachmentType.java b/VM-Core/src/main/java/com/validation/manager/core/db/AttachmentType.java index 247ae686..2015e8f8 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/AttachmentType.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/AttachmentType.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,125 +13,120 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "attachment_type") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "AttachmentType.findAll", - query = "SELECT a FROM AttachmentType a") - , @NamedQuery(name = "AttachmentType.findById", - query = "SELECT a FROM AttachmentType a WHERE a.id = :id") - , @NamedQuery(name = "AttachmentType.findByType", - query = "SELECT a FROM AttachmentType a WHERE a.type = :type")}) -public class AttachmentType implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @NotNull - @Column(name = "id") - private Integer id; - @Lob - @Size(max = 65535) - @Column(name = "description") - private String description; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "TYPE") - private String type; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "attachmentType") - private List attachmentList; - - public AttachmentType() { - } - - public AttachmentType(Integer id) { - this.id = id; - } - - public AttachmentType(Integer id, String type) { - this.id = id; - this.type = type; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - @XmlTransient - @JsonIgnore - public List getAttachmentList() { - return attachmentList; - } - - public void setAttachmentList(List attachmentList) { - this.attachmentList = attachmentList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof AttachmentType)) { - return false; - } - AttachmentType other = (AttachmentType) object; - return this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.AttachmentType[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "attachment_type") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "AttachmentType.findAll", + query = "SELECT a FROM AttachmentType a") + , @NamedQuery(name = "AttachmentType.findById", + query = "SELECT a FROM AttachmentType a WHERE a.id = :id") + , @NamedQuery(name = "AttachmentType.findByType", + query = "SELECT a FROM AttachmentType a WHERE a.type = :type")}) +public class AttachmentType implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @NotNull + @Column(name = "id") + private Integer id; + @Lob + @Size(max = 65_535) + @Column(name = "description") + private String description; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "TYPE") + private String type; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "attachmentType") + private List attachmentList; + + public AttachmentType() { + } + + public AttachmentType(String type) { + this.type = type; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @XmlTransient + @JsonIgnore + public List getAttachmentList() { + return attachmentList; + } + + public void setAttachmentList(List attachmentList) { + this.attachmentList = attachmentList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof AttachmentType)) { + return false; + } + AttachmentType other = (AttachmentType) object; + return this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.AttachmentType[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/Baseline.java b/VM-Core/src/main/java/com/validation/manager/core/db/Baseline.java index e6e11160..91a3cc0b 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/Baseline.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/Baseline.java @@ -13,176 +13,176 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; -import javax.persistence.JoinTable; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "baseline") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Baseline.findAll", - query = "SELECT b FROM Baseline b") - , @NamedQuery(name = "Baseline.findById", - query = "SELECT b FROM Baseline b WHERE b.id = :id") - , @NamedQuery(name = "Baseline.findByCreationDate", - query = "SELECT b FROM Baseline b WHERE b.creationDate = :creationDate") - , @NamedQuery(name = "Baseline.findByBaselineName", - query = "SELECT b FROM Baseline b WHERE b.baselineName = :baselineName")}) -public class Baseline implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @NotNull - @Column(name = "id") - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "Baseline_IDGEN") - @TableGenerator(name = "Baseline_IDGEN", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "baseline", - initialValue = 1, - allocationSize = 1) - private Integer id; - @Basic(optional = false) - @NotNull - @Column(name = "creation_date") - @Temporal(TemporalType.TIMESTAMP) - private Date creationDate; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "baseline_name") - private String baselineName; - @Lob - @Size(max = 2147483647) - @Column(name = "description") - private String description; - @JoinTable(name = "baseline_has_history", joinColumns = { - @JoinColumn(name = "baseline_id", referencedColumnName = "id")}, inverseJoinColumns = { - @JoinColumn(name = "history_id", referencedColumnName = "id")}) - @ManyToMany - private List historyList; - @JoinColumns({ - @JoinColumn(name = "requirement_spec_id", referencedColumnName = "id") - , @JoinColumn(name = "requirement_spec_project_id", referencedColumnName = "project_id") - , @JoinColumn(name = "requirement_spec_spec_level_id", referencedColumnName = "spec_level_id")}) - @ManyToOne(optional = false) - private RequirementSpec requirementSpec; - - public Baseline() { - } - - public Baseline(Date creationDate, String baselineName) { - this.creationDate = creationDate; - this.baselineName = baselineName; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Date getCreationDate() { - return creationDate; - } - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - - public String getBaselineName() { - return baselineName; - } - - public void setBaselineName(String baselineName) { - this.baselineName = baselineName; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof Baseline)) { - return false; - } - Baseline other = (Baseline) object; - return this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.Baseline[ id=" + id + " ]"; - } - - /** - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getHistoryList() { - return historyList; - } - - public void setHistoryList(List historyList) { - this.historyList = historyList; - } - - public RequirementSpec getRequirementSpec() { - return requirementSpec; - } - - public void setRequirementSpec(RequirementSpec requirementSpec) { - this.requirementSpec = requirementSpec; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "baseline") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Baseline.findAll", + query = "SELECT b FROM Baseline b") + , @NamedQuery(name = "Baseline.findById", + query = "SELECT b FROM Baseline b WHERE b.id = :id") + , @NamedQuery(name = "Baseline.findByCreationDate", + query = "SELECT b FROM Baseline b WHERE b.creationDate = :creationDate") + , @NamedQuery(name = "Baseline.findByBaselineName", + query = "SELECT b FROM Baseline b WHERE b.baselineName = :baselineName")}) +public class Baseline implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @NotNull + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "Baseline_IDGEN") + @TableGenerator(name = "Baseline_IDGEN", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "baseline", + initialValue = 1, + allocationSize = 1) + private Integer id; + @Basic(optional = false) + @NotNull + @Column(name = "creation_date") + @Temporal(TemporalType.TIMESTAMP) + private Date creationDate; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "baseline_name") + private String baselineName; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "description") + private String description; + @JoinTable(name = "baseline_has_history", joinColumns = { + @JoinColumn(name = "baseline_id", referencedColumnName = "id")}, inverseJoinColumns = { + @JoinColumn(name = "history_id", referencedColumnName = "id")}) + @ManyToMany + private List historyList; + @JoinColumns({ + @JoinColumn(name = "requirement_spec_id", referencedColumnName = "id") + , @JoinColumn(name = "requirement_spec_project_id", referencedColumnName = "project_id") + , @JoinColumn(name = "requirement_spec_spec_level_id", referencedColumnName = "spec_level_id")}) + @ManyToOne(optional = false) + private RequirementSpec requirementSpec; + + public Baseline() { + } + + public Baseline(Date creationDate, String baselineName) { + this.creationDate = creationDate; + this.baselineName = baselineName; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public String getBaselineName() { + return baselineName; + } + + public void setBaselineName(String baselineName) { + this.baselineName = baselineName; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof Baseline)) { + return false; + } + Baseline other = (Baseline) object; + return this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.Baseline[ id=" + id + " ]"; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getHistoryList() { + return historyList; + } + + public void setHistoryList(List historyList) { + this.historyList = historyList; + } + + public RequirementSpec getRequirementSpec() { + return requirementSpec; + } + + public void setRequirementSpec(RequirementSpec requirementSpec) { + this.requirementSpec = requirementSpec; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/Cause.java b/VM-Core/src/main/java/com/validation/manager/core/db/Cause.java index d3bd4036..6b99ceb7 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/Cause.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/Cause.java @@ -13,140 +13,140 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "cause") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Cause.findAll", - query = "SELECT c FROM Cause c") - , @NamedQuery(name = "Cause.findById", - query = "SELECT c FROM Cause c WHERE c.id = :id") - , @NamedQuery(name = "Cause.findByName", - query = "SELECT c FROM Cause c WHERE c.name = :name")}) -public class Cause implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, generator = "CauseGen") - @TableGenerator(name = "CauseGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "cause", - allocationSize = 1, - initialValue = 1000) - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Basic(optional = false) - @NotNull - @Lob - @Size(min = 1, max = 65535) - @Column(name = "description") - private String description; - @JoinTable(name = "risk_item_has_cause", joinColumns = { - @JoinColumn(name = "cause_id", referencedColumnName = "id")}, - inverseJoinColumns = { - @JoinColumn(name = "risk_item_id", referencedColumnName = "id") - , @JoinColumn(name = "risk_item_FMEA_id", - referencedColumnName = "FMEA_id")}) - @ManyToMany - private List riskItemList; - - public Cause() { - } - - public Cause(String name, String description) { - this.name = name; - this.description = description; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getRiskItemList() { - return riskItemList; - } - - public void setRiskItemList(List riskItemList) { - this.riskItemList = riskItemList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof Cause)) { - return false; - } - Cause other = (Cause) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.Cause[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "cause") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Cause.findAll", + query = "SELECT c FROM Cause c") + , @NamedQuery(name = "Cause.findById", + query = "SELECT c FROM Cause c WHERE c.id = :id") + , @NamedQuery(name = "Cause.findByName", + query = "SELECT c FROM Cause c WHERE c.name = :name")}) +public class Cause implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "CauseGen") + @TableGenerator(name = "CauseGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "cause", + allocationSize = 1, + initialValue = 1_000) + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Basic(optional = false) + @NotNull + @Lob + @Size(min = 1, max = 65_535) + @Column(name = "description") + private String description; + @JoinTable(name = "risk_item_has_cause", joinColumns = { + @JoinColumn(name = "cause_id", referencedColumnName = "id")}, + inverseJoinColumns = { + @JoinColumn(name = "risk_item_id", referencedColumnName = "id") + , @JoinColumn(name = "risk_item_FMEA_id", + referencedColumnName = "FMEA_id")}) + @ManyToMany + private List riskItemList; + + public Cause() { + } + + public Cause(String name, String description) { + this.name = name; + this.description = description; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getRiskItemList() { + return riskItemList; + } + + public void setRiskItemList(List riskItemList) { + this.riskItemList = riskItemList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof Cause)) { + return false; + } + Cause other = (Cause) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.Cause[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/CorrectiveAction.java b/VM-Core/src/main/java/com/validation/manager/core/db/CorrectiveAction.java index 9baeffe3..62860b2c 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/CorrectiveAction.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/CorrectiveAction.java @@ -13,137 +13,137 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "corrective_action") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "CorrectiveAction.findAll", - query = "SELECT c FROM CorrectiveAction c") - , @NamedQuery(name = "CorrectiveAction.findById", - query = "SELECT c FROM CorrectiveAction c WHERE c.id = :id")}) -public class CorrectiveAction implements Serializable { - - @OneToMany(cascade = CascadeType.ALL, mappedBy = "correctiveAction") - private List exceptionHasCorrectiveActionList; - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, generator = "CAGen") - @TableGenerator(name = "CAGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "corrective_action", - allocationSize = 1, - initialValue = 1000) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Lob - @Size(min = 1, max = 65535) - @Column(name = "details") - private String details; - @JoinTable(name = "user_has_corrective_action", joinColumns = { - @JoinColumn(name = "corrective_action_id", - referencedColumnName = "id")}, inverseJoinColumns = { - @JoinColumn(name = "user_id", referencedColumnName = "id")}) - @ManyToMany - private List vmUserList; - - public CorrectiveAction() { - } - - public CorrectiveAction(String details) { - this.details = details; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getDetails() { - return details; - } - - public void setDetails(String details) { - this.details = details; - } - - @XmlTransient - @JsonIgnore - public List getVmUserList() { - return vmUserList; - } - - public void setVmUserList(List vmUserList) { - this.vmUserList = vmUserList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof CorrectiveAction)) { - return false; - } - CorrectiveAction other = (CorrectiveAction) object; - return this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.CorrectiveAction[ id=" + id + " ]"; - } - - @XmlTransient - @JsonIgnore - public List getExceptionHasCorrectiveActionList() { - return exceptionHasCorrectiveActionList; - } - - public void setExceptionHasCorrectiveActionList(List exceptionHasCorrectiveActionList) { - this.exceptionHasCorrectiveActionList = exceptionHasCorrectiveActionList; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "corrective_action") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "CorrectiveAction.findAll", + query = "SELECT c FROM CorrectiveAction c") + , @NamedQuery(name = "CorrectiveAction.findById", + query = "SELECT c FROM CorrectiveAction c WHERE c.id = :id")}) +public class CorrectiveAction implements Serializable { + + @OneToMany(cascade = CascadeType.ALL, mappedBy = "correctiveAction") + private List exceptionHasCorrectiveActionList; + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "CAGen") + @TableGenerator(name = "CAGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "corrective_action", + allocationSize = 1, + initialValue = 1_000) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Lob + @Size(min = 1, max = 65_535) + @Column(name = "details") + private String details; + @JoinTable(name = "user_has_corrective_action", joinColumns = { + @JoinColumn(name = "corrective_action_id", + referencedColumnName = "id")}, inverseJoinColumns = { + @JoinColumn(name = "user_id", referencedColumnName = "id")}) + @ManyToMany + private List vmUserList; + + public CorrectiveAction() { + } + + public CorrectiveAction(String details) { + this.details = details; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + @XmlTransient + @JsonIgnore + public List getVmUserList() { + return vmUserList; + } + + public void setVmUserList(List vmUserList) { + this.vmUserList = vmUserList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof CorrectiveAction)) { + return false; + } + CorrectiveAction other = (CorrectiveAction) object; + return this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.CorrectiveAction[ id=" + id + " ]"; + } + + @XmlTransient + @JsonIgnore + public List getExceptionHasCorrectiveActionList() { + return exceptionHasCorrectiveActionList; + } + + public void setExceptionHasCorrectiveActionList(List exceptionHasCorrectiveActionList) { + this.exceptionHasCorrectiveActionList = exceptionHasCorrectiveActionList; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/ExecutionResult.java b/VM-Core/src/main/java/com/validation/manager/core/db/ExecutionResult.java index 0e22e234..55f3e4e6 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/ExecutionResult.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/ExecutionResult.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,123 +13,118 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "execution_result") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "ExecutionResult.findAll", - query = "SELECT e FROM ExecutionResult e") - , @NamedQuery(name = "ExecutionResult.findById", - query = "SELECT e FROM ExecutionResult e WHERE e.id = :id") - , @NamedQuery(name = "ExecutionResult.findByResultName", - query = "SELECT e FROM ExecutionResult e WHERE e.resultName = :resultName")}) -public class ExecutionResult implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @NotNull - @Column(name = "id") - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "ExecutionResult_IDGEN") - @TableGenerator(name = "ExecutionResult_IDGEN", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "execution_result", - initialValue = 1, - allocationSize = 1) - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "result_name") - private String resultName; - @OneToMany(mappedBy = "resultId") - private List executionStepList; - - public ExecutionResult() { - } - - public ExecutionResult(Integer id) { - this.id = id; - } - - public ExecutionResult(Integer id, String resultName) { - this.id = id; - this.resultName = resultName; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getResultName() { - return resultName; - } - - public void setResultName(String resultName) { - this.resultName = resultName; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepList() { - return executionStepList; - } - - public void setExecutionStepList(List executionStepList) { - this.executionStepList = executionStepList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof ExecutionResult)) { - return false; - } - ExecutionResult other = (ExecutionResult) object; - return this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.ExecutionResult[ id=" + id + " ]"; - } - -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "execution_result") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "ExecutionResult.findAll", + query = "SELECT e FROM ExecutionResult e") + , @NamedQuery(name = "ExecutionResult.findById", + query = "SELECT e FROM ExecutionResult e WHERE e.id = :id") + , @NamedQuery(name = "ExecutionResult.findByResultName", + query = "SELECT e FROM ExecutionResult e WHERE e.resultName = :resultName")}) +public class ExecutionResult implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @NotNull + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "ExecutionResult_IDGEN") + @TableGenerator(name = "ExecutionResult_IDGEN", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "execution_result", + initialValue = 1, + allocationSize = 1) + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "result_name") + private String resultName; + @OneToMany(mappedBy = "resultId") + private List executionStepList; + + public ExecutionResult() { + } + + public ExecutionResult(String resultName) { + this.resultName = resultName; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getResultName() { + return resultName; + } + + public void setResultName(String resultName) { + this.resultName = resultName; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepList() { + return executionStepList; + } + + public void setExecutionStepList(List executionStepList) { + this.executionStepList = executionStepList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof ExecutionResult)) { + return false; + } + ExecutionResult other = (ExecutionResult) object; + return this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.ExecutionResult[ id=" + id + " ]"; + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/ExecutionStep.java b/VM-Core/src/main/java/com/validation/manager/core/db/ExecutionStep.java index 7d83e548..f3570a21 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/ExecutionStep.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/ExecutionStep.java @@ -13,365 +13,365 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; -import javax.persistence.JoinTable; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "execution_step") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "ExecutionStep.findAll", - query = "SELECT e FROM ExecutionStep e") - , @NamedQuery(name = "ExecutionStep.findByTestCaseExecutionId", - query = "SELECT e FROM ExecutionStep e WHERE e.executionStepPK.testCaseExecutionId = :testCaseExecutionId") - , @NamedQuery(name = "ExecutionStep.findByStepId", - query = "SELECT e FROM ExecutionStep e WHERE e.executionStepPK.stepId = :stepId") - , @NamedQuery(name = "ExecutionStep.findByStepTestCaseId", - query = "SELECT e FROM ExecutionStep e WHERE e.executionStepPK.stepTestCaseId = :stepTestCaseId") - , @NamedQuery(name = "ExecutionStep.findByExecutionTime", - query = "SELECT e FROM ExecutionStep e WHERE e.executionTime = :executionTime") - , @NamedQuery(name = "ExecutionStep.findByExecutionStart", - query = "SELECT e FROM ExecutionStep e WHERE e.executionStart = :executionStart") - , @NamedQuery(name = "ExecutionStep.findByExecutionEnd", - query = "SELECT e FROM ExecutionStep e WHERE e.executionEnd = :executionEnd") - , @NamedQuery(name = "ExecutionStep.findByAssignedTime", - query = "SELECT e FROM ExecutionStep e WHERE e.assignedTime = :assignedTime") - , @NamedQuery(name = "ExecutionStep.findByLocked", - query = "SELECT e FROM ExecutionStep e WHERE e.locked = :locked") - , @NamedQuery(name = "ExecutionStep.findByReviewed", - query = "SELECT e FROM ExecutionStep e WHERE e.reviewed = :reviewed")}) -public class ExecutionStep implements Serializable { - - private static final long serialVersionUID = 1L; - @EmbeddedId - protected ExecutionStepPK executionStepPK; - // @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation - @Column(name = "execution_time") - private Double executionTime; - @Lob - @Size(max = 2147483647) - @Column(name = "comment") - private String comment; - @Column(name = "execution_start") - @Temporal(TemporalType.TIMESTAMP) - private Date executionStart; - @Column(name = "execution_end") - @Temporal(TemporalType.TIMESTAMP) - private Date executionEnd; - @Column(name = "review_date") - @Temporal(TemporalType.TIMESTAMP) - private Date reviewDate; - @Column(name = "assigned_time") - @Temporal(TemporalType.TIMESTAMP) - private Date assignedTime; - @Basic(optional = false) - @NotNull - @Column(name = "locked") - private boolean locked; - @Basic(optional = false) - @NotNull - @Column(name = "reviewed") - private boolean reviewed; - @JoinColumn(name = "result_id", referencedColumnName = "id") - @ManyToOne - private ExecutionResult resultId; - @JoinColumn(name = "review_result_id", referencedColumnName = "id") - @ManyToOne - private ReviewResult reviewResultId; - @JoinColumn(name = "assignee", referencedColumnName = "id") - @ManyToOne - private VmUser assignee; - @JoinColumn(name = "assigner", referencedColumnName = "id") - @ManyToOne - private VmUser assigner; - @JoinColumn(name = "reviewer", referencedColumnName = "id") - @ManyToOne - private VmUser reviewer; - @JoinColumns({ - @JoinColumn(name = "step_id", referencedColumnName = "id", - insertable = false, updatable = false) - , @JoinColumn(name = "step_test_case_id", - referencedColumnName = "test_case_id", insertable = false, - updatable = false)}) - @ManyToOne(optional = false) - private Step step; - @JoinColumn(name = "test_case_execution_id", referencedColumnName = "id", - insertable = false, updatable = false) - @ManyToOne(optional = false) - private TestCaseExecution testCaseExecution; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "executionStep") - private List executionStepHasAttachmentList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "executionStep") - private List executionStepHasIssueList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "executionStep") - private List executionStepHasVmUserList; - @JoinTable(name = "execution_step_has_history", joinColumns = { - @JoinColumn(name = "execution_step_test_case_execution_id", referencedColumnName = "test_case_execution_id") - , @JoinColumn(name = "execution_step_step_id", referencedColumnName = "step_id") - , @JoinColumn(name = "execution_step_step_test_case_id", referencedColumnName = "step_test_case_id")}, inverseJoinColumns = { - @JoinColumn(name = "history_id", referencedColumnName = "id")}) - @ManyToMany - private List historyList; - @JoinColumn(name = "step_history", referencedColumnName = "id") - @ManyToOne(optional = false) - private History stepHistory; - - public ExecutionStep() { - } - - public ExecutionStep(ExecutionStepPK executionStepPK) { - this.executionStepPK = executionStepPK; - } - - public ExecutionStep(ExecutionStepPK executionStepPK, boolean locked, boolean reviewed) { - this.executionStepPK = executionStepPK; - this.locked = locked; - this.reviewed = reviewed; - } - - public ExecutionStep(int testCaseExecutionId, int stepId, int stepTestCaseId) { - this.executionStepPK = new ExecutionStepPK(testCaseExecutionId, - stepId, stepTestCaseId); - } - - public ExecutionStepPK getExecutionStepPK() { - return executionStepPK; - } - - public void setExecutionStepPK(ExecutionStepPK executionStepPK) { - this.executionStepPK = executionStepPK; - } - - public Double getExecutionTime() { - return executionTime; - } - - public void setExecutionTime(Double executionTime) { - this.executionTime = executionTime; - } - - public String getComment() { - return comment; - } - - public void setComment(String comment) { - this.comment = comment; - } - - public Date getExecutionStart() { - return executionStart; - } - - public void setExecutionStart(Date executionStart) { - this.executionStart = executionStart; - } - - public Date getExecutionEnd() { - return executionEnd; - } - - public void setExecutionEnd(Date executionEnd) { - this.executionEnd = executionEnd; - } - - public Date getAssignedTime() { - return assignedTime; - } - - public void setAssignedTime(Date assignedTime) { - this.assignedTime = assignedTime; - } - - public boolean getLocked() { - return locked; - } - - public void setLocked(boolean locked) { - this.locked = locked; - } - - public boolean getReviewed() { - return reviewed; - } - - public void setReviewed(boolean reviewed) { - this.reviewed = reviewed; - } - - public ExecutionResult getResultId() { - return resultId; - } - - public void setResultId(ExecutionResult resultId) { - this.resultId = resultId; - } - - public ReviewResult getReviewResultId() { - return reviewResultId; - } - - public void setReviewResultId(ReviewResult reviewResultId) { - this.reviewResultId = reviewResultId; - } - - public VmUser getAssignee() { - return assignee; - } - - public void setAssignee(VmUser assignee) { - this.assignee = assignee; - } - - public VmUser getAssigner() { - return assigner; - } - - public void setAssigner(VmUser assigner) { - this.assigner = assigner; - } - - public Step getStep() { - return step; - } - - public void setStep(Step step) { - this.step = step; - } - - public TestCaseExecution getTestCaseExecution() { - return testCaseExecution; - } - - public void setTestCaseExecution(TestCaseExecution testCaseExecution) { - this.testCaseExecution = testCaseExecution; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepHasAttachmentList() { - return executionStepHasAttachmentList; - } - - public void setExecutionStepHasAttachmentList(List executionStepHasAttachmentList) { - this.executionStepHasAttachmentList = executionStepHasAttachmentList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (executionStepPK != null ? executionStepPK.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof ExecutionStep)) { - return false; - } - ExecutionStep other = (ExecutionStep) object; - return !((this.executionStepPK == null && other.executionStepPK != null) - || (this.executionStepPK != null - && !this.executionStepPK.equals(other.executionStepPK))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.ExecutionStep[ executionStepPK=" + executionStepPK + " ]"; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepHasIssueList() { - return executionStepHasIssueList; - } - - public void setExecutionStepHasIssueList(List executionStepHasIssueList) { - this.executionStepHasIssueList = executionStepHasIssueList; - } - - /** - * @return the reviewDate - */ - public Date getReviewDate() { - return reviewDate; - } - - /** - * @param reviewDate the reviewDate to set - */ - public void setReviewDate(Date reviewDate) { - this.reviewDate = reviewDate; - } - - /** - * @return the reviewer - */ - public VmUser getReviewer() { - return reviewer; - } - - /** - * @param reviewer the reviewer to set - */ - public void setReviewer(VmUser reviewer) { - this.reviewer = reviewer; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepHasVmUserList() { - return executionStepHasVmUserList; - } - - public void setExecutionStepHasVmUserList(List executionStepHasVmUserList) { - this.executionStepHasVmUserList = executionStepHasVmUserList; - } - - @XmlTransient - @JsonIgnore - public List getHistoryList() { - return historyList; - } - - public void setHistoryList(List historyList) { - this.historyList = historyList; - } - - public History getStepHistory() { - return stepHistory; - } - - public void setStepHistory(History stepHistory) { - this.stepHistory = stepHistory; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "execution_step") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "ExecutionStep.findAll", + query = "SELECT e FROM ExecutionStep e") + , @NamedQuery(name = "ExecutionStep.findByTestCaseExecutionId", + query = "SELECT e FROM ExecutionStep e WHERE e.executionStepPK.testCaseExecutionId = :testCaseExecutionId") + , @NamedQuery(name = "ExecutionStep.findByStepId", + query = "SELECT e FROM ExecutionStep e WHERE e.executionStepPK.stepId = :stepId") + , @NamedQuery(name = "ExecutionStep.findByStepTestCaseId", + query = "SELECT e FROM ExecutionStep e WHERE e.executionStepPK.stepTestCaseId = :stepTestCaseId") + , @NamedQuery(name = "ExecutionStep.findByExecutionTime", + query = "SELECT e FROM ExecutionStep e WHERE e.executionTime = :executionTime") + , @NamedQuery(name = "ExecutionStep.findByExecutionStart", + query = "SELECT e FROM ExecutionStep e WHERE e.executionStart = :executionStart") + , @NamedQuery(name = "ExecutionStep.findByExecutionEnd", + query = "SELECT e FROM ExecutionStep e WHERE e.executionEnd = :executionEnd") + , @NamedQuery(name = "ExecutionStep.findByAssignedTime", + query = "SELECT e FROM ExecutionStep e WHERE e.assignedTime = :assignedTime") + , @NamedQuery(name = "ExecutionStep.findByLocked", + query = "SELECT e FROM ExecutionStep e WHERE e.locked = :locked") + , @NamedQuery(name = "ExecutionStep.findByReviewed", + query = "SELECT e FROM ExecutionStep e WHERE e.reviewed = :reviewed")}) +public class ExecutionStep implements Serializable { + + private static final long serialVersionUID = 1L; + @EmbeddedId + protected ExecutionStepPK executionStepPK; + // @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation + @Column(name = "execution_time") + private Double executionTime; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "comment") + private String comment; + @Column(name = "execution_start") + @Temporal(TemporalType.TIMESTAMP) + private Date executionStart; + @Column(name = "execution_end") + @Temporal(TemporalType.TIMESTAMP) + private Date executionEnd; + @Column(name = "review_date") + @Temporal(TemporalType.TIMESTAMP) + private Date reviewDate; + @Column(name = "assigned_time") + @Temporal(TemporalType.TIMESTAMP) + private Date assignedTime; + @Basic(optional = false) + @NotNull + @Column(name = "locked") + private boolean locked; + @Basic(optional = false) + @NotNull + @Column(name = "reviewed") + private boolean reviewed; + @JoinColumn(name = "result_id", referencedColumnName = "id") + @ManyToOne + private ExecutionResult resultId; + @JoinColumn(name = "review_result_id", referencedColumnName = "id") + @ManyToOne + private ReviewResult reviewResultId; + @JoinColumn(name = "assignee", referencedColumnName = "id") + @ManyToOne + private VmUser assignee; + @JoinColumn(name = "assigner", referencedColumnName = "id") + @ManyToOne + private VmUser assigner; + @JoinColumn(name = "reviewer", referencedColumnName = "id") + @ManyToOne + private VmUser reviewer; + @JoinColumns({ + @JoinColumn(name = "step_id", referencedColumnName = "id", + insertable = false, updatable = false) + , @JoinColumn(name = "step_test_case_id", + referencedColumnName = "test_case_id", insertable = false, + updatable = false)}) + @ManyToOne(optional = false) + private Step step; + @JoinColumn(name = "test_case_execution_id", referencedColumnName = "id", + insertable = false, updatable = false) + @ManyToOne(optional = false) + private TestCaseExecution testCaseExecution; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "executionStep") + private List executionStepHasAttachmentList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "executionStep") + private List executionStepHasIssueList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "executionStep") + private List executionStepHasVmUserList; + @JoinTable(name = "execution_step_has_history", joinColumns = { + @JoinColumn(name = "execution_step_test_case_execution_id", referencedColumnName = "test_case_execution_id") + , @JoinColumn(name = "execution_step_step_id", referencedColumnName = "step_id") + , @JoinColumn(name = "execution_step_step_test_case_id", referencedColumnName = "step_test_case_id")}, inverseJoinColumns = { + @JoinColumn(name = "history_id", referencedColumnName = "id")}) + @ManyToMany + private List historyList; + @JoinColumn(name = "step_history", referencedColumnName = "id") + @ManyToOne(optional = false) + private History stepHistory; + + public ExecutionStep() { + } + + public ExecutionStep(ExecutionStepPK executionStepPK) { + this.executionStepPK = executionStepPK; + } + + public ExecutionStep(ExecutionStepPK executionStepPK, boolean locked, boolean reviewed) { + this.executionStepPK = executionStepPK; + this.locked = locked; + this.reviewed = reviewed; + } + + public ExecutionStep(int testCaseExecutionId, int stepId, int stepTestCaseId) { + this.executionStepPK = new ExecutionStepPK(testCaseExecutionId, + stepId, stepTestCaseId); + } + + public ExecutionStepPK getExecutionStepPK() { + return executionStepPK; + } + + public void setExecutionStepPK(ExecutionStepPK executionStepPK) { + this.executionStepPK = executionStepPK; + } + + public Double getExecutionTime() { + return executionTime; + } + + public void setExecutionTime(Double executionTime) { + this.executionTime = executionTime; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public Date getExecutionStart() { + return executionStart; + } + + public void setExecutionStart(Date executionStart) { + this.executionStart = executionStart; + } + + public Date getExecutionEnd() { + return executionEnd; + } + + public void setExecutionEnd(Date executionEnd) { + this.executionEnd = executionEnd; + } + + public Date getAssignedTime() { + return assignedTime; + } + + public void setAssignedTime(Date assignedTime) { + this.assignedTime = assignedTime; + } + + public boolean getLocked() { + return locked; + } + + public void setLocked(boolean locked) { + this.locked = locked; + } + + public boolean getReviewed() { + return reviewed; + } + + public void setReviewed(boolean reviewed) { + this.reviewed = reviewed; + } + + public ExecutionResult getResultId() { + return resultId; + } + + public void setResultId(ExecutionResult resultId) { + this.resultId = resultId; + } + + public ReviewResult getReviewResultId() { + return reviewResultId; + } + + public void setReviewResultId(ReviewResult reviewResultId) { + this.reviewResultId = reviewResultId; + } + + public VmUser getAssignee() { + return assignee; + } + + public void setAssignee(VmUser assignee) { + this.assignee = assignee; + } + + public VmUser getAssigner() { + return assigner; + } + + public void setAssigner(VmUser assigner) { + this.assigner = assigner; + } + + public Step getStep() { + return step; + } + + public void setStep(Step step) { + this.step = step; + } + + public TestCaseExecution getTestCaseExecution() { + return testCaseExecution; + } + + public void setTestCaseExecution(TestCaseExecution testCaseExecution) { + this.testCaseExecution = testCaseExecution; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepHasAttachmentList() { + return executionStepHasAttachmentList; + } + + public void setExecutionStepHasAttachmentList(List executionStepHasAttachmentList) { + this.executionStepHasAttachmentList = executionStepHasAttachmentList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (executionStepPK != null ? executionStepPK.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof ExecutionStep)) { + return false; + } + ExecutionStep other = (ExecutionStep) object; + return !((this.executionStepPK == null && other.executionStepPK != null) + || (this.executionStepPK != null + && !this.executionStepPK.equals(other.executionStepPK))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.ExecutionStep[ executionStepPK=" + executionStepPK + " ]"; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepHasIssueList() { + return executionStepHasIssueList; + } + + public void setExecutionStepHasIssueList(List executionStepHasIssueList) { + this.executionStepHasIssueList = executionStepHasIssueList; + } + + /** + * @return the reviewDate + */ + public Date getReviewDate() { + return reviewDate; + } + + /** + * @param reviewDate the reviewDate to set + */ + public void setReviewDate(Date reviewDate) { + this.reviewDate = reviewDate; + } + + /** + * @return the reviewer + */ + public VmUser getReviewer() { + return reviewer; + } + + /** + * @param reviewer the reviewer to set + */ + public void setReviewer(VmUser reviewer) { + this.reviewer = reviewer; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepHasVmUserList() { + return executionStepHasVmUserList; + } + + public void setExecutionStepHasVmUserList(List executionStepHasVmUserList) { + this.executionStepHasVmUserList = executionStepHasVmUserList; + } + + @XmlTransient + @JsonIgnore + public List getHistoryList() { + return historyList; + } + + public void setHistoryList(List historyList) { + this.historyList = historyList; + } + + public History getStepHistory() { + return stepHistory; + } + + public void setStepHistory(History stepHistory) { + this.stepHistory = stepHistory; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/FailureMode.java b/VM-Core/src/main/java/com/validation/manager/core/db/FailureMode.java index 0da6dbee..4b1714cd 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/FailureMode.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/FailureMode.java @@ -13,140 +13,140 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "failure_mode") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "FailureMode.findAll", - query = "SELECT f FROM FailureMode f") - , @NamedQuery(name = "FailureMode.findById", - query = "SELECT f FROM FailureMode f WHERE f.id = :id") - , @NamedQuery(name = "FailureMode.findByName", - query = "SELECT f FROM FailureMode f WHERE f.name = :name")}) -public class FailureMode implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.TABLE, generator = "FMGen") - @TableGenerator(name = "FMGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "failure_mode", - allocationSize = 1, - initialValue = 1000) - @Basic(optional = false) - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Basic(optional = false) - @NotNull - @Lob - @Size(min = 1, max = 65535) - @Column(name = "description") - private String description; - @JoinTable(name = "risk_item_has_failure_mode", joinColumns = { - @JoinColumn(name = "failure_mode_id", referencedColumnName = "id")}, - inverseJoinColumns = { - @JoinColumn(name = "risk_item_id", referencedColumnName = "id") - , @JoinColumn(name = "risk_item_FMEA_id", - referencedColumnName = "FMEA_id")}) - @ManyToMany - private List riskItemList; - - public FailureMode() { - } - - public FailureMode(String name, String description) { - this.name = name; - this.description = description; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getRiskItemList() { - return riskItemList; - } - - public void setRiskItemList(List riskItemList) { - this.riskItemList = riskItemList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof FailureMode)) { - return false; - } - FailureMode other = (FailureMode) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.FailureMode[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "failure_mode") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "FailureMode.findAll", + query = "SELECT f FROM FailureMode f") + , @NamedQuery(name = "FailureMode.findById", + query = "SELECT f FROM FailureMode f WHERE f.id = :id") + , @NamedQuery(name = "FailureMode.findByName", + query = "SELECT f FROM FailureMode f WHERE f.name = :name")}) +public class FailureMode implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.TABLE, generator = "FMGen") + @TableGenerator(name = "FMGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "failure_mode", + allocationSize = 1, + initialValue = 1_000) + @Basic(optional = false) + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Basic(optional = false) + @NotNull + @Lob + @Size(min = 1, max = 65_535) + @Column(name = "description") + private String description; + @JoinTable(name = "risk_item_has_failure_mode", joinColumns = { + @JoinColumn(name = "failure_mode_id", referencedColumnName = "id")}, + inverseJoinColumns = { + @JoinColumn(name = "risk_item_id", referencedColumnName = "id") + , @JoinColumn(name = "risk_item_FMEA_id", + referencedColumnName = "FMEA_id")}) + @ManyToMany + private List riskItemList; + + public FailureMode() { + } + + public FailureMode(String name, String description) { + this.name = name; + this.description = description; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getRiskItemList() { + return riskItemList; + } + + public void setRiskItemList(List riskItemList) { + this.riskItemList = riskItemList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof FailureMode)) { + return false; + } + FailureMode other = (FailureMode) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.FailureMode[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/Fmea.java b/VM-Core/src/main/java/com/validation/manager/core/db/Fmea.java index edd94860..d0472f58 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/Fmea.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/Fmea.java @@ -13,172 +13,172 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "fmea") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Fmea.findAll", query = "SELECT f FROM Fmea f") - , @NamedQuery(name = "Fmea.findById", query = "SELECT f FROM Fmea f " - + "WHERE f.id = :id") - , @NamedQuery(name = "Fmea.findByName", query = "SELECT f FROM Fmea f " - + "WHERE f.name = :name") - , @NamedQuery(name = "Fmea.findByDescription", query = "SELECT f FROM " - + "Fmea f WHERE f.description = :description")}) -public class Fmea implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @NotNull - @GeneratedValue(strategy = GenerationType.TABLE, generator = "FMEAGen") - @TableGenerator(name = "FMEAGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "fmea", - allocationSize = 1, - initialValue = 1000) - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "name") - private String name; - @Size(max = 45) - @Column(name = "description") - private String description; - @JoinTable(name = "fmea_has_risk_category", joinColumns = { - @JoinColumn(name = "FMEA_id", referencedColumnName = "id")}, - inverseJoinColumns = { - @JoinColumn(name = "risk_category_id", referencedColumnName = "id")}) - @ManyToMany - private List riskCategoryList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "fmea") - private List riskItemList; - @OneToMany(mappedBy = "parent") - private List fmeaList; - @JoinColumn(name = "parent", referencedColumnName = "id") - @ManyToOne - private Fmea parent; - - public Fmea() { - } - - public Fmea(String name) { - this.name = name; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getRiskCategoryList() { - return riskCategoryList; - } - - public void setRiskCategoryList(List riskCategoryList) { - this.riskCategoryList = riskCategoryList; - } - - @XmlTransient - @JsonIgnore - public List getRiskItemList() { - return riskItemList; - } - - public void setRiskItemList(List riskItemList) { - this.riskItemList = riskItemList; - } - - @XmlTransient - @JsonIgnore - public List getFmeaList() { - return fmeaList; - } - - public void setFmeaList(List fmeaList) { - this.fmeaList = fmeaList; - } - - public Fmea getParent() { - return parent; - } - - public void setParent(Fmea parent) { - this.parent = parent; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof Fmea)) { - return false; - } - Fmea other = (Fmea) object; - return this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.Fmea[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "fmea") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Fmea.findAll", query = "SELECT f FROM Fmea f") + , @NamedQuery(name = "Fmea.findById", query = "SELECT f FROM Fmea f " + + "WHERE f.id = :id") + , @NamedQuery(name = "Fmea.findByName", query = "SELECT f FROM Fmea f " + + "WHERE f.name = :name") + , @NamedQuery(name = "Fmea.findByDescription", query = "SELECT f FROM " + + "Fmea f WHERE f.description = :description")}) +public class Fmea implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @NotNull + @GeneratedValue(strategy = GenerationType.TABLE, generator = "FMEAGen") + @TableGenerator(name = "FMEAGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "fmea", + allocationSize = 1, + initialValue = 1_000) + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "name") + private String name; + @Size(max = 45) + @Column(name = "description") + private String description; + @JoinTable(name = "fmea_has_risk_category", joinColumns = { + @JoinColumn(name = "FMEA_id", referencedColumnName = "id")}, + inverseJoinColumns = { + @JoinColumn(name = "risk_category_id", referencedColumnName = "id")}) + @ManyToMany + private List riskCategoryList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "fmea") + private List riskItemList; + @OneToMany(mappedBy = "parent") + private List fmeaList; + @JoinColumn(name = "parent", referencedColumnName = "id") + @ManyToOne + private Fmea parent; + + public Fmea() { + } + + public Fmea(String name) { + this.name = name; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getRiskCategoryList() { + return riskCategoryList; + } + + public void setRiskCategoryList(List riskCategoryList) { + this.riskCategoryList = riskCategoryList; + } + + @XmlTransient + @JsonIgnore + public List getRiskItemList() { + return riskItemList; + } + + public void setRiskItemList(List riskItemList) { + this.riskItemList = riskItemList; + } + + @XmlTransient + @JsonIgnore + public List getFmeaList() { + return fmeaList; + } + + public void setFmeaList(List fmeaList) { + this.fmeaList = fmeaList; + } + + public Fmea getParent() { + return parent; + } + + public void setParent(Fmea parent) { + this.parent = parent; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof Fmea)) { + return false; + } + Fmea other = (Fmea) object; + return this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.Fmea[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/Hazard.java b/VM-Core/src/main/java/com/validation/manager/core/db/Hazard.java index 0c94bfae..1ce93ed3 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/Hazard.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/Hazard.java @@ -13,141 +13,141 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "hazard") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Hazard.findAll", - query = "SELECT h FROM Hazard h") - , @NamedQuery(name = "Hazard.findById", - query = "SELECT h FROM Hazard h WHERE h.id = :id") - , @NamedQuery(name = "Hazard.findByName", - query = "SELECT h FROM Hazard h WHERE h.name = :name")}) -public class Hazard implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "HazardGen") - @TableGenerator(name = "HazardGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "hazard", - allocationSize = 1, - initialValue = 1000) - @Basic(optional = false) - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Basic(optional = false) - @NotNull - @Lob - @Size(min = 1, max = 65535) - @Column(name = "description") - private String description; - @JoinTable(name = "risk_item_has_hazard", joinColumns = { - @JoinColumn(name = "hazard_id", referencedColumnName = "id")}, - inverseJoinColumns = { - @JoinColumn(name = "risk_item_id", referencedColumnName = "id") - , @JoinColumn(name = "risk_item_FMEA_id", - referencedColumnName = "FMEA_id")}) - @ManyToMany - private List riskItemList; - - public Hazard() { - } - - public Hazard(String name, String description) { - this.name = name; - this.description = description; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getRiskItemList() { - return riskItemList; - } - - public void setRiskItemList(List riskItemList) { - this.riskItemList = riskItemList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof Hazard)) { - return false; - } - Hazard other = (Hazard) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.Hazard[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "hazard") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Hazard.findAll", + query = "SELECT h FROM Hazard h") + , @NamedQuery(name = "Hazard.findById", + query = "SELECT h FROM Hazard h WHERE h.id = :id") + , @NamedQuery(name = "Hazard.findByName", + query = "SELECT h FROM Hazard h WHERE h.name = :name")}) +public class Hazard implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "HazardGen") + @TableGenerator(name = "HazardGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "hazard", + allocationSize = 1, + initialValue = 1_000) + @Basic(optional = false) + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Basic(optional = false) + @NotNull + @Lob + @Size(min = 1, max = 65_535) + @Column(name = "description") + private String description; + @JoinTable(name = "risk_item_has_hazard", joinColumns = { + @JoinColumn(name = "hazard_id", referencedColumnName = "id")}, + inverseJoinColumns = { + @JoinColumn(name = "risk_item_id", referencedColumnName = "id") + , @JoinColumn(name = "risk_item_FMEA_id", + referencedColumnName = "FMEA_id")}) + @ManyToMany + private List riskItemList; + + public Hazard() { + } + + public Hazard(String name, String description) { + this.name = name; + this.description = description; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getRiskItemList() { + return riskItemList; + } + + public void setRiskItemList(List riskItemList) { + this.riskItemList = riskItemList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof Hazard)) { + return false; + } + Hazard other = (Hazard) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.Hazard[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/History.java b/VM-Core/src/main/java/com/validation/manager/core/db/History.java index ef7f7f15..b9e98349 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/History.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/History.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,287 +13,300 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "history") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "History.findAll", - query = "SELECT h FROM History h") - , @NamedQuery(name = "History.findById", - query = "SELECT h FROM History h WHERE h.id = :id") - , @NamedQuery(name = "History.findByVersionMajor", - query = "SELECT h FROM History h WHERE h.versionMajor = :versionMajor") - , @NamedQuery(name = "History.findByVersionMid", - query = "SELECT h FROM History h WHERE h.versionMid = :versionMid") - , @NamedQuery(name = "History.findByVersionMinor", - query = "SELECT h FROM History h WHERE h.versionMinor = :versionMinor") - , @NamedQuery(name = "History.findByModificationTime", - query = "SELECT h FROM History h WHERE h.modificationTime = :modificationTime")}) -public class History implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "History_IDGEN") - @TableGenerator(name = "History_IDGEN", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "history", - initialValue = 1, - allocationSize = 1) - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Column(name = "version_major") - private int versionMajor = 0; - @Basic(optional = false) - @NotNull - @Column(name = "version_mid") - private int versionMid = 0; - @Basic(optional = false) - @NotNull - @Column(name = "version_minor") - private int versionMinor = 1; - @Basic(optional = false) - @NotNull - @Lob - @Size(min = 1, max = 2147483647) - @Column(name = "reason") - private String reason; - @Basic(optional = false) - @NotNull - @Column(name = "modification_time") - @Temporal(TemporalType.TIMESTAMP) - private Date modificationTime; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "history") - private List historyFieldList; - @JoinColumn(name = "modifier_id", referencedColumnName = "id") - @ManyToOne(optional = false) - private VmUser modifierId; - @ManyToMany(mappedBy = "historyList") - private List executionStepList; - @ManyToMany(mappedBy = "historyList") - private List baselineList; - @JoinColumn(name = "requirement_id", referencedColumnName = "id") - @ManyToOne(optional = true) - private Requirement requirementId; - @JoinColumn(name = "project_id", referencedColumnName = "id") - @ManyToOne(optional = false) - private Project projectId; - @JoinColumns({ - @JoinColumn(name = "step_id", referencedColumnName = "id") - , @JoinColumn(name = "step_test_case_id", - referencedColumnName = "test_case_id")}) - @ManyToOne(optional = false) - private Step step; - @JoinColumn(name = "vm_setting_id", referencedColumnName = "id") - @ManyToOne(optional = false) - private VmSetting vmSettingId; - - public History() { - } - - public History(Integer id) { - this.id = id; - } - - public History(Integer id, int versionMajor, int versionMid, - int versionMinor, String reason, Date modificationTime) { - this.id = id; - this.versionMajor = versionMajor; - this.versionMid = versionMid; - this.versionMinor = versionMinor; - this.reason = reason; - this.modificationTime = modificationTime; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public int getMajorVersion() { - return versionMajor; - } - - public void setMajorVersion(int versionMajor) { - this.versionMajor = versionMajor; - } - - public int getMidVersion() { - return versionMid; - } - - public void setMidVersion(int versionMid) { - this.versionMid = versionMid; - } - - public int getMinorVersion() { - return versionMinor; - } - - public void setMinorVersion(int versionMinor) { - this.versionMinor = versionMinor; - } - - public String getReason() { - return reason; - } - - public void setReason(String reason) { - this.reason = reason; - } - - public Date getModificationTime() { - return modificationTime; - } - - public void setModificationTime(Date modificationTime) { - this.modificationTime = modificationTime; - } - - @XmlTransient - @JsonIgnore - public List getHistoryFieldList() { - return historyFieldList; - } - - public void setHistoryFieldList(List historyFieldList) { - this.historyFieldList = historyFieldList; - } - - public VmUser getModifierId() { - return modifierId; - } - - public void setModifierId(VmUser modifierId) { - this.modifierId = modifierId; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof History)) { - return false; - } - History other = (History) object; - return !((this.id == null && other.id != null) || (this.id != null - && !this.id.equals(other.id))); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("Fields: "); - getHistoryFieldList().forEach(hf -> { - if (!sb.toString().isEmpty()) { - sb.append(", "); - } - sb.append(hf.getFieldName()) - .append("= ") - .append(hf.getFieldValue()); - }); - return "History{" + "id=" + id + ", versionMajor=" + versionMajor - + ", versionMid=" + versionMid + ", versionMinor=" - + versionMinor + ", reason=" + reason + ", modificationTime=" - + modificationTime + ", modifierId=" + modifierId - + "," + sb.toString() + '}'; - } - - @XmlTransient - @JsonIgnore - public List getBaselineList() { - return baselineList; - } - - public void setBaselineList(List baselineList) { - this.baselineList = baselineList; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepList() { - return executionStepList; - } - - public void setExecutionStepList(List executionStepList) { - this.executionStepList = executionStepList; - } - - public Requirement getRequirementId() { - return requirementId; - } - - public void setRequirementId(Requirement requirement) { - this.requirementId = requirement; - } - - public Project getProjectId() { - return projectId; - } - - public void setProjectId(Project projectId) { - this.projectId = projectId; - } - - public Step getStep() { - return step; - } - - public void setStep(Step step) { - this.step = step; - } - - public VmSetting getVmSettingId() { - return vmSettingId; - } - - public void setVmSettingId(VmSetting vmSettingId) { - this.vmSettingId = vmSettingId; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "history") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "History.findAll", + query = "SELECT h FROM History h") + , @NamedQuery(name = "History.findById", + query = "SELECT h FROM History h WHERE h.id = :id") + , @NamedQuery(name = "History.findByVersionMajor", + query = "SELECT h FROM History h WHERE h.versionMajor = :versionMajor") + , @NamedQuery(name = "History.findByVersionMid", + query = "SELECT h FROM History h WHERE h.versionMid = :versionMid") + , @NamedQuery(name = "History.findByVersionMinor", + query = "SELECT h FROM History h WHERE h.versionMinor = :versionMinor") + , @NamedQuery(name = "History.findByModificationTime", + query = "SELECT h FROM History h WHERE h.modificationTime = :modificationTime")}) +public class History implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "History_IDGEN") + @TableGenerator(name = "History_IDGEN", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "history", + initialValue = 1, + allocationSize = 1) + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Column(name = "version_major") + private int versionMajor = 0; + @Basic(optional = false) + @NotNull + @Column(name = "version_mid") + private int versionMid = 0; + @Basic(optional = false) + @NotNull + @Column(name = "version_minor") + private int versionMinor = 1; + @Basic(optional = false) + @NotNull + @Lob + @Size(min = 1, max = 2_147_483_647) + @Column(name = "reason") + private String reason; + @Basic(optional = false) + @NotNull + @Column(name = "modification_time") + @Temporal(TemporalType.TIMESTAMP) + private Date modificationTime; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "history") + private List historyFieldList; + @JoinColumn(name = "modifier_id", referencedColumnName = "id") + @ManyToOne(optional = false) + private VmUser modifierId; + @ManyToMany(mappedBy = "historyList") + private List executionStepList; + @ManyToMany(mappedBy = "historyList") + private List baselineList; + @JoinColumn(name = "requirement_id", referencedColumnName = "id") + @ManyToOne(optional = true) + private Requirement requirementId; + @JoinColumn(name = "project_id", referencedColumnName = "id") + @ManyToOne(optional = false) + private Project projectId; + @JoinColumns({ + @JoinColumn(name = "step_id", referencedColumnName = "id") + , @JoinColumn(name = "step_test_case_id", + referencedColumnName = "test_case_id")}) + @ManyToOne(optional = false) + private Step step; + @JoinColumn(name = "vm_setting_id", referencedColumnName = "id") + @ManyToOne(optional = false) + private VmSetting vmSettingId; + @JoinColumn(name = "vm_user_id", referencedColumnName = "id") + @ManyToOne(optional = false) + private VmUser vmUserId; + + public History() { + } + + public History(Integer id) { + this.id = id; + } + + public History(Integer id, int versionMajor, int versionMid, + int versionMinor, String reason, Date modificationTime) { + this.id = id; + this.versionMajor = versionMajor; + this.versionMid = versionMid; + this.versionMinor = versionMinor; + this.reason = reason; + this.modificationTime = modificationTime; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public int getMajorVersion() { + return versionMajor; + } + + public void setMajorVersion(int versionMajor) { + this.versionMajor = versionMajor; + } + + public int getMidVersion() { + return versionMid; + } + + public void setMidVersion(int versionMid) { + this.versionMid = versionMid; + } + + public int getMinorVersion() { + return versionMinor; + } + + public void setMinorVersion(int versionMinor) { + this.versionMinor = versionMinor; + } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public Date getModificationTime() { + return modificationTime; + } + + public void setModificationTime(Date modificationTime) { + this.modificationTime = modificationTime; + } + + @XmlTransient + @JsonIgnore + public List getHistoryFieldList() { + return historyFieldList; + } + + public void setHistoryFieldList(List historyFieldList) { + this.historyFieldList = historyFieldList; + } + + public VmUser getModifierId() { + return modifierId; + } + + public void setModifierId(VmUser modifierId) { + this.modifierId = modifierId; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof History)) { + return false; + } + History other = (History) object; + return !((this.id == null && other.id != null) || (this.id != null + && !this.id.equals(other.id))); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + getHistoryFieldList().forEach(hf -> { + if (sb.toString().isEmpty()) { + sb.append("Fields: "); + } else { + sb.append(", "); + } + sb.append(hf.getFieldName()) + .append("= ") + .append(hf.getFieldValue()); + }); + return "History{" + "id=" + id + ", versionMajor=" + versionMajor + + ", versionMid=" + versionMid + ", versionMinor=" + + versionMinor + ", reason=" + reason + ", modificationTime=" + + modificationTime + ", modifierId=" + modifierId + + "," + sb.toString() + '}'; + } + + @XmlTransient + @JsonIgnore + public List getBaselineList() { + return baselineList; + } + + public void setBaselineList(List baselineList) { + this.baselineList = baselineList; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepList() { + return executionStepList; + } + + public void setExecutionStepList(List executionStepList) { + this.executionStepList = executionStepList; + } + + public Requirement getRequirementId() { + return requirementId; + } + + public void setRequirementId(Requirement requirement) { + this.requirementId = requirement; + } + + public Project getProjectId() { + return projectId; + } + + public void setProjectId(Project projectId) { + this.projectId = projectId; + } + + public Step getStep() { + return step; + } + + public void setStep(Step step) { + this.step = step; + } + + public VmSetting getVmSettingId() { + return vmSettingId; + } + + public void setVmSettingId(VmSetting vmSettingId) { + this.vmSettingId = vmSettingId; + } + + public VmUser getVmUserId() { + return vmUserId; + } + + public void setVmUserId(VmUser vmUserId) { + this.vmUserId = vmUserId; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/HistoryField.java b/VM-Core/src/main/java/com/validation/manager/core/db/HistoryField.java index 684f2ea6..ca34b2f1 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/HistoryField.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/HistoryField.java @@ -13,146 +13,146 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "history_field") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "HistoryField.findAll", - query = "SELECT h FROM HistoryField h") - , @NamedQuery(name = "HistoryField.findById", - query = "SELECT h FROM HistoryField h WHERE h.historyFieldPK.id = :id") - , @NamedQuery(name = "HistoryField.findByFieldTypeId", - query = "SELECT h FROM HistoryField h WHERE h.historyFieldPK.fieldTypeId = :fieldTypeId") - , @NamedQuery(name = "HistoryField.findByHistoryId", - query = "SELECT h FROM HistoryField h WHERE h.historyFieldPK.historyId = :historyId") - , @NamedQuery(name = "HistoryField.findByFieldName", - query = "SELECT h FROM HistoryField h WHERE h.fieldName = :fieldName")}) -public class HistoryField implements Serializable { - - private static final long serialVersionUID = 1L; - @EmbeddedId - protected HistoryFieldPK historyFieldPK; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "field_name") - private String fieldName; - @Basic(optional = false) - @NotNull - @Lob - @Size(min = 1, max = 2147483647) - @Column(name = "field_value") - private String fieldValue; - @JoinColumn(name = "field_type_id", referencedColumnName = "id", - insertable = false, updatable = false) - @ManyToOne(optional = false) - private FieldType fieldType; - @JoinColumn(name = "history_id", referencedColumnName = "id", - insertable = false, updatable = false) - @ManyToOne(optional = false) - private History history; - - public HistoryField() { - } - - public HistoryField(HistoryFieldPK historyFieldPK) { - this.historyFieldPK = historyFieldPK; - } - - public HistoryField(HistoryFieldPK historyFieldPK, String fieldName, - String fieldValue) { - this.historyFieldPK = historyFieldPK; - this.fieldName = fieldName; - this.fieldValue = fieldValue; - } - - public HistoryField(int fieldTypeId, int historyId) { - this.historyFieldPK = new HistoryFieldPK(fieldTypeId, historyId); - } - - public HistoryFieldPK getHistoryFieldPK() { - return historyFieldPK; - } - - public void setHistoryFieldPK(HistoryFieldPK historyFieldPK) { - this.historyFieldPK = historyFieldPK; - } - - public String getFieldName() { - return fieldName; - } - - public void setFieldName(String fieldName) { - this.fieldName = fieldName; - } - - public String getFieldValue() { - return fieldValue; - } - - public void setFieldValue(String fieldValue) { - this.fieldValue = fieldValue; - } - - public FieldType getFieldType() { - return fieldType; - } - - public void setFieldType(FieldType fieldType) { - this.fieldType = fieldType; - } - - public History getHistory() { - return history; - } - - public void setHistory(History history) { - this.history = history; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (historyFieldPK != null ? historyFieldPK.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof HistoryField)) { - return false; - } - HistoryField other = (HistoryField) object; - return !((this.historyFieldPK == null && other.historyFieldPK != null) - || (this.historyFieldPK != null - && !this.historyFieldPK.equals(other.historyFieldPK))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.HistoryField[ historyFieldPK=" - + historyFieldPK + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "history_field") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "HistoryField.findAll", + query = "SELECT h FROM HistoryField h") + , @NamedQuery(name = "HistoryField.findById", + query = "SELECT h FROM HistoryField h WHERE h.historyFieldPK.id = :id") + , @NamedQuery(name = "HistoryField.findByFieldTypeId", + query = "SELECT h FROM HistoryField h WHERE h.historyFieldPK.fieldTypeId = :fieldTypeId") + , @NamedQuery(name = "HistoryField.findByHistoryId", + query = "SELECT h FROM HistoryField h WHERE h.historyFieldPK.historyId = :historyId") + , @NamedQuery(name = "HistoryField.findByFieldName", + query = "SELECT h FROM HistoryField h WHERE h.fieldName = :fieldName")}) +public class HistoryField implements Serializable { + + private static final long serialVersionUID = 1L; + @EmbeddedId + protected HistoryFieldPK historyFieldPK; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "field_name") + private String fieldName; + @Basic(optional = false) + @NotNull + @Lob + @Size(min = 1, max = 2_147_483_647) + @Column(name = "field_value") + private String fieldValue; + @JoinColumn(name = "field_type_id", referencedColumnName = "id", + insertable = false, updatable = false) + @ManyToOne(optional = false) + private FieldType fieldType; + @JoinColumn(name = "history_id", referencedColumnName = "id", + insertable = false, updatable = false) + @ManyToOne(optional = false) + private History history; + + public HistoryField() { + } + + public HistoryField(HistoryFieldPK historyFieldPK) { + this.historyFieldPK = historyFieldPK; + } + + public HistoryField(HistoryFieldPK historyFieldPK, String fieldName, + String fieldValue) { + this.historyFieldPK = historyFieldPK; + this.fieldName = fieldName; + this.fieldValue = fieldValue; + } + + public HistoryField(int fieldTypeId, int historyId) { + this.historyFieldPK = new HistoryFieldPK(fieldTypeId, historyId); + } + + public HistoryFieldPK getHistoryFieldPK() { + return historyFieldPK; + } + + public void setHistoryFieldPK(HistoryFieldPK historyFieldPK) { + this.historyFieldPK = historyFieldPK; + } + + public String getFieldName() { + return fieldName; + } + + public void setFieldName(String fieldName) { + this.fieldName = fieldName; + } + + public String getFieldValue() { + return fieldValue; + } + + public void setFieldValue(String fieldValue) { + this.fieldValue = fieldValue; + } + + public FieldType getFieldType() { + return fieldType; + } + + public void setFieldType(FieldType fieldType) { + this.fieldType = fieldType; + } + + public History getHistory() { + return history; + } + + public void setHistory(History history) { + this.history = history; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (historyFieldPK != null ? historyFieldPK.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof HistoryField)) { + return false; + } + HistoryField other = (HistoryField) object; + return !((this.historyFieldPK == null && other.historyFieldPK != null) + || (this.historyFieldPK != null + && !this.historyFieldPK.equals(other.historyFieldPK))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.HistoryField[ historyFieldPK=" + + historyFieldPK + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/Investigation.java b/VM-Core/src/main/java/com/validation/manager/core/db/Investigation.java index 45d0a89f..7eb0c3c7 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/Investigation.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/Investigation.java @@ -13,130 +13,130 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "investigation") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Investigation.findAll", - query = "SELECT i FROM Investigation i") - , @NamedQuery(name = "Investigation.findById", - query = "SELECT i FROM Investigation i WHERE i.id = :id")}) -public class Investigation implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "InvestigationGen") - @TableGenerator(name = "InvestigationGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "investigation", - allocationSize = 1, - initialValue = 1000) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Lob - @Size(min = 1, max = 65535) - @Column(name = "description") - private String description; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "investigation") - private List userHasInvestigationList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "investigation") - private List exceptionHasInvestigationList; - - public Investigation() { - } - - public Investigation(String description) { - this.description = description; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getUserHasInvestigationList() { - return userHasInvestigationList; - } - - public void setUserHasInvestigationList(List userHasInvestigationList) { - this.userHasInvestigationList = userHasInvestigationList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof Investigation)) { - return false; - } - Investigation other = (Investigation) object; - return this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.Investigation[ id=" + id + " ]"; - } - - @XmlTransient - @JsonIgnore - public List getExceptionHasInvestigationList() { - return exceptionHasInvestigationList; - } - - public void setExceptionHasInvestigationList(List exceptionHasInvestigationList) { - this.exceptionHasInvestigationList = exceptionHasInvestigationList; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "investigation") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Investigation.findAll", + query = "SELECT i FROM Investigation i") + , @NamedQuery(name = "Investigation.findById", + query = "SELECT i FROM Investigation i WHERE i.id = :id")}) +public class Investigation implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "InvestigationGen") + @TableGenerator(name = "InvestigationGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "investigation", + allocationSize = 1, + initialValue = 1_000) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Lob + @Size(min = 1, max = 65_535) + @Column(name = "description") + private String description; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "investigation") + private List userHasInvestigationList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "investigation") + private List exceptionHasInvestigationList; + + public Investigation() { + } + + public Investigation(String description) { + this.description = description; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getUserHasInvestigationList() { + return userHasInvestigationList; + } + + public void setUserHasInvestigationList(List userHasInvestigationList) { + this.userHasInvestigationList = userHasInvestigationList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof Investigation)) { + return false; + } + Investigation other = (Investigation) object; + return this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.Investigation[ id=" + id + " ]"; + } + + @XmlTransient + @JsonIgnore + public List getExceptionHasInvestigationList() { + return exceptionHasInvestigationList; + } + + public void setExceptionHasInvestigationList(List exceptionHasInvestigationList) { + this.exceptionHasInvestigationList = exceptionHasInvestigationList; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/Issue.java b/VM-Core/src/main/java/com/validation/manager/core/db/Issue.java index bf097a94..1ba3108f 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/Issue.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/Issue.java @@ -13,176 +13,176 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "issue") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Issue.findAll", query = "SELECT i FROM Issue i") - , @NamedQuery(name = "Issue.findById", - query = "SELECT i FROM Issue i WHERE i.issuePK.id = :id") - , @NamedQuery(name = "Issue.findByIssueTypeId", - query = "SELECT i FROM Issue i WHERE i.issuePK.issueTypeId = :issueTypeId") - , @NamedQuery(name = "Issue.findByTitle", - query = "SELECT i FROM Issue i WHERE i.title = :title") - , @NamedQuery(name = "Issue.findByCreationTime", - query = "SELECT i FROM Issue i WHERE i.creationTime = :creationTime")}) -public class Issue implements Serializable { - - private static final long serialVersionUID = 1L; - @EmbeddedId - protected IssuePK issuePK; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "title") - private String title; - @Basic(optional = false) - @NotNull - @Lob - @Size(min = 1, max = 2147483647) - @Column(name = "description") - private String description; - @Basic(optional = false) - @NotNull - @Column(name = "creationTime") - @Temporal(TemporalType.TIMESTAMP) - private Date creationTime; - @JoinColumn(name = "issue_resolution_id", referencedColumnName = "id") - @ManyToOne(optional = false) - private IssueResolution issueResolutionId; - @JoinColumn(name = "issue_type_id", referencedColumnName = "id", - insertable = false, updatable = false) - @ManyToOne(optional = false) - private IssueType issueType; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "issue") - private List executionStepHasIssueList; - - public Issue() { - } - - public Issue(IssuePK issuePK) { - this.issuePK = issuePK; - } - - public Issue(IssuePK issuePK, String title, String description, - Date creationTime) { - this.issuePK = issuePK; - this.title = title; - this.description = description; - this.creationTime = creationTime; - } - - public Issue(int issueTypeId) { - this.issuePK = new IssuePK(issueTypeId); - } - - public IssuePK getIssuePK() { - return issuePK; - } - - public void setIssuePK(IssuePK issuePK) { - this.issuePK = issuePK; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Date getCreationTime() { - return creationTime; - } - - public void setCreationTime(Date creationTime) { - this.creationTime = creationTime; - } - - public IssueResolution getIssueResolutionId() { - return issueResolutionId; - } - - public void setIssueResolutionId(IssueResolution issueResolutionId) { - this.issueResolutionId = issueResolutionId; - } - - public IssueType getIssueType() { - return issueType; - } - - public void setIssueType(IssueType issueType) { - this.issueType = issueType; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepHasIssueList() { - return executionStepHasIssueList; - } - - public void setExecutionStepHasIssueList(List executionStepHasIssueList) { - this.executionStepHasIssueList = executionStepHasIssueList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (issuePK != null ? issuePK.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof Issue)) { - return false; - } - Issue other = (Issue) object; - return !((this.issuePK == null && other.issuePK != null) - || (this.issuePK != null && !this.issuePK.equals(other.issuePK))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.Issue[ issuePK=" + issuePK + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "issue") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Issue.findAll", query = "SELECT i FROM Issue i") + , @NamedQuery(name = "Issue.findById", + query = "SELECT i FROM Issue i WHERE i.issuePK.id = :id") + , @NamedQuery(name = "Issue.findByIssueTypeId", + query = "SELECT i FROM Issue i WHERE i.issuePK.issueTypeId = :issueTypeId") + , @NamedQuery(name = "Issue.findByTitle", + query = "SELECT i FROM Issue i WHERE i.title = :title") + , @NamedQuery(name = "Issue.findByCreationTime", + query = "SELECT i FROM Issue i WHERE i.creationTime = :creationTime")}) +public class Issue implements Serializable { + + private static final long serialVersionUID = 1L; + @EmbeddedId + protected IssuePK issuePK; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "title") + private String title; + @Basic(optional = false) + @NotNull + @Lob + @Size(min = 1, max = 2_147_483_647) + @Column(name = "description") + private String description; + @Basic(optional = false) + @NotNull + @Column(name = "creationTime") + @Temporal(TemporalType.TIMESTAMP) + private Date creationTime; + @JoinColumn(name = "issue_resolution_id", referencedColumnName = "id") + @ManyToOne(optional = false) + private IssueResolution issueResolutionId; + @JoinColumn(name = "issue_type_id", referencedColumnName = "id", + insertable = false, updatable = false) + @ManyToOne(optional = false) + private IssueType issueType; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "issue") + private List executionStepHasIssueList; + + public Issue() { + } + + public Issue(IssuePK issuePK) { + this.issuePK = issuePK; + } + + public Issue(IssuePK issuePK, String title, String description, + Date creationTime) { + this.issuePK = issuePK; + this.title = title; + this.description = description; + this.creationTime = creationTime; + } + + public Issue(int issueTypeId) { + this.issuePK = new IssuePK(issueTypeId); + } + + public IssuePK getIssuePK() { + return issuePK; + } + + public void setIssuePK(IssuePK issuePK) { + this.issuePK = issuePK; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getCreationTime() { + return creationTime; + } + + public void setCreationTime(Date creationTime) { + this.creationTime = creationTime; + } + + public IssueResolution getIssueResolutionId() { + return issueResolutionId; + } + + public void setIssueResolutionId(IssueResolution issueResolutionId) { + this.issueResolutionId = issueResolutionId; + } + + public IssueType getIssueType() { + return issueType; + } + + public void setIssueType(IssueType issueType) { + this.issueType = issueType; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepHasIssueList() { + return executionStepHasIssueList; + } + + public void setExecutionStepHasIssueList(List executionStepHasIssueList) { + this.executionStepHasIssueList = executionStepHasIssueList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (issuePK != null ? issuePK.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof Issue)) { + return false; + } + Issue other = (Issue) object; + return !((this.issuePK == null && other.issuePK != null) + || (this.issuePK != null && !this.issuePK.equals(other.issuePK))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.Issue[ issuePK=" + issuePK + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/IssueResolution.java b/VM-Core/src/main/java/com/validation/manager/core/db/IssueResolution.java index 9816c790..e0b3c8d4 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/IssueResolution.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/IssueResolution.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,123 +13,123 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "issue_resolution") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "IssueResolution.findAll", - query = "SELECT i FROM IssueResolution i") - , @NamedQuery(name = "IssueResolution.findById", - query = "SELECT i FROM IssueResolution i WHERE i.id = :id") - , @NamedQuery(name = "IssueResolution.findByName", - query = "SELECT i FROM IssueResolution i WHERE i.name = :name")}) -public class IssueResolution implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @NotNull - @Column(name = "id") - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "ISSUE_RESOLUTION_IDGEN") - @TableGenerator(name = "ISSUE_RESOLUTION_IDGEN", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "issue_resolution", - initialValue = 1, - allocationSize = 1) - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "name") - private String name; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "issueResolutionId") - private List issueList; - - public IssueResolution() { - } - - public IssueResolution(Integer id) { - this.id = id; - } - - public IssueResolution(Integer id, String name) { - this.id = id; - this.name = name; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @XmlTransient - @JsonIgnore - public List getIssueList() { - return issueList; - } - - public void setIssueList(List issueList) { - this.issueList = issueList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof IssueResolution)) { - return false; - } - IssueResolution other = (IssueResolution) object; - return this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.IssueResolution[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "issue_resolution") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "IssueResolution.findAll", + query = "SELECT i FROM IssueResolution i") + , @NamedQuery(name = "IssueResolution.findById", + query = "SELECT i FROM IssueResolution i WHERE i.id = :id") + , @NamedQuery(name = "IssueResolution.findByName", + query = "SELECT i FROM IssueResolution i WHERE i.name = :name")}) +public class IssueResolution implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @NotNull + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "ISSUE_RESOLUTION_IDGEN") + @TableGenerator(name = "ISSUE_RESOLUTION_IDGEN", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "issue_resolution", + initialValue = 1_000, + allocationSize = 1) + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "name") + private String name; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "issueResolutionId") + private List issueList; + + public IssueResolution() { + } + + public IssueResolution(Integer id) { + this.id = id; + } + + public IssueResolution(Integer id, String name) { + this.id = id; + this.name = name; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlTransient + @JsonIgnore + public List getIssueList() { + return issueList; + } + + public void setIssueList(List issueList) { + this.issueList = issueList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof IssueResolution)) { + return false; + } + IssueResolution other = (IssueResolution) object; + return this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.IssueResolution[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/IssueType.java b/VM-Core/src/main/java/com/validation/manager/core/db/IssueType.java index 7ffc2ada..7aee0e0a 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/IssueType.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/IssueType.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,137 +13,132 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "issue_type") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "IssueType.findAll", - query = "SELECT i FROM IssueType i") - , @NamedQuery(name = "IssueType.findById", - query = "SELECT i FROM IssueType i WHERE i.id = :id") - , @NamedQuery(name = "IssueType.findByTypeName", - query = "SELECT i FROM IssueType i WHERE i.typeName = :typeName")}) -public class IssueType implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @NotNull - @Column(name = "id") - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "ISSUE_TYPE_IDGEN") - @TableGenerator(name = "ISSUE_TYPE_IDGEN", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "issue_type", - initialValue = 1, - allocationSize = 1) - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "type_name") - private String typeName; - @Lob - @Size(max = 2147483647) - @Column(name = "description") - private String description; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "issueType") - private List issueList; - - public IssueType() { - } - - public IssueType(Integer id) { - this.id = id; - } - - public IssueType(Integer id, String typeName) { - this.id = id; - this.typeName = typeName; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getTypeName() { - return typeName; - } - - public void setTypeName(String typeName) { - this.typeName = typeName; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getIssueList() { - return issueList; - } - - public void setIssueList(List issueList) { - this.issueList = issueList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof IssueType)) { - return false; - } - IssueType other = (IssueType) object; - return this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.IssueType[ id=" + id + " ]"; - } - -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "issue_type") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "IssueType.findAll", + query = "SELECT i FROM IssueType i") + , @NamedQuery(name = "IssueType.findById", + query = "SELECT i FROM IssueType i WHERE i.id = :id") + , @NamedQuery(name = "IssueType.findByTypeName", + query = "SELECT i FROM IssueType i WHERE i.typeName = :typeName")}) +public class IssueType implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @NotNull + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "ISSUE_TYPE_IDGEN") + @TableGenerator(name = "ISSUE_TYPE_IDGEN", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "issue_type", + initialValue = 1_000, + allocationSize = 1) + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "type_name") + private String typeName; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "description") + private String description; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "issueType") + private List issueList; + + public IssueType() { + } + + public IssueType(String typeName) { + this.typeName = typeName; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getTypeName() { + return typeName; + } + + public void setTypeName(String typeName) { + this.typeName = typeName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getIssueList() { + return issueList; + } + + public void setIssueList(List issueList) { + this.issueList = issueList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof IssueType)) { + return false; + } + IssueType other = (IssueType) object; + return this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.IssueType[ id=" + id + " ]"; + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/Notification.java b/VM-Core/src/main/java/com/validation/manager/core/db/Notification.java index a3c8912d..f4e3ceb8 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/Notification.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/Notification.java @@ -13,182 +13,182 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.Date; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "notification") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Notification.findAll", - query = "SELECT n FROM Notification n") - , @NamedQuery(name = "Notification.findById", - query = "SELECT n FROM Notification n WHERE n.notificationPK.id = :id") - , @NamedQuery(name = "Notification.findByNotificationTypeId", - query = "SELECT n FROM Notification n WHERE n.notificationPK.notificationTypeId = :notificationTypeId") - , @NamedQuery(name = "Notification.findByCreationDate", - query = "SELECT n FROM Notification n WHERE n.creationDate = :creationDate") - , @NamedQuery(name = "Notification.findByAcknowledgeDate", - query = "SELECT n FROM Notification n WHERE n.acknowledgeDate = :acknowledgeDate")}) -public class Notification implements Serializable { - - private static final long serialVersionUID = 1L; - @EmbeddedId - protected NotificationPK notificationPK; - @Basic(optional = false) - @NotNull - @Lob - @Size(min = 1, max = 2147483647) - @Column(name = "content") - private String content; - @Basic(optional = false) - @NotNull - @Column(name = "creation_date") - @Temporal(TemporalType.TIMESTAMP) - private Date creationDate; - @Column(name = "acknowledge_date") - @Temporal(TemporalType.TIMESTAMP) - private Date acknowledgeDate; - @JoinColumn(name = "notification_type_id", referencedColumnName = "id", - insertable = false, updatable = false) - @ManyToOne(optional = false) - private NotificationType notificationType; - @JoinColumn(name = "target_user", referencedColumnName = "id") - @ManyToOne(optional = false) - private VmUser targetUser; - @JoinColumn(name = "author", referencedColumnName = "id") - @ManyToOne(optional = false) - private VmUser author; - @Basic(optional = false) - @NotNull - @Column(name = "archieved") - private boolean archieved; - - public Notification() { - } - - public Notification(NotificationPK notificationPK) { - this.notificationPK = notificationPK; - } - - public Notification(NotificationPK notificationPK, String content, Date creationDate) { - this.notificationPK = notificationPK; - this.content = content; - this.creationDate = creationDate; - } - - public Notification(int id, int notificationTypeId) { - this.notificationPK = new NotificationPK(id, notificationTypeId); - } - - public NotificationPK getNotificationPK() { - return notificationPK; - } - - public void setNotificationPK(NotificationPK notificationPK) { - this.notificationPK = notificationPK; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public Date getCreationDate() { - return creationDate; - } - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - - public Date getAcknowledgeDate() { - return acknowledgeDate; - } - - public void setAcknowledgeDate(Date acknowledgeDate) { - this.acknowledgeDate = acknowledgeDate; - } - - public NotificationType getNotificationType() { - return notificationType; - } - - public void setNotificationType(NotificationType notificationType) { - this.notificationType = notificationType; - } - - public VmUser getTargetUser() { - return targetUser; - } - - public void setTargetUser(VmUser targetUser) { - this.targetUser = targetUser; - } - - public VmUser getAuthor() { - return author; - } - - public void setAuthor(VmUser author) { - this.author = author; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (notificationPK != null ? notificationPK.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set - if (!(object instanceof Notification)) { - return false; - } - Notification other = (Notification) object; - if ((this.notificationPK == null && other.notificationPK != null) || (this.notificationPK != null && !this.notificationPK.equals(other.notificationPK))) { - return false; - } - return true; - } - - @Override - public String toString() { - return "com.validation.manager.core.db.Notification[ notificationPK=" + notificationPK + " ]"; - } - - public boolean getArchieved() { - return archieved; - } - - public void setArchieved(boolean archieved) { - this.archieved = archieved; - } - -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.Date; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "notification") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Notification.findAll", + query = "SELECT n FROM Notification n") + , @NamedQuery(name = "Notification.findById", + query = "SELECT n FROM Notification n WHERE n.notificationPK.id = :id") + , @NamedQuery(name = "Notification.findByNotificationTypeId", + query = "SELECT n FROM Notification n WHERE n.notificationPK.notificationTypeId = :notificationTypeId") + , @NamedQuery(name = "Notification.findByCreationDate", + query = "SELECT n FROM Notification n WHERE n.creationDate = :creationDate") + , @NamedQuery(name = "Notification.findByAcknowledgeDate", + query = "SELECT n FROM Notification n WHERE n.acknowledgeDate = :acknowledgeDate")}) +public class Notification implements Serializable { + + private static final long serialVersionUID = 1L; + @EmbeddedId + protected NotificationPK notificationPK; + @Basic(optional = false) + @NotNull + @Lob + @Size(min = 1, max = 2_147_483_647) + @Column(name = "content") + private String content; + @Basic(optional = false) + @NotNull + @Column(name = "creation_date") + @Temporal(TemporalType.TIMESTAMP) + private Date creationDate; + @Column(name = "acknowledge_date") + @Temporal(TemporalType.TIMESTAMP) + private Date acknowledgeDate; + @JoinColumn(name = "notification_type_id", referencedColumnName = "id", + insertable = false, updatable = false) + @ManyToOne(optional = false) + private NotificationType notificationType; + @JoinColumn(name = "target_user", referencedColumnName = "id") + @ManyToOne(optional = false) + private VmUser targetUser; + @JoinColumn(name = "author", referencedColumnName = "id") + @ManyToOne(optional = false) + private VmUser author; + @Basic(optional = false) + @NotNull + @Column(name = "archieved") + private boolean archieved; + + public Notification() { + } + + public Notification(NotificationPK notificationPK) { + this.notificationPK = notificationPK; + } + + public Notification(NotificationPK notificationPK, String content, Date creationDate) { + this.notificationPK = notificationPK; + this.content = content; + this.creationDate = creationDate; + } + + public Notification(int id, int notificationTypeId) { + this.notificationPK = new NotificationPK(id, notificationTypeId); + } + + public NotificationPK getNotificationPK() { + return notificationPK; + } + + public void setNotificationPK(NotificationPK notificationPK) { + this.notificationPK = notificationPK; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public Date getAcknowledgeDate() { + return acknowledgeDate; + } + + public void setAcknowledgeDate(Date acknowledgeDate) { + this.acknowledgeDate = acknowledgeDate; + } + + public NotificationType getNotificationType() { + return notificationType; + } + + public void setNotificationType(NotificationType notificationType) { + this.notificationType = notificationType; + } + + public VmUser getTargetUser() { + return targetUser; + } + + public void setTargetUser(VmUser targetUser) { + this.targetUser = targetUser; + } + + public VmUser getAuthor() { + return author; + } + + public void setAuthor(VmUser author) { + this.author = author; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (notificationPK != null ? notificationPK.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof Notification)) { + return false; + } + Notification other = (Notification) object; + if ((this.notificationPK == null && other.notificationPK != null) || (this.notificationPK != null && !this.notificationPK.equals(other.notificationPK))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "com.validation.manager.core.db.Notification[ notificationPK=" + notificationPK + " ]"; + } + + public boolean getArchieved() { + return archieved; + } + + public void setArchieved(boolean archieved) { + this.archieved = archieved; + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/NotificationPK.java b/VM-Core/src/main/java/com/validation/manager/core/db/NotificationPK.java index 2945c91a..59f4b8d2 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/NotificationPK.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/NotificationPK.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,81 +13,92 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.validation.constraints.NotNull; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Embeddable -public class NotificationPK implements Serializable { - - @Basic(optional = false) - @NotNull - @Column(name = "id") - private int id; - @Basic(optional = false) - @NotNull - @Column(name = "notification_type_id") - private int notificationTypeId; - - public NotificationPK() { - } - - public NotificationPK(int id, int notificationTypeId) { - this.id = id; - this.notificationTypeId = notificationTypeId; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getNotificationTypeId() { - return notificationTypeId; - } - - public void setNotificationTypeId(int notificationTypeId) { - this.notificationTypeId = notificationTypeId; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (int) id; - hash += (int) notificationTypeId; - return hash; - } - - @Override - public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set - if (!(object instanceof NotificationPK)) { - return false; - } - NotificationPK other = (NotificationPK) object; - if (this.id != other.id) { - return false; - } - if (this.notificationTypeId != other.notificationTypeId) { - return false; - } - return true; - } - - @Override - public String toString() { - return "com.validation.manager.core.db.NotificationPK[ id=" + id + ", notificationTypeId=" + notificationTypeId + " ]"; - } - -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Embeddable +public class NotificationPK implements Serializable { + + @Basic(optional = false) + @NotNull + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "Notification_IDGEN") + @TableGenerator(name = "Notification_IDGEN", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "notification", + initialValue = 1, + allocationSize = 1) + private int id; + @Basic(optional = false) + @NotNull + @Column(name = "notification_type_id") + private int notificationTypeId; + + public NotificationPK() { + } + + public NotificationPK(int id, int notificationTypeId) { + this.id = id; + this.notificationTypeId = notificationTypeId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getNotificationTypeId() { + return notificationTypeId; + } + + public void setNotificationTypeId(int notificationTypeId) { + this.notificationTypeId = notificationTypeId; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (int) id; + hash += (int) notificationTypeId; + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof NotificationPK)) { + return false; + } + NotificationPK other = (NotificationPK) object; + if (this.id != other.id) { + return false; + } + if (this.notificationTypeId != other.notificationTypeId) { + return false; + } + return true; + } + + @Override + public String toString() { + return "com.validation.manager.core.db.NotificationPK[ id=" + id + ", notificationTypeId=" + notificationTypeId + " ]"; + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/Project.java b/VM-Core/src/main/java/com/validation/manager/core/db/Project.java index 3158f241..0d1bf42b 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/Project.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/Project.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,190 +13,193 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import com.validation.manager.core.history.Versionable; -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "project") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Project.findAll", - query = "SELECT p FROM Project p") - , @NamedQuery(name = "Project.findById", - query = "SELECT p FROM Project p WHERE p.id = :id") - , @NamedQuery(name = "Project.findByName", - query = "SELECT p FROM Project p WHERE p.name = :name")}) -public class Project extends Versionable implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "ProjectGen") - @TableGenerator(name = "ProjectGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "project", - allocationSize = 1, - initialValue = 1000) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Lob - @Size(max = 2147483647) - @Column(name = "notes") - private String notes; - @JoinTable(name = "project_has_test_project", joinColumns = { - @JoinColumn(name = "project_id", referencedColumnName = "id")}, - inverseJoinColumns = { - @JoinColumn(name = "test_project_id", - referencedColumnName = "id")}) - @ManyToMany - private List testProjectList; - @OneToMany(mappedBy = "parentProjectId") - private List projectList; - @JoinColumn(name = "parent_project_id", referencedColumnName = "id") - @ManyToOne - private Project parentProjectId; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "project") - private List requirementSpecList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "projectId") - private List historyList; - - public Project(String name) { - this.name = name; - } - - public Project() { - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; - } - - @XmlTransient - @JsonIgnore - public List getTestProjectList() { - return testProjectList; - } - - public void setTestProjectList(List testProjectList) { - this.testProjectList = testProjectList; - } - - @XmlTransient - @JsonIgnore - public List getProjectList() { - return projectList; - } - - public void setProjectList(List projectList) { - this.projectList = projectList; - } - - public Project getParentProjectId() { - return parentProjectId; - } - - public void setParentProjectId(Project parentProjectId) { - this.parentProjectId = parentProjectId; - } - - @XmlTransient - @JsonIgnore - public List getRequirementSpecList() { - return requirementSpecList; - } - - public void setRequirementSpecList(List requirementSpecList) { - this.requirementSpecList = requirementSpecList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof Project)) { - return false; - } - Project other = (Project) object; - return this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.Project[ id=" + id + " ]"; - } - - @XmlTransient - @JsonIgnore - @Override - public List getHistoryList() { - return historyList; - } - - @Override - public void setHistoryList(List historyList) { - this.historyList = historyList; - } -} +package com.validation.manager.core.db; + +import com.validation.manager.core.history.Auditable; +import com.validation.manager.core.history.Versionable; +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "project") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Project.findAll", + query = "SELECT p FROM Project p") + , @NamedQuery(name = "Project.findById", + query = "SELECT p FROM Project p WHERE p.id = :id") + , @NamedQuery(name = "Project.findByName", + query = "SELECT p FROM Project p WHERE p.name = :name")}) +public class Project extends Versionable implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "ProjectGen") + @TableGenerator(name = "ProjectGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "project", + allocationSize = 1, + initialValue = 1_000) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + @Auditable + private String name; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "notes") + @Auditable + private String notes; + @JoinTable(name = "project_has_test_project", joinColumns = { + @JoinColumn(name = "project_id", referencedColumnName = "id")}, + inverseJoinColumns = { + @JoinColumn(name = "test_project_id", + referencedColumnName = "id")}) + @ManyToMany + private List testProjectList; + @OneToMany(mappedBy = "parentProjectId") + private List projectList; + @JoinColumn(name = "parent_project_id", referencedColumnName = "id") + @ManyToOne + private Project parentProjectId; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "project") + private List requirementSpecList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "projectId") + private List historyList; + + public Project(String name) { + this.name = name; + } + + public Project() { + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + + @XmlTransient + @JsonIgnore + public List getTestProjectList() { + return testProjectList; + } + + public void setTestProjectList(List testProjectList) { + this.testProjectList = testProjectList; + } + + @XmlTransient + @JsonIgnore + public List getProjectList() { + return projectList; + } + + public void setProjectList(List projectList) { + this.projectList = projectList; + } + + public Project getParentProjectId() { + return parentProjectId; + } + + public void setParentProjectId(Project parentProjectId) { + this.parentProjectId = parentProjectId; + } + + @XmlTransient + @JsonIgnore + public List getRequirementSpecList() { + return requirementSpecList; + } + + public void setRequirementSpecList(List requirementSpecList) { + this.requirementSpecList = requirementSpecList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof Project)) { + return false; + } + Project other = (Project) object; + return this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.Project[ id=" + id + " ]"; + } + + @XmlTransient + @JsonIgnore + @Override + public List getHistoryList() { + return historyList; + } + + @Override + public void setHistoryList(List historyList) { + this.historyList = historyList; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/Requirement.java b/VM-Core/src/main/java/com/validation/manager/core/db/Requirement.java index bd0f08d0..bbadbe2b 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/Requirement.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/Requirement.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,265 +13,265 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import com.validation.manager.core.history.Auditable; -import com.validation.manager.core.history.Versionable; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; -import javax.persistence.JoinTable; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "requirement") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Requirement.findAll", - query = "SELECT r FROM Requirement r") - , @NamedQuery(name = "Requirement.findById", - query = "SELECT r FROM Requirement r WHERE r.id = :id") - , @NamedQuery(name = "Requirement.findByUniqueId", - query = "SELECT r FROM Requirement r WHERE r.uniqueId = :uniqueId")}) -public class Requirement extends Versionable implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "ReqGen") - @TableGenerator(name = "ReqGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "requirement", - allocationSize = 1, - initialValue = 1000) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "unique_id") - @Auditable - private String uniqueId; - @Basic(optional = false) - @NotNull - @Lob - @Size(max = 2147483647) - @Column(name = "description") - @Auditable - private String description; - @Lob - @Size(max = 2147483647) - @Column(name = "notes") - @Auditable - private String notes; - @OneToMany(mappedBy = "parentRequirementId") - private List requirementList; - @JoinTable(name = "step_has_requirement", joinColumns = { - @JoinColumn(name = "requirement_id", referencedColumnName = "id")}, - inverseJoinColumns = { - @JoinColumn(name = "step_id", referencedColumnName = "id") - , @JoinColumn(name = "step_test_case_id", - referencedColumnName = "test_case_id")}) - @ManyToMany - private List stepList; - @JoinColumn(name = "parent_requirement_id", referencedColumnName = "id") - @ManyToOne - private Requirement parentRequirementId; - @JoinColumns({ - @JoinColumn(name = "requirement_spec_node_id", - referencedColumnName = "id") - , @JoinColumn(name = "requirement_spec_node_requirement_spec_id", - referencedColumnName = "requirement_spec_id") - , @JoinColumn(name = "requirement_spec_node_requirement_spec_project_id", - referencedColumnName = "requirement_spec_project_id") - , @JoinColumn(name = "requirement_spec_node_requirement_spec_spec_level_id", - referencedColumnName = "requirement_spec_spec_level_id")}) - @ManyToOne(optional = false) - private RequirementSpecNode requirementSpecNode; - @JoinColumn(name = "requirement_status_id", referencedColumnName = "id") - @ManyToOne(optional = false) - private RequirementStatus requirementStatusId; - @JoinColumn(name = "requirement_type_id", referencedColumnName = "id") - @ManyToOne(optional = false) - private RequirementType requirementTypeId; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "requirement") - private List riskControlHasRequirementList; - @OneToMany(mappedBy = "requirementId") - private List historyList; - - public Requirement() { - super(); - } - - public Requirement(String uniqueId, String description) { - this.uniqueId = uniqueId; - this.description = description; - } - - public Requirement(String uniqueId, String description, String notes) { - this.uniqueId = uniqueId; - this.description = description; - this.notes = notes; - setRiskControlHasRequirementList(new ArrayList<>()); - setRequirementList(new ArrayList<>()); - setStepList(new ArrayList<>()); - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getUniqueId() { - return uniqueId; - } - - public void setUniqueId(String uniqueId) { - this.uniqueId = uniqueId; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; - } - - @XmlTransient - @JsonIgnore - public List getRequirementList() { - return requirementList; - } - - public void setRequirementList(List requirementList) { - this.requirementList = requirementList; - } - - public Requirement getParentRequirementId() { - return parentRequirementId; - } - - public void setParentRequirementId(Requirement parentRequirementId) { - this.parentRequirementId = parentRequirementId; - } - - @XmlTransient - @JsonIgnore - public List getStepList() { - return stepList; - } - - public void setStepList(List stepList) { - this.stepList = stepList; - } - - public RequirementSpecNode getRequirementSpecNode() { - return requirementSpecNode; - } - - public void setRequirementSpecNode(RequirementSpecNode requirementSpecNode) { - this.requirementSpecNode = requirementSpecNode; - } - - public RequirementStatus getRequirementStatusId() { - return requirementStatusId; - } - - public void setRequirementStatusId(RequirementStatus requirementStatusId) { - this.requirementStatusId = requirementStatusId; - } - - public RequirementType getRequirementTypeId() { - return requirementTypeId; - } - - public void setRequirementTypeId(RequirementType requirementTypeId) { - this.requirementTypeId = requirementTypeId; - } - - @XmlTransient - @JsonIgnore - public List getRiskControlHasRequirementList() { - return riskControlHasRequirementList; - } - - public void setRiskControlHasRequirementList(List riskControlHasRequirementList) { - this.riskControlHasRequirementList = riskControlHasRequirementList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - if (!(object instanceof Requirement)) { - return false; - } - Requirement other = (Requirement) object; - return this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.Requirement[ id=" + getId() - + ", uniqueId=" + getUniqueId() - + ", description=" + getDescription() - + " " + super.toString() + " ]"; - } - - @XmlTransient - @JsonIgnore - @Override - public List getHistoryList() { - return historyList; - } - - @Override - public void setHistoryList(List historyList) { - this.historyList = historyList; - } -} +package com.validation.manager.core.db; + +import com.validation.manager.core.history.Auditable; +import com.validation.manager.core.history.Versionable; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "requirement") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Requirement.findAll", + query = "SELECT r FROM Requirement r") + , @NamedQuery(name = "Requirement.findById", + query = "SELECT r FROM Requirement r WHERE r.id = :id") + , @NamedQuery(name = "Requirement.findByUniqueId", + query = "SELECT r FROM Requirement r WHERE r.uniqueId = :uniqueId")}) +public class Requirement extends Versionable implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "ReqGen") + @TableGenerator(name = "ReqGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "requirement", + allocationSize = 1, + initialValue = 1_000) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "unique_id") + @Auditable + private String uniqueId; + @Basic(optional = false) + @NotNull + @Lob + @Size(max = 2_147_483_647) + @Column(name = "description") + @Auditable + private String description; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "notes") + @Auditable + private String notes; + @OneToMany(mappedBy = "parentRequirementId") + private List requirementList; + @JoinTable(name = "step_has_requirement", joinColumns = { + @JoinColumn(name = "requirement_id", referencedColumnName = "id")}, + inverseJoinColumns = { + @JoinColumn(name = "step_id", referencedColumnName = "id") + , @JoinColumn(name = "step_test_case_id", + referencedColumnName = "test_case_id")}) + @ManyToMany + private List stepList; + @JoinColumn(name = "parent_requirement_id", referencedColumnName = "id") + @ManyToOne + private Requirement parentRequirementId; + @JoinColumns({ + @JoinColumn(name = "requirement_spec_node_id", + referencedColumnName = "id") + , @JoinColumn(name = "requirement_spec_node_requirement_spec_id", + referencedColumnName = "requirement_spec_id") + , @JoinColumn(name = "requirement_spec_node_requirement_spec_project_id", + referencedColumnName = "requirement_spec_project_id") + , @JoinColumn(name = "requirement_spec_node_requirement_spec_spec_level_id", + referencedColumnName = "requirement_spec_spec_level_id")}) + @ManyToOne(optional = false) + private RequirementSpecNode requirementSpecNode; + @JoinColumn(name = "requirement_status_id", referencedColumnName = "id") + @ManyToOne(optional = false) + private RequirementStatus requirementStatusId; + @JoinColumn(name = "requirement_type_id", referencedColumnName = "id") + @ManyToOne(optional = false) + private RequirementType requirementTypeId; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "requirement") + private List riskControlHasRequirementList; + @OneToMany(mappedBy = "requirementId") + private List historyList; + + public Requirement() { + super(); + } + + public Requirement(String uniqueId, String description) { + this.uniqueId = uniqueId; + this.description = description; + } + + public Requirement(String uniqueId, String description, String notes) { + this.uniqueId = uniqueId; + this.description = description; + this.notes = notes; + setRiskControlHasRequirementList(new ArrayList<>()); + setRequirementList(new ArrayList<>()); + setStepList(new ArrayList<>()); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUniqueId() { + return uniqueId; + } + + public void setUniqueId(String uniqueId) { + this.uniqueId = uniqueId; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + + @XmlTransient + @JsonIgnore + public List getRequirementList() { + return requirementList; + } + + public void setRequirementList(List requirementList) { + this.requirementList = requirementList; + } + + public Requirement getParentRequirementId() { + return parentRequirementId; + } + + public void setParentRequirementId(Requirement parentRequirementId) { + this.parentRequirementId = parentRequirementId; + } + + @XmlTransient + @JsonIgnore + public List getStepList() { + return stepList; + } + + public void setStepList(List stepList) { + this.stepList = stepList; + } + + public RequirementSpecNode getRequirementSpecNode() { + return requirementSpecNode; + } + + public void setRequirementSpecNode(RequirementSpecNode requirementSpecNode) { + this.requirementSpecNode = requirementSpecNode; + } + + public RequirementStatus getRequirementStatusId() { + return requirementStatusId; + } + + public void setRequirementStatusId(RequirementStatus requirementStatusId) { + this.requirementStatusId = requirementStatusId; + } + + public RequirementType getRequirementTypeId() { + return requirementTypeId; + } + + public void setRequirementTypeId(RequirementType requirementTypeId) { + this.requirementTypeId = requirementTypeId; + } + + @XmlTransient + @JsonIgnore + public List getRiskControlHasRequirementList() { + return riskControlHasRequirementList; + } + + public void setRiskControlHasRequirementList(List riskControlHasRequirementList) { + this.riskControlHasRequirementList = riskControlHasRequirementList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof Requirement)) { + return false; + } + Requirement other = (Requirement) object; + return this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.Requirement[ id=" + getId() + + ", uniqueId=" + getUniqueId() + + ", description=" + getDescription() + + " " + super.toString() + " ]"; + } + + @XmlTransient + @JsonIgnore + @Override + public List getHistoryList() { + return historyList; + } + + @Override + public void setHistoryList(List historyList) { + this.historyList = historyList; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpec.java b/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpec.java index 311ed1af..961d9360 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpec.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpec.java @@ -13,195 +13,195 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "requirement_spec") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "RequirementSpec.findAll", - query = "SELECT r FROM RequirementSpec r") - , @NamedQuery(name = "RequirementSpec.findById", - query = "SELECT r FROM RequirementSpec r WHERE r.requirementSpecPK.id = :id") - , @NamedQuery(name = "RequirementSpec.findByProjectId", - query = "SELECT r FROM RequirementSpec r WHERE r.requirementSpecPK.projectId = :projectId") - , @NamedQuery(name = "RequirementSpec.findBySpecLevelId", - query = "SELECT r FROM RequirementSpec r WHERE r.requirementSpecPK.specLevelId = :specLevelId") - , @NamedQuery(name = "RequirementSpec.findByName", - query = "SELECT r FROM RequirementSpec r WHERE r.name = :name") - , @NamedQuery(name = "RequirementSpec.findByModificationDate", - query = "SELECT r FROM RequirementSpec r WHERE r.modificationDate = :modificationDate")}) -public class RequirementSpec implements Serializable { - - private static final long serialVersionUID = 1L; - @EmbeddedId - protected RequirementSpecPK requirementSpecPK; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Lob - @Size(max = 2147483647) - @Column(name = "description") - private String description; - @Basic(optional = false) - @NotNull - @Column(name = "modificationDate") - @Temporal(TemporalType.TIMESTAMP) - private Date modificationDate; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "requirementSpec") - private List requirementSpecNodeList; - @JoinColumn(name = "project_id", referencedColumnName = "id", - insertable = false, updatable = false) - @ManyToOne(optional = false) - private Project project; - @JoinColumn(name = "spec_level_id", referencedColumnName = "id", - insertable = false, updatable = false) - @ManyToOne(optional = false) - private SpecLevel specLevel; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "requirementSpec") - private List baselineList; - - public RequirementSpec() { - super(); - } - - public RequirementSpec(RequirementSpecPK requirementSpecPK) { - this.requirementSpecPK = requirementSpecPK; - } - - public RequirementSpec(RequirementSpecPK requirementSpecPK, - String name, Date modificationDate) { - super(); - this.requirementSpecPK = requirementSpecPK; - this.name = name; - this.modificationDate = modificationDate; - } - - public RequirementSpec(int projectId, int specLevelId) { - super(); - this.requirementSpecPK = new RequirementSpecPK(projectId, specLevelId); - } - - public RequirementSpecPK getRequirementSpecPK() { - return requirementSpecPK; - } - - public void setRequirementSpecPK(RequirementSpecPK requirementSpecPK) { - this.requirementSpecPK = requirementSpecPK; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Date getModificationDate() { - return modificationDate; - } - - public void setModificationDate(Date modificationDate) { - this.modificationDate = modificationDate; - } - - @XmlTransient - @JsonIgnore - public List getRequirementSpecNodeList() { - return requirementSpecNodeList; - } - - public void setRequirementSpecNodeList(List requirementSpecNodeList) { - this.requirementSpecNodeList = requirementSpecNodeList; - } - - public Project getProject() { - return project; - } - - public void setProject(Project project) { - this.project = project; - } - - public SpecLevel getSpecLevel() { - return specLevel; - } - - public void setSpecLevel(SpecLevel specLevel) { - this.specLevel = specLevel; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (requirementSpecPK != null ? requirementSpecPK.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RequirementSpec)) { - return false; - } - RequirementSpec other = (RequirementSpec) object; - return !((this.requirementSpecPK == null - && other.requirementSpecPK != null) - || (this.requirementSpecPK != null - && !this.requirementSpecPK.equals(other.requirementSpecPK))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RequirementSpec[ requirementSpecPK=" - + requirementSpecPK + " ]"; - } - - @XmlTransient - @JsonIgnore - public List getBaselineList() { - return baselineList; - } - - public void setBaselineList(List baselineList) { - this.baselineList = baselineList; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "requirement_spec") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "RequirementSpec.findAll", + query = "SELECT r FROM RequirementSpec r") + , @NamedQuery(name = "RequirementSpec.findById", + query = "SELECT r FROM RequirementSpec r WHERE r.requirementSpecPK.id = :id") + , @NamedQuery(name = "RequirementSpec.findByProjectId", + query = "SELECT r FROM RequirementSpec r WHERE r.requirementSpecPK.projectId = :projectId") + , @NamedQuery(name = "RequirementSpec.findBySpecLevelId", + query = "SELECT r FROM RequirementSpec r WHERE r.requirementSpecPK.specLevelId = :specLevelId") + , @NamedQuery(name = "RequirementSpec.findByName", + query = "SELECT r FROM RequirementSpec r WHERE r.name = :name") + , @NamedQuery(name = "RequirementSpec.findByModificationDate", + query = "SELECT r FROM RequirementSpec r WHERE r.modificationDate = :modificationDate")}) +public class RequirementSpec implements Serializable { + + private static final long serialVersionUID = 1L; + @EmbeddedId + protected RequirementSpecPK requirementSpecPK; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "description") + private String description; + @Basic(optional = false) + @NotNull + @Column(name = "modificationDate") + @Temporal(TemporalType.TIMESTAMP) + private Date modificationDate; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "requirementSpec") + private List requirementSpecNodeList; + @JoinColumn(name = "project_id", referencedColumnName = "id", + insertable = false, updatable = false) + @ManyToOne(optional = false) + private Project project; + @JoinColumn(name = "spec_level_id", referencedColumnName = "id", + insertable = false, updatable = false) + @ManyToOne(optional = false) + private SpecLevel specLevel; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "requirementSpec") + private List baselineList; + + public RequirementSpec() { + super(); + } + + public RequirementSpec(RequirementSpecPK requirementSpecPK) { + this.requirementSpecPK = requirementSpecPK; + } + + public RequirementSpec(RequirementSpecPK requirementSpecPK, + String name, Date modificationDate) { + super(); + this.requirementSpecPK = requirementSpecPK; + this.name = name; + this.modificationDate = modificationDate; + } + + public RequirementSpec(int projectId, int specLevelId) { + super(); + this.requirementSpecPK = new RequirementSpecPK(projectId, specLevelId); + } + + public RequirementSpecPK getRequirementSpecPK() { + return requirementSpecPK; + } + + public void setRequirementSpecPK(RequirementSpecPK requirementSpecPK) { + this.requirementSpecPK = requirementSpecPK; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getModificationDate() { + return modificationDate; + } + + public void setModificationDate(Date modificationDate) { + this.modificationDate = modificationDate; + } + + @XmlTransient + @JsonIgnore + public List getRequirementSpecNodeList() { + return requirementSpecNodeList; + } + + public void setRequirementSpecNodeList(List requirementSpecNodeList) { + this.requirementSpecNodeList = requirementSpecNodeList; + } + + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } + + public SpecLevel getSpecLevel() { + return specLevel; + } + + public void setSpecLevel(SpecLevel specLevel) { + this.specLevel = specLevel; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (requirementSpecPK != null ? requirementSpecPK.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RequirementSpec)) { + return false; + } + RequirementSpec other = (RequirementSpec) object; + return !((this.requirementSpecPK == null + && other.requirementSpecPK != null) + || (this.requirementSpecPK != null + && !this.requirementSpecPK.equals(other.requirementSpecPK))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RequirementSpec[ requirementSpecPK=" + + requirementSpecPK + " ]"; + } + + @XmlTransient + @JsonIgnore + public List getBaselineList() { + return baselineList; + } + + public void setBaselineList(List baselineList) { + this.baselineList = baselineList; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpecNode.java b/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpecNode.java index 8a322c02..abe1f015 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpecNode.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpecNode.java @@ -13,210 +13,210 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "requirement_spec_node") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "RequirementSpecNode.findAll", - query = "SELECT r FROM RequirementSpecNode r") - , @NamedQuery(name = "RequirementSpecNode.findById", - query = "SELECT r FROM RequirementSpecNode r WHERE r.requirementSpecNodePK.id = :id") - , @NamedQuery(name = "RequirementSpecNode.findByRequirementSpecId", - query = "SELECT r FROM RequirementSpecNode r WHERE r.requirementSpecNodePK.requirementSpecId = :requirementSpecId") - , @NamedQuery(name = "RequirementSpecNode.findByRequirementSpecProjectId", - query = "SELECT r FROM RequirementSpecNode r WHERE r.requirementSpecNodePK.requirementSpecProjectId = :requirementSpecProjectId") - , @NamedQuery(name = "RequirementSpecNode.findByRequirementSpecSpecLevelId", - query = "SELECT r FROM RequirementSpecNode r WHERE r.requirementSpecNodePK.requirementSpecSpecLevelId = :requirementSpecSpecLevelId") - , @NamedQuery(name = "RequirementSpecNode.findByName", - query = "SELECT r FROM RequirementSpecNode r WHERE r.name = :name")}) -public class RequirementSpecNode implements Serializable { - - private static final long serialVersionUID = 1L; - @EmbeddedId - protected RequirementSpecNodePK requirementSpecNodePK; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Lob - @Size(max = 2147483647) - @Column(name = "description") - private String description; - @Lob - @Size(max = 2147483647) - @Column(name = "scope") - private String scope; - @JoinColumns({ - @JoinColumn(name = "requirement_spec_id", referencedColumnName = "id", - insertable = false, updatable = false) - , @JoinColumn(name = "requirement_spec_project_id", - referencedColumnName = "project_id", insertable = false, - updatable = false) - , @JoinColumn(name = "requirement_spec_spec_level_id", - referencedColumnName = "spec_level_id", insertable = false, - updatable = false)}) - @ManyToOne(optional = false) - private RequirementSpec requirementSpec; - @OneToMany(mappedBy = "requirementSpecNode") - private List requirementSpecNodeList; - @JoinColumns({ - @JoinColumn(name = "requirement_spec_node_id", - referencedColumnName = "id") - , @JoinColumn(name = "requirement_spec_node_requirement_spec_id", - referencedColumnName = "requirement_spec_id") - , @JoinColumn(name = "requirement_spec_node_requirement_spec_project_id", - referencedColumnName = "requirement_spec_project_id") - , @JoinColumn(name = "requirement_spec_node_requirement_spec_spec_level_id", - referencedColumnName = "requirement_spec_spec_level_id")}) - @ManyToOne - private RequirementSpecNode requirementSpecNode; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "requirementSpecNode") - private List requirementList; - - public RequirementSpecNode() { - } - - public RequirementSpecNode(RequirementSpecNodePK requirementSpecNodePK) { - this.requirementSpecNodePK = requirementSpecNodePK; - } - - public RequirementSpecNode(RequirementSpecNodePK requirementSpecNodePK, - String name) { - this.requirementSpecNodePK = requirementSpecNodePK; - this.name = name; - } - - public RequirementSpecNode(RequirementSpecPK pk) { - this.requirementSpecNodePK = new RequirementSpecNodePK(pk.getId(), - pk.getProjectId(), pk.getSpecLevelId()); - } - - public RequirementSpecNode(int requirementSpecId, - int requirementSpecProjectId, int requirementSpecSpecLevelId) { - this.requirementSpecNodePK - = new RequirementSpecNodePK(requirementSpecId, - requirementSpecProjectId, requirementSpecSpecLevelId); - } - - public RequirementSpecNodePK getRequirementSpecNodePK() { - return requirementSpecNodePK; - } - - public void setRequirementSpecNodePK(RequirementSpecNodePK requirementSpecNodePK) { - this.requirementSpecNodePK = requirementSpecNodePK; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getScope() { - return scope; - } - - public void setScope(String scope) { - this.scope = scope; - } - - public RequirementSpec getRequirementSpec() { - return requirementSpec; - } - - public void setRequirementSpec(RequirementSpec requirementSpec) { - this.requirementSpec = requirementSpec; - } - - @XmlTransient - @JsonIgnore - public List getRequirementSpecNodeList() { - return requirementSpecNodeList; - } - - public void setRequirementSpecNodeList(List requirementSpecNodeList) { - this.requirementSpecNodeList = requirementSpecNodeList; - } - - public RequirementSpecNode getRequirementSpecNode() { - return requirementSpecNode; - } - - public void setRequirementSpecNode(RequirementSpecNode requirementSpecNode) { - this.requirementSpecNode = requirementSpecNode; - } - - @XmlTransient - @JsonIgnore - public List getRequirementList() { - return requirementList; - } - - public void setRequirementList(List requirementList) { - this.requirementList = requirementList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (requirementSpecNodePK != null ? requirementSpecNodePK.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RequirementSpecNode)) { - return false; - } - RequirementSpecNode other = (RequirementSpecNode) object; - return !((this.requirementSpecNodePK == null - && other.requirementSpecNodePK != null) - || (this.requirementSpecNodePK != null - && !this.requirementSpecNodePK.equals(other.requirementSpecNodePK))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RequirementSpecNode[ requirementSpecNodePK=" - + requirementSpecNodePK + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "requirement_spec_node") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "RequirementSpecNode.findAll", + query = "SELECT r FROM RequirementSpecNode r") + , @NamedQuery(name = "RequirementSpecNode.findById", + query = "SELECT r FROM RequirementSpecNode r WHERE r.requirementSpecNodePK.id = :id") + , @NamedQuery(name = "RequirementSpecNode.findByRequirementSpecId", + query = "SELECT r FROM RequirementSpecNode r WHERE r.requirementSpecNodePK.requirementSpecId = :requirementSpecId") + , @NamedQuery(name = "RequirementSpecNode.findByRequirementSpecProjectId", + query = "SELECT r FROM RequirementSpecNode r WHERE r.requirementSpecNodePK.requirementSpecProjectId = :requirementSpecProjectId") + , @NamedQuery(name = "RequirementSpecNode.findByRequirementSpecSpecLevelId", + query = "SELECT r FROM RequirementSpecNode r WHERE r.requirementSpecNodePK.requirementSpecSpecLevelId = :requirementSpecSpecLevelId") + , @NamedQuery(name = "RequirementSpecNode.findByName", + query = "SELECT r FROM RequirementSpecNode r WHERE r.name = :name")}) +public class RequirementSpecNode implements Serializable { + + private static final long serialVersionUID = 1L; + @EmbeddedId + protected RequirementSpecNodePK requirementSpecNodePK; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "description") + private String description; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "scope") + private String scope; + @JoinColumns({ + @JoinColumn(name = "requirement_spec_id", referencedColumnName = "id", + insertable = false, updatable = false) + , @JoinColumn(name = "requirement_spec_project_id", + referencedColumnName = "project_id", insertable = false, + updatable = false) + , @JoinColumn(name = "requirement_spec_spec_level_id", + referencedColumnName = "spec_level_id", insertable = false, + updatable = false)}) + @ManyToOne(optional = false) + private RequirementSpec requirementSpec; + @OneToMany(mappedBy = "requirementSpecNode") + private List requirementSpecNodeList; + @JoinColumns({ + @JoinColumn(name = "requirement_spec_node_id", + referencedColumnName = "id") + , @JoinColumn(name = "requirement_spec_node_requirement_spec_id", + referencedColumnName = "requirement_spec_id") + , @JoinColumn(name = "requirement_spec_node_requirement_spec_project_id", + referencedColumnName = "requirement_spec_project_id") + , @JoinColumn(name = "requirement_spec_node_requirement_spec_spec_level_id", + referencedColumnName = "requirement_spec_spec_level_id")}) + @ManyToOne + private RequirementSpecNode requirementSpecNode; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "requirementSpecNode") + private List requirementList; + + public RequirementSpecNode() { + } + + public RequirementSpecNode(RequirementSpecNodePK requirementSpecNodePK) { + this.requirementSpecNodePK = requirementSpecNodePK; + } + + public RequirementSpecNode(RequirementSpecNodePK requirementSpecNodePK, + String name) { + this.requirementSpecNodePK = requirementSpecNodePK; + this.name = name; + } + + public RequirementSpecNode(RequirementSpecPK pk) { + this.requirementSpecNodePK = new RequirementSpecNodePK(pk.getId(), + pk.getProjectId(), pk.getSpecLevelId()); + } + + public RequirementSpecNode(int requirementSpecId, + int requirementSpecProjectId, int requirementSpecSpecLevelId) { + this.requirementSpecNodePK + = new RequirementSpecNodePK(requirementSpecId, + requirementSpecProjectId, requirementSpecSpecLevelId); + } + + public RequirementSpecNodePK getRequirementSpecNodePK() { + return requirementSpecNodePK; + } + + public void setRequirementSpecNodePK(RequirementSpecNodePK requirementSpecNodePK) { + this.requirementSpecNodePK = requirementSpecNodePK; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public RequirementSpec getRequirementSpec() { + return requirementSpec; + } + + public void setRequirementSpec(RequirementSpec requirementSpec) { + this.requirementSpec = requirementSpec; + } + + @XmlTransient + @JsonIgnore + public List getRequirementSpecNodeList() { + return requirementSpecNodeList; + } + + public void setRequirementSpecNodeList(List requirementSpecNodeList) { + this.requirementSpecNodeList = requirementSpecNodeList; + } + + public RequirementSpecNode getRequirementSpecNode() { + return requirementSpecNode; + } + + public void setRequirementSpecNode(RequirementSpecNode requirementSpecNode) { + this.requirementSpecNode = requirementSpecNode; + } + + @XmlTransient + @JsonIgnore + public List getRequirementList() { + return requirementList; + } + + public void setRequirementList(List requirementList) { + this.requirementList = requirementList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (requirementSpecNodePK != null ? requirementSpecNodePK.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RequirementSpecNode)) { + return false; + } + RequirementSpecNode other = (RequirementSpecNode) object; + return !((this.requirementSpecNodePK == null + && other.requirementSpecNodePK != null) + || (this.requirementSpecNodePK != null + && !this.requirementSpecNodePK.equals(other.requirementSpecNodePK))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RequirementSpecNode[ requirementSpecNodePK=" + + requirementSpecNodePK + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpecNodePK.java b/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpecNodePK.java index 2f76c9b8..fdad1f04 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpecNodePK.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpecNodePK.java @@ -13,125 +13,125 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Embeddable -public class RequirementSpecNodePK implements Serializable { - - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "RequirementSpecNodeGen") - @TableGenerator(name = "RequirementSpecNodeGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "requirement_spec_node", - allocationSize = 1, - initialValue = 1000) - @NotNull - @Column(name = "id") - private int id; - @Basic(optional = false) - @NotNull - @Column(name = "requirement_spec_id") - private int requirementSpecId; - @Basic(optional = false) - @NotNull - @Column(name = "requirement_spec_project_id") - private int requirementSpecProjectId; - @Basic(optional = false) - @NotNull - @Column(name = "requirement_spec_spec_level_id") - private int requirementSpecSpecLevelId; - - public RequirementSpecNodePK() { - } - - public RequirementSpecNodePK(int requirementSpecId, - int requirementSpecProjectId, int requirementSpecSpecLevelId) { - this.requirementSpecId = requirementSpecId; - this.requirementSpecProjectId = requirementSpecProjectId; - this.requirementSpecSpecLevelId = requirementSpecSpecLevelId; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getRequirementSpecId() { - return requirementSpecId; - } - - public void setRequirementSpecId(int requirementSpecId) { - this.requirementSpecId = requirementSpecId; - } - - public int getRequirementSpecProjectId() { - return requirementSpecProjectId; - } - - public void setRequirementSpecProjectId(int requirementSpecProjectId) { - this.requirementSpecProjectId = requirementSpecProjectId; - } - - public int getRequirementSpecSpecLevelId() { - return requirementSpecSpecLevelId; - } - - public void setRequirementSpecSpecLevelId(int requirementSpecSpecLevelId) { - this.requirementSpecSpecLevelId = requirementSpecSpecLevelId; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (int) id; - hash += (int) requirementSpecId; - hash += (int) requirementSpecProjectId; - hash += (int) requirementSpecSpecLevelId; - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RequirementSpecNodePK)) { - return false; - } - RequirementSpecNodePK other = (RequirementSpecNodePK) object; - if (this.id != other.id) { - return false; - } - if (this.requirementSpecId != other.requirementSpecId) { - return false; - } - if (this.requirementSpecProjectId != other.requirementSpecProjectId) { - return false; - } - return this.requirementSpecSpecLevelId == other.requirementSpecSpecLevelId; - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RequirementSpecNodePK[ id=" - + id + ", requirementSpecId=" + requirementSpecId - + ", requirementSpecProjectId=" + requirementSpecProjectId - + ", requirementSpecSpecLevelId=" + requirementSpecSpecLevelId + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Embeddable +public class RequirementSpecNodePK implements Serializable { + + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "RequirementSpecNodeGen") + @TableGenerator(name = "RequirementSpecNodeGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "requirement_spec_node", + allocationSize = 1, + initialValue = 1_000) + @NotNull + @Column(name = "id") + private int id; + @Basic(optional = false) + @NotNull + @Column(name = "requirement_spec_id") + private int requirementSpecId; + @Basic(optional = false) + @NotNull + @Column(name = "requirement_spec_project_id") + private int requirementSpecProjectId; + @Basic(optional = false) + @NotNull + @Column(name = "requirement_spec_spec_level_id") + private int requirementSpecSpecLevelId; + + public RequirementSpecNodePK() { + } + + public RequirementSpecNodePK(int requirementSpecId, + int requirementSpecProjectId, int requirementSpecSpecLevelId) { + this.requirementSpecId = requirementSpecId; + this.requirementSpecProjectId = requirementSpecProjectId; + this.requirementSpecSpecLevelId = requirementSpecSpecLevelId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getRequirementSpecId() { + return requirementSpecId; + } + + public void setRequirementSpecId(int requirementSpecId) { + this.requirementSpecId = requirementSpecId; + } + + public int getRequirementSpecProjectId() { + return requirementSpecProjectId; + } + + public void setRequirementSpecProjectId(int requirementSpecProjectId) { + this.requirementSpecProjectId = requirementSpecProjectId; + } + + public int getRequirementSpecSpecLevelId() { + return requirementSpecSpecLevelId; + } + + public void setRequirementSpecSpecLevelId(int requirementSpecSpecLevelId) { + this.requirementSpecSpecLevelId = requirementSpecSpecLevelId; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (int) id; + hash += (int) requirementSpecId; + hash += (int) requirementSpecProjectId; + hash += (int) requirementSpecSpecLevelId; + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RequirementSpecNodePK)) { + return false; + } + RequirementSpecNodePK other = (RequirementSpecNodePK) object; + if (this.id != other.id) { + return false; + } + if (this.requirementSpecId != other.requirementSpecId) { + return false; + } + if (this.requirementSpecProjectId != other.requirementSpecProjectId) { + return false; + } + return this.requirementSpecSpecLevelId == other.requirementSpecSpecLevelId; + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RequirementSpecNodePK[ id=" + + id + ", requirementSpecId=" + requirementSpecId + + ", requirementSpecProjectId=" + requirementSpecProjectId + + ", requirementSpecSpecLevelId=" + requirementSpecSpecLevelId + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpecPK.java b/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpecPK.java index 73396a14..df54ea48 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpecPK.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RequirementSpecPK.java @@ -13,105 +13,105 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Embeddable -public class RequirementSpecPK implements Serializable { - - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, generator = "ReqSpecGen") - @TableGenerator(name = "ReqSpecGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "requirement_spec", - allocationSize = 1, - initialValue = 1000) - @NotNull - @Column(name = "id") - private int id; - @Basic(optional = false) - @NotNull - @Column(name = "project_id") - private int projectId; - @Basic(optional = false) - @NotNull - @Column(name = "spec_level_id") - private int specLevelId; - - public RequirementSpecPK() { - } - - public RequirementSpecPK(int projectId, int specLevelId) { - this.projectId = projectId; - this.specLevelId = specLevelId; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getProjectId() { - return projectId; - } - - public void setProjectId(int projectId) { - this.projectId = projectId; - } - - public int getSpecLevelId() { - return specLevelId; - } - - public void setSpecLevelId(int specLevelId) { - this.specLevelId = specLevelId; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (int) id; - hash += (int) projectId; - hash += (int) specLevelId; - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RequirementSpecPK)) { - return false; - } - RequirementSpecPK other = (RequirementSpecPK) object; - if (this.id != other.id) { - return false; - } - if (this.projectId != other.projectId) { - return false; - } - return this.specLevelId == other.specLevelId; - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RequirementSpecPK[ id=" + id - + ", projectId=" + projectId + ", specLevelId=" + specLevelId + " ]"; - } - -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Embeddable +public class RequirementSpecPK implements Serializable { + + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "ReqSpecGen") + @TableGenerator(name = "ReqSpecGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "requirement_spec", + allocationSize = 1, + initialValue = 1_000) + @NotNull + @Column(name = "id") + private int id; + @Basic(optional = false) + @NotNull + @Column(name = "project_id") + private int projectId; + @Basic(optional = false) + @NotNull + @Column(name = "spec_level_id") + private int specLevelId; + + public RequirementSpecPK() { + } + + public RequirementSpecPK(int projectId, int specLevelId) { + this.projectId = projectId; + this.specLevelId = specLevelId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getProjectId() { + return projectId; + } + + public void setProjectId(int projectId) { + this.projectId = projectId; + } + + public int getSpecLevelId() { + return specLevelId; + } + + public void setSpecLevelId(int specLevelId) { + this.specLevelId = specLevelId; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (int) id; + hash += (int) projectId; + hash += (int) specLevelId; + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RequirementSpecPK)) { + return false; + } + RequirementSpecPK other = (RequirementSpecPK) object; + if (this.id != other.id) { + return false; + } + if (this.projectId != other.projectId) { + return false; + } + return this.specLevelId == other.specLevelId; + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RequirementSpecPK[ id=" + id + + ", projectId=" + projectId + ", specLevelId=" + specLevelId + " ]"; + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RequirementStatus.java b/VM-Core/src/main/java/com/validation/manager/core/db/RequirementStatus.java index 9c2cd3c9..87c14762 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RequirementStatus.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RequirementStatus.java @@ -13,118 +13,118 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "requirement_status") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "RequirementStatus.findAll", - query = "SELECT r FROM RequirementStatus r") - , @NamedQuery(name = "RequirementStatus.findById", - query = "SELECT r FROM RequirementStatus r WHERE r.id = :id") - , @NamedQuery(name = "RequirementStatus.findByStatus", - query = "SELECT r FROM RequirementStatus r WHERE r.status = :status")}) -public class RequirementStatus implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "ReqStatusGen") - @TableGenerator(name = "ReqStatusGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "requirement_status", - allocationSize = 1, - initialValue = 1000) - @Basic(optional = false) - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "status") - private String status; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "requirementStatusId") - private List requirementList; - - public RequirementStatus() { - } - - public RequirementStatus(String status) { - this.status = status; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - @XmlTransient - @JsonIgnore - public List getRequirementList() { - return requirementList; - } - - public void setRequirementList(List requirementList) { - this.requirementList = requirementList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RequirementStatus)) { - return false; - } - RequirementStatus other = (RequirementStatus) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RequirementStatus[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "requirement_status") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "RequirementStatus.findAll", + query = "SELECT r FROM RequirementStatus r") + , @NamedQuery(name = "RequirementStatus.findById", + query = "SELECT r FROM RequirementStatus r WHERE r.id = :id") + , @NamedQuery(name = "RequirementStatus.findByStatus", + query = "SELECT r FROM RequirementStatus r WHERE r.status = :status")}) +public class RequirementStatus implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "ReqStatusGen") + @TableGenerator(name = "ReqStatusGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "requirement_status", + allocationSize = 1, + initialValue = 1_000) + @Basic(optional = false) + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "status") + private String status; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "requirementStatusId") + private List requirementList; + + public RequirementStatus() { + } + + public RequirementStatus(String status) { + this.status = status; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @XmlTransient + @JsonIgnore + public List getRequirementList() { + return requirementList; + } + + public void setRequirementList(List requirementList) { + this.requirementList = requirementList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RequirementStatus)) { + return false; + } + RequirementStatus other = (RequirementStatus) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RequirementStatus[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RequirementType.java b/VM-Core/src/main/java/com/validation/manager/core/db/RequirementType.java index ea37099e..1a1b185a 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RequirementType.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RequirementType.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,153 +13,153 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "requirement_type") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "RequirementType.findAll", - query = "SELECT r FROM RequirementType r") - , @NamedQuery(name = "RequirementType.findById", - query = "SELECT r FROM RequirementType r WHERE r.id = :id") - , @NamedQuery(name = "RequirementType.findByName", - query = "SELECT r FROM RequirementType r WHERE r.name = :name") - , @NamedQuery(name = "RequirementType.findByDescription", - query = "SELECT r FROM RequirementType r WHERE " - + "r.description = :description")}) -public class RequirementType implements Serializable { - - @Basic(optional = false) - @NotNull - @Column(name = "level") - private int level; - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "ReqTypeGen") - @TableGenerator(name = "ReqType", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "requirement_type", - allocationSize = 1, - initialValue = 1000) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Size(max = 255) - @Column(name = "description") - private String description; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "requirementTypeId") - private List requirementList; - - public RequirementType() { - super(); - } - - public RequirementType(String name) { - super(); - this.name = name; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getRequirementList() { - return requirementList; - } - - public void setRequirementList(List requirementList) { - this.requirementList = requirementList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RequirementType)) { - return false; - } - RequirementType other = (RequirementType) object; - return !this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RequirementType[ id=" + id + " ]"; - } - - /** - * @return the level - */ - public int getLevel() { - return level; - } - - /** - * @param level the level to set - */ - public void setLevel(int level) { - this.level = level; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "requirement_type") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "RequirementType.findAll", + query = "SELECT r FROM RequirementType r") + , @NamedQuery(name = "RequirementType.findById", + query = "SELECT r FROM RequirementType r WHERE r.id = :id") + , @NamedQuery(name = "RequirementType.findByName", + query = "SELECT r FROM RequirementType r WHERE r.name = :name") + , @NamedQuery(name = "RequirementType.findByDescription", + query = "SELECT r FROM RequirementType r WHERE " + + "r.description = :description")}) +public class RequirementType implements Serializable { + + @Basic(optional = false) + @NotNull + @Column(name = "level") + private int level; + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "ReqTypeGen") + @TableGenerator(name = "ReqTypeGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "requirement_type", + allocationSize = 1, + initialValue = 1_000) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Size(max = 255) + @Column(name = "description") + private String description; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "requirementTypeId") + private List requirementList; + + public RequirementType() { + super(); + } + + public RequirementType(String name) { + super(); + this.name = name; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getRequirementList() { + return requirementList; + } + + public void setRequirementList(List requirementList) { + this.requirementList = requirementList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RequirementType)) { + return false; + } + RequirementType other = (RequirementType) object; + return !this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RequirementType[ id=" + id + " ]"; + } + + /** + * @return the level + */ + public int getLevel() { + return level; + } + + /** + * @param level the level to set + */ + public void setLevel(int level) { + this.level = level; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RiskCategory.java b/VM-Core/src/main/java/com/validation/manager/core/db/RiskCategory.java index 96f1c92d..c3db294c 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RiskCategory.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RiskCategory.java @@ -13,160 +13,160 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.ManyToMany; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "risk_category") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "RiskCategory.findAll", - query = "SELECT r FROM RiskCategory r") - , @NamedQuery(name = "RiskCategory.findById", - query = "SELECT r FROM RiskCategory r WHERE r.id = :id") - , @NamedQuery(name = "RiskCategory.findByName", - query = "SELECT r FROM RiskCategory r WHERE r.name = :name") - , @NamedQuery(name = "RiskCategory.findByMinimum", - query = "SELECT r FROM RiskCategory r WHERE r.minimum = :minimum") - , @NamedQuery(name = "RiskCategory.findByMaximum", - query = "SELECT r FROM RiskCategory r WHERE r.maximum = :maximum")}) -public class RiskCategory implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.TABLE, generator = "RCGen") - @TableGenerator(name = "RCGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "risk_category", - allocationSize = 1, - initialValue = 1000) - @Basic(optional = false) - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "name") - private String name; - @Basic(optional = false) - @NotNull - @Column(name = "minimum") - private int minimum; - @Basic(optional = false) - @NotNull - @Column(name = "maximum") - private int maximum; - @ManyToMany(mappedBy = "riskCategoryList") - private List fmeaList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "riskCategory") - private List riskItemHasRiskCategoryList; - - public RiskCategory() { - } - - public RiskCategory(String name, int minimum, int maximum) { - this.name = name; - this.minimum = minimum; - this.maximum = maximum; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getMinimum() { - return minimum; - } - - public void setMinimum(int minimum) { - this.minimum = minimum; - } - - public int getMaximum() { - return maximum; - } - - public void setMaximum(int maximum) { - this.maximum = maximum; - } - - @XmlTransient - @JsonIgnore - public List getFmeaList() { - return fmeaList; - } - - public void setFmeaList(List fmeaList) { - this.fmeaList = fmeaList; - } - - @XmlTransient - @JsonIgnore - public List getRiskItemHasRiskCategoryList() { - return riskItemHasRiskCategoryList; - } - - public void setRiskItemHasRiskCategoryList(List riskItemHasRiskCategoryList) { - this.riskItemHasRiskCategoryList = riskItemHasRiskCategoryList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RiskCategory)) { - return false; - } - RiskCategory other = (RiskCategory) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RiskCategory[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "risk_category") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "RiskCategory.findAll", + query = "SELECT r FROM RiskCategory r") + , @NamedQuery(name = "RiskCategory.findById", + query = "SELECT r FROM RiskCategory r WHERE r.id = :id") + , @NamedQuery(name = "RiskCategory.findByName", + query = "SELECT r FROM RiskCategory r WHERE r.name = :name") + , @NamedQuery(name = "RiskCategory.findByMinimum", + query = "SELECT r FROM RiskCategory r WHERE r.minimum = :minimum") + , @NamedQuery(name = "RiskCategory.findByMaximum", + query = "SELECT r FROM RiskCategory r WHERE r.maximum = :maximum")}) +public class RiskCategory implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.TABLE, generator = "RCGen") + @TableGenerator(name = "RCGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "risk_category", + allocationSize = 1, + initialValue = 1_000) + @Basic(optional = false) + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "name") + private String name; + @Basic(optional = false) + @NotNull + @Column(name = "minimum") + private int minimum; + @Basic(optional = false) + @NotNull + @Column(name = "maximum") + private int maximum; + @ManyToMany(mappedBy = "riskCategoryList") + private List fmeaList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "riskCategory") + private List riskItemHasRiskCategoryList; + + public RiskCategory() { + } + + public RiskCategory(String name, int minimum, int maximum) { + this.name = name; + this.minimum = minimum; + this.maximum = maximum; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getMinimum() { + return minimum; + } + + public void setMinimum(int minimum) { + this.minimum = minimum; + } + + public int getMaximum() { + return maximum; + } + + public void setMaximum(int maximum) { + this.maximum = maximum; + } + + @XmlTransient + @JsonIgnore + public List getFmeaList() { + return fmeaList; + } + + public void setFmeaList(List fmeaList) { + this.fmeaList = fmeaList; + } + + @XmlTransient + @JsonIgnore + public List getRiskItemHasRiskCategoryList() { + return riskItemHasRiskCategoryList; + } + + public void setRiskItemHasRiskCategoryList(List riskItemHasRiskCategoryList) { + this.riskItemHasRiskCategoryList = riskItemHasRiskCategoryList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RiskCategory)) { + return false; + } + RiskCategory other = (RiskCategory) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RiskCategory[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RiskControlPK.java b/VM-Core/src/main/java/com/validation/manager/core/db/RiskControlPK.java index 0c1492a0..e9dd0147 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RiskControlPK.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RiskControlPK.java @@ -13,87 +13,87 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Embeddable -public class RiskControlPK implements Serializable { - - @Basic(optional = false) - @NotNull - @Column(name = "id") - @GeneratedValue(strategy = GenerationType.TABLE, generator = "RiskCGen") - @TableGenerator(name = "RiskCGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "risk_control", - allocationSize = 1, - initialValue = 1000) - private int id; - @Basic(optional = false) - @NotNull - @Column(name = "risk_control_type_id") - private int riskControlTypeId; - - public RiskControlPK() { - } - - public RiskControlPK(int riskControlTypeId) { - this.riskControlTypeId = riskControlTypeId; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getRiskControlTypeId() { - return riskControlTypeId; - } - - public void setRiskControlTypeId(int riskControlTypeId) { - this.riskControlTypeId = riskControlTypeId; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (int) id; - hash += (int) riskControlTypeId; - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RiskControlPK)) { - return false; - } - RiskControlPK other = (RiskControlPK) object; - if (this.id != other.id) { - return false; - } - return this.riskControlTypeId == other.riskControlTypeId; - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RiskControlPK[ id=" + id - + ", riskControlTypeId=" + riskControlTypeId + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Embeddable +public class RiskControlPK implements Serializable { + + @Basic(optional = false) + @NotNull + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.TABLE, generator = "RiskCGen") + @TableGenerator(name = "RiskCGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "risk_control", + allocationSize = 1, + initialValue = 1_000) + private int id; + @Basic(optional = false) + @NotNull + @Column(name = "risk_control_type_id") + private int riskControlTypeId; + + public RiskControlPK() { + } + + public RiskControlPK(int riskControlTypeId) { + this.riskControlTypeId = riskControlTypeId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getRiskControlTypeId() { + return riskControlTypeId; + } + + public void setRiskControlTypeId(int riskControlTypeId) { + this.riskControlTypeId = riskControlTypeId; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (int) id; + hash += (int) riskControlTypeId; + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RiskControlPK)) { + return false; + } + RiskControlPK other = (RiskControlPK) object; + if (this.id != other.id) { + return false; + } + return this.riskControlTypeId == other.riskControlTypeId; + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RiskControlPK[ id=" + id + + ", riskControlTypeId=" + riskControlTypeId + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RiskControlType.java b/VM-Core/src/main/java/com/validation/manager/core/db/RiskControlType.java index 3a25038c..1fc3a017 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RiskControlType.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RiskControlType.java @@ -13,134 +13,134 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "risk_control_type") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "RiskControlType.findAll", - query = "SELECT r FROM RiskControlType r") - , @NamedQuery(name = "RiskControlType.findById", - query = "SELECT r FROM RiskControlType r WHERE r.id = :id") - , @NamedQuery(name = "RiskControlType.findByName", - query = "SELECT r FROM RiskControlType r WHERE r.name = :name")}) -public class RiskControlType implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "RiskControlTypeGen") - @TableGenerator(name = "RiskControlTypeGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "risk_control_type", - allocationSize = 1, - initialValue = 1000) - @Basic(optional = false) - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Basic(optional = false) - @NotNull - @Lob - @Size(max = 2147483647) - @Column(name = "description") - private String description; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "riskControlType") - private List riskControlList; - - public RiskControlType() { - } - - public RiskControlType(String name, String description) { - this.name = name; - this.description = description; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getRiskControlList() { - return riskControlList; - } - - public void setRiskControlList(List riskControlList) { - this.riskControlList = riskControlList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RiskControlType)) { - return false; - } - RiskControlType other = (RiskControlType) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RiskControlType[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "risk_control_type") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "RiskControlType.findAll", + query = "SELECT r FROM RiskControlType r") + , @NamedQuery(name = "RiskControlType.findById", + query = "SELECT r FROM RiskControlType r WHERE r.id = :id") + , @NamedQuery(name = "RiskControlType.findByName", + query = "SELECT r FROM RiskControlType r WHERE r.name = :name")}) +public class RiskControlType implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "RiskControlTypeGen") + @TableGenerator(name = "RiskControlTypeGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "risk_control_type", + allocationSize = 1, + initialValue = 1_000) + @Basic(optional = false) + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Basic(optional = false) + @NotNull + @Lob + @Size(max = 2_147_483_647) + @Column(name = "description") + private String description; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "riskControlType") + private List riskControlList; + + public RiskControlType() { + } + + public RiskControlType(String name, String description) { + this.name = name; + this.description = description; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getRiskControlList() { + return riskControlList; + } + + public void setRiskControlList(List riskControlList) { + this.riskControlList = riskControlList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RiskControlType)) { + return false; + } + RiskControlType other = (RiskControlType) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RiskControlType[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RiskItemPK.java b/VM-Core/src/main/java/com/validation/manager/core/db/RiskItemPK.java index 56185f60..48d6e758 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RiskItemPK.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RiskItemPK.java @@ -13,86 +13,86 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Embeddable -public class RiskItemPK implements Serializable { - - @Basic(optional = false) - @Column(name = "id") - @GeneratedValue(strategy = GenerationType.TABLE, generator = "RIGen") - @TableGenerator(name = "RIGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "risk_item", - allocationSize = 1, - initialValue = 1000) - private int id; - @Basic(optional = false) - @NotNull - @Column(name = "FMEA_id") - private int fMEAid; - - public RiskItemPK() { - } - - public RiskItemPK(int fMEAid) { - this.fMEAid = fMEAid; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getFMEAid() { - return fMEAid; - } - - public void setFMEAid(int fMEAid) { - this.fMEAid = fMEAid; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (int) id; - hash += (int) fMEAid; - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RiskItemPK)) { - return false; - } - RiskItemPK other = (RiskItemPK) object; - if (this.id != other.id) { - return false; - } - return this.fMEAid == other.fMEAid; - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RiskItemPK[ id=" + id - + ", fMEAid=" + fMEAid + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Embeddable +public class RiskItemPK implements Serializable { + + @Basic(optional = false) + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.TABLE, generator = "RIGen") + @TableGenerator(name = "RIGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "risk_item", + allocationSize = 1, + initialValue = 1_000) + private int id; + @Basic(optional = false) + @NotNull + @Column(name = "FMEA_id") + private int fMEAid; + + public RiskItemPK() { + } + + public RiskItemPK(int fMEAid) { + this.fMEAid = fMEAid; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getFMEAid() { + return fMEAid; + } + + public void setFMEAid(int fMEAid) { + this.fMEAid = fMEAid; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (int) id; + hash += (int) fMEAid; + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RiskItemPK)) { + return false; + } + RiskItemPK other = (RiskItemPK) object; + if (this.id != other.id) { + return false; + } + return this.fMEAid == other.fMEAid; + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RiskItemPK[ id=" + id + + ", fMEAid=" + fMEAid + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/Role.java b/VM-Core/src/main/java/com/validation/manager/core/db/Role.java index 20c2f5b7..2ceab0b1 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/Role.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/Role.java @@ -13,185 +13,185 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "role") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Role.findAll", query = "SELECT r FROM Role r") - , @NamedQuery(name = "Role.findById", - query = "SELECT r FROM Role r WHERE r.id = :id") - , @NamedQuery(name = "Role.findByName", - query = "SELECT r FROM Role r WHERE r.roleName = :name")}) -public class Role implements Serializable { - - private static final long serialVersionUID = 1L; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "role") - private List executionStepHasVmUserList; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, generator = "RoleGen") - @TableGenerator(name = "RoleGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "role", - allocationSize = 1, - initialValue = 1000) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "role_name") - private String roleName; - @Lob - @Size(max = 65535) - @Column(name = "description") - private String description; - @JoinTable(name = "user_has_role", joinColumns = { - @JoinColumn(name = "role_id", referencedColumnName = "id")}, - inverseJoinColumns = { - @JoinColumn(name = "user_id", referencedColumnName = "id")}) - @ManyToMany - private List vmUserList; - @ManyToMany(mappedBy = "roleList") - private List userRightList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "role") - private List userTestProjectRoleList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "role") - private List userTestPlanRoleList; - - public Role() { - } - - public Role(String description) { - this.description = description; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getRoleName() { - return roleName; - } - - public void setRoleName(String roleName) { - this.roleName = roleName; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getVmUserList() { - return vmUserList; - } - - public void setVmUserList(List vmUserList) { - this.vmUserList = vmUserList; - } - - @XmlTransient - @JsonIgnore - public List getUserRightList() { - return userRightList; - } - - public void setUserRightList(List userRightList) { - this.userRightList = userRightList; - } - - @XmlTransient - @JsonIgnore - public List getUserTestProjectRoleList() { - return userTestProjectRoleList; - } - - public void setUserTestProjectRoleList(List userTestProjectRoleList) { - this.userTestProjectRoleList = userTestProjectRoleList; - } - - @XmlTransient - @JsonIgnore - public List getUserTestPlanRoleList() { - return userTestPlanRoleList; - } - - public void setUserTestPlanRoleList(List userTestPlanRoleList) { - this.userTestPlanRoleList = userTestPlanRoleList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof Role)) { - return false; - } - Role other = (Role) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.Role[ id=" + id + " ]"; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepHasVmUserList() { - return executionStepHasVmUserList; - } - - public void setExecutionStepHasVmUserList(List executionStepHasVmUserList) { - this.executionStepHasVmUserList = executionStepHasVmUserList; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "role") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Role.findAll", query = "SELECT r FROM Role r") + , @NamedQuery(name = "Role.findById", + query = "SELECT r FROM Role r WHERE r.id = :id") + , @NamedQuery(name = "Role.findByName", + query = "SELECT r FROM Role r WHERE r.roleName = :name")}) +public class Role implements Serializable { + + private static final long serialVersionUID = 1L; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "role") + private List executionStepHasVmUserList; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "RoleGen") + @TableGenerator(name = "RoleGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "role", + allocationSize = 1, + initialValue = 1_000) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "role_name") + private String roleName; + @Lob + @Size(max = 65_535) + @Column(name = "description") + private String description; + @JoinTable(name = "user_has_role", joinColumns = { + @JoinColumn(name = "role_id", referencedColumnName = "id")}, + inverseJoinColumns = { + @JoinColumn(name = "user_id", referencedColumnName = "id")}) + @ManyToMany + private List vmUserList; + @ManyToMany(mappedBy = "roleList") + private List userRightList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "role") + private List userTestProjectRoleList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "role") + private List userTestPlanRoleList; + + public Role() { + } + + public Role(String description) { + this.description = description; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getRoleName() { + return roleName; + } + + public void setRoleName(String roleName) { + this.roleName = roleName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getVmUserList() { + return vmUserList; + } + + public void setVmUserList(List vmUserList) { + this.vmUserList = vmUserList; + } + + @XmlTransient + @JsonIgnore + public List getUserRightList() { + return userRightList; + } + + public void setUserRightList(List userRightList) { + this.userRightList = userRightList; + } + + @XmlTransient + @JsonIgnore + public List getUserTestProjectRoleList() { + return userTestProjectRoleList; + } + + public void setUserTestProjectRoleList(List userTestProjectRoleList) { + this.userTestProjectRoleList = userTestProjectRoleList; + } + + @XmlTransient + @JsonIgnore + public List getUserTestPlanRoleList() { + return userTestPlanRoleList; + } + + public void setUserTestPlanRoleList(List userTestPlanRoleList) { + this.userTestPlanRoleList = userTestPlanRoleList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof Role)) { + return false; + } + Role other = (Role) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.Role[ id=" + id + " ]"; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepHasVmUserList() { + return executionStepHasVmUserList; + } + + public void setExecutionStepHasVmUserList(List executionStepHasVmUserList) { + this.executionStepHasVmUserList = executionStepHasVmUserList; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RootCause.java b/VM-Core/src/main/java/com/validation/manager/core/db/RootCause.java index 212ee4fd..1536da24 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RootCause.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RootCause.java @@ -13,153 +13,153 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "root_cause") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "RootCause.findAll", - query = "SELECT r FROM RootCause r") - , @NamedQuery(name = "RootCause.findById", - query = "SELECT r FROM RootCause r WHERE r.rootCausePK.id = :id") - , @NamedQuery(name = "RootCause.findByRootCauseTypeId", - query = "SELECT r FROM RootCause r WHERE " - + "r.rootCausePK.rootCauseTypeId = :rootCauseTypeId")}) -public class RootCause implements Serializable { - - private static final long serialVersionUID = 1L; - @EmbeddedId - protected RootCausePK rootCausePK; - @Basic(optional = false) - @NotNull - @Lob - @Size(max = 2147483647) - @Column(name = "details") - private String details; - @JoinTable(name = "root_cause_has_user", joinColumns = { - @JoinColumn(name = "root_cause_id", referencedColumnName = "id") - , @JoinColumn(name = "root_cause_root_cause_type_id", - referencedColumnName = "root_cause_type_id")}, - inverseJoinColumns = { - @JoinColumn(name = "vm_user_id", referencedColumnName = "id")}) - @ManyToMany - private List vmUserList; - @JoinColumn(name = "root_cause_type_id", referencedColumnName = "id", - insertable = false, updatable = false) - @ManyToOne(optional = false) - private RootCauseType rootCauseType; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "rootCause") - private List exceptionHasRootCauseList; - - public RootCause() { - } - - public RootCause(RootCausePK rootCausePK) { - this.rootCausePK = rootCausePK; - } - - public RootCause(RootCausePK rootCausePK, String details) { - this.rootCausePK = rootCausePK; - this.details = details; - } - - public RootCause(int id, int rootCauseTypeId) { - this.rootCausePK = new RootCausePK(id, rootCauseTypeId); - } - - public RootCausePK getRootCausePK() { - return rootCausePK; - } - - public void setRootCausePK(RootCausePK rootCausePK) { - this.rootCausePK = rootCausePK; - } - - public String getDetails() { - return details; - } - - public void setDetails(String details) { - this.details = details; - } - - @XmlTransient - @JsonIgnore - public List getVmUserList() { - return vmUserList; - } - - public void setVmUserList(List vmUserList) { - this.vmUserList = vmUserList; - } - - public RootCauseType getRootCauseType() { - return rootCauseType; - } - - public void setRootCauseType(RootCauseType rootCauseType) { - this.rootCauseType = rootCauseType; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (rootCausePK != null ? rootCausePK.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RootCause)) { - return false; - } - RootCause other = (RootCause) object; - return !((this.rootCausePK == null && other.rootCausePK != null) - || (this.rootCausePK != null - && !this.rootCausePK.equals(other.rootCausePK))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RootCause[ rootCausePK=" - + rootCausePK + " ]"; - } - - @XmlTransient - @JsonIgnore - public List getExceptionHasRootCauseList() { - return exceptionHasRootCauseList; - } - - public void setExceptionHasRootCauseList(List exceptionHasRootCauseList) { - this.exceptionHasRootCauseList = exceptionHasRootCauseList; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "root_cause") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "RootCause.findAll", + query = "SELECT r FROM RootCause r") + , @NamedQuery(name = "RootCause.findById", + query = "SELECT r FROM RootCause r WHERE r.rootCausePK.id = :id") + , @NamedQuery(name = "RootCause.findByRootCauseTypeId", + query = "SELECT r FROM RootCause r WHERE " + + "r.rootCausePK.rootCauseTypeId = :rootCauseTypeId")}) +public class RootCause implements Serializable { + + private static final long serialVersionUID = 1L; + @EmbeddedId + protected RootCausePK rootCausePK; + @Basic(optional = false) + @NotNull + @Lob + @Size(max = 2_147_483_647) + @Column(name = "details") + private String details; + @JoinTable(name = "root_cause_has_user", joinColumns = { + @JoinColumn(name = "root_cause_id", referencedColumnName = "id") + , @JoinColumn(name = "root_cause_root_cause_type_id", + referencedColumnName = "root_cause_type_id")}, + inverseJoinColumns = { + @JoinColumn(name = "vm_user_id", referencedColumnName = "id")}) + @ManyToMany + private List vmUserList; + @JoinColumn(name = "root_cause_type_id", referencedColumnName = "id", + insertable = false, updatable = false) + @ManyToOne(optional = false) + private RootCauseType rootCauseType; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "rootCause") + private List exceptionHasRootCauseList; + + public RootCause() { + } + + public RootCause(RootCausePK rootCausePK) { + this.rootCausePK = rootCausePK; + } + + public RootCause(RootCausePK rootCausePK, String details) { + this.rootCausePK = rootCausePK; + this.details = details; + } + + public RootCause(int id, int rootCauseTypeId) { + this.rootCausePK = new RootCausePK(id, rootCauseTypeId); + } + + public RootCausePK getRootCausePK() { + return rootCausePK; + } + + public void setRootCausePK(RootCausePK rootCausePK) { + this.rootCausePK = rootCausePK; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + @XmlTransient + @JsonIgnore + public List getVmUserList() { + return vmUserList; + } + + public void setVmUserList(List vmUserList) { + this.vmUserList = vmUserList; + } + + public RootCauseType getRootCauseType() { + return rootCauseType; + } + + public void setRootCauseType(RootCauseType rootCauseType) { + this.rootCauseType = rootCauseType; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (rootCausePK != null ? rootCausePK.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RootCause)) { + return false; + } + RootCause other = (RootCause) object; + return !((this.rootCausePK == null && other.rootCausePK != null) + || (this.rootCausePK != null + && !this.rootCausePK.equals(other.rootCausePK))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RootCause[ rootCausePK=" + + rootCausePK + " ]"; + } + + @XmlTransient + @JsonIgnore + public List getExceptionHasRootCauseList() { + return exceptionHasRootCauseList; + } + + public void setExceptionHasRootCauseList(List exceptionHasRootCauseList) { + this.exceptionHasRootCauseList = exceptionHasRootCauseList; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RootCausePK.java b/VM-Core/src/main/java/com/validation/manager/core/db/RootCausePK.java index 75f22b5d..395fd8ed 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RootCausePK.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RootCausePK.java @@ -13,88 +13,88 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Embeddable -public class RootCausePK implements Serializable { - - @Basic(optional = false) - @NotNull - @Column(name = "id") - @GeneratedValue(strategy = GenerationType.TABLE, generator = "RootCGen") - @TableGenerator(name = "RootCGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "root_cause", - allocationSize = 1, - initialValue = 1000) - private int id; - @Basic(optional = false) - @NotNull - @Column(name = "root_cause_type_id") - private int rootCauseTypeId; - - public RootCausePK() { - } - - public RootCausePK(int id, int rootCauseTypeId) { - this.id = id; - this.rootCauseTypeId = rootCauseTypeId; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getRootCauseTypeId() { - return rootCauseTypeId; - } - - public void setRootCauseTypeId(int rootCauseTypeId) { - this.rootCauseTypeId = rootCauseTypeId; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (int) id; - hash += (int) rootCauseTypeId; - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RootCausePK)) { - return false; - } - RootCausePK other = (RootCausePK) object; - if (this.id != other.id) { - return false; - } - return this.rootCauseTypeId == other.rootCauseTypeId; - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RootCausePK[ id=" + id - + ", rootCauseTypeId=" + rootCauseTypeId + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Embeddable +public class RootCausePK implements Serializable { + + @Basic(optional = false) + @NotNull + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.TABLE, generator = "RootCGen") + @TableGenerator(name = "RootCGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "root_cause", + allocationSize = 1, + initialValue = 1_000) + private int id; + @Basic(optional = false) + @NotNull + @Column(name = "root_cause_type_id") + private int rootCauseTypeId; + + public RootCausePK() { + } + + public RootCausePK(int id, int rootCauseTypeId) { + this.id = id; + this.rootCauseTypeId = rootCauseTypeId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getRootCauseTypeId() { + return rootCauseTypeId; + } + + public void setRootCauseTypeId(int rootCauseTypeId) { + this.rootCauseTypeId = rootCauseTypeId; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (int) id; + hash += (int) rootCauseTypeId; + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RootCausePK)) { + return false; + } + RootCausePK other = (RootCausePK) object; + if (this.id != other.id) { + return false; + } + return this.rootCauseTypeId == other.rootCauseTypeId; + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RootCausePK[ id=" + id + + ", rootCauseTypeId=" + rootCauseTypeId + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/RootCauseType.java b/VM-Core/src/main/java/com/validation/manager/core/db/RootCauseType.java index 726f6b01..78ba305e 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/RootCauseType.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/RootCauseType.java @@ -13,140 +13,140 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "root_cause_type") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "RootCauseType.findAll", - query = "SELECT r FROM RootCauseType r") - , @NamedQuery(name = "RootCauseType.findById", - query = "SELECT r FROM RootCauseType r WHERE r.id = :id") - , @NamedQuery(name = "RootCauseType.findByName", - query = "SELECT r FROM RootCauseType r WHERE r.name = :name") - , @NamedQuery(name = "RootCauseType.findByDescription", - query = "SELECT r FROM RootCauseType r WHERE r.description = :description")}) -public class RootCauseType implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @NotNull - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "RootCauseTypeGen") - @TableGenerator(name = "RootCauseTypeGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "root_cause_type", - allocationSize = 1, - initialValue = 1000) - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "description") - private String description; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "rootCauseType") - private List rootCauseList; - - public RootCauseType() { - } - - public RootCauseType(Integer id) { - this.id = id; - } - - public RootCauseType(Integer id, String name, String description) { - this.id = id; - this.name = name; - this.description = description; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getRootCauseList() { - return rootCauseList; - } - - public void setRootCauseList(List rootCauseList) { - this.rootCauseList = rootCauseList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof RootCauseType)) { - return false; - } - RootCauseType other = (RootCauseType) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.RootCauseType[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "root_cause_type") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "RootCauseType.findAll", + query = "SELECT r FROM RootCauseType r") + , @NamedQuery(name = "RootCauseType.findById", + query = "SELECT r FROM RootCauseType r WHERE r.id = :id") + , @NamedQuery(name = "RootCauseType.findByName", + query = "SELECT r FROM RootCauseType r WHERE r.name = :name") + , @NamedQuery(name = "RootCauseType.findByDescription", + query = "SELECT r FROM RootCauseType r WHERE r.description = :description")}) +public class RootCauseType implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @NotNull + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "RootCauseTypeGen") + @TableGenerator(name = "RootCauseTypeGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "root_cause_type", + allocationSize = 1, + initialValue = 1_000) + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "description") + private String description; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "rootCauseType") + private List rootCauseList; + + public RootCauseType() { + } + + public RootCauseType(Integer id) { + this.id = id; + } + + public RootCauseType(Integer id, String name, String description) { + this.id = id; + this.name = name; + this.description = description; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getRootCauseList() { + return rootCauseList; + } + + public void setRootCauseList(List rootCauseList) { + this.rootCauseList = rootCauseList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RootCauseType)) { + return false; + } + RootCauseType other = (RootCauseType) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.RootCauseType[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/SpecLevel.java b/VM-Core/src/main/java/com/validation/manager/core/db/SpecLevel.java index bab75591..ff61abbb 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/SpecLevel.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/SpecLevel.java @@ -13,135 +13,135 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "spec_level") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "SpecLevel.findAll", - query = "SELECT s FROM SpecLevel s") - , @NamedQuery(name = "SpecLevel.findById", - query = "SELECT s FROM SpecLevel s WHERE s.id = :id") - , @NamedQuery(name = "SpecLevel.findByName", - query = "SELECT s FROM SpecLevel s WHERE s.name = :name")}) -public class SpecLevel implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "Spec_Level_IDGEN") - @TableGenerator(name = "Spec_Level_IDGEN", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "spec_level", - initialValue = 1000, - allocationSize = 1) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Basic(optional = false) - @NotNull - @Lob - @Size(min = 1, max = 65535) - @Column(name = "description") - private String description; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "specLevel") - private List requirementSpecList; - - public SpecLevel() { - } - - public SpecLevel(String name, String description) { - this.name = name; - this.description = description; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getRequirementSpecList() { - return requirementSpecList; - } - - public void setRequirementSpecList(List requirementSpecList) { - this.requirementSpecList = requirementSpecList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof SpecLevel)) { - return false; - } - SpecLevel other = (SpecLevel) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.SpecLevel[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "spec_level") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "SpecLevel.findAll", + query = "SELECT s FROM SpecLevel s") + , @NamedQuery(name = "SpecLevel.findById", + query = "SELECT s FROM SpecLevel s WHERE s.id = :id") + , @NamedQuery(name = "SpecLevel.findByName", + query = "SELECT s FROM SpecLevel s WHERE s.name = :name")}) +public class SpecLevel implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "Spec_Level_IDGEN") + @TableGenerator(name = "Spec_Level_IDGEN", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "spec_level", + initialValue = 1_000, + allocationSize = 1) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Basic(optional = false) + @NotNull + @Lob + @Size(min = 1, max = 65_535) + @Column(name = "description") + private String description; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "specLevel") + private List requirementSpecList; + + public SpecLevel() { + } + + public SpecLevel(String name, String description) { + this.name = name; + this.description = description; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getRequirementSpecList() { + return requirementSpecList; + } + + public void setRequirementSpecList(List requirementSpecList) { + this.requirementSpecList = requirementSpecList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof SpecLevel)) { + return false; + } + SpecLevel other = (SpecLevel) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.SpecLevel[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/Step.java b/VM-Core/src/main/java/com/validation/manager/core/db/Step.java index d99d2fbd..b8b74211 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/Step.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/Step.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,198 +13,198 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import com.validation.manager.core.history.Auditable; -import com.validation.manager.core.history.Versionable; -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "step") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Step.findAll", - query = "SELECT s FROM Step s") - , @NamedQuery(name = "Step.findById", - query = "SELECT s FROM Step s WHERE s.stepPK.id = :id") - , @NamedQuery(name = "Step.findByTestCaseId", - query = "SELECT s FROM Step s WHERE s.stepPK.testCaseId = :testCaseId") - , @NamedQuery(name = "Step.findByStepSequence", - query = "SELECT s FROM Step s WHERE s.stepSequence = :stepSequence")}) -public class Step extends Versionable implements Serializable { - - private static final long serialVersionUID = 1L; - @EmbeddedId - protected StepPK stepPK; - @Basic(optional = false) - @NotNull - @Column(name = "step_sequence") - private int stepSequence; - @Basic(optional = false) - @NotNull - @Lob - @Column(name = "text") - @Auditable - private byte[] text; - @Lob - @Column(name = "expected_result") - @Auditable - private byte[] expectedResult; - @Lob - @Size(max = 2147483647) - @Column(name = "notes") - @Auditable - private String notes; - @ManyToMany(mappedBy = "stepList") - private List requirementList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "step") - private List executionStepList; - @JoinColumn(name = "test_case_id", referencedColumnName = "id", - insertable = false, updatable = false) - @ManyToOne(optional = false) - private TestCase testCase; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "step") - private List historyList; - - public Step() { - } - - public Step(StepPK stepPK) { - this.stepPK = stepPK; - } - - public Step(StepPK stepPK, int stepSequence, byte[] text) { - this.stepPK = stepPK; - this.stepSequence = stepSequence; - this.text = text; - } - - public Step(int testCaseId) { - this.stepPK = new StepPK(testCaseId); - } - - public StepPK getStepPK() { - return stepPK; - } - - public void setStepPK(StepPK stepPK) { - this.stepPK = stepPK; - } - - public int getStepSequence() { - return stepSequence; - } - - public void setStepSequence(int stepSequence) { - this.stepSequence = stepSequence; - } - - public byte[] getExpectedResult() { - return expectedResult; - } - - public void setExpectedResult(byte[] expectedResult) { - this.expectedResult = expectedResult; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; - } - - @XmlTransient - @JsonIgnore - public List getRequirementList() { - return requirementList; - } - - public void setRequirementList(List requirementList) { - this.requirementList = requirementList; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepList() { - return executionStepList; - } - - public void setExecutionStepList(List executionStepList) { - this.executionStepList = executionStepList; - } - - public TestCase getTestCase() { - return testCase; - } - - public void setTestCase(TestCase testCase) { - this.testCase = testCase; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (stepPK != null ? stepPK.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - if (!(object instanceof Step)) { - return false; - } - Step other = (Step) object; - return !((this.stepPK == null && other.stepPK != null) - || (this.stepPK != null && !this.stepPK.equals(other.stepPK))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.Step[ stepPK=" + stepPK + " ]"; - } - - public byte[] getText() { - return text; - } - - public void setText(byte[] text) { - this.text = text; - } - - @XmlTransient - @JsonIgnore - @Override - public List getHistoryList() { - return historyList; - } - - @Override - public void setHistoryList(List historyList) { - this.historyList = historyList; - } -} +package com.validation.manager.core.db; + +import com.validation.manager.core.history.Auditable; +import com.validation.manager.core.history.Versionable; +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "step") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Step.findAll", + query = "SELECT s FROM Step s") + , @NamedQuery(name = "Step.findById", + query = "SELECT s FROM Step s WHERE s.stepPK.id = :id") + , @NamedQuery(name = "Step.findByTestCaseId", + query = "SELECT s FROM Step s WHERE s.stepPK.testCaseId = :testCaseId") + , @NamedQuery(name = "Step.findByStepSequence", + query = "SELECT s FROM Step s WHERE s.stepSequence = :stepSequence")}) +public class Step extends Versionable implements Serializable { + + private static final long serialVersionUID = 1L; + @EmbeddedId + protected StepPK stepPK; + @Basic(optional = false) + @NotNull + @Column(name = "step_sequence") + private int stepSequence; + @Basic(optional = false) + @NotNull + @Lob + @Column(name = "text") + @Auditable + private byte[] text; + @Lob + @Column(name = "expected_result") + @Auditable + private byte[] expectedResult; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "notes") + @Auditable + private String notes; + @ManyToMany(mappedBy = "stepList") + private List requirementList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "step") + private List executionStepList; + @JoinColumn(name = "test_case_id", referencedColumnName = "id", + insertable = false, updatable = false) + @ManyToOne(optional = false) + private TestCase testCase; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "step") + private List historyList; + + public Step() { + } + + public Step(StepPK stepPK) { + this.stepPK = stepPK; + } + + public Step(StepPK stepPK, int stepSequence, byte[] text) { + this.stepPK = stepPK; + this.stepSequence = stepSequence; + this.text = text; + } + + public Step(int testCaseId) { + this.stepPK = new StepPK(testCaseId); + } + + public StepPK getStepPK() { + return stepPK; + } + + public void setStepPK(StepPK stepPK) { + this.stepPK = stepPK; + } + + public int getStepSequence() { + return stepSequence; + } + + public void setStepSequence(int stepSequence) { + this.stepSequence = stepSequence; + } + + public byte[] getExpectedResult() { + return expectedResult; + } + + public void setExpectedResult(byte[] expectedResult) { + this.expectedResult = expectedResult; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + + @XmlTransient + @JsonIgnore + public List getRequirementList() { + return requirementList; + } + + public void setRequirementList(List requirementList) { + this.requirementList = requirementList; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepList() { + return executionStepList; + } + + public void setExecutionStepList(List executionStepList) { + this.executionStepList = executionStepList; + } + + public TestCase getTestCase() { + return testCase; + } + + public void setTestCase(TestCase testCase) { + this.testCase = testCase; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (stepPK != null ? stepPK.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof Step)) { + return false; + } + Step other = (Step) object; + return !((this.stepPK == null && other.stepPK != null) + || (this.stepPK != null && !this.stepPK.equals(other.stepPK))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.Step[ stepPK=" + stepPK + " ]"; + } + + @XmlTransient + @JsonIgnore + @Override + public List getHistoryList() { + return historyList; + } + + @Override + public void setHistoryList(List historyList) { + this.historyList = historyList; + } + + public byte[] getText() { + return text; + } + + public void setText(byte[] text) { + this.text = text; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/StepPK.java b/VM-Core/src/main/java/com/validation/manager/core/db/StepPK.java index 9c9ab829..f6e1d7dc 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/StepPK.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/StepPK.java @@ -13,87 +13,87 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Embeddable -public class StepPK implements Serializable { - - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, generator = "StepGen") - @TableGenerator(name = "StepGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "step", - allocationSize = 1, - initialValue = 1000) - @NotNull - @Column(name = "id") - private int id; - @Basic(optional = false) - @NotNull - @Column(name = "test_case_id") - private int testCaseId; - - public StepPK() { - } - - public StepPK(int testCaseId) { - this.testCaseId = testCaseId; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getTestCaseId() { - return testCaseId; - } - - public void setTestCaseId(int testCaseId) { - this.testCaseId = testCaseId; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (int) id; - hash += (int) testCaseId; - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof StepPK)) { - return false; - } - StepPK other = (StepPK) object; - if (this.id != other.id) { - return false; - } - return this.testCaseId == other.testCaseId; - } - - @Override - public String toString() { - return "com.validation.manager.core.db.StepPK[ id=" + id - + ", testCaseId=" + testCaseId + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Embeddable +public class StepPK implements Serializable { + + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "StepGen") + @TableGenerator(name = "StepGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "step", + allocationSize = 1, + initialValue = 1_000) + @NotNull + @Column(name = "id") + private int id; + @Basic(optional = false) + @NotNull + @Column(name = "test_case_id") + private int testCaseId; + + public StepPK() { + } + + public StepPK(int testCaseId) { + this.testCaseId = testCaseId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getTestCaseId() { + return testCaseId; + } + + public void setTestCaseId(int testCaseId) { + this.testCaseId = testCaseId; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (int) id; + hash += (int) testCaseId; + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof StepPK)) { + return false; + } + StepPK other = (StepPK) object; + if (this.id != other.id) { + return false; + } + return this.testCaseId == other.testCaseId; + } + + @Override + public String toString() { + return "com.validation.manager.core.db.StepPK[ id=" + id + + ", testCaseId=" + testCaseId + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/TestCase.java b/VM-Core/src/main/java/com/validation/manager/core/db/TestCase.java index f22c6ad4..ef598c9d 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/TestCase.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/TestCase.java @@ -13,213 +13,213 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "test_case") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "TestCase.findAll", - query = "SELECT t FROM TestCase t") - , @NamedQuery(name = "TestCase.findById", - query = "SELECT t FROM TestCase t WHERE t.id = :id") - , @NamedQuery(name = "TestCase.findByName", - query = "SELECT t FROM TestCase t WHERE t.name = :name") - , @NamedQuery(name = "TestCase.findByCreationDate", - query = "SELECT t FROM TestCase t WHERE t.creationDate = :creationDate") - , @NamedQuery(name = "TestCase.findByActive", - query = "SELECT t FROM TestCase t WHERE t.active = :active") - , @NamedQuery(name = "TestCase.findByIsOpen", - query = "SELECT t FROM TestCase t WHERE t.isOpen = :isOpen")}) -public class TestCase implements Serializable { - - @Lob - @Column(name = "summary") - private byte[] summary; - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @NotNull - @Column(name = "id") - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "TestCase_IDGEN") - @TableGenerator(name = "TestCase_IDGEN", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "test_case", - initialValue = 1000, - allocationSize = 1) - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Basic(optional = false) - @NotNull - @Column(name = "creation_date") - @Temporal(TemporalType.TIMESTAMP) - private Date creationDate; - @Column(name = "active") - private Boolean active; - @Column(name = "is_open") - private Boolean isOpen; - @JoinTable(name = "test_plan_has_test_case", joinColumns = { - @JoinColumn(name = "test_case_id", referencedColumnName = "id")}, - inverseJoinColumns = { - @JoinColumn(name = "test_plan_id", referencedColumnName = "id") - , @JoinColumn(name = "test_plan_test_project_id", - referencedColumnName = "test_project_id")}) - @ManyToMany - private List testPlanList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "testCase") - private List riskControlHasTestCaseList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "testCase") - private List stepList; - - public TestCase() { - } - - public TestCase(int id) { - this.id = id; - } - - public TestCase(String name, Date creationDate) { - this.name = name; - this.creationDate = creationDate; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - - public Date getCreationDate() { - return creationDate; - } - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - - public Boolean getActive() { - return active; - } - - public void setActive(Boolean active) { - this.active = active; - } - - public Boolean getIsOpen() { - return isOpen; - } - - public void setIsOpen(Boolean isOpen) { - this.isOpen = isOpen; - } - - @XmlTransient - @JsonIgnore - public List getTestPlanList() { - return testPlanList; - } - - public void setTestPlanList(List testPlanList) { - this.testPlanList = testPlanList; - } - - @XmlTransient - @JsonIgnore - public List getRiskControlHasTestCaseList() { - return riskControlHasTestCaseList; - } - - public void setRiskControlHasTestCaseList(List riskControlHasTestCaseList) { - this.riskControlHasTestCaseList = riskControlHasTestCaseList; - } - - @XmlTransient - @JsonIgnore - public List getStepList() { - return stepList; - } - - public void setStepList(List stepList) { - this.stepList = stepList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof TestCase)) { - return false; - } - TestCase other = (TestCase) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.TestCase[ id=" + id + " ]"; - } - - public byte[] getSummary() { - return summary; - } - - public void setSummary(byte[] summary) { - this.summary = summary; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "test_case") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "TestCase.findAll", + query = "SELECT t FROM TestCase t") + , @NamedQuery(name = "TestCase.findById", + query = "SELECT t FROM TestCase t WHERE t.id = :id") + , @NamedQuery(name = "TestCase.findByName", + query = "SELECT t FROM TestCase t WHERE t.name = :name") + , @NamedQuery(name = "TestCase.findByCreationDate", + query = "SELECT t FROM TestCase t WHERE t.creationDate = :creationDate") + , @NamedQuery(name = "TestCase.findByActive", + query = "SELECT t FROM TestCase t WHERE t.active = :active") + , @NamedQuery(name = "TestCase.findByIsOpen", + query = "SELECT t FROM TestCase t WHERE t.isOpen = :isOpen")}) +public class TestCase implements Serializable { + + @Lob + @Column(name = "summary") + private byte[] summary; + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @NotNull + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "TestCase_IDGEN") + @TableGenerator(name = "TestCase_IDGEN", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "test_case", + initialValue = 1_000, + allocationSize = 1) + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Basic(optional = false) + @NotNull + @Column(name = "creation_date") + @Temporal(TemporalType.TIMESTAMP) + private Date creationDate; + @Column(name = "active") + private Boolean active; + @Column(name = "is_open") + private Boolean isOpen; + @JoinTable(name = "test_plan_has_test_case", joinColumns = { + @JoinColumn(name = "test_case_id", referencedColumnName = "id")}, + inverseJoinColumns = { + @JoinColumn(name = "test_plan_id", referencedColumnName = "id") + , @JoinColumn(name = "test_plan_test_project_id", + referencedColumnName = "test_project_id")}) + @ManyToMany + private List testPlanList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "testCase") + private List riskControlHasTestCaseList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "testCase") + private List stepList; + + public TestCase() { + } + + public TestCase(int id) { + this.id = id; + } + + public TestCase(String name, Date creationDate) { + this.name = name; + this.creationDate = creationDate; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public Boolean getActive() { + return active; + } + + public void setActive(Boolean active) { + this.active = active; + } + + public Boolean getIsOpen() { + return isOpen; + } + + public void setIsOpen(Boolean isOpen) { + this.isOpen = isOpen; + } + + @XmlTransient + @JsonIgnore + public List getTestPlanList() { + return testPlanList; + } + + public void setTestPlanList(List testPlanList) { + this.testPlanList = testPlanList; + } + + @XmlTransient + @JsonIgnore + public List getRiskControlHasTestCaseList() { + return riskControlHasTestCaseList; + } + + public void setRiskControlHasTestCaseList(List riskControlHasTestCaseList) { + this.riskControlHasTestCaseList = riskControlHasTestCaseList; + } + + @XmlTransient + @JsonIgnore + public List getStepList() { + return stepList; + } + + public void setStepList(List stepList) { + this.stepList = stepList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof TestCase)) { + return false; + } + TestCase other = (TestCase) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.TestCase[ id=" + id + " ]"; + } + + public byte[] getSummary() { + return summary; + } + + public void setSummary(byte[] summary) { + this.summary = summary; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/TestCaseExecution.java b/VM-Core/src/main/java/com/validation/manager/core/db/TestCaseExecution.java index 2f1ea4b2..bbd217db 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/TestCaseExecution.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/TestCaseExecution.java @@ -13,145 +13,145 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "test_case_execution") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "TestCaseExecution.findAll", - query = "SELECT t FROM TestCaseExecution t") - , @NamedQuery(name = "TestCaseExecution.findById", - query = "SELECT t FROM TestCaseExecution t WHERE t.id = :id")}) -public class TestCaseExecution implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "TestCaseExecGen") - @TableGenerator(name = "TestCaseExecGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "test_case_execution", - allocationSize = 1, - initialValue = 1000) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Lob - @Size(max = 2147483647) - @Column(name = "scope") - private String scope; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Lob - @Size(max = 2147483647) - @Column(name = "conclusion") - private String conclusion; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "testCaseExecution") - private List executionStepList; - - public TestCaseExecution(String name, String scope) { - this.name = name; - this.scope = scope; - } - - public TestCaseExecution() { - } - - public Integer getId() { - return this.id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getScope() { - return scope; - } - - public void setScope(String scope) { - this.scope = scope; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getConclusion() { - return conclusion; - } - - public void setConclusion(String conclusion) { - this.conclusion = conclusion; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepList() { - return executionStepList; - } - - public void setExecutionStepList(List executionStepList) { - this.executionStepList = executionStepList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof TestCaseExecution)) { - return false; - } - TestCaseExecution other = (TestCaseExecution) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.TestCaseExecution[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "test_case_execution") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "TestCaseExecution.findAll", + query = "SELECT t FROM TestCaseExecution t") + , @NamedQuery(name = "TestCaseExecution.findById", + query = "SELECT t FROM TestCaseExecution t WHERE t.id = :id")}) +public class TestCaseExecution implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "TestCaseExecGen") + @TableGenerator(name = "TestCaseExecGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "test_case_execution", + allocationSize = 1, + initialValue = 1_000) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Lob + @Size(max = 2_147_483_647) + @Column(name = "scope") + private String scope; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "conclusion") + private String conclusion; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "testCaseExecution") + private List executionStepList; + + public TestCaseExecution(String name, String scope) { + this.name = name; + this.scope = scope; + } + + public TestCaseExecution() { + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getConclusion() { + return conclusion; + } + + public void setConclusion(String conclusion) { + this.conclusion = conclusion; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepList() { + return executionStepList; + } + + public void setExecutionStepList(List executionStepList) { + this.executionStepList = executionStepList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof TestCaseExecution)) { + return false; + } + TestCaseExecution other = (TestCaseExecution) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.TestCaseExecution[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/TestPlan.java b/VM-Core/src/main/java/com/validation/manager/core/db/TestPlan.java index cfc51caf..baa778d3 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/TestPlan.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/TestPlan.java @@ -13,212 +13,212 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "test_plan") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "TestPlan.findAll", - query = "SELECT t FROM TestPlan t") - , @NamedQuery(name = "TestPlan.findById", - query = "SELECT t FROM TestPlan t WHERE t.testPlanPK.id = :id") - , @NamedQuery(name = "TestPlan.findByTestProjectId", - query = "SELECT t FROM TestPlan t WHERE t.testPlanPK.testProjectId = :testProjectId") - , @NamedQuery(name = "TestPlan.findByName", - query = "SELECT t FROM TestPlan t WHERE t.name = :name") - , @NamedQuery(name = "TestPlan.findByActive", - query = "SELECT t FROM TestPlan t WHERE t.active = :active") - , @NamedQuery(name = "TestPlan.findByIsOpen", - query = "SELECT t FROM TestPlan t WHERE t.isOpen = :isOpen")}) -public class TestPlan implements Serializable { - - private static final long serialVersionUID = 1L; - @EmbeddedId - protected TestPlanPK testPlanPK; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Lob - @Size(max = 65535) - @Column(name = "notes") - private String notes; - @Basic(optional = false) - @NotNull - @Column(name = "active") - private boolean active; - @Basic(optional = false) - @NotNull - @Column(name = "is_open") - private boolean isOpen; - @ManyToMany(mappedBy = "testPlanList") - private List testCaseList; - @OneToMany(mappedBy = "testPlan") - private List testPlanList; - @JoinColumns({ - @JoinColumn(name = "regression_test_plan_id", - referencedColumnName = "id") - , @JoinColumn(name = "regression_test_plan_test_project_id", - referencedColumnName = "test_project_id")}) - @ManyToOne - private TestPlan testPlan; - @JoinColumn(name = "test_project_id", referencedColumnName = "id", - insertable = false, updatable = false) - @ManyToOne(optional = false) - private TestProject testProject; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "testPlan") - private List userTestPlanRoleList; - - public TestPlan() { - } - - public TestPlan(TestPlanPK testPlanPK) { - this.testPlanPK = testPlanPK; - } - - public TestPlan(TestProject testProject, boolean active, boolean isOpen) { - this.testProject = testProject; - this.testPlanPK = new TestPlanPK(testProject.getId()); - this.active = active; - this.isOpen = isOpen; - } - - public TestPlanPK getTestPlanPK() { - return testPlanPK; - } - - public void setTestPlanPK(TestPlanPK testPlanPK) { - this.testPlanPK = testPlanPK; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; - } - - public boolean getActive() { - return active; - } - - public void setActive(boolean active) { - this.active = active; - } - - public boolean getIsOpen() { - return isOpen; - } - - public void setIsOpen(boolean isOpen) { - this.isOpen = isOpen; - } - - @XmlTransient - @JsonIgnore - public List getTestCaseList() { - return testCaseList; - } - - public void setTestCaseList(List testCaseList) { - this.testCaseList = testCaseList; - } - - @XmlTransient - @JsonIgnore - public List getTestPlanList() { - return testPlanList; - } - - public void setTestPlanList(List testPlanList) { - this.testPlanList = testPlanList; - } - - public TestPlan getTestPlan() { - return testPlan; - } - - public void setTestPlan(TestPlan testPlan) { - this.testPlan = testPlan; - } - - public TestProject getTestProject() { - return testProject; - } - - public void setTestProject(TestProject testProject) { - this.testProject = testProject; - } - - @XmlTransient - @JsonIgnore - public List getUserTestPlanRoleList() { - return userTestPlanRoleList; - } - - public void setUserTestPlanRoleList(List userTestPlanRoleList) { - this.userTestPlanRoleList = userTestPlanRoleList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (testPlanPK != null ? testPlanPK.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof TestPlan)) { - return false; - } - TestPlan other = (TestPlan) object; - return !((this.testPlanPK == null && other.testPlanPK != null) - || (this.testPlanPK != null - && !this.testPlanPK.equals(other.testPlanPK))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.TestPlan[ testPlanPK=" - + testPlanPK + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "test_plan") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "TestPlan.findAll", + query = "SELECT t FROM TestPlan t") + , @NamedQuery(name = "TestPlan.findById", + query = "SELECT t FROM TestPlan t WHERE t.testPlanPK.id = :id") + , @NamedQuery(name = "TestPlan.findByTestProjectId", + query = "SELECT t FROM TestPlan t WHERE t.testPlanPK.testProjectId = :testProjectId") + , @NamedQuery(name = "TestPlan.findByName", + query = "SELECT t FROM TestPlan t WHERE t.name = :name") + , @NamedQuery(name = "TestPlan.findByActive", + query = "SELECT t FROM TestPlan t WHERE t.active = :active") + , @NamedQuery(name = "TestPlan.findByIsOpen", + query = "SELECT t FROM TestPlan t WHERE t.isOpen = :isOpen")}) +public class TestPlan implements Serializable { + + private static final long serialVersionUID = 1L; + @EmbeddedId + protected TestPlanPK testPlanPK; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Lob + @Size(max = 65_535) + @Column(name = "notes") + private String notes; + @Basic(optional = false) + @NotNull + @Column(name = "active") + private boolean active; + @Basic(optional = false) + @NotNull + @Column(name = "is_open") + private boolean isOpen; + @ManyToMany(mappedBy = "testPlanList") + private List testCaseList; + @OneToMany(mappedBy = "testPlan") + private List testPlanList; + @JoinColumns({ + @JoinColumn(name = "regression_test_plan_id", + referencedColumnName = "id") + , @JoinColumn(name = "regression_test_plan_test_project_id", + referencedColumnName = "test_project_id")}) + @ManyToOne + private TestPlan testPlan; + @JoinColumn(name = "test_project_id", referencedColumnName = "id", + insertable = false, updatable = false) + @ManyToOne(optional = false) + private TestProject testProject; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "testPlan") + private List userTestPlanRoleList; + + public TestPlan() { + } + + public TestPlan(TestPlanPK testPlanPK) { + this.testPlanPK = testPlanPK; + } + + public TestPlan(TestProject testProject, boolean active, boolean isOpen) { + this.testProject = testProject; + this.testPlanPK = new TestPlanPK(testProject.getId()); + this.active = active; + this.isOpen = isOpen; + } + + public TestPlanPK getTestPlanPK() { + return testPlanPK; + } + + public void setTestPlanPK(TestPlanPK testPlanPK) { + this.testPlanPK = testPlanPK; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + + public boolean getActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public boolean getIsOpen() { + return isOpen; + } + + public void setIsOpen(boolean isOpen) { + this.isOpen = isOpen; + } + + @XmlTransient + @JsonIgnore + public List getTestCaseList() { + return testCaseList; + } + + public void setTestCaseList(List testCaseList) { + this.testCaseList = testCaseList; + } + + @XmlTransient + @JsonIgnore + public List getTestPlanList() { + return testPlanList; + } + + public void setTestPlanList(List testPlanList) { + this.testPlanList = testPlanList; + } + + public TestPlan getTestPlan() { + return testPlan; + } + + public void setTestPlan(TestPlan testPlan) { + this.testPlan = testPlan; + } + + public TestProject getTestProject() { + return testProject; + } + + public void setTestProject(TestProject testProject) { + this.testProject = testProject; + } + + @XmlTransient + @JsonIgnore + public List getUserTestPlanRoleList() { + return userTestPlanRoleList; + } + + public void setUserTestPlanRoleList(List userTestPlanRoleList) { + this.userTestPlanRoleList = userTestPlanRoleList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (testPlanPK != null ? testPlanPK.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof TestPlan)) { + return false; + } + TestPlan other = (TestPlan) object; + return !((this.testPlanPK == null && other.testPlanPK != null) + || (this.testPlanPK != null + && !this.testPlanPK.equals(other.testPlanPK))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.TestPlan[ testPlanPK=" + + testPlanPK + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/TestPlanPK.java b/VM-Core/src/main/java/com/validation/manager/core/db/TestPlanPK.java index 5740b29a..84fd961a 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/TestPlanPK.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/TestPlanPK.java @@ -13,88 +13,88 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Embeddable -public class TestPlanPK implements Serializable { - - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, generator = "Test_Plan_IDGEN") - @TableGenerator(name = "Test_Plan_IDGEN", - table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "test_plan", - initialValue = 1000, - allocationSize = 1) - @NotNull - @Column(name = "id") - private int id; - @Basic(optional = false) - @NotNull - @Column(name = "test_project_id") - private int testProjectId; - - public TestPlanPK() { - } - - public TestPlanPK(int testProjectId) { - this.testProjectId = testProjectId; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getTestProjectId() { - return testProjectId; - } - - public void setTestProjectId(int testProjectId) { - this.testProjectId = testProjectId; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (int) id; - hash += (int) testProjectId; - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof TestPlanPK)) { - return false; - } - TestPlanPK other = (TestPlanPK) object; - if (this.id != other.id) { - return false; - } - return this.testProjectId == other.testProjectId; - } - - @Override - public String toString() { - return "com.validation.manager.core.db.TestPlanPK[ id=" + id - + ", testProjectId=" + testProjectId + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Embeddable +public class TestPlanPK implements Serializable { + + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "Test_Plan_IDGEN") + @TableGenerator(name = "Test_Plan_IDGEN", + table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "test_plan", + initialValue = 1_000, + allocationSize = 1) + @NotNull + @Column(name = "id") + private int id; + @Basic(optional = false) + @NotNull + @Column(name = "test_project_id") + private int testProjectId; + + public TestPlanPK() { + } + + public TestPlanPK(int testProjectId) { + this.testProjectId = testProjectId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getTestProjectId() { + return testProjectId; + } + + public void setTestProjectId(int testProjectId) { + this.testProjectId = testProjectId; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (int) id; + hash += (int) testProjectId; + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof TestPlanPK)) { + return false; + } + TestPlanPK other = (TestPlanPK) object; + if (this.id != other.id) { + return false; + } + return this.testProjectId == other.testProjectId; + } + + @Override + public String toString() { + return "com.validation.manager.core.db.TestPlanPK[ id=" + id + + ", testProjectId=" + testProjectId + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/TestProject.java b/VM-Core/src/main/java/com/validation/manager/core/db/TestProject.java index 5dd5e4ea..2beb68e4 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/TestProject.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/TestProject.java @@ -13,171 +13,171 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "test_project") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "TestProject.findAll", - query = "SELECT t FROM TestProject t") - , @NamedQuery(name = "TestProject.findById", - query = "SELECT t FROM TestProject t WHERE t.id = :id") - , @NamedQuery(name = "TestProject.findByName", - query = "SELECT t FROM TestProject t WHERE t.name = :name") - , @NamedQuery(name = "TestProject.findByActive", - query = "SELECT t FROM TestProject t WHERE t.active = :active")}) -public class TestProject implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.TABLE, generator = "TestProjectGen") - @TableGenerator(name = "TestProjectGen", table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "test_project", - allocationSize = 1, - initialValue = 1000) - @Basic(optional = false) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "name") - private String name; - @Basic(optional = false) - @NotNull - @Column(name = "active") - private boolean active; - @Lob - @Size(max = 2147483647) - @Column(name = "notes") - private String notes; - @ManyToMany(mappedBy = "testProjectList") - private List projectList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "testProject") - private List userTestProjectRoleList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "testProject") - private List testPlanList; - - public TestProject() { - } - - public TestProject(String name, boolean active) { - this.name = name; - this.active = active; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public boolean getActive() { - return active; - } - - public void setActive(boolean active) { - this.active = active; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; - } - - @XmlTransient - @JsonIgnore - public List getProjectList() { - return projectList; - } - - public void setProjectList(List projectList) { - this.projectList = projectList; - } - - @XmlTransient - @JsonIgnore - public List getUserTestProjectRoleList() { - return userTestProjectRoleList; - } - - public void setUserTestProjectRoleList(List userTestProjectRoleList) { - this.userTestProjectRoleList = userTestProjectRoleList; - } - - @XmlTransient - @JsonIgnore - public List getTestPlanList() { - return testPlanList; - } - - public void setTestPlanList(List testPlanList) { - this.testPlanList = testPlanList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof TestProject)) { - return false; - } - TestProject other = (TestProject) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.TestProject[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "test_project") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "TestProject.findAll", + query = "SELECT t FROM TestProject t") + , @NamedQuery(name = "TestProject.findById", + query = "SELECT t FROM TestProject t WHERE t.id = :id") + , @NamedQuery(name = "TestProject.findByName", + query = "SELECT t FROM TestProject t WHERE t.name = :name") + , @NamedQuery(name = "TestProject.findByActive", + query = "SELECT t FROM TestProject t WHERE t.active = :active")}) +public class TestProject implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.TABLE, generator = "TestProjectGen") + @TableGenerator(name = "TestProjectGen", table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "test_project", + allocationSize = 1, + initialValue = 1_000) + @Basic(optional = false) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "name") + private String name; + @Basic(optional = false) + @NotNull + @Column(name = "active") + private boolean active; + @Lob + @Size(max = 2_147_483_647) + @Column(name = "notes") + private String notes; + @ManyToMany(mappedBy = "testProjectList") + private List projectList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "testProject") + private List userTestProjectRoleList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "testProject") + private List testPlanList; + + public TestProject() { + } + + public TestProject(String name, boolean active) { + this.name = name; + this.active = active; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean getActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + + @XmlTransient + @JsonIgnore + public List getProjectList() { + return projectList; + } + + public void setProjectList(List projectList) { + this.projectList = projectList; + } + + @XmlTransient + @JsonIgnore + public List getUserTestProjectRoleList() { + return userTestProjectRoleList; + } + + public void setUserTestProjectRoleList(List userTestProjectRoleList) { + this.userTestProjectRoleList = userTestProjectRoleList; + } + + @XmlTransient + @JsonIgnore + public List getTestPlanList() { + return testPlanList; + } + + public void setTestPlanList(List testPlanList) { + this.testPlanList = testPlanList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof TestProject)) { + return false; + } + TestProject other = (TestProject) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.TestProject[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/UserAssigmentPK.java b/VM-Core/src/main/java/com/validation/manager/core/db/UserAssigmentPK.java index 42277d09..68985775 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/UserAssigmentPK.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/UserAssigmentPK.java @@ -13,126 +13,126 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Embeddable -public class UserAssigmentPK implements Serializable { - - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, - generator = "UserAssignmentGEN") - @TableGenerator(name = "UserAssignmentGEN", - table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "user_assignment", - initialValue = 1000, - allocationSize = 1) - @NotNull - @Column(name = "id") - private int id; - @Basic(optional = false) - @NotNull - @Column(name = "assigner_id") - private int assignerId; - @Basic(optional = false) - @NotNull - @Column(name = "assigment_type_id") - private int assigmentTypeId; - @Basic(optional = false) - @NotNull - @Column(name = "assignment_status_id") - private int assignmentStatusId; - - public UserAssigmentPK() { - } - - public UserAssigmentPK(int assignerId, int assigmentTypeId, - int assignmentStatusId) { - this.assignerId = assignerId; - this.assigmentTypeId = assigmentTypeId; - this.assignmentStatusId = assignmentStatusId; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getAssignerId() { - return assignerId; - } - - public void setAssignerId(int assignerId) { - this.assignerId = assignerId; - } - - public int getAssigmentTypeId() { - return assigmentTypeId; - } - - public void setAssigmentTypeId(int assigmentTypeId) { - this.assigmentTypeId = assigmentTypeId; - } - - public int getAssignmentStatusId() { - return assignmentStatusId; - } - - public void setAssignmentStatusId(int assignmentStatusId) { - this.assignmentStatusId = assignmentStatusId; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (int) id; - hash += (int) assignerId; - hash += (int) assigmentTypeId; - hash += (int) assignmentStatusId; - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof UserAssigmentPK)) { - return false; - } - UserAssigmentPK other = (UserAssigmentPK) object; - if (this.id != other.id) { - return false; - } - if (this.assignerId != other.assignerId) { - return false; - } - if (this.assigmentTypeId != other.assigmentTypeId) { - return false; - } - return this.assignmentStatusId == other.assignmentStatusId; - } - - @Override - public String toString() { - return "com.validation.manager.core.db.UserAssigmentPK[ id=" + id - + ", assignerId=" + assignerId + ", assigmentTypeId=" - + assigmentTypeId + ", assignmentStatusId=" - + assignmentStatusId + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Embeddable +public class UserAssigmentPK implements Serializable { + + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, + generator = "UserAssignmentGEN") + @TableGenerator(name = "UserAssignmentGEN", + table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "user_assignment", + initialValue = 1_000, + allocationSize = 1) + @NotNull + @Column(name = "id") + private int id; + @Basic(optional = false) + @NotNull + @Column(name = "assigner_id") + private int assignerId; + @Basic(optional = false) + @NotNull + @Column(name = "assigment_type_id") + private int assigmentTypeId; + @Basic(optional = false) + @NotNull + @Column(name = "assignment_status_id") + private int assignmentStatusId; + + public UserAssigmentPK() { + } + + public UserAssigmentPK(int assignerId, int assigmentTypeId, + int assignmentStatusId) { + this.assignerId = assignerId; + this.assigmentTypeId = assigmentTypeId; + this.assignmentStatusId = assignmentStatusId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getAssignerId() { + return assignerId; + } + + public void setAssignerId(int assignerId) { + this.assignerId = assignerId; + } + + public int getAssigmentTypeId() { + return assigmentTypeId; + } + + public void setAssigmentTypeId(int assigmentTypeId) { + this.assigmentTypeId = assigmentTypeId; + } + + public int getAssignmentStatusId() { + return assignmentStatusId; + } + + public void setAssignmentStatusId(int assignmentStatusId) { + this.assignmentStatusId = assignmentStatusId; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (int) id; + hash += (int) assignerId; + hash += (int) assigmentTypeId; + hash += (int) assignmentStatusId; + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof UserAssigmentPK)) { + return false; + } + UserAssigmentPK other = (UserAssigmentPK) object; + if (this.id != other.id) { + return false; + } + if (this.assignerId != other.assignerId) { + return false; + } + if (this.assigmentTypeId != other.assigmentTypeId) { + return false; + } + return this.assignmentStatusId == other.assignmentStatusId; + } + + @Override + public String toString() { + return "com.validation.manager.core.db.UserAssigmentPK[ id=" + id + + ", assignerId=" + assignerId + ", assigmentTypeId=" + + assigmentTypeId + ", assignmentStatusId=" + + assignmentStatusId + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/UserRight.java b/VM-Core/src/main/java/com/validation/manager/core/db/UserRight.java index dd67004e..ffcb2bb2 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/UserRight.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/UserRight.java @@ -13,129 +13,129 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "user_right") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "UserRight.findAll", - query = "SELECT u FROM UserRight u") - , @NamedQuery(name = "UserRight.findById", - query = "SELECT u FROM UserRight u WHERE u.id = :id") - , @NamedQuery(name = "UserRight.findByDescription", - query = "SELECT u FROM UserRight u WHERE u.description = :description")}) -public class UserRight implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, generator = "UserRightGEN") - @TableGenerator(name = "UserRightGEN", - table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "user_right", - initialValue = 1000, - allocationSize = 1) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "description") - private String description; - @JoinTable(name = "role_has_right", joinColumns = { - @JoinColumn(name = "right_id", referencedColumnName = "id")}, - inverseJoinColumns = { - @JoinColumn(name = "role_id", referencedColumnName = "id")}) - @ManyToMany - private List roleList; - - public UserRight() { - } - - public UserRight(Integer id) { - this.id = id; - } - - public UserRight(Integer id, String description) { - this.id = id; - this.description = description; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getRoleList() { - return roleList; - } - - public void setRoleList(List roleList) { - this.roleList = roleList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof UserRight)) { - return false; - } - UserRight other = (UserRight) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.UserRight[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "user_right") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "UserRight.findAll", + query = "SELECT u FROM UserRight u") + , @NamedQuery(name = "UserRight.findById", + query = "SELECT u FROM UserRight u WHERE u.id = :id") + , @NamedQuery(name = "UserRight.findByDescription", + query = "SELECT u FROM UserRight u WHERE u.description = :description")}) +public class UserRight implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "UserRightGEN") + @TableGenerator(name = "UserRightGEN", + table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "user_right", + initialValue = 1_000, + allocationSize = 1) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "description") + private String description; + @JoinTable(name = "role_has_right", joinColumns = { + @JoinColumn(name = "right_id", referencedColumnName = "id")}, + inverseJoinColumns = { + @JoinColumn(name = "role_id", referencedColumnName = "id")}) + @ManyToMany + private List roleList; + + public UserRight() { + } + + public UserRight(Integer id) { + this.id = id; + } + + public UserRight(Integer id, String description) { + this.id = id; + this.description = description; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getRoleList() { + return roleList; + } + + public void setRoleList(List roleList) { + this.roleList = roleList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof UserRight)) { + return false; + } + UserRight other = (UserRight) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.UserRight[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/UserStatus.java b/VM-Core/src/main/java/com/validation/manager/core/db/UserStatus.java index 8176d883..8d902398 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/UserStatus.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/UserStatus.java @@ -13,132 +13,132 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "user_status") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "UserStatus.findAll", - query = "SELECT u FROM UserStatus u") - , @NamedQuery(name = "UserStatus.findById", - query = "SELECT u FROM UserStatus u WHERE u.id = :id") - , @NamedQuery(name = "UserStatus.findByStatus", - query = "SELECT u FROM UserStatus u WHERE u.status = :status") - , @NamedQuery(name = "UserStatus.findByDescription", - query = "SELECT u FROM UserStatus u WHERE u.description = :description")}) -public class UserStatus implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, generator = "UserStatusGEN") - @TableGenerator(name = "UserStatusGEN", - table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "user_status", - initialValue = 1000, - allocationSize = 1) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "status") - private String status; - @Size(max = 255) - @Column(name = "description") - private String description; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "userStatusId") - private List vmUserList; - - public UserStatus() { - } - - public UserStatus(String status) { - this.status = status; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlTransient - @JsonIgnore - public List getVmUserList() { - return vmUserList; - } - - public void setVmUserList(List vmUserList) { - this.vmUserList = vmUserList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof UserStatus)) { - return false; - } - UserStatus other = (UserStatus) object; - return !((this.id == null && other.id != null) - || (this.id != null && !this.id.equals(other.id))); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.UserStatus[ id=" + id + " ]"; - } -} +package com.validation.manager.core.db; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "user_status") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "UserStatus.findAll", + query = "SELECT u FROM UserStatus u") + , @NamedQuery(name = "UserStatus.findById", + query = "SELECT u FROM UserStatus u WHERE u.id = :id") + , @NamedQuery(name = "UserStatus.findByStatus", + query = "SELECT u FROM UserStatus u WHERE u.status = :status") + , @NamedQuery(name = "UserStatus.findByDescription", + query = "SELECT u FROM UserStatus u WHERE u.description = :description")}) +public class UserStatus implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "UserStatusGEN") + @TableGenerator(name = "UserStatusGEN", + table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "user_status", + initialValue = 1_000, + allocationSize = 1) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "status") + private String status; + @Size(max = 255) + @Column(name = "description") + private String description; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "userStatusId") + private List vmUserList; + + public UserStatus() { + } + + public UserStatus(String status) { + this.status = status; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlTransient + @JsonIgnore + public List getVmUserList() { + return vmUserList; + } + + public void setVmUserList(List vmUserList) { + this.vmUserList = vmUserList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof UserStatus)) { + return false; + } + UserStatus other = (UserStatus) object; + return !((this.id == null && other.id != null) + || (this.id != null && !this.id.equals(other.id))); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.UserStatus[ id=" + id + " ]"; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/VmSetting.java b/VM-Core/src/main/java/com/validation/manager/core/db/VmSetting.java index d4bce094..bff702e2 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/VmSetting.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/VmSetting.java @@ -13,179 +13,179 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import com.validation.manager.core.history.Auditable; -import com.validation.manager.core.history.Versionable; -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "vm_setting") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "VmSetting.findAll", - query = "SELECT v FROM VmSetting v") - , @NamedQuery(name = "VmSetting.findById", - query = "SELECT v FROM VmSetting v WHERE v.id = :id") - , @NamedQuery(name = "VmSetting.findBySetting", - query = "SELECT v FROM VmSetting v WHERE v.setting = :setting") - , @NamedQuery(name = "VmSetting.findByBoolVal", - query = "SELECT v FROM VmSetting v WHERE v.boolVal = :boolVal") - , @NamedQuery(name = "VmSetting.findByIntVal", - query = "SELECT v FROM VmSetting v WHERE v.intVal = :intVal")}) -public class VmSetting extends Versionable implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, generator = "VM_SettingGEN") - @TableGenerator(name = "VM_SettingGEN", - table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "vm_setting", - initialValue = 1000, - allocationSize = 1) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Auditable - @Column(name = "setting") - private String setting; - @Auditable - @Column(name = "bool_val") - private Boolean boolVal; - @Auditable - @Column(name = "int_val") - private Integer intVal; - @Lob - @Size(max = 2147483647) - @Auditable - @Column(name = "long_val") - private String longVal; - @Lob - @Size(max = 2147483647) - @Auditable - @Column(name = "string_val") - private String stringVal; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmSettingId") - private List historyList; - - public VmSetting() { - } - - public VmSetting(String setting) { - this.setting = setting; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getSetting() { - return setting; - } - - public void setSetting(String setting) { - this.setting = setting; - } - - public Boolean getBoolVal() { - return boolVal; - } - - public void setBoolVal(Boolean boolVal) { - this.boolVal = boolVal; - } - - public Integer getIntVal() { - return intVal; - } - - public void setIntVal(Integer intVal) { - this.intVal = intVal; - } - - public String getLongVal() { - return longVal; - } - - public void setLongVal(String longVal) { - this.longVal = longVal; - } - - public String getStringVal() { - return stringVal; - } - - public void setStringVal(String stringVal) { - this.stringVal = stringVal; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof VmSetting)) { - return false; - } - VmSetting other = (VmSetting) object; - return this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.VmSetting[ id=" + id + " ]"; - } - - @XmlTransient - @JsonIgnore - @Override - public List getHistoryList() { - return historyList; - } - - /** - * @param historyList the historyList to set - */ - @Override - public void setHistoryList(List historyList) { - this.historyList = historyList; - } -} +package com.validation.manager.core.db; + +import com.validation.manager.core.history.Auditable; +import com.validation.manager.core.history.Versionable; +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "vm_setting") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "VmSetting.findAll", + query = "SELECT v FROM VmSetting v") + , @NamedQuery(name = "VmSetting.findById", + query = "SELECT v FROM VmSetting v WHERE v.id = :id") + , @NamedQuery(name = "VmSetting.findBySetting", + query = "SELECT v FROM VmSetting v WHERE v.setting = :setting") + , @NamedQuery(name = "VmSetting.findByBoolVal", + query = "SELECT v FROM VmSetting v WHERE v.boolVal = :boolVal") + , @NamedQuery(name = "VmSetting.findByIntVal", + query = "SELECT v FROM VmSetting v WHERE v.intVal = :intVal")}) +public class VmSetting extends Versionable implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "VM_SettingGEN") + @TableGenerator(name = "VM_SettingGEN", + table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "vm_setting", + initialValue = 1_000, + allocationSize = 1) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Auditable + @Column(name = "setting") + private String setting; + @Auditable + @Column(name = "bool_val") + private Boolean boolVal; + @Auditable + @Column(name = "int_val") + private Integer intVal; + @Lob + @Size(max = 2_147_483_647) + @Auditable + @Column(name = "long_val") + private String longVal; + @Lob + @Size(max = 2_147_483_647) + @Auditable + @Column(name = "string_val") + private String stringVal; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmSettingId") + private List historyList; + + public VmSetting() { + } + + public VmSetting(String setting) { + this.setting = setting; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getSetting() { + return setting; + } + + public void setSetting(String setting) { + this.setting = setting; + } + + public Boolean getBoolVal() { + return boolVal; + } + + public void setBoolVal(Boolean boolVal) { + this.boolVal = boolVal; + } + + public Integer getIntVal() { + return intVal; + } + + public void setIntVal(Integer intVal) { + this.intVal = intVal; + } + + public String getLongVal() { + return longVal; + } + + public void setLongVal(String longVal) { + this.longVal = longVal; + } + + public String getStringVal() { + return stringVal; + } + + public void setStringVal(String stringVal) { + this.stringVal = stringVal; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof VmSetting)) { + return false; + } + VmSetting other = (VmSetting) object; + return this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.VmSetting[ id=" + id + " ]"; + } + + @XmlTransient + @JsonIgnore + @Override + public List getHistoryList() { + return historyList; + } + + /** + * @param historyList the historyList to set + */ + @Override + public void setHistoryList(List historyList) { + this.historyList = historyList; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/VmUser.java b/VM-Core/src/main/java/com/validation/manager/core/db/VmUser.java index 318d00c4..e528c520 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/VmUser.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/VmUser.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,414 +13,438 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import com.validation.manager.core.history.Auditable; -import com.validation.manager.core.history.Login; -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.TableGenerator; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@Entity -@Table(name = "vm_user") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "VmUser.findAll", - query = "SELECT v FROM VmUser v") - , @NamedQuery(name = "VmUser.findById", - query = "SELECT v FROM VmUser v WHERE v.id = :id") - , @NamedQuery(name = "VmUser.findByUsername", - query = "SELECT v FROM VmUser v WHERE v.username = :username") - , @NamedQuery(name = "VmUser.findByPassword", - query = "SELECT v FROM VmUser v WHERE v.password = :password") - , @NamedQuery(name = "VmUser.findByEmail", - query = "SELECT v FROM VmUser v WHERE v.email = :email") - , @NamedQuery(name = "VmUser.findByFirstName", - query = "SELECT v FROM VmUser v WHERE v.firstName = :firstName") - , @NamedQuery(name = "VmUser.findByLastName", - query = "SELECT v FROM VmUser v WHERE v.lastName = :lastName") - , @NamedQuery(name = "VmUser.findByLocale", - query = "SELECT v FROM VmUser v WHERE v.locale = :locale") - , @NamedQuery(name = "VmUser.findByLastModified", - query = "SELECT v FROM VmUser v WHERE v.lastModified = :lastModified") - , @NamedQuery(name = "VmUser.findByAttempts", - query = "SELECT v FROM VmUser v WHERE v.attempts = :attempts")}) -public class VmUser extends Login implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.TABLE, generator = "VM_UserGEN") - @TableGenerator(name = "VM_UserGEN", - table = "vm_id", - pkColumnName = "table_name", - valueColumnName = "last_id", - pkColumnValue = "vm_user", - initialValue = 1000, - allocationSize = 1) - @NotNull - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Auditable - @Column(name = "username") - private String username; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "password") - @Auditable - private String password; - @Pattern(regexp = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`" - + "{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:" - + "[a-z0-9-]*[a-z0-9])?", - message = "Invalid email")//if the field contains email address consider using this annotation to enforce field validation - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 100) - @Auditable - @Column(name = "email") - private String email; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "first_name") - @Auditable - private String firstName; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Column(name = "last_name") - @Auditable - private String lastName; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 255) - @Auditable - @Column(name = "locale") - private String locale; - @ManyToMany(mappedBy = "vmUserList") - private List correctiveActionList; - @ManyToMany(mappedBy = "vmUserList") - private List roleList; - @ManyToMany(mappedBy = "vmUserList") - private List rootCauseList; - @JoinColumn(name = "user_status_id", referencedColumnName = "id") - @ManyToOne(optional = false) - private UserStatus userStatusId; - @OneToMany(mappedBy = "assignee") - private List executionStepList; - @OneToMany(mappedBy = "assigner") - private List executionStepList1; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmUser") - private List userTestProjectRoleList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmUser") - private List userTestPlanRoleList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmUser") - private List userModifiedRecordList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmUser") - private List userHasInvestigationList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmUser") - private List userAssigmentList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "assigneeId") - private List userAssigmentList1; - @ManyToMany(mappedBy = "vmUserList") - private List executionStepHasIssueList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmUser") - private List executionStepHasVmUserList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "modifierId") - private List historyModificationList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "targetUser") - private List notificationList; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") - private List notificationList1; - - public VmUser() { - super(); - } - - public VmUser(String username, String password, String email, String first, - String last, String locale, Date lastModified, - UserStatus userStatus, int attempts) { - this.username = username; - this.password = password; - this.email = email; - this.firstName = first; - this.lastName = last; - this.locale = locale; - this.userStatusId = userStatus; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getLocale() { - return locale; - } - - public void setLocale(String locale) { - this.locale = locale; - } - - @XmlTransient - @JsonIgnore - public List getCorrectiveActionList() { - return correctiveActionList; - } - - public void setCorrectiveActionList(List correctiveActionList) { - this.correctiveActionList = correctiveActionList; - } - - @XmlTransient - @JsonIgnore - public List getRoleList() { - return roleList; - } - - public void setRoleList(List roleList) { - this.roleList = roleList; - } - - @XmlTransient - @JsonIgnore - public List getRootCauseList() { - return rootCauseList; - } - - public void setRootCauseList(List rootCauseList) { - this.rootCauseList = rootCauseList; - } - - public UserStatus getUserStatusId() { - return userStatusId; - } - - public void setUserStatusId(UserStatus userStatusId) { - this.userStatusId = userStatusId; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepList() { - return executionStepList; - } - - public void setExecutionStepList(List executionStepList) { - this.executionStepList = executionStepList; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepList1() { - return executionStepList1; - } - - public void setExecutionStepList1(List executionStepList1) { - this.executionStepList1 = executionStepList1; - } - - @XmlTransient - @JsonIgnore - public List getUserTestProjectRoleList() { - return userTestProjectRoleList; - } - - public void setUserTestProjectRoleList(List userTestProjectRoleList) { - this.userTestProjectRoleList = userTestProjectRoleList; - } - - @XmlTransient - @JsonIgnore - public List getUserTestPlanRoleList() { - return userTestPlanRoleList; - } - - public void setUserTestPlanRoleList(List userTestPlanRoleList) { - this.userTestPlanRoleList = userTestPlanRoleList; - } - - @XmlTransient - @JsonIgnore - public List getUserModifiedRecordList() { - return userModifiedRecordList; - } - - public void setUserModifiedRecordList(List userModifiedRecordList) { - this.userModifiedRecordList = userModifiedRecordList; - } - - @XmlTransient - @JsonIgnore - public List getUserHasInvestigationList() { - return userHasInvestigationList; - } - - public void setUserHasInvestigationList(List userHasInvestigationList) { - this.userHasInvestigationList = userHasInvestigationList; - } - - @XmlTransient - @JsonIgnore - public List getUserAssigmentList() { - return userAssigmentList; - } - - public void setUserAssigmentList(List userAssigmentList) { - this.userAssigmentList = userAssigmentList; - } - - @XmlTransient - @JsonIgnore - public List getUserAssigmentList1() { - return userAssigmentList1; - } - - public void setUserAssigmentList1(List userAssigmentList1) { - this.userAssigmentList1 = userAssigmentList1; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - - if (!(object instanceof VmUser)) { - return false; - } - VmUser other = (VmUser) object; - return this.id.equals(other.id); - } - - @Override - public String toString() { - return "com.validation.manager.core.db.VmUser[ id=" + id + " ]"; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepHasIssueList() { - return executionStepHasIssueList; - } - - public void setExecutionStepHasIssueList(List executionStepHasIssueList) { - this.executionStepHasIssueList = executionStepHasIssueList; - } - - @XmlTransient - @JsonIgnore - public List getExecutionStepHasVmUserList() { - return executionStepHasVmUserList; - } - - public void setExecutionStepHasVmUserList(List executionStepHasVmUserList) { - this.executionStepHasVmUserList = executionStepHasVmUserList; - } - - @XmlTransient - @JsonIgnore - public List getHistoryModificationList() { - return historyModificationList; - } - - public void setHistoryModificationList(List historyList) { - this.historyModificationList = historyList; - } - - @XmlTransient - @JsonIgnore - public List getNotificationList() { - return notificationList; - } - - public void setNotificationList(List notificationList) { - this.notificationList = notificationList; - } - - @XmlTransient - @JsonIgnore - public List getNotificationList1() { - return notificationList1; - } - - public void setNotificationList1(List notificationList1) { - this.notificationList1 = notificationList1; - } -} +package com.validation.manager.core.db; + +import com.validation.manager.core.history.Auditable; +import com.validation.manager.core.history.Versionable; +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@Entity +@Table(name = "vm_user") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "VmUser.findAll", + query = "SELECT v FROM VmUser v") + , @NamedQuery(name = "VmUser.findById", + query = "SELECT v FROM VmUser v WHERE v.id = :id") + , @NamedQuery(name = "VmUser.findByUsername", + query = "SELECT v FROM VmUser v WHERE v.username = :username") + , @NamedQuery(name = "VmUser.findByPassword", + query = "SELECT v FROM VmUser v WHERE v.password = :password") + , @NamedQuery(name = "VmUser.findByEmail", + query = "SELECT v FROM VmUser v WHERE v.email = :email") + , @NamedQuery(name = "VmUser.findByFirstName", + query = "SELECT v FROM VmUser v WHERE v.firstName = :firstName") + , @NamedQuery(name = "VmUser.findByLastName", + query = "SELECT v FROM VmUser v WHERE v.lastName = :lastName") + , @NamedQuery(name = "VmUser.findByLocale", + query = "SELECT v FROM VmUser v WHERE v.locale = :locale") + , @NamedQuery(name = "VmUser.findByAttempts", + query = "SELECT v FROM VmUser v WHERE v.attempts = :attempts")}) +public class VmUser extends Versionable implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "VM_UserGEN") + @TableGenerator(name = "VM_UserGEN", + table = "vm_id", + pkColumnName = "table_name", + valueColumnName = "last_id", + pkColumnValue = "vm_user", + initialValue = 1_000, + allocationSize = 1) + @NotNull + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Auditable + @Column(name = "username") + private String username; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "password") + @Auditable + private String password; + @Pattern(regexp = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`" + + "{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:" + + "[a-z0-9-]*[a-z0-9])?", + message = "Invalid email")//if the field contains email address consider using this annotation to enforce field validation + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 100) + @Auditable + @Column(name = "email") + private String email; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "first_name") + @Auditable + private String firstName; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "last_name") + @Auditable + private String lastName; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Auditable + @Column(name = "locale") + private String locale; + @ManyToMany(mappedBy = "vmUserList") + private List correctiveActionList; + @ManyToMany(mappedBy = "vmUserList") + private List roleList; + @ManyToMany(mappedBy = "vmUserList") + private List rootCauseList; + @JoinColumn(name = "user_status_id", referencedColumnName = "id") + @ManyToOne(optional = false) + private UserStatus userStatusId; + @OneToMany(mappedBy = "assignee") + private List executionStepList; + @OneToMany(mappedBy = "assigner") + private List executionStepList1; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmUser") + private List userTestProjectRoleList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmUser") + private List userTestPlanRoleList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmUser") + private List userModifiedRecordList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmUser") + private List userHasInvestigationList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmUser") + private List userAssigmentList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "assigneeId") + private List userAssigmentList1; + @ManyToMany(mappedBy = "vmUserList") + private List executionStepHasIssueList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "vmUser") + private List executionStepHasVmUserList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "modifierId") + private List historyModificationList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "targetUser") + private List notificationList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") + private List notificationList1; + @OneToMany(mappedBy = "vmUserId") + private List historyList; + @Basic(optional = false) + @NotNull + @Column(name = "attempts") + @Min(value = 0) + private int attempts; + + public VmUser() { + super(); + } + + public VmUser(String username, String password, String email, String first, + String last, String locale, UserStatus userStatus, int attempts) { + this.username = username; + this.password = password; + this.email = email; + this.firstName = first; + this.lastName = last; + this.locale = locale; + this.userStatusId = userStatus; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getLocale() { + return locale; + } + + public void setLocale(String locale) { + this.locale = locale; + } + + @XmlTransient + @JsonIgnore + public List getCorrectiveActionList() { + return correctiveActionList; + } + + public void setCorrectiveActionList(List correctiveActionList) { + this.correctiveActionList = correctiveActionList; + } + + @XmlTransient + @JsonIgnore + public List getRoleList() { + return roleList; + } + + public void setRoleList(List roleList) { + this.roleList = roleList; + } + + @XmlTransient + @JsonIgnore + public List getRootCauseList() { + return rootCauseList; + } + + public void setRootCauseList(List rootCauseList) { + this.rootCauseList = rootCauseList; + } + + public UserStatus getUserStatusId() { + return userStatusId; + } + + public void setUserStatusId(UserStatus userStatusId) { + this.userStatusId = userStatusId; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepList() { + return executionStepList; + } + + public void setExecutionStepList(List executionStepList) { + this.executionStepList = executionStepList; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepList1() { + return executionStepList1; + } + + public void setExecutionStepList1(List executionStepList1) { + this.executionStepList1 = executionStepList1; + } + + @XmlTransient + @JsonIgnore + public List getUserTestProjectRoleList() { + return userTestProjectRoleList; + } + + public void setUserTestProjectRoleList(List userTestProjectRoleList) { + this.userTestProjectRoleList = userTestProjectRoleList; + } + + @XmlTransient + @JsonIgnore + public List getUserTestPlanRoleList() { + return userTestPlanRoleList; + } + + public void setUserTestPlanRoleList(List userTestPlanRoleList) { + this.userTestPlanRoleList = userTestPlanRoleList; + } + + @XmlTransient + @JsonIgnore + public List getUserModifiedRecordList() { + return userModifiedRecordList; + } + + public void setUserModifiedRecordList(List userModifiedRecordList) { + this.userModifiedRecordList = userModifiedRecordList; + } + + @XmlTransient + @JsonIgnore + public List getUserHasInvestigationList() { + return userHasInvestigationList; + } + + public void setUserHasInvestigationList(List userHasInvestigationList) { + this.userHasInvestigationList = userHasInvestigationList; + } + + @XmlTransient + @JsonIgnore + public List getUserAssigmentList() { + return userAssigmentList; + } + + public void setUserAssigmentList(List userAssigmentList) { + this.userAssigmentList = userAssigmentList; + } + + @XmlTransient + @JsonIgnore + public List getUserAssigmentList1() { + return userAssigmentList1; + } + + public void setUserAssigmentList1(List userAssigmentList1) { + this.userAssigmentList1 = userAssigmentList1; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof VmUser)) { + return false; + } + VmUser other = (VmUser) object; + return this.id.equals(other.id); + } + + @Override + public String toString() { + return "com.validation.manager.core.db.VmUser[ id=" + id + " ]"; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepHasIssueList() { + return executionStepHasIssueList; + } + + public void setExecutionStepHasIssueList(List executionStepHasIssueList) { + this.executionStepHasIssueList = executionStepHasIssueList; + } + + @XmlTransient + @JsonIgnore + public List getExecutionStepHasVmUserList() { + return executionStepHasVmUserList; + } + + public void setExecutionStepHasVmUserList(List executionStepHasVmUserList) { + this.executionStepHasVmUserList = executionStepHasVmUserList; + } + + @XmlTransient + @JsonIgnore + public List getHistoryModificationList() { + return historyModificationList; + } + + public void setHistoryModificationList(List historyList) { + this.historyModificationList = historyList; + } + + @XmlTransient + @JsonIgnore + public List getNotificationList() { + return notificationList; + } + + public void setNotificationList(List notificationList) { + this.notificationList = notificationList; + } + + @XmlTransient + @JsonIgnore + public List getNotificationList1() { + return notificationList1; + } + + public void setNotificationList1(List notificationList1) { + this.notificationList1 = notificationList1; + } + + @XmlTransient + @JsonIgnore + @Override + public List getHistoryList() { + return historyList; + } + + @Override + public void setHistoryList(List historyList) { + this.historyList = historyList; + } + + public int getAttempts() { + return attempts; + } + + public void setAttempts(int attempts) { + this.attempts = attempts; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/AssigmentTypeJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/AssigmentTypeJpaController.java index 9844a7af..9dd288ab 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/AssigmentTypeJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/AssigmentTypeJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.AssigmentType; -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.UserAssigment; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class AssigmentTypeJpaController implements Serializable { - - public AssigmentTypeJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(AssigmentType assigmentType) { - if (assigmentType.getUserAssigmentList() == null) { - assigmentType.setUserAssigmentList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedUserAssigmentList = new ArrayList(); - for (UserAssigment userAssigmentListUserAssigmentToAttach : assigmentType.getUserAssigmentList()) { - userAssigmentListUserAssigmentToAttach = em.getReference(userAssigmentListUserAssigmentToAttach.getClass(), userAssigmentListUserAssigmentToAttach.getUserAssigmentPK()); - attachedUserAssigmentList.add(userAssigmentListUserAssigmentToAttach); - } - assigmentType.setUserAssigmentList(attachedUserAssigmentList); - em.persist(assigmentType); - for (UserAssigment userAssigmentListUserAssigment : assigmentType.getUserAssigmentList()) { - AssigmentType oldAssigmentTypeOfUserAssigmentListUserAssigment = userAssigmentListUserAssigment.getAssigmentType(); - userAssigmentListUserAssigment.setAssigmentType(assigmentType); - userAssigmentListUserAssigment = em.merge(userAssigmentListUserAssigment); - if (oldAssigmentTypeOfUserAssigmentListUserAssigment != null) { - oldAssigmentTypeOfUserAssigmentListUserAssigment.getUserAssigmentList().remove(userAssigmentListUserAssigment); - oldAssigmentTypeOfUserAssigmentListUserAssigment = em.merge(oldAssigmentTypeOfUserAssigmentListUserAssigment); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(AssigmentType assigmentType) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - AssigmentType persistentAssigmentType = em.find(AssigmentType.class, assigmentType.getId()); - List userAssigmentListOld = persistentAssigmentType.getUserAssigmentList(); - List userAssigmentListNew = assigmentType.getUserAssigmentList(); - List illegalOrphanMessages = null; - for (UserAssigment userAssigmentListOldUserAssigment : userAssigmentListOld) { - if (!userAssigmentListNew.contains(userAssigmentListOldUserAssigment)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserAssigment " + userAssigmentListOldUserAssigment + " since its assigmentType field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedUserAssigmentListNew = new ArrayList(); - for (UserAssigment userAssigmentListNewUserAssigmentToAttach : userAssigmentListNew) { - userAssigmentListNewUserAssigmentToAttach = em.getReference(userAssigmentListNewUserAssigmentToAttach.getClass(), userAssigmentListNewUserAssigmentToAttach.getUserAssigmentPK()); - attachedUserAssigmentListNew.add(userAssigmentListNewUserAssigmentToAttach); - } - userAssigmentListNew = attachedUserAssigmentListNew; - assigmentType.setUserAssigmentList(userAssigmentListNew); - assigmentType = em.merge(assigmentType); - for (UserAssigment userAssigmentListNewUserAssigment : userAssigmentListNew) { - if (!userAssigmentListOld.contains(userAssigmentListNewUserAssigment)) { - AssigmentType oldAssigmentTypeOfUserAssigmentListNewUserAssigment = userAssigmentListNewUserAssigment.getAssigmentType(); - userAssigmentListNewUserAssigment.setAssigmentType(assigmentType); - userAssigmentListNewUserAssigment = em.merge(userAssigmentListNewUserAssigment); - if (oldAssigmentTypeOfUserAssigmentListNewUserAssigment != null && !oldAssigmentTypeOfUserAssigmentListNewUserAssigment.equals(assigmentType)) { - oldAssigmentTypeOfUserAssigmentListNewUserAssigment.getUserAssigmentList().remove(userAssigmentListNewUserAssigment); - oldAssigmentTypeOfUserAssigmentListNewUserAssigment = em.merge(oldAssigmentTypeOfUserAssigmentListNewUserAssigment); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = assigmentType.getId(); - if (findAssigmentType(id) == null) { - throw new NonexistentEntityException("The assigmentType with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - AssigmentType assigmentType; - try { - assigmentType = em.getReference(AssigmentType.class, id); - assigmentType.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The assigmentType with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List userAssigmentListOrphanCheck = assigmentType.getUserAssigmentList(); - for (UserAssigment userAssigmentListOrphanCheckUserAssigment : userAssigmentListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This AssigmentType (" + assigmentType + ") cannot be destroyed since the UserAssigment " + userAssigmentListOrphanCheckUserAssigment + " in its userAssigmentList field has a non-nullable assigmentType field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(assigmentType); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findAssigmentTypeEntities() { - return findAssigmentTypeEntities(true, -1, -1); - } - - public List findAssigmentTypeEntities(int maxResults, int firstResult) { - return findAssigmentTypeEntities(false, maxResults, firstResult); - } - - private List findAssigmentTypeEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(AssigmentType.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public AssigmentType findAssigmentType(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(AssigmentType.class, id); - } - finally { - em.close(); - } - } - - public int getAssigmentTypeCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(AssigmentType.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import com.validation.manager.core.db.AssigmentType; +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.UserAssigment; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class AssigmentTypeJpaController implements Serializable { + + public AssigmentTypeJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(AssigmentType assigmentType) { + if (assigmentType.getUserAssigmentList() == null) { + assigmentType.setUserAssigmentList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedUserAssigmentList = new ArrayList<>(); + for (UserAssigment userAssigmentListUserAssigmentToAttach : assigmentType.getUserAssigmentList()) { + userAssigmentListUserAssigmentToAttach = em.getReference(userAssigmentListUserAssigmentToAttach.getClass(), userAssigmentListUserAssigmentToAttach.getUserAssigmentPK()); + attachedUserAssigmentList.add(userAssigmentListUserAssigmentToAttach); + } + assigmentType.setUserAssigmentList(attachedUserAssigmentList); + em.persist(assigmentType); + for (UserAssigment userAssigmentListUserAssigment : assigmentType.getUserAssigmentList()) { + AssigmentType oldAssigmentTypeOfUserAssigmentListUserAssigment = userAssigmentListUserAssigment.getAssigmentType(); + userAssigmentListUserAssigment.setAssigmentType(assigmentType); + userAssigmentListUserAssigment = em.merge(userAssigmentListUserAssigment); + if (oldAssigmentTypeOfUserAssigmentListUserAssigment != null) { + oldAssigmentTypeOfUserAssigmentListUserAssigment.getUserAssigmentList().remove(userAssigmentListUserAssigment); + oldAssigmentTypeOfUserAssigmentListUserAssigment = em.merge(oldAssigmentTypeOfUserAssigmentListUserAssigment); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(AssigmentType assigmentType) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + AssigmentType persistentAssigmentType = em.find(AssigmentType.class, assigmentType.getId()); + List userAssigmentListOld = persistentAssigmentType.getUserAssigmentList(); + List userAssigmentListNew = assigmentType.getUserAssigmentList(); + List illegalOrphanMessages = null; + for (UserAssigment userAssigmentListOldUserAssigment : userAssigmentListOld) { + if (!userAssigmentListNew.contains(userAssigmentListOldUserAssigment)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserAssigment " + userAssigmentListOldUserAssigment + " since its assigmentType field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedUserAssigmentListNew = new ArrayList<>(); + for (UserAssigment userAssigmentListNewUserAssigmentToAttach : userAssigmentListNew) { + userAssigmentListNewUserAssigmentToAttach = em.getReference(userAssigmentListNewUserAssigmentToAttach.getClass(), userAssigmentListNewUserAssigmentToAttach.getUserAssigmentPK()); + attachedUserAssigmentListNew.add(userAssigmentListNewUserAssigmentToAttach); + } + userAssigmentListNew = attachedUserAssigmentListNew; + assigmentType.setUserAssigmentList(userAssigmentListNew); + assigmentType = em.merge(assigmentType); + for (UserAssigment userAssigmentListNewUserAssigment : userAssigmentListNew) { + if (!userAssigmentListOld.contains(userAssigmentListNewUserAssigment)) { + AssigmentType oldAssigmentTypeOfUserAssigmentListNewUserAssigment = userAssigmentListNewUserAssigment.getAssigmentType(); + userAssigmentListNewUserAssigment.setAssigmentType(assigmentType); + userAssigmentListNewUserAssigment = em.merge(userAssigmentListNewUserAssigment); + if (oldAssigmentTypeOfUserAssigmentListNewUserAssigment != null && !oldAssigmentTypeOfUserAssigmentListNewUserAssigment.equals(assigmentType)) { + oldAssigmentTypeOfUserAssigmentListNewUserAssigment.getUserAssigmentList().remove(userAssigmentListNewUserAssigment); + oldAssigmentTypeOfUserAssigmentListNewUserAssigment = em.merge(oldAssigmentTypeOfUserAssigmentListNewUserAssigment); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = assigmentType.getId(); + if (findAssigmentType(id) == null) { + throw new NonexistentEntityException("The assigmentType with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + AssigmentType assigmentType; + try { + assigmentType = em.getReference(AssigmentType.class, id); + assigmentType.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The assigmentType with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List userAssigmentListOrphanCheck = assigmentType.getUserAssigmentList(); + for (UserAssigment userAssigmentListOrphanCheckUserAssigment : userAssigmentListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This AssigmentType (" + assigmentType + ") cannot be destroyed since the UserAssigment " + userAssigmentListOrphanCheckUserAssigment + " in its userAssigmentList field has a non-nullable assigmentType field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(assigmentType); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findAssigmentTypeEntities() { + return findAssigmentTypeEntities(true, -1, -1); + } + + public List findAssigmentTypeEntities(int maxResults, int firstResult) { + return findAssigmentTypeEntities(false, maxResults, firstResult); + } + + private List findAssigmentTypeEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(AssigmentType.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public AssigmentType findAssigmentType(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(AssigmentType.class, id); + } + finally { + em.close(); + } + } + + public int getAssigmentTypeCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(AssigmentType.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/AssignmentStatusJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/AssignmentStatusJpaController.java index 618ca14c..97769f3c 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/AssignmentStatusJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/AssignmentStatusJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.AssignmentStatus; -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.UserAssigment; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class AssignmentStatusJpaController implements Serializable { - - public AssignmentStatusJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(AssignmentStatus assignmentStatus) { - if (assignmentStatus.getUserAssigmentList() == null) { - assignmentStatus.setUserAssigmentList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedUserAssigmentList = new ArrayList(); - for (UserAssigment userAssigmentListUserAssigmentToAttach : assignmentStatus.getUserAssigmentList()) { - userAssigmentListUserAssigmentToAttach = em.getReference(userAssigmentListUserAssigmentToAttach.getClass(), userAssigmentListUserAssigmentToAttach.getUserAssigmentPK()); - attachedUserAssigmentList.add(userAssigmentListUserAssigmentToAttach); - } - assignmentStatus.setUserAssigmentList(attachedUserAssigmentList); - em.persist(assignmentStatus); - for (UserAssigment userAssigmentListUserAssigment : assignmentStatus.getUserAssigmentList()) { - AssignmentStatus oldAssignmentStatusOfUserAssigmentListUserAssigment = userAssigmentListUserAssigment.getAssignmentStatus(); - userAssigmentListUserAssigment.setAssignmentStatus(assignmentStatus); - userAssigmentListUserAssigment = em.merge(userAssigmentListUserAssigment); - if (oldAssignmentStatusOfUserAssigmentListUserAssigment != null) { - oldAssignmentStatusOfUserAssigmentListUserAssigment.getUserAssigmentList().remove(userAssigmentListUserAssigment); - oldAssignmentStatusOfUserAssigmentListUserAssigment = em.merge(oldAssignmentStatusOfUserAssigmentListUserAssigment); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(AssignmentStatus assignmentStatus) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - AssignmentStatus persistentAssignmentStatus = em.find(AssignmentStatus.class, assignmentStatus.getId()); - List userAssigmentListOld = persistentAssignmentStatus.getUserAssigmentList(); - List userAssigmentListNew = assignmentStatus.getUserAssigmentList(); - List illegalOrphanMessages = null; - for (UserAssigment userAssigmentListOldUserAssigment : userAssigmentListOld) { - if (!userAssigmentListNew.contains(userAssigmentListOldUserAssigment)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserAssigment " + userAssigmentListOldUserAssigment + " since its assignmentStatus field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedUserAssigmentListNew = new ArrayList(); - for (UserAssigment userAssigmentListNewUserAssigmentToAttach : userAssigmentListNew) { - userAssigmentListNewUserAssigmentToAttach = em.getReference(userAssigmentListNewUserAssigmentToAttach.getClass(), userAssigmentListNewUserAssigmentToAttach.getUserAssigmentPK()); - attachedUserAssigmentListNew.add(userAssigmentListNewUserAssigmentToAttach); - } - userAssigmentListNew = attachedUserAssigmentListNew; - assignmentStatus.setUserAssigmentList(userAssigmentListNew); - assignmentStatus = em.merge(assignmentStatus); - for (UserAssigment userAssigmentListNewUserAssigment : userAssigmentListNew) { - if (!userAssigmentListOld.contains(userAssigmentListNewUserAssigment)) { - AssignmentStatus oldAssignmentStatusOfUserAssigmentListNewUserAssigment = userAssigmentListNewUserAssigment.getAssignmentStatus(); - userAssigmentListNewUserAssigment.setAssignmentStatus(assignmentStatus); - userAssigmentListNewUserAssigment = em.merge(userAssigmentListNewUserAssigment); - if (oldAssignmentStatusOfUserAssigmentListNewUserAssigment != null && !oldAssignmentStatusOfUserAssigmentListNewUserAssigment.equals(assignmentStatus)) { - oldAssignmentStatusOfUserAssigmentListNewUserAssigment.getUserAssigmentList().remove(userAssigmentListNewUserAssigment); - oldAssignmentStatusOfUserAssigmentListNewUserAssigment = em.merge(oldAssignmentStatusOfUserAssigmentListNewUserAssigment); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = assignmentStatus.getId(); - if (findAssignmentStatus(id) == null) { - throw new NonexistentEntityException("The assignmentStatus with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - AssignmentStatus assignmentStatus; - try { - assignmentStatus = em.getReference(AssignmentStatus.class, id); - assignmentStatus.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The assignmentStatus with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List userAssigmentListOrphanCheck = assignmentStatus.getUserAssigmentList(); - for (UserAssigment userAssigmentListOrphanCheckUserAssigment : userAssigmentListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This AssignmentStatus (" + assignmentStatus + ") cannot be destroyed since the UserAssigment " + userAssigmentListOrphanCheckUserAssigment + " in its userAssigmentList field has a non-nullable assignmentStatus field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(assignmentStatus); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findAssignmentStatusEntities() { - return findAssignmentStatusEntities(true, -1, -1); - } - - public List findAssignmentStatusEntities(int maxResults, int firstResult) { - return findAssignmentStatusEntities(false, maxResults, firstResult); - } - - private List findAssignmentStatusEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(AssignmentStatus.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public AssignmentStatus findAssignmentStatus(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(AssignmentStatus.class, id); - } - finally { - em.close(); - } - } - - public int getAssignmentStatusCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(AssignmentStatus.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import com.validation.manager.core.db.AssignmentStatus; +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.UserAssigment; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class AssignmentStatusJpaController implements Serializable { + + public AssignmentStatusJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(AssignmentStatus assignmentStatus) { + if (assignmentStatus.getUserAssigmentList() == null) { + assignmentStatus.setUserAssigmentList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedUserAssigmentList = new ArrayList<>(); + for (UserAssigment userAssigmentListUserAssigmentToAttach : assignmentStatus.getUserAssigmentList()) { + userAssigmentListUserAssigmentToAttach = em.getReference(userAssigmentListUserAssigmentToAttach.getClass(), userAssigmentListUserAssigmentToAttach.getUserAssigmentPK()); + attachedUserAssigmentList.add(userAssigmentListUserAssigmentToAttach); + } + assignmentStatus.setUserAssigmentList(attachedUserAssigmentList); + em.persist(assignmentStatus); + for (UserAssigment userAssigmentListUserAssigment : assignmentStatus.getUserAssigmentList()) { + AssignmentStatus oldAssignmentStatusOfUserAssigmentListUserAssigment = userAssigmentListUserAssigment.getAssignmentStatus(); + userAssigmentListUserAssigment.setAssignmentStatus(assignmentStatus); + userAssigmentListUserAssigment = em.merge(userAssigmentListUserAssigment); + if (oldAssignmentStatusOfUserAssigmentListUserAssigment != null) { + oldAssignmentStatusOfUserAssigmentListUserAssigment.getUserAssigmentList().remove(userAssigmentListUserAssigment); + oldAssignmentStatusOfUserAssigmentListUserAssigment = em.merge(oldAssignmentStatusOfUserAssigmentListUserAssigment); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(AssignmentStatus assignmentStatus) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + AssignmentStatus persistentAssignmentStatus = em.find(AssignmentStatus.class, assignmentStatus.getId()); + List userAssigmentListOld = persistentAssignmentStatus.getUserAssigmentList(); + List userAssigmentListNew = assignmentStatus.getUserAssigmentList(); + List illegalOrphanMessages = null; + for (UserAssigment userAssigmentListOldUserAssigment : userAssigmentListOld) { + if (!userAssigmentListNew.contains(userAssigmentListOldUserAssigment)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserAssigment " + userAssigmentListOldUserAssigment + " since its assignmentStatus field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedUserAssigmentListNew = new ArrayList<>(); + for (UserAssigment userAssigmentListNewUserAssigmentToAttach : userAssigmentListNew) { + userAssigmentListNewUserAssigmentToAttach = em.getReference(userAssigmentListNewUserAssigmentToAttach.getClass(), userAssigmentListNewUserAssigmentToAttach.getUserAssigmentPK()); + attachedUserAssigmentListNew.add(userAssigmentListNewUserAssigmentToAttach); + } + userAssigmentListNew = attachedUserAssigmentListNew; + assignmentStatus.setUserAssigmentList(userAssigmentListNew); + assignmentStatus = em.merge(assignmentStatus); + for (UserAssigment userAssigmentListNewUserAssigment : userAssigmentListNew) { + if (!userAssigmentListOld.contains(userAssigmentListNewUserAssigment)) { + AssignmentStatus oldAssignmentStatusOfUserAssigmentListNewUserAssigment = userAssigmentListNewUserAssigment.getAssignmentStatus(); + userAssigmentListNewUserAssigment.setAssignmentStatus(assignmentStatus); + userAssigmentListNewUserAssigment = em.merge(userAssigmentListNewUserAssigment); + if (oldAssignmentStatusOfUserAssigmentListNewUserAssigment != null && !oldAssignmentStatusOfUserAssigmentListNewUserAssigment.equals(assignmentStatus)) { + oldAssignmentStatusOfUserAssigmentListNewUserAssigment.getUserAssigmentList().remove(userAssigmentListNewUserAssigment); + oldAssignmentStatusOfUserAssigmentListNewUserAssigment = em.merge(oldAssignmentStatusOfUserAssigmentListNewUserAssigment); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = assignmentStatus.getId(); + if (findAssignmentStatus(id) == null) { + throw new NonexistentEntityException("The assignmentStatus with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + AssignmentStatus assignmentStatus; + try { + assignmentStatus = em.getReference(AssignmentStatus.class, id); + assignmentStatus.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The assignmentStatus with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List userAssigmentListOrphanCheck = assignmentStatus.getUserAssigmentList(); + for (UserAssigment userAssigmentListOrphanCheckUserAssigment : userAssigmentListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This AssignmentStatus (" + assignmentStatus + ") cannot be destroyed since the UserAssigment " + userAssigmentListOrphanCheckUserAssigment + " in its userAssigmentList field has a non-nullable assignmentStatus field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(assignmentStatus); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findAssignmentStatusEntities() { + return findAssignmentStatusEntities(true, -1, -1); + } + + public List findAssignmentStatusEntities(int maxResults, int firstResult) { + return findAssignmentStatusEntities(false, maxResults, firstResult); + } + + private List findAssignmentStatusEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(AssignmentStatus.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public AssignmentStatus findAssignmentStatus(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(AssignmentStatus.class, id); + } + finally { + em.close(); + } + } + + public int getAssignmentStatusCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(AssignmentStatus.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/AttachmentJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/AttachmentJpaController.java index ff5bc8d6..db0b078a 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/AttachmentJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/AttachmentJpaController.java @@ -13,251 +13,251 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.Attachment; -import com.validation.manager.core.db.AttachmentPK; -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.AttachmentType; -import com.validation.manager.core.db.ExecutionStepHasAttachment; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class AttachmentJpaController implements Serializable { - - public AttachmentJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Attachment attachment) throws PreexistingEntityException, Exception { - if (attachment.getAttachmentPK() == null) { - attachment.setAttachmentPK(new AttachmentPK()); - } - if (attachment.getExecutionStepHasAttachmentList() == null) { - attachment.setExecutionStepHasAttachmentList(new ArrayList()); - } - attachment.getAttachmentPK().setAttachmentTypeId(attachment.getAttachmentType().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - AttachmentType attachmentType = attachment.getAttachmentType(); - if (attachmentType != null) { - attachmentType = em.getReference(attachmentType.getClass(), attachmentType.getId()); - attachment.setAttachmentType(attachmentType); - } - List attachedExecutionStepHasAttachmentList = new ArrayList(); - for (ExecutionStepHasAttachment executionStepHasAttachmentListExecutionStepHasAttachmentToAttach : attachment.getExecutionStepHasAttachmentList()) { - executionStepHasAttachmentListExecutionStepHasAttachmentToAttach = em.getReference(executionStepHasAttachmentListExecutionStepHasAttachmentToAttach.getClass(), executionStepHasAttachmentListExecutionStepHasAttachmentToAttach.getExecutionStepHasAttachmentPK()); - attachedExecutionStepHasAttachmentList.add(executionStepHasAttachmentListExecutionStepHasAttachmentToAttach); - } - attachment.setExecutionStepHasAttachmentList(attachedExecutionStepHasAttachmentList); - em.persist(attachment); - if (attachmentType != null) { - attachmentType.getAttachmentList().add(attachment); - attachmentType = em.merge(attachmentType); - } - for (ExecutionStepHasAttachment executionStepHasAttachmentListExecutionStepHasAttachment : attachment.getExecutionStepHasAttachmentList()) { - Attachment oldAttachmentOfExecutionStepHasAttachmentListExecutionStepHasAttachment = executionStepHasAttachmentListExecutionStepHasAttachment.getAttachment(); - executionStepHasAttachmentListExecutionStepHasAttachment.setAttachment(attachment); - executionStepHasAttachmentListExecutionStepHasAttachment = em.merge(executionStepHasAttachmentListExecutionStepHasAttachment); - if (oldAttachmentOfExecutionStepHasAttachmentListExecutionStepHasAttachment != null) { - oldAttachmentOfExecutionStepHasAttachmentListExecutionStepHasAttachment.getExecutionStepHasAttachmentList().remove(executionStepHasAttachmentListExecutionStepHasAttachment); - oldAttachmentOfExecutionStepHasAttachmentListExecutionStepHasAttachment = em.merge(oldAttachmentOfExecutionStepHasAttachmentListExecutionStepHasAttachment); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - if (findAttachment(attachment.getAttachmentPK()) != null) { - throw new PreexistingEntityException("Attachment " + attachment + " already exists.", ex); - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Attachment attachment) throws IllegalOrphanException, NonexistentEntityException, Exception { - attachment.getAttachmentPK().setAttachmentTypeId(attachment.getAttachmentType().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Attachment persistentAttachment = em.find(Attachment.class, attachment.getAttachmentPK()); - AttachmentType attachmentTypeOld = persistentAttachment.getAttachmentType(); - AttachmentType attachmentTypeNew = attachment.getAttachmentType(); - List executionStepHasAttachmentListOld = persistentAttachment.getExecutionStepHasAttachmentList(); - List executionStepHasAttachmentListNew = attachment.getExecutionStepHasAttachmentList(); - List illegalOrphanMessages = null; - for (ExecutionStepHasAttachment executionStepHasAttachmentListOldExecutionStepHasAttachment : executionStepHasAttachmentListOld) { - if (!executionStepHasAttachmentListNew.contains(executionStepHasAttachmentListOldExecutionStepHasAttachment)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain ExecutionStepHasAttachment " + executionStepHasAttachmentListOldExecutionStepHasAttachment + " since its attachment field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (attachmentTypeNew != null) { - attachmentTypeNew = em.getReference(attachmentTypeNew.getClass(), attachmentTypeNew.getId()); - attachment.setAttachmentType(attachmentTypeNew); - } - List attachedExecutionStepHasAttachmentListNew = new ArrayList(); - for (ExecutionStepHasAttachment executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach : executionStepHasAttachmentListNew) { - executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach = em.getReference(executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach.getClass(), executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach.getExecutionStepHasAttachmentPK()); - attachedExecutionStepHasAttachmentListNew.add(executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach); - } - executionStepHasAttachmentListNew = attachedExecutionStepHasAttachmentListNew; - attachment.setExecutionStepHasAttachmentList(executionStepHasAttachmentListNew); - attachment = em.merge(attachment); - if (attachmentTypeOld != null && !attachmentTypeOld.equals(attachmentTypeNew)) { - attachmentTypeOld.getAttachmentList().remove(attachment); - attachmentTypeOld = em.merge(attachmentTypeOld); - } - if (attachmentTypeNew != null && !attachmentTypeNew.equals(attachmentTypeOld)) { - attachmentTypeNew.getAttachmentList().add(attachment); - attachmentTypeNew = em.merge(attachmentTypeNew); - } - for (ExecutionStepHasAttachment executionStepHasAttachmentListNewExecutionStepHasAttachment : executionStepHasAttachmentListNew) { - if (!executionStepHasAttachmentListOld.contains(executionStepHasAttachmentListNewExecutionStepHasAttachment)) { - Attachment oldAttachmentOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment = executionStepHasAttachmentListNewExecutionStepHasAttachment.getAttachment(); - executionStepHasAttachmentListNewExecutionStepHasAttachment.setAttachment(attachment); - executionStepHasAttachmentListNewExecutionStepHasAttachment = em.merge(executionStepHasAttachmentListNewExecutionStepHasAttachment); - if (oldAttachmentOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment != null && !oldAttachmentOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment.equals(attachment)) { - oldAttachmentOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment.getExecutionStepHasAttachmentList().remove(executionStepHasAttachmentListNewExecutionStepHasAttachment); - oldAttachmentOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment = em.merge(oldAttachmentOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - AttachmentPK id = attachment.getAttachmentPK(); - if (findAttachment(id) == null) { - throw new NonexistentEntityException("The attachment with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(AttachmentPK id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Attachment attachment; - try { - attachment = em.getReference(Attachment.class, id); - attachment.getAttachmentPK(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The attachment with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List executionStepHasAttachmentListOrphanCheck = attachment.getExecutionStepHasAttachmentList(); - for (ExecutionStepHasAttachment executionStepHasAttachmentListOrphanCheckExecutionStepHasAttachment : executionStepHasAttachmentListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Attachment (" + attachment + ") cannot be destroyed since the ExecutionStepHasAttachment " + executionStepHasAttachmentListOrphanCheckExecutionStepHasAttachment + " in its executionStepHasAttachmentList field has a non-nullable attachment field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - AttachmentType attachmentType = attachment.getAttachmentType(); - if (attachmentType != null) { - attachmentType.getAttachmentList().remove(attachment); - attachmentType = em.merge(attachmentType); - } - em.remove(attachment); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findAttachmentEntities() { - return findAttachmentEntities(true, -1, -1); - } - - public List findAttachmentEntities(int maxResults, int firstResult) { - return findAttachmentEntities(false, maxResults, firstResult); - } - - private List findAttachmentEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Attachment.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public Attachment findAttachment(AttachmentPK id) { - EntityManager em = getEntityManager(); - try { - return em.find(Attachment.class, id); - } - finally { - em.close(); - } - } - - public int getAttachmentCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(Attachment.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import com.validation.manager.core.db.Attachment; +import com.validation.manager.core.db.AttachmentPK; +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.AttachmentType; +import com.validation.manager.core.db.ExecutionStepHasAttachment; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class AttachmentJpaController implements Serializable { + + public AttachmentJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Attachment attachment) throws PreexistingEntityException, Exception { + if (attachment.getAttachmentPK() == null) { + attachment.setAttachmentPK(new AttachmentPK()); + } + if (attachment.getExecutionStepHasAttachmentList() == null) { + attachment.setExecutionStepHasAttachmentList(new ArrayList<>()); + } + attachment.getAttachmentPK().setAttachmentTypeId(attachment.getAttachmentType().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + AttachmentType attachmentType = attachment.getAttachmentType(); + if (attachmentType != null) { + attachmentType = em.getReference(attachmentType.getClass(), attachmentType.getId()); + attachment.setAttachmentType(attachmentType); + } + List attachedExecutionStepHasAttachmentList = new ArrayList<>(); + for (ExecutionStepHasAttachment executionStepHasAttachmentListExecutionStepHasAttachmentToAttach : attachment.getExecutionStepHasAttachmentList()) { + executionStepHasAttachmentListExecutionStepHasAttachmentToAttach = em.getReference(executionStepHasAttachmentListExecutionStepHasAttachmentToAttach.getClass(), executionStepHasAttachmentListExecutionStepHasAttachmentToAttach.getExecutionStepHasAttachmentPK()); + attachedExecutionStepHasAttachmentList.add(executionStepHasAttachmentListExecutionStepHasAttachmentToAttach); + } + attachment.setExecutionStepHasAttachmentList(attachedExecutionStepHasAttachmentList); + em.persist(attachment); + if (attachmentType != null) { + attachmentType.getAttachmentList().add(attachment); + attachmentType = em.merge(attachmentType); + } + for (ExecutionStepHasAttachment executionStepHasAttachmentListExecutionStepHasAttachment : attachment.getExecutionStepHasAttachmentList()) { + Attachment oldAttachmentOfExecutionStepHasAttachmentListExecutionStepHasAttachment = executionStepHasAttachmentListExecutionStepHasAttachment.getAttachment(); + executionStepHasAttachmentListExecutionStepHasAttachment.setAttachment(attachment); + executionStepHasAttachmentListExecutionStepHasAttachment = em.merge(executionStepHasAttachmentListExecutionStepHasAttachment); + if (oldAttachmentOfExecutionStepHasAttachmentListExecutionStepHasAttachment != null) { + oldAttachmentOfExecutionStepHasAttachmentListExecutionStepHasAttachment.getExecutionStepHasAttachmentList().remove(executionStepHasAttachmentListExecutionStepHasAttachment); + oldAttachmentOfExecutionStepHasAttachmentListExecutionStepHasAttachment = em.merge(oldAttachmentOfExecutionStepHasAttachmentListExecutionStepHasAttachment); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + if (findAttachment(attachment.getAttachmentPK()) != null) { + throw new PreexistingEntityException("Attachment " + attachment + " already exists.", ex); + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Attachment attachment) throws IllegalOrphanException, NonexistentEntityException, Exception { + attachment.getAttachmentPK().setAttachmentTypeId(attachment.getAttachmentType().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Attachment persistentAttachment = em.find(Attachment.class, attachment.getAttachmentPK()); + AttachmentType attachmentTypeOld = persistentAttachment.getAttachmentType(); + AttachmentType attachmentTypeNew = attachment.getAttachmentType(); + List executionStepHasAttachmentListOld = persistentAttachment.getExecutionStepHasAttachmentList(); + List executionStepHasAttachmentListNew = attachment.getExecutionStepHasAttachmentList(); + List illegalOrphanMessages = null; + for (ExecutionStepHasAttachment executionStepHasAttachmentListOldExecutionStepHasAttachment : executionStepHasAttachmentListOld) { + if (!executionStepHasAttachmentListNew.contains(executionStepHasAttachmentListOldExecutionStepHasAttachment)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain ExecutionStepHasAttachment " + executionStepHasAttachmentListOldExecutionStepHasAttachment + " since its attachment field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (attachmentTypeNew != null) { + attachmentTypeNew = em.getReference(attachmentTypeNew.getClass(), attachmentTypeNew.getId()); + attachment.setAttachmentType(attachmentTypeNew); + } + List attachedExecutionStepHasAttachmentListNew = new ArrayList<>(); + for (ExecutionStepHasAttachment executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach : executionStepHasAttachmentListNew) { + executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach = em.getReference(executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach.getClass(), executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach.getExecutionStepHasAttachmentPK()); + attachedExecutionStepHasAttachmentListNew.add(executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach); + } + executionStepHasAttachmentListNew = attachedExecutionStepHasAttachmentListNew; + attachment.setExecutionStepHasAttachmentList(executionStepHasAttachmentListNew); + attachment = em.merge(attachment); + if (attachmentTypeOld != null && !attachmentTypeOld.equals(attachmentTypeNew)) { + attachmentTypeOld.getAttachmentList().remove(attachment); + attachmentTypeOld = em.merge(attachmentTypeOld); + } + if (attachmentTypeNew != null && !attachmentTypeNew.equals(attachmentTypeOld)) { + attachmentTypeNew.getAttachmentList().add(attachment); + attachmentTypeNew = em.merge(attachmentTypeNew); + } + for (ExecutionStepHasAttachment executionStepHasAttachmentListNewExecutionStepHasAttachment : executionStepHasAttachmentListNew) { + if (!executionStepHasAttachmentListOld.contains(executionStepHasAttachmentListNewExecutionStepHasAttachment)) { + Attachment oldAttachmentOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment = executionStepHasAttachmentListNewExecutionStepHasAttachment.getAttachment(); + executionStepHasAttachmentListNewExecutionStepHasAttachment.setAttachment(attachment); + executionStepHasAttachmentListNewExecutionStepHasAttachment = em.merge(executionStepHasAttachmentListNewExecutionStepHasAttachment); + if (oldAttachmentOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment != null && !oldAttachmentOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment.equals(attachment)) { + oldAttachmentOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment.getExecutionStepHasAttachmentList().remove(executionStepHasAttachmentListNewExecutionStepHasAttachment); + oldAttachmentOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment = em.merge(oldAttachmentOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + AttachmentPK id = attachment.getAttachmentPK(); + if (findAttachment(id) == null) { + throw new NonexistentEntityException("The attachment with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(AttachmentPK id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Attachment attachment; + try { + attachment = em.getReference(Attachment.class, id); + attachment.getAttachmentPK(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The attachment with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List executionStepHasAttachmentListOrphanCheck = attachment.getExecutionStepHasAttachmentList(); + for (ExecutionStepHasAttachment executionStepHasAttachmentListOrphanCheckExecutionStepHasAttachment : executionStepHasAttachmentListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Attachment (" + attachment + ") cannot be destroyed since the ExecutionStepHasAttachment " + executionStepHasAttachmentListOrphanCheckExecutionStepHasAttachment + " in its executionStepHasAttachmentList field has a non-nullable attachment field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + AttachmentType attachmentType = attachment.getAttachmentType(); + if (attachmentType != null) { + attachmentType.getAttachmentList().remove(attachment); + attachmentType = em.merge(attachmentType); + } + em.remove(attachment); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findAttachmentEntities() { + return findAttachmentEntities(true, -1, -1); + } + + public List findAttachmentEntities(int maxResults, int firstResult) { + return findAttachmentEntities(false, maxResults, firstResult); + } + + private List findAttachmentEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Attachment.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public Attachment findAttachment(AttachmentPK id) { + EntityManager em = getEntityManager(); + try { + return em.find(Attachment.class, id); + } + finally { + em.close(); + } + } + + public int getAttachmentCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Attachment.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/AttachmentTypeJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/AttachmentTypeJpaController.java index dc21299b..bed6c230 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/AttachmentTypeJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/AttachmentTypeJpaController.java @@ -13,216 +13,216 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Attachment; -import com.validation.manager.core.db.AttachmentType; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class AttachmentTypeJpaController implements Serializable { - - public AttachmentTypeJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(AttachmentType attachmentType) throws PreexistingEntityException, Exception { - if (attachmentType.getAttachmentList() == null) { - attachmentType.setAttachmentList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedAttachmentList = new ArrayList(); - for (Attachment attachmentListAttachmentToAttach : attachmentType.getAttachmentList()) { - attachmentListAttachmentToAttach = em.getReference(attachmentListAttachmentToAttach.getClass(), attachmentListAttachmentToAttach.getAttachmentPK()); - attachedAttachmentList.add(attachmentListAttachmentToAttach); - } - attachmentType.setAttachmentList(attachedAttachmentList); - em.persist(attachmentType); - for (Attachment attachmentListAttachment : attachmentType.getAttachmentList()) { - AttachmentType oldAttachmentTypeOfAttachmentListAttachment = attachmentListAttachment.getAttachmentType(); - attachmentListAttachment.setAttachmentType(attachmentType); - attachmentListAttachment = em.merge(attachmentListAttachment); - if (oldAttachmentTypeOfAttachmentListAttachment != null) { - oldAttachmentTypeOfAttachmentListAttachment.getAttachmentList().remove(attachmentListAttachment); - oldAttachmentTypeOfAttachmentListAttachment = em.merge(oldAttachmentTypeOfAttachmentListAttachment); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - if (findAttachmentType(attachmentType.getId()) != null) { - throw new PreexistingEntityException("AttachmentType " + attachmentType + " already exists.", ex); - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(AttachmentType attachmentType) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - AttachmentType persistentAttachmentType = em.find(AttachmentType.class, attachmentType.getId()); - List attachmentListOld = persistentAttachmentType.getAttachmentList(); - List attachmentListNew = attachmentType.getAttachmentList(); - List illegalOrphanMessages = null; - for (Attachment attachmentListOldAttachment : attachmentListOld) { - if (!attachmentListNew.contains(attachmentListOldAttachment)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain Attachment " + attachmentListOldAttachment + " since its attachmentType field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedAttachmentListNew = new ArrayList(); - for (Attachment attachmentListNewAttachmentToAttach : attachmentListNew) { - attachmentListNewAttachmentToAttach = em.getReference(attachmentListNewAttachmentToAttach.getClass(), attachmentListNewAttachmentToAttach.getAttachmentPK()); - attachedAttachmentListNew.add(attachmentListNewAttachmentToAttach); - } - attachmentListNew = attachedAttachmentListNew; - attachmentType.setAttachmentList(attachmentListNew); - attachmentType = em.merge(attachmentType); - for (Attachment attachmentListNewAttachment : attachmentListNew) { - if (!attachmentListOld.contains(attachmentListNewAttachment)) { - AttachmentType oldAttachmentTypeOfAttachmentListNewAttachment = attachmentListNewAttachment.getAttachmentType(); - attachmentListNewAttachment.setAttachmentType(attachmentType); - attachmentListNewAttachment = em.merge(attachmentListNewAttachment); - if (oldAttachmentTypeOfAttachmentListNewAttachment != null && !oldAttachmentTypeOfAttachmentListNewAttachment.equals(attachmentType)) { - oldAttachmentTypeOfAttachmentListNewAttachment.getAttachmentList().remove(attachmentListNewAttachment); - oldAttachmentTypeOfAttachmentListNewAttachment = em.merge(oldAttachmentTypeOfAttachmentListNewAttachment); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = attachmentType.getId(); - if (findAttachmentType(id) == null) { - throw new NonexistentEntityException("The attachmentType with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - AttachmentType attachmentType; - try { - attachmentType = em.getReference(AttachmentType.class, id); - attachmentType.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The attachmentType with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List attachmentListOrphanCheck = attachmentType.getAttachmentList(); - for (Attachment attachmentListOrphanCheckAttachment : attachmentListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This AttachmentType (" + attachmentType + ") cannot be destroyed since the Attachment " + attachmentListOrphanCheckAttachment + " in its attachmentList field has a non-nullable attachmentType field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(attachmentType); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findAttachmentTypeEntities() { - return findAttachmentTypeEntities(true, -1, -1); - } - - public List findAttachmentTypeEntities(int maxResults, int firstResult) { - return findAttachmentTypeEntities(false, maxResults, firstResult); - } - - private List findAttachmentTypeEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(AttachmentType.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public AttachmentType findAttachmentType(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(AttachmentType.class, id); - } - finally { - em.close(); - } - } - - public int getAttachmentTypeCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(AttachmentType.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Attachment; +import com.validation.manager.core.db.AttachmentType; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class AttachmentTypeJpaController implements Serializable { + + public AttachmentTypeJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(AttachmentType attachmentType) throws PreexistingEntityException, Exception { + if (attachmentType.getAttachmentList() == null) { + attachmentType.setAttachmentList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedAttachmentList = new ArrayList<>(); + for (Attachment attachmentListAttachmentToAttach : attachmentType.getAttachmentList()) { + attachmentListAttachmentToAttach = em.getReference(attachmentListAttachmentToAttach.getClass(), attachmentListAttachmentToAttach.getAttachmentPK()); + attachedAttachmentList.add(attachmentListAttachmentToAttach); + } + attachmentType.setAttachmentList(attachedAttachmentList); + em.persist(attachmentType); + for (Attachment attachmentListAttachment : attachmentType.getAttachmentList()) { + AttachmentType oldAttachmentTypeOfAttachmentListAttachment = attachmentListAttachment.getAttachmentType(); + attachmentListAttachment.setAttachmentType(attachmentType); + attachmentListAttachment = em.merge(attachmentListAttachment); + if (oldAttachmentTypeOfAttachmentListAttachment != null) { + oldAttachmentTypeOfAttachmentListAttachment.getAttachmentList().remove(attachmentListAttachment); + oldAttachmentTypeOfAttachmentListAttachment = em.merge(oldAttachmentTypeOfAttachmentListAttachment); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + if (findAttachmentType(attachmentType.getId()) != null) { + throw new PreexistingEntityException("AttachmentType " + attachmentType + " already exists.", ex); + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(AttachmentType attachmentType) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + AttachmentType persistentAttachmentType = em.find(AttachmentType.class, attachmentType.getId()); + List attachmentListOld = persistentAttachmentType.getAttachmentList(); + List attachmentListNew = attachmentType.getAttachmentList(); + List illegalOrphanMessages = null; + for (Attachment attachmentListOldAttachment : attachmentListOld) { + if (!attachmentListNew.contains(attachmentListOldAttachment)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain Attachment " + attachmentListOldAttachment + " since its attachmentType field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedAttachmentListNew = new ArrayList<>(); + for (Attachment attachmentListNewAttachmentToAttach : attachmentListNew) { + attachmentListNewAttachmentToAttach = em.getReference(attachmentListNewAttachmentToAttach.getClass(), attachmentListNewAttachmentToAttach.getAttachmentPK()); + attachedAttachmentListNew.add(attachmentListNewAttachmentToAttach); + } + attachmentListNew = attachedAttachmentListNew; + attachmentType.setAttachmentList(attachmentListNew); + attachmentType = em.merge(attachmentType); + for (Attachment attachmentListNewAttachment : attachmentListNew) { + if (!attachmentListOld.contains(attachmentListNewAttachment)) { + AttachmentType oldAttachmentTypeOfAttachmentListNewAttachment = attachmentListNewAttachment.getAttachmentType(); + attachmentListNewAttachment.setAttachmentType(attachmentType); + attachmentListNewAttachment = em.merge(attachmentListNewAttachment); + if (oldAttachmentTypeOfAttachmentListNewAttachment != null && !oldAttachmentTypeOfAttachmentListNewAttachment.equals(attachmentType)) { + oldAttachmentTypeOfAttachmentListNewAttachment.getAttachmentList().remove(attachmentListNewAttachment); + oldAttachmentTypeOfAttachmentListNewAttachment = em.merge(oldAttachmentTypeOfAttachmentListNewAttachment); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = attachmentType.getId(); + if (findAttachmentType(id) == null) { + throw new NonexistentEntityException("The attachmentType with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + AttachmentType attachmentType; + try { + attachmentType = em.getReference(AttachmentType.class, id); + attachmentType.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The attachmentType with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List attachmentListOrphanCheck = attachmentType.getAttachmentList(); + for (Attachment attachmentListOrphanCheckAttachment : attachmentListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This AttachmentType (" + attachmentType + ") cannot be destroyed since the Attachment " + attachmentListOrphanCheckAttachment + " in its attachmentList field has a non-nullable attachmentType field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(attachmentType); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findAttachmentTypeEntities() { + return findAttachmentTypeEntities(true, -1, -1); + } + + public List findAttachmentTypeEntities(int maxResults, int firstResult) { + return findAttachmentTypeEntities(false, maxResults, firstResult); + } + + private List findAttachmentTypeEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(AttachmentType.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public AttachmentType findAttachmentType(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(AttachmentType.class, id); + } + finally { + em.close(); + } + } + + public int getAttachmentTypeCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(AttachmentType.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/BaselineJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/BaselineJpaController.java index b0be06f0..00adada8 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/BaselineJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/BaselineJpaController.java @@ -13,215 +13,215 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.Baseline; -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.RequirementSpec; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class BaselineJpaController implements Serializable { - - public BaselineJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Baseline baseline) { - if (baseline.getHistoryList() == null) { - baseline.setHistoryList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RequirementSpec requirementSpec = baseline.getRequirementSpec(); - if (requirementSpec != null) { - requirementSpec = em.getReference(requirementSpec.getClass(), requirementSpec.getRequirementSpecPK()); - baseline.setRequirementSpec(requirementSpec); - } - List attachedHistoryList = new ArrayList(); - for (History historyListHistoryToAttach : baseline.getHistoryList()) { - historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); - attachedHistoryList.add(historyListHistoryToAttach); - } - baseline.setHistoryList(attachedHistoryList); - em.persist(baseline); - if (requirementSpec != null) { - requirementSpec.getBaselineList().add(baseline); - requirementSpec = em.merge(requirementSpec); - } - for (History historyListHistory : baseline.getHistoryList()) { - historyListHistory.getBaselineList().add(baseline); - historyListHistory = em.merge(historyListHistory); - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Baseline baseline) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Baseline persistentBaseline = em.find(Baseline.class, baseline.getId()); - RequirementSpec requirementSpecOld = persistentBaseline.getRequirementSpec(); - RequirementSpec requirementSpecNew = baseline.getRequirementSpec(); - List historyListOld = persistentBaseline.getHistoryList(); - List historyListNew = baseline.getHistoryList(); - if (requirementSpecNew != null) { - requirementSpecNew = em.getReference(requirementSpecNew.getClass(), requirementSpecNew.getRequirementSpecPK()); - baseline.setRequirementSpec(requirementSpecNew); - } - List attachedHistoryListNew = new ArrayList(); - for (History historyListNewHistoryToAttach : historyListNew) { - historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); - attachedHistoryListNew.add(historyListNewHistoryToAttach); - } - historyListNew = attachedHistoryListNew; - baseline.setHistoryList(historyListNew); - baseline = em.merge(baseline); - if (requirementSpecOld != null && !requirementSpecOld.equals(requirementSpecNew)) { - requirementSpecOld.getBaselineList().remove(baseline); - requirementSpecOld = em.merge(requirementSpecOld); - } - if (requirementSpecNew != null && !requirementSpecNew.equals(requirementSpecOld)) { - requirementSpecNew.getBaselineList().add(baseline); - requirementSpecNew = em.merge(requirementSpecNew); - } - for (History historyListOldHistory : historyListOld) { - if (!historyListNew.contains(historyListOldHistory)) { - historyListOldHistory.getBaselineList().remove(baseline); - historyListOldHistory = em.merge(historyListOldHistory); - } - } - for (History historyListNewHistory : historyListNew) { - if (!historyListOld.contains(historyListNewHistory)) { - historyListNewHistory.getBaselineList().add(baseline); - historyListNewHistory = em.merge(historyListNewHistory); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = baseline.getId(); - if (findBaseline(id) == null) { - throw new NonexistentEntityException("The baseline with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Baseline baseline; - try { - baseline = em.getReference(Baseline.class, id); - baseline.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The baseline with id " + id + " no longer exists.", enfe); - } - RequirementSpec requirementSpec = baseline.getRequirementSpec(); - if (requirementSpec != null) { - requirementSpec.getBaselineList().remove(baseline); - requirementSpec = em.merge(requirementSpec); - } - List historyList = baseline.getHistoryList(); - for (History historyListHistory : historyList) { - historyListHistory.getBaselineList().remove(baseline); - historyListHistory = em.merge(historyListHistory); - } - em.remove(baseline); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findBaselineEntities() { - return findBaselineEntities(true, -1, -1); - } - - public List findBaselineEntities(int maxResults, int firstResult) { - return findBaselineEntities(false, maxResults, firstResult); - } - - private List findBaselineEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Baseline.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public Baseline findBaseline(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(Baseline.class, id); - } - finally { - em.close(); - } - } - - public int getBaselineCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(Baseline.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import com.validation.manager.core.db.Baseline; +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.RequirementSpec; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class BaselineJpaController implements Serializable { + + public BaselineJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Baseline baseline) { + if (baseline.getHistoryList() == null) { + baseline.setHistoryList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RequirementSpec requirementSpec = baseline.getRequirementSpec(); + if (requirementSpec != null) { + requirementSpec = em.getReference(requirementSpec.getClass(), requirementSpec.getRequirementSpecPK()); + baseline.setRequirementSpec(requirementSpec); + } + List attachedHistoryList = new ArrayList<>(); + for (History historyListHistoryToAttach : baseline.getHistoryList()) { + historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); + attachedHistoryList.add(historyListHistoryToAttach); + } + baseline.setHistoryList(attachedHistoryList); + em.persist(baseline); + if (requirementSpec != null) { + requirementSpec.getBaselineList().add(baseline); + requirementSpec = em.merge(requirementSpec); + } + for (History historyListHistory : baseline.getHistoryList()) { + historyListHistory.getBaselineList().add(baseline); + historyListHistory = em.merge(historyListHistory); + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Baseline baseline) throws NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Baseline persistentBaseline = em.find(Baseline.class, baseline.getId()); + RequirementSpec requirementSpecOld = persistentBaseline.getRequirementSpec(); + RequirementSpec requirementSpecNew = baseline.getRequirementSpec(); + List historyListOld = persistentBaseline.getHistoryList(); + List historyListNew = baseline.getHistoryList(); + if (requirementSpecNew != null) { + requirementSpecNew = em.getReference(requirementSpecNew.getClass(), requirementSpecNew.getRequirementSpecPK()); + baseline.setRequirementSpec(requirementSpecNew); + } + List attachedHistoryListNew = new ArrayList<>(); + for (History historyListNewHistoryToAttach : historyListNew) { + historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); + attachedHistoryListNew.add(historyListNewHistoryToAttach); + } + historyListNew = attachedHistoryListNew; + baseline.setHistoryList(historyListNew); + baseline = em.merge(baseline); + if (requirementSpecOld != null && !requirementSpecOld.equals(requirementSpecNew)) { + requirementSpecOld.getBaselineList().remove(baseline); + requirementSpecOld = em.merge(requirementSpecOld); + } + if (requirementSpecNew != null && !requirementSpecNew.equals(requirementSpecOld)) { + requirementSpecNew.getBaselineList().add(baseline); + requirementSpecNew = em.merge(requirementSpecNew); + } + for (History historyListOldHistory : historyListOld) { + if (!historyListNew.contains(historyListOldHistory)) { + historyListOldHistory.getBaselineList().remove(baseline); + historyListOldHistory = em.merge(historyListOldHistory); + } + } + for (History historyListNewHistory : historyListNew) { + if (!historyListOld.contains(historyListNewHistory)) { + historyListNewHistory.getBaselineList().add(baseline); + historyListNewHistory = em.merge(historyListNewHistory); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = baseline.getId(); + if (findBaseline(id) == null) { + throw new NonexistentEntityException("The baseline with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Baseline baseline; + try { + baseline = em.getReference(Baseline.class, id); + baseline.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The baseline with id " + id + " no longer exists.", enfe); + } + RequirementSpec requirementSpec = baseline.getRequirementSpec(); + if (requirementSpec != null) { + requirementSpec.getBaselineList().remove(baseline); + requirementSpec = em.merge(requirementSpec); + } + List historyList = baseline.getHistoryList(); + for (History historyListHistory : historyList) { + historyListHistory.getBaselineList().remove(baseline); + historyListHistory = em.merge(historyListHistory); + } + em.remove(baseline); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findBaselineEntities() { + return findBaselineEntities(true, -1, -1); + } + + public List findBaselineEntities(int maxResults, int firstResult) { + return findBaselineEntities(false, maxResults, firstResult); + } + + private List findBaselineEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Baseline.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public Baseline findBaseline(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(Baseline.class, id); + } + finally { + em.close(); + } + } + + public int getBaselineCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Baseline.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/CauseJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/CauseJpaController.java index 1ed661c0..fd88059d 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/CauseJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/CauseJpaController.java @@ -13,186 +13,186 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.Cause; -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.RiskItem; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class CauseJpaController implements Serializable { - - public CauseJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Cause cause) { - if (cause.getRiskItemList() == null) { - cause.setRiskItemList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedRiskItemList = new ArrayList(); - for (RiskItem riskItemListRiskItemToAttach : cause.getRiskItemList()) { - riskItemListRiskItemToAttach = em.getReference(riskItemListRiskItemToAttach.getClass(), riskItemListRiskItemToAttach.getRiskItemPK()); - attachedRiskItemList.add(riskItemListRiskItemToAttach); - } - cause.setRiskItemList(attachedRiskItemList); - em.persist(cause); - for (RiskItem riskItemListRiskItem : cause.getRiskItemList()) { - riskItemListRiskItem.getCauseList().add(cause); - riskItemListRiskItem = em.merge(riskItemListRiskItem); - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Cause cause) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Cause persistentCause = em.find(Cause.class, cause.getId()); - List riskItemListOld = persistentCause.getRiskItemList(); - List riskItemListNew = cause.getRiskItemList(); - List attachedRiskItemListNew = new ArrayList(); - for (RiskItem riskItemListNewRiskItemToAttach : riskItemListNew) { - riskItemListNewRiskItemToAttach = em.getReference(riskItemListNewRiskItemToAttach.getClass(), riskItemListNewRiskItemToAttach.getRiskItemPK()); - attachedRiskItemListNew.add(riskItemListNewRiskItemToAttach); - } - riskItemListNew = attachedRiskItemListNew; - cause.setRiskItemList(riskItemListNew); - cause = em.merge(cause); - for (RiskItem riskItemListOldRiskItem : riskItemListOld) { - if (!riskItemListNew.contains(riskItemListOldRiskItem)) { - riskItemListOldRiskItem.getCauseList().remove(cause); - riskItemListOldRiskItem = em.merge(riskItemListOldRiskItem); - } - } - for (RiskItem riskItemListNewRiskItem : riskItemListNew) { - if (!riskItemListOld.contains(riskItemListNewRiskItem)) { - riskItemListNewRiskItem.getCauseList().add(cause); - riskItemListNewRiskItem = em.merge(riskItemListNewRiskItem); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = cause.getId(); - if (findCause(id) == null) { - throw new NonexistentEntityException("The cause with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Cause cause; - try { - cause = em.getReference(Cause.class, id); - cause.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The cause with id " + id + " no longer exists.", enfe); - } - List riskItemList = cause.getRiskItemList(); - for (RiskItem riskItemListRiskItem : riskItemList) { - riskItemListRiskItem.getCauseList().remove(cause); - riskItemListRiskItem = em.merge(riskItemListRiskItem); - } - em.remove(cause); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findCauseEntities() { - return findCauseEntities(true, -1, -1); - } - - public List findCauseEntities(int maxResults, int firstResult) { - return findCauseEntities(false, maxResults, firstResult); - } - - private List findCauseEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Cause.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public Cause findCause(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(Cause.class, id); - } - finally { - em.close(); - } - } - - public int getCauseCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(Cause.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import com.validation.manager.core.db.Cause; +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.RiskItem; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class CauseJpaController implements Serializable { + + public CauseJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Cause cause) { + if (cause.getRiskItemList() == null) { + cause.setRiskItemList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedRiskItemList = new ArrayList<>(); + for (RiskItem riskItemListRiskItemToAttach : cause.getRiskItemList()) { + riskItemListRiskItemToAttach = em.getReference(riskItemListRiskItemToAttach.getClass(), riskItemListRiskItemToAttach.getRiskItemPK()); + attachedRiskItemList.add(riskItemListRiskItemToAttach); + } + cause.setRiskItemList(attachedRiskItemList); + em.persist(cause); + for (RiskItem riskItemListRiskItem : cause.getRiskItemList()) { + riskItemListRiskItem.getCauseList().add(cause); + riskItemListRiskItem = em.merge(riskItemListRiskItem); + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Cause cause) throws NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Cause persistentCause = em.find(Cause.class, cause.getId()); + List riskItemListOld = persistentCause.getRiskItemList(); + List riskItemListNew = cause.getRiskItemList(); + List attachedRiskItemListNew = new ArrayList<>(); + for (RiskItem riskItemListNewRiskItemToAttach : riskItemListNew) { + riskItemListNewRiskItemToAttach = em.getReference(riskItemListNewRiskItemToAttach.getClass(), riskItemListNewRiskItemToAttach.getRiskItemPK()); + attachedRiskItemListNew.add(riskItemListNewRiskItemToAttach); + } + riskItemListNew = attachedRiskItemListNew; + cause.setRiskItemList(riskItemListNew); + cause = em.merge(cause); + for (RiskItem riskItemListOldRiskItem : riskItemListOld) { + if (!riskItemListNew.contains(riskItemListOldRiskItem)) { + riskItemListOldRiskItem.getCauseList().remove(cause); + riskItemListOldRiskItem = em.merge(riskItemListOldRiskItem); + } + } + for (RiskItem riskItemListNewRiskItem : riskItemListNew) { + if (!riskItemListOld.contains(riskItemListNewRiskItem)) { + riskItemListNewRiskItem.getCauseList().add(cause); + riskItemListNewRiskItem = em.merge(riskItemListNewRiskItem); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = cause.getId(); + if (findCause(id) == null) { + throw new NonexistentEntityException("The cause with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Cause cause; + try { + cause = em.getReference(Cause.class, id); + cause.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The cause with id " + id + " no longer exists.", enfe); + } + List riskItemList = cause.getRiskItemList(); + for (RiskItem riskItemListRiskItem : riskItemList) { + riskItemListRiskItem.getCauseList().remove(cause); + riskItemListRiskItem = em.merge(riskItemListRiskItem); + } + em.remove(cause); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findCauseEntities() { + return findCauseEntities(true, -1, -1); + } + + public List findCauseEntities(int maxResults, int firstResult) { + return findCauseEntities(false, maxResults, firstResult); + } + + private List findCauseEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Cause.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public Cause findCause(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(Cause.class, id); + } + finally { + em.close(); + } + } + + public int getCauseCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Cause.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/CorrectiveActionJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/CorrectiveActionJpaController.java index 6e8a30b7..3f22d37b 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/CorrectiveActionJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/CorrectiveActionJpaController.java @@ -13,249 +13,249 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.CorrectiveAction; -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.VmUser; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.ExceptionHasCorrectiveAction; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class CorrectiveActionJpaController implements Serializable { - - public CorrectiveActionJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(CorrectiveAction correctiveAction) { - if (correctiveAction.getVmUserList() == null) { - correctiveAction.setVmUserList(new ArrayList()); - } - if (correctiveAction.getExceptionHasCorrectiveActionList() == null) { - correctiveAction.setExceptionHasCorrectiveActionList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedVmUserList = new ArrayList(); - for (VmUser vmUserListVmUserToAttach : correctiveAction.getVmUserList()) { - vmUserListVmUserToAttach = em.getReference(vmUserListVmUserToAttach.getClass(), vmUserListVmUserToAttach.getId()); - attachedVmUserList.add(vmUserListVmUserToAttach); - } - correctiveAction.setVmUserList(attachedVmUserList); - List attachedExceptionHasCorrectiveActionList = new ArrayList(); - for (ExceptionHasCorrectiveAction exceptionHasCorrectiveActionListExceptionHasCorrectiveActionToAttach : correctiveAction.getExceptionHasCorrectiveActionList()) { - exceptionHasCorrectiveActionListExceptionHasCorrectiveActionToAttach = em.getReference(exceptionHasCorrectiveActionListExceptionHasCorrectiveActionToAttach.getClass(), exceptionHasCorrectiveActionListExceptionHasCorrectiveActionToAttach.getExceptionHasCorrectiveActionPK()); - attachedExceptionHasCorrectiveActionList.add(exceptionHasCorrectiveActionListExceptionHasCorrectiveActionToAttach); - } - correctiveAction.setExceptionHasCorrectiveActionList(attachedExceptionHasCorrectiveActionList); - em.persist(correctiveAction); - for (VmUser vmUserListVmUser : correctiveAction.getVmUserList()) { - vmUserListVmUser.getCorrectiveActionList().add(correctiveAction); - vmUserListVmUser = em.merge(vmUserListVmUser); - } - for (ExceptionHasCorrectiveAction exceptionHasCorrectiveActionListExceptionHasCorrectiveAction : correctiveAction.getExceptionHasCorrectiveActionList()) { - CorrectiveAction oldCorrectiveActionOfExceptionHasCorrectiveActionListExceptionHasCorrectiveAction = exceptionHasCorrectiveActionListExceptionHasCorrectiveAction.getCorrectiveAction(); - exceptionHasCorrectiveActionListExceptionHasCorrectiveAction.setCorrectiveAction(correctiveAction); - exceptionHasCorrectiveActionListExceptionHasCorrectiveAction = em.merge(exceptionHasCorrectiveActionListExceptionHasCorrectiveAction); - if (oldCorrectiveActionOfExceptionHasCorrectiveActionListExceptionHasCorrectiveAction != null) { - oldCorrectiveActionOfExceptionHasCorrectiveActionListExceptionHasCorrectiveAction.getExceptionHasCorrectiveActionList().remove(exceptionHasCorrectiveActionListExceptionHasCorrectiveAction); - oldCorrectiveActionOfExceptionHasCorrectiveActionListExceptionHasCorrectiveAction = em.merge(oldCorrectiveActionOfExceptionHasCorrectiveActionListExceptionHasCorrectiveAction); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(CorrectiveAction correctiveAction) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - CorrectiveAction persistentCorrectiveAction = em.find(CorrectiveAction.class, correctiveAction.getId()); - List vmUserListOld = persistentCorrectiveAction.getVmUserList(); - List vmUserListNew = correctiveAction.getVmUserList(); - List exceptionHasCorrectiveActionListOld = persistentCorrectiveAction.getExceptionHasCorrectiveActionList(); - List exceptionHasCorrectiveActionListNew = correctiveAction.getExceptionHasCorrectiveActionList(); - List illegalOrphanMessages = null; - for (ExceptionHasCorrectiveAction exceptionHasCorrectiveActionListOldExceptionHasCorrectiveAction : exceptionHasCorrectiveActionListOld) { - if (!exceptionHasCorrectiveActionListNew.contains(exceptionHasCorrectiveActionListOldExceptionHasCorrectiveAction)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain ExceptionHasCorrectiveAction " + exceptionHasCorrectiveActionListOldExceptionHasCorrectiveAction + " since its correctiveAction field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedVmUserListNew = new ArrayList(); - for (VmUser vmUserListNewVmUserToAttach : vmUserListNew) { - vmUserListNewVmUserToAttach = em.getReference(vmUserListNewVmUserToAttach.getClass(), vmUserListNewVmUserToAttach.getId()); - attachedVmUserListNew.add(vmUserListNewVmUserToAttach); - } - vmUserListNew = attachedVmUserListNew; - correctiveAction.setVmUserList(vmUserListNew); - List attachedExceptionHasCorrectiveActionListNew = new ArrayList(); - for (ExceptionHasCorrectiveAction exceptionHasCorrectiveActionListNewExceptionHasCorrectiveActionToAttach : exceptionHasCorrectiveActionListNew) { - exceptionHasCorrectiveActionListNewExceptionHasCorrectiveActionToAttach = em.getReference(exceptionHasCorrectiveActionListNewExceptionHasCorrectiveActionToAttach.getClass(), exceptionHasCorrectiveActionListNewExceptionHasCorrectiveActionToAttach.getExceptionHasCorrectiveActionPK()); - attachedExceptionHasCorrectiveActionListNew.add(exceptionHasCorrectiveActionListNewExceptionHasCorrectiveActionToAttach); - } - exceptionHasCorrectiveActionListNew = attachedExceptionHasCorrectiveActionListNew; - correctiveAction.setExceptionHasCorrectiveActionList(exceptionHasCorrectiveActionListNew); - correctiveAction = em.merge(correctiveAction); - for (VmUser vmUserListOldVmUser : vmUserListOld) { - if (!vmUserListNew.contains(vmUserListOldVmUser)) { - vmUserListOldVmUser.getCorrectiveActionList().remove(correctiveAction); - vmUserListOldVmUser = em.merge(vmUserListOldVmUser); - } - } - for (VmUser vmUserListNewVmUser : vmUserListNew) { - if (!vmUserListOld.contains(vmUserListNewVmUser)) { - vmUserListNewVmUser.getCorrectiveActionList().add(correctiveAction); - vmUserListNewVmUser = em.merge(vmUserListNewVmUser); - } - } - for (ExceptionHasCorrectiveAction exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction : exceptionHasCorrectiveActionListNew) { - if (!exceptionHasCorrectiveActionListOld.contains(exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction)) { - CorrectiveAction oldCorrectiveActionOfExceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction = exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction.getCorrectiveAction(); - exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction.setCorrectiveAction(correctiveAction); - exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction = em.merge(exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction); - if (oldCorrectiveActionOfExceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction != null && !oldCorrectiveActionOfExceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction.equals(correctiveAction)) { - oldCorrectiveActionOfExceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction.getExceptionHasCorrectiveActionList().remove(exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction); - oldCorrectiveActionOfExceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction = em.merge(oldCorrectiveActionOfExceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = correctiveAction.getId(); - if (findCorrectiveAction(id) == null) { - throw new NonexistentEntityException("The correctiveAction with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - CorrectiveAction correctiveAction; - try { - correctiveAction = em.getReference(CorrectiveAction.class, id); - correctiveAction.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The correctiveAction with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List exceptionHasCorrectiveActionListOrphanCheck = correctiveAction.getExceptionHasCorrectiveActionList(); - for (ExceptionHasCorrectiveAction exceptionHasCorrectiveActionListOrphanCheckExceptionHasCorrectiveAction : exceptionHasCorrectiveActionListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This CorrectiveAction (" + correctiveAction + ") cannot be destroyed since the ExceptionHasCorrectiveAction " + exceptionHasCorrectiveActionListOrphanCheckExceptionHasCorrectiveAction + " in its exceptionHasCorrectiveActionList field has a non-nullable correctiveAction field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List vmUserList = correctiveAction.getVmUserList(); - for (VmUser vmUserListVmUser : vmUserList) { - vmUserListVmUser.getCorrectiveActionList().remove(correctiveAction); - vmUserListVmUser = em.merge(vmUserListVmUser); - } - em.remove(correctiveAction); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findCorrectiveActionEntities() { - return findCorrectiveActionEntities(true, -1, -1); - } - - public List findCorrectiveActionEntities(int maxResults, int firstResult) { - return findCorrectiveActionEntities(false, maxResults, firstResult); - } - - private List findCorrectiveActionEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(CorrectiveAction.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public CorrectiveAction findCorrectiveAction(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(CorrectiveAction.class, id); - } - finally { - em.close(); - } - } - - public int getCorrectiveActionCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(CorrectiveAction.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import com.validation.manager.core.db.CorrectiveAction; +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.VmUser; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.ExceptionHasCorrectiveAction; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class CorrectiveActionJpaController implements Serializable { + + public CorrectiveActionJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(CorrectiveAction correctiveAction) { + if (correctiveAction.getVmUserList() == null) { + correctiveAction.setVmUserList(new ArrayList<>()); + } + if (correctiveAction.getExceptionHasCorrectiveActionList() == null) { + correctiveAction.setExceptionHasCorrectiveActionList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedVmUserList = new ArrayList<>(); + for (VmUser vmUserListVmUserToAttach : correctiveAction.getVmUserList()) { + vmUserListVmUserToAttach = em.getReference(vmUserListVmUserToAttach.getClass(), vmUserListVmUserToAttach.getId()); + attachedVmUserList.add(vmUserListVmUserToAttach); + } + correctiveAction.setVmUserList(attachedVmUserList); + List attachedExceptionHasCorrectiveActionList = new ArrayList<>(); + for (ExceptionHasCorrectiveAction exceptionHasCorrectiveActionListExceptionHasCorrectiveActionToAttach : correctiveAction.getExceptionHasCorrectiveActionList()) { + exceptionHasCorrectiveActionListExceptionHasCorrectiveActionToAttach = em.getReference(exceptionHasCorrectiveActionListExceptionHasCorrectiveActionToAttach.getClass(), exceptionHasCorrectiveActionListExceptionHasCorrectiveActionToAttach.getExceptionHasCorrectiveActionPK()); + attachedExceptionHasCorrectiveActionList.add(exceptionHasCorrectiveActionListExceptionHasCorrectiveActionToAttach); + } + correctiveAction.setExceptionHasCorrectiveActionList(attachedExceptionHasCorrectiveActionList); + em.persist(correctiveAction); + for (VmUser vmUserListVmUser : correctiveAction.getVmUserList()) { + vmUserListVmUser.getCorrectiveActionList().add(correctiveAction); + vmUserListVmUser = em.merge(vmUserListVmUser); + } + for (ExceptionHasCorrectiveAction exceptionHasCorrectiveActionListExceptionHasCorrectiveAction : correctiveAction.getExceptionHasCorrectiveActionList()) { + CorrectiveAction oldCorrectiveActionOfExceptionHasCorrectiveActionListExceptionHasCorrectiveAction = exceptionHasCorrectiveActionListExceptionHasCorrectiveAction.getCorrectiveAction(); + exceptionHasCorrectiveActionListExceptionHasCorrectiveAction.setCorrectiveAction(correctiveAction); + exceptionHasCorrectiveActionListExceptionHasCorrectiveAction = em.merge(exceptionHasCorrectiveActionListExceptionHasCorrectiveAction); + if (oldCorrectiveActionOfExceptionHasCorrectiveActionListExceptionHasCorrectiveAction != null) { + oldCorrectiveActionOfExceptionHasCorrectiveActionListExceptionHasCorrectiveAction.getExceptionHasCorrectiveActionList().remove(exceptionHasCorrectiveActionListExceptionHasCorrectiveAction); + oldCorrectiveActionOfExceptionHasCorrectiveActionListExceptionHasCorrectiveAction = em.merge(oldCorrectiveActionOfExceptionHasCorrectiveActionListExceptionHasCorrectiveAction); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(CorrectiveAction correctiveAction) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + CorrectiveAction persistentCorrectiveAction = em.find(CorrectiveAction.class, correctiveAction.getId()); + List vmUserListOld = persistentCorrectiveAction.getVmUserList(); + List vmUserListNew = correctiveAction.getVmUserList(); + List exceptionHasCorrectiveActionListOld = persistentCorrectiveAction.getExceptionHasCorrectiveActionList(); + List exceptionHasCorrectiveActionListNew = correctiveAction.getExceptionHasCorrectiveActionList(); + List illegalOrphanMessages = null; + for (ExceptionHasCorrectiveAction exceptionHasCorrectiveActionListOldExceptionHasCorrectiveAction : exceptionHasCorrectiveActionListOld) { + if (!exceptionHasCorrectiveActionListNew.contains(exceptionHasCorrectiveActionListOldExceptionHasCorrectiveAction)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain ExceptionHasCorrectiveAction " + exceptionHasCorrectiveActionListOldExceptionHasCorrectiveAction + " since its correctiveAction field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedVmUserListNew = new ArrayList<>(); + for (VmUser vmUserListNewVmUserToAttach : vmUserListNew) { + vmUserListNewVmUserToAttach = em.getReference(vmUserListNewVmUserToAttach.getClass(), vmUserListNewVmUserToAttach.getId()); + attachedVmUserListNew.add(vmUserListNewVmUserToAttach); + } + vmUserListNew = attachedVmUserListNew; + correctiveAction.setVmUserList(vmUserListNew); + List attachedExceptionHasCorrectiveActionListNew = new ArrayList<>(); + for (ExceptionHasCorrectiveAction exceptionHasCorrectiveActionListNewExceptionHasCorrectiveActionToAttach : exceptionHasCorrectiveActionListNew) { + exceptionHasCorrectiveActionListNewExceptionHasCorrectiveActionToAttach = em.getReference(exceptionHasCorrectiveActionListNewExceptionHasCorrectiveActionToAttach.getClass(), exceptionHasCorrectiveActionListNewExceptionHasCorrectiveActionToAttach.getExceptionHasCorrectiveActionPK()); + attachedExceptionHasCorrectiveActionListNew.add(exceptionHasCorrectiveActionListNewExceptionHasCorrectiveActionToAttach); + } + exceptionHasCorrectiveActionListNew = attachedExceptionHasCorrectiveActionListNew; + correctiveAction.setExceptionHasCorrectiveActionList(exceptionHasCorrectiveActionListNew); + correctiveAction = em.merge(correctiveAction); + for (VmUser vmUserListOldVmUser : vmUserListOld) { + if (!vmUserListNew.contains(vmUserListOldVmUser)) { + vmUserListOldVmUser.getCorrectiveActionList().remove(correctiveAction); + vmUserListOldVmUser = em.merge(vmUserListOldVmUser); + } + } + for (VmUser vmUserListNewVmUser : vmUserListNew) { + if (!vmUserListOld.contains(vmUserListNewVmUser)) { + vmUserListNewVmUser.getCorrectiveActionList().add(correctiveAction); + vmUserListNewVmUser = em.merge(vmUserListNewVmUser); + } + } + for (ExceptionHasCorrectiveAction exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction : exceptionHasCorrectiveActionListNew) { + if (!exceptionHasCorrectiveActionListOld.contains(exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction)) { + CorrectiveAction oldCorrectiveActionOfExceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction = exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction.getCorrectiveAction(); + exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction.setCorrectiveAction(correctiveAction); + exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction = em.merge(exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction); + if (oldCorrectiveActionOfExceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction != null && !oldCorrectiveActionOfExceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction.equals(correctiveAction)) { + oldCorrectiveActionOfExceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction.getExceptionHasCorrectiveActionList().remove(exceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction); + oldCorrectiveActionOfExceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction = em.merge(oldCorrectiveActionOfExceptionHasCorrectiveActionListNewExceptionHasCorrectiveAction); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = correctiveAction.getId(); + if (findCorrectiveAction(id) == null) { + throw new NonexistentEntityException("The correctiveAction with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + CorrectiveAction correctiveAction; + try { + correctiveAction = em.getReference(CorrectiveAction.class, id); + correctiveAction.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The correctiveAction with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List exceptionHasCorrectiveActionListOrphanCheck = correctiveAction.getExceptionHasCorrectiveActionList(); + for (ExceptionHasCorrectiveAction exceptionHasCorrectiveActionListOrphanCheckExceptionHasCorrectiveAction : exceptionHasCorrectiveActionListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This CorrectiveAction (" + correctiveAction + ") cannot be destroyed since the ExceptionHasCorrectiveAction " + exceptionHasCorrectiveActionListOrphanCheckExceptionHasCorrectiveAction + " in its exceptionHasCorrectiveActionList field has a non-nullable correctiveAction field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List vmUserList = correctiveAction.getVmUserList(); + for (VmUser vmUserListVmUser : vmUserList) { + vmUserListVmUser.getCorrectiveActionList().remove(correctiveAction); + vmUserListVmUser = em.merge(vmUserListVmUser); + } + em.remove(correctiveAction); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findCorrectiveActionEntities() { + return findCorrectiveActionEntities(true, -1, -1); + } + + public List findCorrectiveActionEntities(int maxResults, int firstResult) { + return findCorrectiveActionEntities(false, maxResults, firstResult); + } + + private List findCorrectiveActionEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(CorrectiveAction.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public CorrectiveAction findCorrectiveAction(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(CorrectiveAction.class, id); + } + finally { + em.close(); + } + } + + public int getCorrectiveActionCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(CorrectiveAction.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/ExecutionResultJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/ExecutionResultJpaController.java index fb65a08c..9cc7c881 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/ExecutionResultJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/ExecutionResultJpaController.java @@ -13,196 +13,196 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.ExecutionResult; -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class ExecutionResultJpaController implements Serializable { - - public ExecutionResultJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(ExecutionResult executionResult) { - if (executionResult.getExecutionStepList() == null) { - executionResult.setExecutionStepList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedExecutionStepList = new ArrayList(); - for (ExecutionStep executionStepListExecutionStepToAttach : executionResult.getExecutionStepList()) { - executionStepListExecutionStepToAttach = em.getReference(executionStepListExecutionStepToAttach.getClass(), executionStepListExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepList.add(executionStepListExecutionStepToAttach); - } - executionResult.setExecutionStepList(attachedExecutionStepList); - em.persist(executionResult); - for (ExecutionStep executionStepListExecutionStep : executionResult.getExecutionStepList()) { - ExecutionResult oldResultIdOfExecutionStepListExecutionStep = executionStepListExecutionStep.getResultId(); - executionStepListExecutionStep.setResultId(executionResult); - executionStepListExecutionStep = em.merge(executionStepListExecutionStep); - if (oldResultIdOfExecutionStepListExecutionStep != null) { - oldResultIdOfExecutionStepListExecutionStep.getExecutionStepList().remove(executionStepListExecutionStep); - oldResultIdOfExecutionStepListExecutionStep = em.merge(oldResultIdOfExecutionStepListExecutionStep); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(ExecutionResult executionResult) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - ExecutionResult persistentExecutionResult = em.find(ExecutionResult.class, executionResult.getId()); - List executionStepListOld = persistentExecutionResult.getExecutionStepList(); - List executionStepListNew = executionResult.getExecutionStepList(); - List attachedExecutionStepListNew = new ArrayList(); - for (ExecutionStep executionStepListNewExecutionStepToAttach : executionStepListNew) { - executionStepListNewExecutionStepToAttach = em.getReference(executionStepListNewExecutionStepToAttach.getClass(), executionStepListNewExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepListNew.add(executionStepListNewExecutionStepToAttach); - } - executionStepListNew = attachedExecutionStepListNew; - executionResult.setExecutionStepList(executionStepListNew); - executionResult = em.merge(executionResult); - for (ExecutionStep executionStepListOldExecutionStep : executionStepListOld) { - if (!executionStepListNew.contains(executionStepListOldExecutionStep)) { - executionStepListOldExecutionStep.setResultId(null); - executionStepListOldExecutionStep = em.merge(executionStepListOldExecutionStep); - } - } - for (ExecutionStep executionStepListNewExecutionStep : executionStepListNew) { - if (!executionStepListOld.contains(executionStepListNewExecutionStep)) { - ExecutionResult oldResultIdOfExecutionStepListNewExecutionStep = executionStepListNewExecutionStep.getResultId(); - executionStepListNewExecutionStep.setResultId(executionResult); - executionStepListNewExecutionStep = em.merge(executionStepListNewExecutionStep); - if (oldResultIdOfExecutionStepListNewExecutionStep != null && !oldResultIdOfExecutionStepListNewExecutionStep.equals(executionResult)) { - oldResultIdOfExecutionStepListNewExecutionStep.getExecutionStepList().remove(executionStepListNewExecutionStep); - oldResultIdOfExecutionStepListNewExecutionStep = em.merge(oldResultIdOfExecutionStepListNewExecutionStep); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = executionResult.getId(); - if (findExecutionResult(id) == null) { - throw new NonexistentEntityException("The executionResult with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - ExecutionResult executionResult; - try { - executionResult = em.getReference(ExecutionResult.class, id); - executionResult.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The executionResult with id " + id + " no longer exists.", enfe); - } - List executionStepList = executionResult.getExecutionStepList(); - for (ExecutionStep executionStepListExecutionStep : executionStepList) { - executionStepListExecutionStep.setResultId(null); - executionStepListExecutionStep = em.merge(executionStepListExecutionStep); - } - em.remove(executionResult); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findExecutionResultEntities() { - return findExecutionResultEntities(true, -1, -1); - } - - public List findExecutionResultEntities(int maxResults, int firstResult) { - return findExecutionResultEntities(false, maxResults, firstResult); - } - - private List findExecutionResultEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(ExecutionResult.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public ExecutionResult findExecutionResult(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(ExecutionResult.class, id); - } - finally { - em.close(); - } - } - - public int getExecutionResultCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(ExecutionResult.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import com.validation.manager.core.db.ExecutionResult; +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ExecutionResultJpaController implements Serializable { + + public ExecutionResultJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(ExecutionResult executionResult) { + if (executionResult.getExecutionStepList() == null) { + executionResult.setExecutionStepList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedExecutionStepList = new ArrayList<>(); + for (ExecutionStep executionStepListExecutionStepToAttach : executionResult.getExecutionStepList()) { + executionStepListExecutionStepToAttach = em.getReference(executionStepListExecutionStepToAttach.getClass(), executionStepListExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepList.add(executionStepListExecutionStepToAttach); + } + executionResult.setExecutionStepList(attachedExecutionStepList); + em.persist(executionResult); + for (ExecutionStep executionStepListExecutionStep : executionResult.getExecutionStepList()) { + ExecutionResult oldResultIdOfExecutionStepListExecutionStep = executionStepListExecutionStep.getResultId(); + executionStepListExecutionStep.setResultId(executionResult); + executionStepListExecutionStep = em.merge(executionStepListExecutionStep); + if (oldResultIdOfExecutionStepListExecutionStep != null) { + oldResultIdOfExecutionStepListExecutionStep.getExecutionStepList().remove(executionStepListExecutionStep); + oldResultIdOfExecutionStepListExecutionStep = em.merge(oldResultIdOfExecutionStepListExecutionStep); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(ExecutionResult executionResult) throws NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + ExecutionResult persistentExecutionResult = em.find(ExecutionResult.class, executionResult.getId()); + List executionStepListOld = persistentExecutionResult.getExecutionStepList(); + List executionStepListNew = executionResult.getExecutionStepList(); + List attachedExecutionStepListNew = new ArrayList<>(); + for (ExecutionStep executionStepListNewExecutionStepToAttach : executionStepListNew) { + executionStepListNewExecutionStepToAttach = em.getReference(executionStepListNewExecutionStepToAttach.getClass(), executionStepListNewExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepListNew.add(executionStepListNewExecutionStepToAttach); + } + executionStepListNew = attachedExecutionStepListNew; + executionResult.setExecutionStepList(executionStepListNew); + executionResult = em.merge(executionResult); + for (ExecutionStep executionStepListOldExecutionStep : executionStepListOld) { + if (!executionStepListNew.contains(executionStepListOldExecutionStep)) { + executionStepListOldExecutionStep.setResultId(null); + executionStepListOldExecutionStep = em.merge(executionStepListOldExecutionStep); + } + } + for (ExecutionStep executionStepListNewExecutionStep : executionStepListNew) { + if (!executionStepListOld.contains(executionStepListNewExecutionStep)) { + ExecutionResult oldResultIdOfExecutionStepListNewExecutionStep = executionStepListNewExecutionStep.getResultId(); + executionStepListNewExecutionStep.setResultId(executionResult); + executionStepListNewExecutionStep = em.merge(executionStepListNewExecutionStep); + if (oldResultIdOfExecutionStepListNewExecutionStep != null && !oldResultIdOfExecutionStepListNewExecutionStep.equals(executionResult)) { + oldResultIdOfExecutionStepListNewExecutionStep.getExecutionStepList().remove(executionStepListNewExecutionStep); + oldResultIdOfExecutionStepListNewExecutionStep = em.merge(oldResultIdOfExecutionStepListNewExecutionStep); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = executionResult.getId(); + if (findExecutionResult(id) == null) { + throw new NonexistentEntityException("The executionResult with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + ExecutionResult executionResult; + try { + executionResult = em.getReference(ExecutionResult.class, id); + executionResult.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The executionResult with id " + id + " no longer exists.", enfe); + } + List executionStepList = executionResult.getExecutionStepList(); + for (ExecutionStep executionStepListExecutionStep : executionStepList) { + executionStepListExecutionStep.setResultId(null); + executionStepListExecutionStep = em.merge(executionStepListExecutionStep); + } + em.remove(executionResult); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findExecutionResultEntities() { + return findExecutionResultEntities(true, -1, -1); + } + + public List findExecutionResultEntities(int maxResults, int firstResult) { + return findExecutionResultEntities(false, maxResults, firstResult); + } + + private List findExecutionResultEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(ExecutionResult.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public ExecutionResult findExecutionResult(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(ExecutionResult.class, id); + } + finally { + em.close(); + } + } + + public int getExecutionResultCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(ExecutionResult.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/ExecutionStepHasIssueJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/ExecutionStepHasIssueJpaController.java index b285713e..c0612ae2 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/ExecutionStepHasIssueJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/ExecutionStepHasIssueJpaController.java @@ -13,265 +13,265 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.ExecutionStepHasIssue; -import com.validation.manager.core.db.ExecutionStepHasIssuePK; -import com.validation.manager.core.db.Issue; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class ExecutionStepHasIssueJpaController implements Serializable { - - public ExecutionStepHasIssueJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(ExecutionStepHasIssue executionStepHasIssue) throws PreexistingEntityException, Exception { - if (executionStepHasIssue.getExecutionStepHasIssuePK() == null) { - executionStepHasIssue.setExecutionStepHasIssuePK(new ExecutionStepHasIssuePK()); - } - if (executionStepHasIssue.getVmUserList() == null) { - executionStepHasIssue.setVmUserList(new ArrayList()); - } - executionStepHasIssue.getExecutionStepHasIssuePK().setExecutionStepStepTestCaseId(executionStepHasIssue.getExecutionStep().getExecutionStepPK().getStepTestCaseId()); - executionStepHasIssue.getExecutionStepHasIssuePK().setIssueId(executionStepHasIssue.getIssue().getIssuePK().getId()); - executionStepHasIssue.getExecutionStepHasIssuePK().setIssueIssueTypeId(executionStepHasIssue.getIssue().getIssuePK().getIssueTypeId()); - executionStepHasIssue.getExecutionStepHasIssuePK().setExecutionStepTestCaseExecutionId(executionStepHasIssue.getExecutionStep().getExecutionStepPK().getTestCaseExecutionId()); - executionStepHasIssue.getExecutionStepHasIssuePK().setExecutionStepStepId(executionStepHasIssue.getExecutionStep().getExecutionStepPK().getStepId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - ExecutionStep executionStep = executionStepHasIssue.getExecutionStep(); - if (executionStep != null) { - executionStep = em.getReference(executionStep.getClass(), executionStep.getExecutionStepPK()); - executionStepHasIssue.setExecutionStep(executionStep); - } - Issue issue = executionStepHasIssue.getIssue(); - if (issue != null) { - issue = em.getReference(issue.getClass(), issue.getIssuePK()); - executionStepHasIssue.setIssue(issue); - } - List attachedVmUserList = new ArrayList(); - for (VmUser vmUserListVmUserToAttach : executionStepHasIssue.getVmUserList()) { - vmUserListVmUserToAttach = em.getReference(vmUserListVmUserToAttach.getClass(), vmUserListVmUserToAttach.getId()); - attachedVmUserList.add(vmUserListVmUserToAttach); - } - executionStepHasIssue.setVmUserList(attachedVmUserList); - em.persist(executionStepHasIssue); - if (executionStep != null) { - executionStep.getExecutionStepHasIssueList().add(executionStepHasIssue); - executionStep = em.merge(executionStep); - } - if (issue != null) { - issue.getExecutionStepHasIssueList().add(executionStepHasIssue); - issue = em.merge(issue); - } - for (VmUser vmUserListVmUser : executionStepHasIssue.getVmUserList()) { - vmUserListVmUser.getExecutionStepHasIssueList().add(executionStepHasIssue); - vmUserListVmUser = em.merge(vmUserListVmUser); - } - em.getTransaction().commit(); - } - catch (Exception ex) { - if (findExecutionStepHasIssue(executionStepHasIssue.getExecutionStepHasIssuePK()) != null) { - throw new PreexistingEntityException("ExecutionStepHasIssue " + executionStepHasIssue + " already exists.", ex); - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(ExecutionStepHasIssue executionStepHasIssue) throws NonexistentEntityException, Exception { - executionStepHasIssue.getExecutionStepHasIssuePK().setExecutionStepStepTestCaseId(executionStepHasIssue.getExecutionStep().getExecutionStepPK().getStepTestCaseId()); - executionStepHasIssue.getExecutionStepHasIssuePK().setIssueId(executionStepHasIssue.getIssue().getIssuePK().getId()); - executionStepHasIssue.getExecutionStepHasIssuePK().setIssueIssueTypeId(executionStepHasIssue.getIssue().getIssuePK().getIssueTypeId()); - executionStepHasIssue.getExecutionStepHasIssuePK().setExecutionStepTestCaseExecutionId(executionStepHasIssue.getExecutionStep().getExecutionStepPK().getTestCaseExecutionId()); - executionStepHasIssue.getExecutionStepHasIssuePK().setExecutionStepStepId(executionStepHasIssue.getExecutionStep().getExecutionStepPK().getStepId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - ExecutionStepHasIssue persistentExecutionStepHasIssue = em.find(ExecutionStepHasIssue.class, executionStepHasIssue.getExecutionStepHasIssuePK()); - ExecutionStep executionStepOld = persistentExecutionStepHasIssue.getExecutionStep(); - ExecutionStep executionStepNew = executionStepHasIssue.getExecutionStep(); - Issue issueOld = persistentExecutionStepHasIssue.getIssue(); - Issue issueNew = executionStepHasIssue.getIssue(); - List vmUserListOld = persistentExecutionStepHasIssue.getVmUserList(); - List vmUserListNew = executionStepHasIssue.getVmUserList(); - if (executionStepNew != null) { - executionStepNew = em.getReference(executionStepNew.getClass(), executionStepNew.getExecutionStepPK()); - executionStepHasIssue.setExecutionStep(executionStepNew); - } - if (issueNew != null) { - issueNew = em.getReference(issueNew.getClass(), issueNew.getIssuePK()); - executionStepHasIssue.setIssue(issueNew); - } - List attachedVmUserListNew = new ArrayList(); - for (VmUser vmUserListNewVmUserToAttach : vmUserListNew) { - vmUserListNewVmUserToAttach = em.getReference(vmUserListNewVmUserToAttach.getClass(), vmUserListNewVmUserToAttach.getId()); - attachedVmUserListNew.add(vmUserListNewVmUserToAttach); - } - vmUserListNew = attachedVmUserListNew; - executionStepHasIssue.setVmUserList(vmUserListNew); - executionStepHasIssue = em.merge(executionStepHasIssue); - if (executionStepOld != null && !executionStepOld.equals(executionStepNew)) { - executionStepOld.getExecutionStepHasIssueList().remove(executionStepHasIssue); - executionStepOld = em.merge(executionStepOld); - } - if (executionStepNew != null && !executionStepNew.equals(executionStepOld)) { - executionStepNew.getExecutionStepHasIssueList().add(executionStepHasIssue); - executionStepNew = em.merge(executionStepNew); - } - if (issueOld != null && !issueOld.equals(issueNew)) { - issueOld.getExecutionStepHasIssueList().remove(executionStepHasIssue); - issueOld = em.merge(issueOld); - } - if (issueNew != null && !issueNew.equals(issueOld)) { - issueNew.getExecutionStepHasIssueList().add(executionStepHasIssue); - issueNew = em.merge(issueNew); - } - for (VmUser vmUserListOldVmUser : vmUserListOld) { - if (!vmUserListNew.contains(vmUserListOldVmUser)) { - vmUserListOldVmUser.getExecutionStepHasIssueList().remove(executionStepHasIssue); - vmUserListOldVmUser = em.merge(vmUserListOldVmUser); - } - } - for (VmUser vmUserListNewVmUser : vmUserListNew) { - if (!vmUserListOld.contains(vmUserListNewVmUser)) { - vmUserListNewVmUser.getExecutionStepHasIssueList().add(executionStepHasIssue); - vmUserListNewVmUser = em.merge(vmUserListNewVmUser); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - ExecutionStepHasIssuePK id = executionStepHasIssue.getExecutionStepHasIssuePK(); - if (findExecutionStepHasIssue(id) == null) { - throw new NonexistentEntityException("The executionStepHasIssue with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(ExecutionStepHasIssuePK id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - ExecutionStepHasIssue executionStepHasIssue; - try { - executionStepHasIssue = em.getReference(ExecutionStepHasIssue.class, id); - executionStepHasIssue.getExecutionStepHasIssuePK(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The executionStepHasIssue with id " + id + " no longer exists.", enfe); - } - ExecutionStep executionStep = executionStepHasIssue.getExecutionStep(); - if (executionStep != null) { - executionStep.getExecutionStepHasIssueList().remove(executionStepHasIssue); - executionStep = em.merge(executionStep); - } - Issue issue = executionStepHasIssue.getIssue(); - if (issue != null) { - issue.getExecutionStepHasIssueList().remove(executionStepHasIssue); - issue = em.merge(issue); - } - List vmUserList = executionStepHasIssue.getVmUserList(); - for (VmUser vmUserListVmUser : vmUserList) { - vmUserListVmUser.getExecutionStepHasIssueList().remove(executionStepHasIssue); - vmUserListVmUser = em.merge(vmUserListVmUser); - } - em.remove(executionStepHasIssue); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findExecutionStepHasIssueEntities() { - return findExecutionStepHasIssueEntities(true, -1, -1); - } - - public List findExecutionStepHasIssueEntities(int maxResults, int firstResult) { - return findExecutionStepHasIssueEntities(false, maxResults, firstResult); - } - - private List findExecutionStepHasIssueEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(ExecutionStepHasIssue.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public ExecutionStepHasIssue findExecutionStepHasIssue(ExecutionStepHasIssuePK id) { - EntityManager em = getEntityManager(); - try { - return em.find(ExecutionStepHasIssue.class, id); - } - finally { - em.close(); - } - } - - public int getExecutionStepHasIssueCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(ExecutionStepHasIssue.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.ExecutionStepHasIssue; +import com.validation.manager.core.db.ExecutionStepHasIssuePK; +import com.validation.manager.core.db.Issue; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ExecutionStepHasIssueJpaController implements Serializable { + + public ExecutionStepHasIssueJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(ExecutionStepHasIssue executionStepHasIssue) throws PreexistingEntityException, Exception { + if (executionStepHasIssue.getExecutionStepHasIssuePK() == null) { + executionStepHasIssue.setExecutionStepHasIssuePK(new ExecutionStepHasIssuePK()); + } + if (executionStepHasIssue.getVmUserList() == null) { + executionStepHasIssue.setVmUserList(new ArrayList<>()); + } + executionStepHasIssue.getExecutionStepHasIssuePK().setExecutionStepStepTestCaseId(executionStepHasIssue.getExecutionStep().getExecutionStepPK().getStepTestCaseId()); + executionStepHasIssue.getExecutionStepHasIssuePK().setIssueId(executionStepHasIssue.getIssue().getIssuePK().getId()); + executionStepHasIssue.getExecutionStepHasIssuePK().setIssueIssueTypeId(executionStepHasIssue.getIssue().getIssuePK().getIssueTypeId()); + executionStepHasIssue.getExecutionStepHasIssuePK().setExecutionStepTestCaseExecutionId(executionStepHasIssue.getExecutionStep().getExecutionStepPK().getTestCaseExecutionId()); + executionStepHasIssue.getExecutionStepHasIssuePK().setExecutionStepStepId(executionStepHasIssue.getExecutionStep().getExecutionStepPK().getStepId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + ExecutionStep executionStep = executionStepHasIssue.getExecutionStep(); + if (executionStep != null) { + executionStep = em.getReference(executionStep.getClass(), executionStep.getExecutionStepPK()); + executionStepHasIssue.setExecutionStep(executionStep); + } + Issue issue = executionStepHasIssue.getIssue(); + if (issue != null) { + issue = em.getReference(issue.getClass(), issue.getIssuePK()); + executionStepHasIssue.setIssue(issue); + } + List attachedVmUserList = new ArrayList<>(); + for (VmUser vmUserListVmUserToAttach : executionStepHasIssue.getVmUserList()) { + vmUserListVmUserToAttach = em.getReference(vmUserListVmUserToAttach.getClass(), vmUserListVmUserToAttach.getId()); + attachedVmUserList.add(vmUserListVmUserToAttach); + } + executionStepHasIssue.setVmUserList(attachedVmUserList); + em.persist(executionStepHasIssue); + if (executionStep != null) { + executionStep.getExecutionStepHasIssueList().add(executionStepHasIssue); + executionStep = em.merge(executionStep); + } + if (issue != null) { + issue.getExecutionStepHasIssueList().add(executionStepHasIssue); + issue = em.merge(issue); + } + for (VmUser vmUserListVmUser : executionStepHasIssue.getVmUserList()) { + vmUserListVmUser.getExecutionStepHasIssueList().add(executionStepHasIssue); + vmUserListVmUser = em.merge(vmUserListVmUser); + } + em.getTransaction().commit(); + } + catch (Exception ex) { + if (findExecutionStepHasIssue(executionStepHasIssue.getExecutionStepHasIssuePK()) != null) { + throw new PreexistingEntityException("ExecutionStepHasIssue " + executionStepHasIssue + " already exists.", ex); + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(ExecutionStepHasIssue executionStepHasIssue) throws NonexistentEntityException, Exception { + executionStepHasIssue.getExecutionStepHasIssuePK().setExecutionStepStepTestCaseId(executionStepHasIssue.getExecutionStep().getExecutionStepPK().getStepTestCaseId()); + executionStepHasIssue.getExecutionStepHasIssuePK().setIssueId(executionStepHasIssue.getIssue().getIssuePK().getId()); + executionStepHasIssue.getExecutionStepHasIssuePK().setIssueIssueTypeId(executionStepHasIssue.getIssue().getIssuePK().getIssueTypeId()); + executionStepHasIssue.getExecutionStepHasIssuePK().setExecutionStepTestCaseExecutionId(executionStepHasIssue.getExecutionStep().getExecutionStepPK().getTestCaseExecutionId()); + executionStepHasIssue.getExecutionStepHasIssuePK().setExecutionStepStepId(executionStepHasIssue.getExecutionStep().getExecutionStepPK().getStepId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + ExecutionStepHasIssue persistentExecutionStepHasIssue = em.find(ExecutionStepHasIssue.class, executionStepHasIssue.getExecutionStepHasIssuePK()); + ExecutionStep executionStepOld = persistentExecutionStepHasIssue.getExecutionStep(); + ExecutionStep executionStepNew = executionStepHasIssue.getExecutionStep(); + Issue issueOld = persistentExecutionStepHasIssue.getIssue(); + Issue issueNew = executionStepHasIssue.getIssue(); + List vmUserListOld = persistentExecutionStepHasIssue.getVmUserList(); + List vmUserListNew = executionStepHasIssue.getVmUserList(); + if (executionStepNew != null) { + executionStepNew = em.getReference(executionStepNew.getClass(), executionStepNew.getExecutionStepPK()); + executionStepHasIssue.setExecutionStep(executionStepNew); + } + if (issueNew != null) { + issueNew = em.getReference(issueNew.getClass(), issueNew.getIssuePK()); + executionStepHasIssue.setIssue(issueNew); + } + List attachedVmUserListNew = new ArrayList<>(); + for (VmUser vmUserListNewVmUserToAttach : vmUserListNew) { + vmUserListNewVmUserToAttach = em.getReference(vmUserListNewVmUserToAttach.getClass(), vmUserListNewVmUserToAttach.getId()); + attachedVmUserListNew.add(vmUserListNewVmUserToAttach); + } + vmUserListNew = attachedVmUserListNew; + executionStepHasIssue.setVmUserList(vmUserListNew); + executionStepHasIssue = em.merge(executionStepHasIssue); + if (executionStepOld != null && !executionStepOld.equals(executionStepNew)) { + executionStepOld.getExecutionStepHasIssueList().remove(executionStepHasIssue); + executionStepOld = em.merge(executionStepOld); + } + if (executionStepNew != null && !executionStepNew.equals(executionStepOld)) { + executionStepNew.getExecutionStepHasIssueList().add(executionStepHasIssue); + executionStepNew = em.merge(executionStepNew); + } + if (issueOld != null && !issueOld.equals(issueNew)) { + issueOld.getExecutionStepHasIssueList().remove(executionStepHasIssue); + issueOld = em.merge(issueOld); + } + if (issueNew != null && !issueNew.equals(issueOld)) { + issueNew.getExecutionStepHasIssueList().add(executionStepHasIssue); + issueNew = em.merge(issueNew); + } + for (VmUser vmUserListOldVmUser : vmUserListOld) { + if (!vmUserListNew.contains(vmUserListOldVmUser)) { + vmUserListOldVmUser.getExecutionStepHasIssueList().remove(executionStepHasIssue); + vmUserListOldVmUser = em.merge(vmUserListOldVmUser); + } + } + for (VmUser vmUserListNewVmUser : vmUserListNew) { + if (!vmUserListOld.contains(vmUserListNewVmUser)) { + vmUserListNewVmUser.getExecutionStepHasIssueList().add(executionStepHasIssue); + vmUserListNewVmUser = em.merge(vmUserListNewVmUser); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + ExecutionStepHasIssuePK id = executionStepHasIssue.getExecutionStepHasIssuePK(); + if (findExecutionStepHasIssue(id) == null) { + throw new NonexistentEntityException("The executionStepHasIssue with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(ExecutionStepHasIssuePK id) throws NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + ExecutionStepHasIssue executionStepHasIssue; + try { + executionStepHasIssue = em.getReference(ExecutionStepHasIssue.class, id); + executionStepHasIssue.getExecutionStepHasIssuePK(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The executionStepHasIssue with id " + id + " no longer exists.", enfe); + } + ExecutionStep executionStep = executionStepHasIssue.getExecutionStep(); + if (executionStep != null) { + executionStep.getExecutionStepHasIssueList().remove(executionStepHasIssue); + executionStep = em.merge(executionStep); + } + Issue issue = executionStepHasIssue.getIssue(); + if (issue != null) { + issue.getExecutionStepHasIssueList().remove(executionStepHasIssue); + issue = em.merge(issue); + } + List vmUserList = executionStepHasIssue.getVmUserList(); + for (VmUser vmUserListVmUser : vmUserList) { + vmUserListVmUser.getExecutionStepHasIssueList().remove(executionStepHasIssue); + vmUserListVmUser = em.merge(vmUserListVmUser); + } + em.remove(executionStepHasIssue); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findExecutionStepHasIssueEntities() { + return findExecutionStepHasIssueEntities(true, -1, -1); + } + + public List findExecutionStepHasIssueEntities(int maxResults, int firstResult) { + return findExecutionStepHasIssueEntities(false, maxResults, firstResult); + } + + private List findExecutionStepHasIssueEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(ExecutionStepHasIssue.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public ExecutionStepHasIssue findExecutionStepHasIssue(ExecutionStepHasIssuePK id) { + EntityManager em = getEntityManager(); + try { + return em.find(ExecutionStepHasIssue.class, id); + } + finally { + em.close(); + } + } + + public int getExecutionStepHasIssueCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(ExecutionStepHasIssue.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/ExecutionStepJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/ExecutionStepJpaController.java index 53b13aa6..0b924133 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/ExecutionStepJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/ExecutionStepJpaController.java @@ -13,603 +13,603 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.ExecutionResult; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.ReviewResult; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.Step; -import com.validation.manager.core.db.TestCaseExecution; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.ExecutionStepHasAttachment; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.ExecutionStepHasIssue; -import com.validation.manager.core.db.ExecutionStepHasVmUser; -import com.validation.manager.core.db.ExecutionStepPK; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class ExecutionStepJpaController implements Serializable { - - public ExecutionStepJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(ExecutionStep executionStep) throws PreexistingEntityException, Exception { - if (executionStep.getExecutionStepPK() == null) { - executionStep.setExecutionStepPK(new ExecutionStepPK()); - } - if (executionStep.getExecutionStepHasAttachmentList() == null) { - executionStep.setExecutionStepHasAttachmentList(new ArrayList()); - } - if (executionStep.getExecutionStepHasIssueList() == null) { - executionStep.setExecutionStepHasIssueList(new ArrayList()); - } - if (executionStep.getExecutionStepHasVmUserList() == null) { - executionStep.setExecutionStepHasVmUserList(new ArrayList()); - } - if (executionStep.getHistoryList() == null) { - executionStep.setHistoryList(new ArrayList()); - } - executionStep.getExecutionStepPK().setTestCaseExecutionId(executionStep.getTestCaseExecution().getId()); - executionStep.getExecutionStepPK().setStepTestCaseId(executionStep.getStep().getStepPK().getTestCaseId()); - executionStep.getExecutionStepPK().setStepId(executionStep.getStep().getStepPK().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - ExecutionResult resultId = executionStep.getResultId(); - if (resultId != null) { - resultId = em.getReference(resultId.getClass(), resultId.getId()); - executionStep.setResultId(resultId); - } - ReviewResult reviewResultId = executionStep.getReviewResultId(); - if (reviewResultId != null) { - reviewResultId = em.getReference(reviewResultId.getClass(), reviewResultId.getId()); - executionStep.setReviewResultId(reviewResultId); - } - VmUser assignee = executionStep.getAssignee(); - if (assignee != null) { - assignee = em.getReference(assignee.getClass(), assignee.getId()); - executionStep.setAssignee(assignee); - } - VmUser assigner = executionStep.getAssigner(); - if (assigner != null) { - assigner = em.getReference(assigner.getClass(), assigner.getId()); - executionStep.setAssigner(assigner); - } - Step step = executionStep.getStep(); - if (step != null) { - step = em.getReference(step.getClass(), step.getStepPK()); - executionStep.setStep(step); - } - TestCaseExecution testCaseExecution = executionStep.getTestCaseExecution(); - if (testCaseExecution != null) { - testCaseExecution = em.getReference(testCaseExecution.getClass(), testCaseExecution.getId()); - executionStep.setTestCaseExecution(testCaseExecution); - } - VmUser reviewer = executionStep.getReviewer(); - if (reviewer != null) { - reviewer = em.getReference(reviewer.getClass(), reviewer.getId()); - executionStep.setReviewer(reviewer); - } - History stepHistory = executionStep.getStepHistory(); - if (stepHistory != null) { - stepHistory = em.getReference(stepHistory.getClass(), stepHistory.getId()); - executionStep.setStepHistory(stepHistory); - } - List attachedExecutionStepHasAttachmentList = new ArrayList(); - for (ExecutionStepHasAttachment executionStepHasAttachmentListExecutionStepHasAttachmentToAttach : executionStep.getExecutionStepHasAttachmentList()) { - executionStepHasAttachmentListExecutionStepHasAttachmentToAttach = em.getReference(executionStepHasAttachmentListExecutionStepHasAttachmentToAttach.getClass(), executionStepHasAttachmentListExecutionStepHasAttachmentToAttach.getExecutionStepHasAttachmentPK()); - attachedExecutionStepHasAttachmentList.add(executionStepHasAttachmentListExecutionStepHasAttachmentToAttach); - } - executionStep.setExecutionStepHasAttachmentList(attachedExecutionStepHasAttachmentList); - List attachedExecutionStepHasIssueList = new ArrayList(); - for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssueToAttach : executionStep.getExecutionStepHasIssueList()) { - executionStepHasIssueListExecutionStepHasIssueToAttach = em.getReference(executionStepHasIssueListExecutionStepHasIssueToAttach.getClass(), executionStepHasIssueListExecutionStepHasIssueToAttach.getExecutionStepHasIssuePK()); - attachedExecutionStepHasIssueList.add(executionStepHasIssueListExecutionStepHasIssueToAttach); - } - executionStep.setExecutionStepHasIssueList(attachedExecutionStepHasIssueList); - List attachedExecutionStepHasVmUserList = new ArrayList(); - for (ExecutionStepHasVmUser executionStepHasVmUserListExecutionStepHasVmUserToAttach : executionStep.getExecutionStepHasVmUserList()) { - executionStepHasVmUserListExecutionStepHasVmUserToAttach = em.getReference(executionStepHasVmUserListExecutionStepHasVmUserToAttach.getClass(), executionStepHasVmUserListExecutionStepHasVmUserToAttach.getExecutionStepHasVmUserPK()); - attachedExecutionStepHasVmUserList.add(executionStepHasVmUserListExecutionStepHasVmUserToAttach); - } - executionStep.setExecutionStepHasVmUserList(attachedExecutionStepHasVmUserList); - List attachedHistoryList = new ArrayList(); - for (History historyListHistoryToAttach : executionStep.getHistoryList()) { - historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); - attachedHistoryList.add(historyListHistoryToAttach); - } - executionStep.setHistoryList(attachedHistoryList); - em.persist(executionStep); - if (resultId != null) { - resultId.getExecutionStepList().add(executionStep); - resultId = em.merge(resultId); - } - if (reviewResultId != null) { - reviewResultId.getExecutionStepList().add(executionStep); - reviewResultId = em.merge(reviewResultId); - } - if (assignee != null) { - assignee.getExecutionStepList().add(executionStep); - assignee = em.merge(assignee); - } - if (assigner != null) { - assigner.getExecutionStepList().add(executionStep); - assigner = em.merge(assigner); - } - if (step != null) { - step.getExecutionStepList().add(executionStep); - step = em.merge(step); - } - if (testCaseExecution != null) { - testCaseExecution.getExecutionStepList().add(executionStep); - testCaseExecution = em.merge(testCaseExecution); - } - if (reviewer != null) { - reviewer.getExecutionStepList().add(executionStep); - reviewer = em.merge(reviewer); - } - if (stepHistory != null) { - stepHistory.getExecutionStepList().add(executionStep); - stepHistory = em.merge(stepHistory); - } - for (ExecutionStepHasAttachment executionStepHasAttachmentListExecutionStepHasAttachment : executionStep.getExecutionStepHasAttachmentList()) { - ExecutionStep oldExecutionStepOfExecutionStepHasAttachmentListExecutionStepHasAttachment = executionStepHasAttachmentListExecutionStepHasAttachment.getExecutionStep(); - executionStepHasAttachmentListExecutionStepHasAttachment.setExecutionStep(executionStep); - executionStepHasAttachmentListExecutionStepHasAttachment = em.merge(executionStepHasAttachmentListExecutionStepHasAttachment); - if (oldExecutionStepOfExecutionStepHasAttachmentListExecutionStepHasAttachment != null) { - oldExecutionStepOfExecutionStepHasAttachmentListExecutionStepHasAttachment.getExecutionStepHasAttachmentList().remove(executionStepHasAttachmentListExecutionStepHasAttachment); - oldExecutionStepOfExecutionStepHasAttachmentListExecutionStepHasAttachment = em.merge(oldExecutionStepOfExecutionStepHasAttachmentListExecutionStepHasAttachment); - } - } - for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssue : executionStep.getExecutionStepHasIssueList()) { - ExecutionStep oldExecutionStepOfExecutionStepHasIssueListExecutionStepHasIssue = executionStepHasIssueListExecutionStepHasIssue.getExecutionStep(); - executionStepHasIssueListExecutionStepHasIssue.setExecutionStep(executionStep); - executionStepHasIssueListExecutionStepHasIssue = em.merge(executionStepHasIssueListExecutionStepHasIssue); - if (oldExecutionStepOfExecutionStepHasIssueListExecutionStepHasIssue != null) { - oldExecutionStepOfExecutionStepHasIssueListExecutionStepHasIssue.getExecutionStepHasIssueList().remove(executionStepHasIssueListExecutionStepHasIssue); - oldExecutionStepOfExecutionStepHasIssueListExecutionStepHasIssue = em.merge(oldExecutionStepOfExecutionStepHasIssueListExecutionStepHasIssue); - } - } - for (ExecutionStepHasVmUser executionStepHasVmUserListExecutionStepHasVmUser : executionStep.getExecutionStepHasVmUserList()) { - ExecutionStep oldExecutionStepOfExecutionStepHasVmUserListExecutionStepHasVmUser = executionStepHasVmUserListExecutionStepHasVmUser.getExecutionStep(); - executionStepHasVmUserListExecutionStepHasVmUser.setExecutionStep(executionStep); - executionStepHasVmUserListExecutionStepHasVmUser = em.merge(executionStepHasVmUserListExecutionStepHasVmUser); - if (oldExecutionStepOfExecutionStepHasVmUserListExecutionStepHasVmUser != null) { - oldExecutionStepOfExecutionStepHasVmUserListExecutionStepHasVmUser.getExecutionStepHasVmUserList().remove(executionStepHasVmUserListExecutionStepHasVmUser); - oldExecutionStepOfExecutionStepHasVmUserListExecutionStepHasVmUser = em.merge(oldExecutionStepOfExecutionStepHasVmUserListExecutionStepHasVmUser); - } - } - for (History historyListHistory : executionStep.getHistoryList()) { - historyListHistory.getExecutionStepList().add(executionStep); - historyListHistory = em.merge(historyListHistory); - } - em.getTransaction().commit(); - } - catch (Exception ex) { - if (findExecutionStep(executionStep.getExecutionStepPK()) != null) { - throw new PreexistingEntityException("ExecutionStep " + executionStep + " already exists.", ex); - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(ExecutionStep executionStep) throws IllegalOrphanException, NonexistentEntityException, Exception { - executionStep.getExecutionStepPK().setTestCaseExecutionId(executionStep.getTestCaseExecution().getId()); - executionStep.getExecutionStepPK().setStepTestCaseId(executionStep.getStep().getStepPK().getTestCaseId()); - executionStep.getExecutionStepPK().setStepId(executionStep.getStep().getStepPK().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - ExecutionStep persistentExecutionStep = em.find(ExecutionStep.class, executionStep.getExecutionStepPK()); - ExecutionResult resultIdOld = persistentExecutionStep.getResultId(); - ExecutionResult resultIdNew = executionStep.getResultId(); - ReviewResult reviewResultIdOld = persistentExecutionStep.getReviewResultId(); - ReviewResult reviewResultIdNew = executionStep.getReviewResultId(); - VmUser assigneeOld = persistentExecutionStep.getAssignee(); - VmUser assigneeNew = executionStep.getAssignee(); - VmUser assignerOld = persistentExecutionStep.getAssigner(); - VmUser assignerNew = executionStep.getAssigner(); - Step stepOld = persistentExecutionStep.getStep(); - Step stepNew = executionStep.getStep(); - TestCaseExecution testCaseExecutionOld = persistentExecutionStep.getTestCaseExecution(); - TestCaseExecution testCaseExecutionNew = executionStep.getTestCaseExecution(); - VmUser reviewerOld = persistentExecutionStep.getReviewer(); - VmUser reviewerNew = executionStep.getReviewer(); - History stepHistoryOld = persistentExecutionStep.getStepHistory(); - History stepHistoryNew = executionStep.getStepHistory(); - List executionStepHasAttachmentListOld = persistentExecutionStep.getExecutionStepHasAttachmentList(); - List executionStepHasAttachmentListNew = executionStep.getExecutionStepHasAttachmentList(); - List executionStepHasIssueListOld = persistentExecutionStep.getExecutionStepHasIssueList(); - List executionStepHasIssueListNew = executionStep.getExecutionStepHasIssueList(); - List executionStepHasVmUserListOld = persistentExecutionStep.getExecutionStepHasVmUserList(); - List executionStepHasVmUserListNew = executionStep.getExecutionStepHasVmUserList(); - List historyListOld = persistentExecutionStep.getHistoryList(); - List historyListNew = executionStep.getHistoryList(); - List illegalOrphanMessages = null; - for (ExecutionStepHasAttachment executionStepHasAttachmentListOldExecutionStepHasAttachment : executionStepHasAttachmentListOld) { - if (!executionStepHasAttachmentListNew.contains(executionStepHasAttachmentListOldExecutionStepHasAttachment)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain ExecutionStepHasAttachment " + executionStepHasAttachmentListOldExecutionStepHasAttachment + " since its executionStep field is not nullable."); - } - } - for (ExecutionStepHasIssue executionStepHasIssueListOldExecutionStepHasIssue : executionStepHasIssueListOld) { - if (!executionStepHasIssueListNew.contains(executionStepHasIssueListOldExecutionStepHasIssue)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain ExecutionStepHasIssue " + executionStepHasIssueListOldExecutionStepHasIssue + " since its executionStep field is not nullable."); - } - } - for (ExecutionStepHasVmUser executionStepHasVmUserListOldExecutionStepHasVmUser : executionStepHasVmUserListOld) { - if (!executionStepHasVmUserListNew.contains(executionStepHasVmUserListOldExecutionStepHasVmUser)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain ExecutionStepHasVmUser " + executionStepHasVmUserListOldExecutionStepHasVmUser + " since its executionStep field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (resultIdNew != null) { - resultIdNew = em.getReference(resultIdNew.getClass(), resultIdNew.getId()); - executionStep.setResultId(resultIdNew); - } - if (reviewResultIdNew != null) { - reviewResultIdNew = em.getReference(reviewResultIdNew.getClass(), reviewResultIdNew.getId()); - executionStep.setReviewResultId(reviewResultIdNew); - } - if (assigneeNew != null) { - assigneeNew = em.getReference(assigneeNew.getClass(), assigneeNew.getId()); - executionStep.setAssignee(assigneeNew); - } - if (assignerNew != null) { - assignerNew = em.getReference(assignerNew.getClass(), assignerNew.getId()); - executionStep.setAssigner(assignerNew); - } - if (stepNew != null) { - stepNew = em.getReference(stepNew.getClass(), stepNew.getStepPK()); - executionStep.setStep(stepNew); - } - if (testCaseExecutionNew != null) { - testCaseExecutionNew = em.getReference(testCaseExecutionNew.getClass(), testCaseExecutionNew.getId()); - executionStep.setTestCaseExecution(testCaseExecutionNew); - } - if (reviewerNew != null) { - reviewerNew = em.getReference(reviewerNew.getClass(), reviewerNew.getId()); - executionStep.setReviewer(reviewerNew); - } - if (stepHistoryNew != null) { - stepHistoryNew = em.getReference(stepHistoryNew.getClass(), stepHistoryNew.getId()); - executionStep.setStepHistory(stepHistoryNew); - } - List attachedExecutionStepHasAttachmentListNew = new ArrayList(); - for (ExecutionStepHasAttachment executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach : executionStepHasAttachmentListNew) { - executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach = em.getReference(executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach.getClass(), executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach.getExecutionStepHasAttachmentPK()); - attachedExecutionStepHasAttachmentListNew.add(executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach); - } - executionStepHasAttachmentListNew = attachedExecutionStepHasAttachmentListNew; - executionStep.setExecutionStepHasAttachmentList(executionStepHasAttachmentListNew); - List attachedExecutionStepHasIssueListNew = new ArrayList(); - for (ExecutionStepHasIssue executionStepHasIssueListNewExecutionStepHasIssueToAttach : executionStepHasIssueListNew) { - executionStepHasIssueListNewExecutionStepHasIssueToAttach = em.getReference(executionStepHasIssueListNewExecutionStepHasIssueToAttach.getClass(), executionStepHasIssueListNewExecutionStepHasIssueToAttach.getExecutionStepHasIssuePK()); - attachedExecutionStepHasIssueListNew.add(executionStepHasIssueListNewExecutionStepHasIssueToAttach); - } - executionStepHasIssueListNew = attachedExecutionStepHasIssueListNew; - executionStep.setExecutionStepHasIssueList(executionStepHasIssueListNew); - List attachedExecutionStepHasVmUserListNew = new ArrayList(); - for (ExecutionStepHasVmUser executionStepHasVmUserListNewExecutionStepHasVmUserToAttach : executionStepHasVmUserListNew) { - executionStepHasVmUserListNewExecutionStepHasVmUserToAttach = em.getReference(executionStepHasVmUserListNewExecutionStepHasVmUserToAttach.getClass(), executionStepHasVmUserListNewExecutionStepHasVmUserToAttach.getExecutionStepHasVmUserPK()); - attachedExecutionStepHasVmUserListNew.add(executionStepHasVmUserListNewExecutionStepHasVmUserToAttach); - } - executionStepHasVmUserListNew = attachedExecutionStepHasVmUserListNew; - executionStep.setExecutionStepHasVmUserList(executionStepHasVmUserListNew); - List attachedHistoryListNew = new ArrayList(); - for (History historyListNewHistoryToAttach : historyListNew) { - historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); - attachedHistoryListNew.add(historyListNewHistoryToAttach); - } - historyListNew = attachedHistoryListNew; - executionStep.setHistoryList(historyListNew); - executionStep = em.merge(executionStep); - if (resultIdOld != null && !resultIdOld.equals(resultIdNew)) { - resultIdOld.getExecutionStepList().remove(executionStep); - resultIdOld = em.merge(resultIdOld); - } - if (resultIdNew != null && !resultIdNew.equals(resultIdOld)) { - resultIdNew.getExecutionStepList().add(executionStep); - resultIdNew = em.merge(resultIdNew); - } - if (reviewResultIdOld != null && !reviewResultIdOld.equals(reviewResultIdNew)) { - reviewResultIdOld.getExecutionStepList().remove(executionStep); - reviewResultIdOld = em.merge(reviewResultIdOld); - } - if (reviewResultIdNew != null && !reviewResultIdNew.equals(reviewResultIdOld)) { - reviewResultIdNew.getExecutionStepList().add(executionStep); - reviewResultIdNew = em.merge(reviewResultIdNew); - } - if (assigneeOld != null && !assigneeOld.equals(assigneeNew)) { - assigneeOld.getExecutionStepList().remove(executionStep); - assigneeOld = em.merge(assigneeOld); - } - if (assigneeNew != null && !assigneeNew.equals(assigneeOld)) { - assigneeNew.getExecutionStepList().add(executionStep); - assigneeNew = em.merge(assigneeNew); - } - if (assignerOld != null && !assignerOld.equals(assignerNew)) { - assignerOld.getExecutionStepList().remove(executionStep); - assignerOld = em.merge(assignerOld); - } - if (assignerNew != null && !assignerNew.equals(assignerOld)) { - assignerNew.getExecutionStepList().add(executionStep); - assignerNew = em.merge(assignerNew); - } - if (stepOld != null && !stepOld.equals(stepNew)) { - stepOld.getExecutionStepList().remove(executionStep); - stepOld = em.merge(stepOld); - } - if (stepNew != null && !stepNew.equals(stepOld)) { - stepNew.getExecutionStepList().add(executionStep); - stepNew = em.merge(stepNew); - } - if (testCaseExecutionOld != null && !testCaseExecutionOld.equals(testCaseExecutionNew)) { - testCaseExecutionOld.getExecutionStepList().remove(executionStep); - testCaseExecutionOld = em.merge(testCaseExecutionOld); - } - if (testCaseExecutionNew != null && !testCaseExecutionNew.equals(testCaseExecutionOld)) { - testCaseExecutionNew.getExecutionStepList().add(executionStep); - testCaseExecutionNew = em.merge(testCaseExecutionNew); - } - if (reviewerOld != null && !reviewerOld.equals(reviewerNew)) { - reviewerOld.getExecutionStepList().remove(executionStep); - reviewerOld = em.merge(reviewerOld); - } - if (reviewerNew != null && !reviewerNew.equals(reviewerOld)) { - reviewerNew.getExecutionStepList().add(executionStep); - reviewerNew = em.merge(reviewerNew); - } - if (stepHistoryOld != null && !stepHistoryOld.equals(stepHistoryNew)) { - stepHistoryOld.getExecutionStepList().remove(executionStep); - stepHistoryOld = em.merge(stepHistoryOld); - } - if (stepHistoryNew != null && !stepHistoryNew.equals(stepHistoryOld)) { - stepHistoryNew.getExecutionStepList().add(executionStep); - stepHistoryNew = em.merge(stepHistoryNew); - } - for (ExecutionStepHasAttachment executionStepHasAttachmentListNewExecutionStepHasAttachment : executionStepHasAttachmentListNew) { - if (!executionStepHasAttachmentListOld.contains(executionStepHasAttachmentListNewExecutionStepHasAttachment)) { - ExecutionStep oldExecutionStepOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment = executionStepHasAttachmentListNewExecutionStepHasAttachment.getExecutionStep(); - executionStepHasAttachmentListNewExecutionStepHasAttachment.setExecutionStep(executionStep); - executionStepHasAttachmentListNewExecutionStepHasAttachment = em.merge(executionStepHasAttachmentListNewExecutionStepHasAttachment); - if (oldExecutionStepOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment != null && !oldExecutionStepOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment.equals(executionStep)) { - oldExecutionStepOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment.getExecutionStepHasAttachmentList().remove(executionStepHasAttachmentListNewExecutionStepHasAttachment); - oldExecutionStepOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment = em.merge(oldExecutionStepOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment); - } - } - } - for (ExecutionStepHasIssue executionStepHasIssueListNewExecutionStepHasIssue : executionStepHasIssueListNew) { - if (!executionStepHasIssueListOld.contains(executionStepHasIssueListNewExecutionStepHasIssue)) { - ExecutionStep oldExecutionStepOfExecutionStepHasIssueListNewExecutionStepHasIssue = executionStepHasIssueListNewExecutionStepHasIssue.getExecutionStep(); - executionStepHasIssueListNewExecutionStepHasIssue.setExecutionStep(executionStep); - executionStepHasIssueListNewExecutionStepHasIssue = em.merge(executionStepHasIssueListNewExecutionStepHasIssue); - if (oldExecutionStepOfExecutionStepHasIssueListNewExecutionStepHasIssue != null && !oldExecutionStepOfExecutionStepHasIssueListNewExecutionStepHasIssue.equals(executionStep)) { - oldExecutionStepOfExecutionStepHasIssueListNewExecutionStepHasIssue.getExecutionStepHasIssueList().remove(executionStepHasIssueListNewExecutionStepHasIssue); - oldExecutionStepOfExecutionStepHasIssueListNewExecutionStepHasIssue = em.merge(oldExecutionStepOfExecutionStepHasIssueListNewExecutionStepHasIssue); - } - } - } - for (ExecutionStepHasVmUser executionStepHasVmUserListNewExecutionStepHasVmUser : executionStepHasVmUserListNew) { - if (!executionStepHasVmUserListOld.contains(executionStepHasVmUserListNewExecutionStepHasVmUser)) { - ExecutionStep oldExecutionStepOfExecutionStepHasVmUserListNewExecutionStepHasVmUser = executionStepHasVmUserListNewExecutionStepHasVmUser.getExecutionStep(); - executionStepHasVmUserListNewExecutionStepHasVmUser.setExecutionStep(executionStep); - executionStepHasVmUserListNewExecutionStepHasVmUser = em.merge(executionStepHasVmUserListNewExecutionStepHasVmUser); - if (oldExecutionStepOfExecutionStepHasVmUserListNewExecutionStepHasVmUser != null && !oldExecutionStepOfExecutionStepHasVmUserListNewExecutionStepHasVmUser.equals(executionStep)) { - oldExecutionStepOfExecutionStepHasVmUserListNewExecutionStepHasVmUser.getExecutionStepHasVmUserList().remove(executionStepHasVmUserListNewExecutionStepHasVmUser); - oldExecutionStepOfExecutionStepHasVmUserListNewExecutionStepHasVmUser = em.merge(oldExecutionStepOfExecutionStepHasVmUserListNewExecutionStepHasVmUser); - } - } - } - for (History historyListOldHistory : historyListOld) { - if (!historyListNew.contains(historyListOldHistory)) { - historyListOldHistory.getExecutionStepList().remove(executionStep); - historyListOldHistory = em.merge(historyListOldHistory); - } - } - for (History historyListNewHistory : historyListNew) { - if (!historyListOld.contains(historyListNewHistory)) { - historyListNewHistory.getExecutionStepList().add(executionStep); - historyListNewHistory = em.merge(historyListNewHistory); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - ExecutionStepPK id = executionStep.getExecutionStepPK(); - if (findExecutionStep(id) == null) { - throw new NonexistentEntityException("The executionStep with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(ExecutionStepPK id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - ExecutionStep executionStep; - try { - executionStep = em.getReference(ExecutionStep.class, id); - executionStep.getExecutionStepPK(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The executionStep with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List executionStepHasAttachmentListOrphanCheck = executionStep.getExecutionStepHasAttachmentList(); - for (ExecutionStepHasAttachment executionStepHasAttachmentListOrphanCheckExecutionStepHasAttachment : executionStepHasAttachmentListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This ExecutionStep (" + executionStep + ") cannot be destroyed since the ExecutionStepHasAttachment " + executionStepHasAttachmentListOrphanCheckExecutionStepHasAttachment + " in its executionStepHasAttachmentList field has a non-nullable executionStep field."); - } - List executionStepHasIssueListOrphanCheck = executionStep.getExecutionStepHasIssueList(); - for (ExecutionStepHasIssue executionStepHasIssueListOrphanCheckExecutionStepHasIssue : executionStepHasIssueListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This ExecutionStep (" + executionStep + ") cannot be destroyed since the ExecutionStepHasIssue " + executionStepHasIssueListOrphanCheckExecutionStepHasIssue + " in its executionStepHasIssueList field has a non-nullable executionStep field."); - } - List executionStepHasVmUserListOrphanCheck = executionStep.getExecutionStepHasVmUserList(); - for (ExecutionStepHasVmUser executionStepHasVmUserListOrphanCheckExecutionStepHasVmUser : executionStepHasVmUserListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This ExecutionStep (" + executionStep + ") cannot be destroyed since the ExecutionStepHasVmUser " + executionStepHasVmUserListOrphanCheckExecutionStepHasVmUser + " in its executionStepHasVmUserList field has a non-nullable executionStep field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - ExecutionResult resultId = executionStep.getResultId(); - if (resultId != null) { - resultId.getExecutionStepList().remove(executionStep); - resultId = em.merge(resultId); - } - ReviewResult reviewResultId = executionStep.getReviewResultId(); - if (reviewResultId != null) { - reviewResultId.getExecutionStepList().remove(executionStep); - reviewResultId = em.merge(reviewResultId); - } - VmUser assignee = executionStep.getAssignee(); - if (assignee != null) { - assignee.getExecutionStepList().remove(executionStep); - assignee = em.merge(assignee); - } - VmUser assigner = executionStep.getAssigner(); - if (assigner != null) { - assigner.getExecutionStepList().remove(executionStep); - assigner = em.merge(assigner); - } - Step step = executionStep.getStep(); - if (step != null) { - step.getExecutionStepList().remove(executionStep); - step = em.merge(step); - } - TestCaseExecution testCaseExecution = executionStep.getTestCaseExecution(); - if (testCaseExecution != null) { - testCaseExecution.getExecutionStepList().remove(executionStep); - testCaseExecution = em.merge(testCaseExecution); - } - VmUser reviewer = executionStep.getReviewer(); - if (reviewer != null) { - reviewer.getExecutionStepList().remove(executionStep); - reviewer = em.merge(reviewer); - } - History stepHistory = executionStep.getStepHistory(); - if (stepHistory != null) { - stepHistory.getExecutionStepList().remove(executionStep); - stepHistory = em.merge(stepHistory); - } - List historyList = executionStep.getHistoryList(); - for (History historyListHistory : historyList) { - historyListHistory.getExecutionStepList().remove(executionStep); - historyListHistory = em.merge(historyListHistory); - } - em.remove(executionStep); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findExecutionStepEntities() { - return findExecutionStepEntities(true, -1, -1); - } - - public List findExecutionStepEntities(int maxResults, int firstResult) { - return findExecutionStepEntities(false, maxResults, firstResult); - } - - private List findExecutionStepEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(ExecutionStep.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public ExecutionStep findExecutionStep(ExecutionStepPK id) { - EntityManager em = getEntityManager(); - try { - return em.find(ExecutionStep.class, id); - } - finally { - em.close(); - } - } - - public int getExecutionStepCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(ExecutionStep.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.ExecutionResult; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.ReviewResult; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.Step; +import com.validation.manager.core.db.TestCaseExecution; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.ExecutionStepHasAttachment; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.ExecutionStepHasIssue; +import com.validation.manager.core.db.ExecutionStepHasVmUser; +import com.validation.manager.core.db.ExecutionStepPK; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ExecutionStepJpaController implements Serializable { + + public ExecutionStepJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(ExecutionStep executionStep) throws PreexistingEntityException, Exception { + if (executionStep.getExecutionStepPK() == null) { + executionStep.setExecutionStepPK(new ExecutionStepPK()); + } + if (executionStep.getExecutionStepHasAttachmentList() == null) { + executionStep.setExecutionStepHasAttachmentList(new ArrayList<>()); + } + if (executionStep.getExecutionStepHasIssueList() == null) { + executionStep.setExecutionStepHasIssueList(new ArrayList<>()); + } + if (executionStep.getExecutionStepHasVmUserList() == null) { + executionStep.setExecutionStepHasVmUserList(new ArrayList<>()); + } + if (executionStep.getHistoryList() == null) { + executionStep.setHistoryList(new ArrayList<>()); + } + executionStep.getExecutionStepPK().setTestCaseExecutionId(executionStep.getTestCaseExecution().getId()); + executionStep.getExecutionStepPK().setStepTestCaseId(executionStep.getStep().getStepPK().getTestCaseId()); + executionStep.getExecutionStepPK().setStepId(executionStep.getStep().getStepPK().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + ExecutionResult resultId = executionStep.getResultId(); + if (resultId != null) { + resultId = em.getReference(resultId.getClass(), resultId.getId()); + executionStep.setResultId(resultId); + } + ReviewResult reviewResultId = executionStep.getReviewResultId(); + if (reviewResultId != null) { + reviewResultId = em.getReference(reviewResultId.getClass(), reviewResultId.getId()); + executionStep.setReviewResultId(reviewResultId); + } + VmUser assignee = executionStep.getAssignee(); + if (assignee != null) { + assignee = em.getReference(assignee.getClass(), assignee.getId()); + executionStep.setAssignee(assignee); + } + VmUser assigner = executionStep.getAssigner(); + if (assigner != null) { + assigner = em.getReference(assigner.getClass(), assigner.getId()); + executionStep.setAssigner(assigner); + } + Step step = executionStep.getStep(); + if (step != null) { + step = em.getReference(step.getClass(), step.getStepPK()); + executionStep.setStep(step); + } + TestCaseExecution testCaseExecution = executionStep.getTestCaseExecution(); + if (testCaseExecution != null) { + testCaseExecution = em.getReference(testCaseExecution.getClass(), testCaseExecution.getId()); + executionStep.setTestCaseExecution(testCaseExecution); + } + VmUser reviewer = executionStep.getReviewer(); + if (reviewer != null) { + reviewer = em.getReference(reviewer.getClass(), reviewer.getId()); + executionStep.setReviewer(reviewer); + } + History stepHistory = executionStep.getStepHistory(); + if (stepHistory != null) { + stepHistory = em.getReference(stepHistory.getClass(), stepHistory.getId()); + executionStep.setStepHistory(stepHistory); + } + List attachedExecutionStepHasAttachmentList = new ArrayList<>(); + for (ExecutionStepHasAttachment executionStepHasAttachmentListExecutionStepHasAttachmentToAttach : executionStep.getExecutionStepHasAttachmentList()) { + executionStepHasAttachmentListExecutionStepHasAttachmentToAttach = em.getReference(executionStepHasAttachmentListExecutionStepHasAttachmentToAttach.getClass(), executionStepHasAttachmentListExecutionStepHasAttachmentToAttach.getExecutionStepHasAttachmentPK()); + attachedExecutionStepHasAttachmentList.add(executionStepHasAttachmentListExecutionStepHasAttachmentToAttach); + } + executionStep.setExecutionStepHasAttachmentList(attachedExecutionStepHasAttachmentList); + List attachedExecutionStepHasIssueList = new ArrayList<>(); + for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssueToAttach : executionStep.getExecutionStepHasIssueList()) { + executionStepHasIssueListExecutionStepHasIssueToAttach = em.getReference(executionStepHasIssueListExecutionStepHasIssueToAttach.getClass(), executionStepHasIssueListExecutionStepHasIssueToAttach.getExecutionStepHasIssuePK()); + attachedExecutionStepHasIssueList.add(executionStepHasIssueListExecutionStepHasIssueToAttach); + } + executionStep.setExecutionStepHasIssueList(attachedExecutionStepHasIssueList); + List attachedExecutionStepHasVmUserList = new ArrayList<>(); + for (ExecutionStepHasVmUser executionStepHasVmUserListExecutionStepHasVmUserToAttach : executionStep.getExecutionStepHasVmUserList()) { + executionStepHasVmUserListExecutionStepHasVmUserToAttach = em.getReference(executionStepHasVmUserListExecutionStepHasVmUserToAttach.getClass(), executionStepHasVmUserListExecutionStepHasVmUserToAttach.getExecutionStepHasVmUserPK()); + attachedExecutionStepHasVmUserList.add(executionStepHasVmUserListExecutionStepHasVmUserToAttach); + } + executionStep.setExecutionStepHasVmUserList(attachedExecutionStepHasVmUserList); + List attachedHistoryList = new ArrayList<>(); + for (History historyListHistoryToAttach : executionStep.getHistoryList()) { + historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); + attachedHistoryList.add(historyListHistoryToAttach); + } + executionStep.setHistoryList(attachedHistoryList); + em.persist(executionStep); + if (resultId != null) { + resultId.getExecutionStepList().add(executionStep); + resultId = em.merge(resultId); + } + if (reviewResultId != null) { + reviewResultId.getExecutionStepList().add(executionStep); + reviewResultId = em.merge(reviewResultId); + } + if (assignee != null) { + assignee.getExecutionStepList().add(executionStep); + assignee = em.merge(assignee); + } + if (assigner != null) { + assigner.getExecutionStepList().add(executionStep); + assigner = em.merge(assigner); + } + if (step != null) { + step.getExecutionStepList().add(executionStep); + step = em.merge(step); + } + if (testCaseExecution != null) { + testCaseExecution.getExecutionStepList().add(executionStep); + testCaseExecution = em.merge(testCaseExecution); + } + if (reviewer != null) { + reviewer.getExecutionStepList().add(executionStep); + reviewer = em.merge(reviewer); + } + if (stepHistory != null) { + stepHistory.getExecutionStepList().add(executionStep); + stepHistory = em.merge(stepHistory); + } + for (ExecutionStepHasAttachment executionStepHasAttachmentListExecutionStepHasAttachment : executionStep.getExecutionStepHasAttachmentList()) { + ExecutionStep oldExecutionStepOfExecutionStepHasAttachmentListExecutionStepHasAttachment = executionStepHasAttachmentListExecutionStepHasAttachment.getExecutionStep(); + executionStepHasAttachmentListExecutionStepHasAttachment.setExecutionStep(executionStep); + executionStepHasAttachmentListExecutionStepHasAttachment = em.merge(executionStepHasAttachmentListExecutionStepHasAttachment); + if (oldExecutionStepOfExecutionStepHasAttachmentListExecutionStepHasAttachment != null) { + oldExecutionStepOfExecutionStepHasAttachmentListExecutionStepHasAttachment.getExecutionStepHasAttachmentList().remove(executionStepHasAttachmentListExecutionStepHasAttachment); + oldExecutionStepOfExecutionStepHasAttachmentListExecutionStepHasAttachment = em.merge(oldExecutionStepOfExecutionStepHasAttachmentListExecutionStepHasAttachment); + } + } + for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssue : executionStep.getExecutionStepHasIssueList()) { + ExecutionStep oldExecutionStepOfExecutionStepHasIssueListExecutionStepHasIssue = executionStepHasIssueListExecutionStepHasIssue.getExecutionStep(); + executionStepHasIssueListExecutionStepHasIssue.setExecutionStep(executionStep); + executionStepHasIssueListExecutionStepHasIssue = em.merge(executionStepHasIssueListExecutionStepHasIssue); + if (oldExecutionStepOfExecutionStepHasIssueListExecutionStepHasIssue != null) { + oldExecutionStepOfExecutionStepHasIssueListExecutionStepHasIssue.getExecutionStepHasIssueList().remove(executionStepHasIssueListExecutionStepHasIssue); + oldExecutionStepOfExecutionStepHasIssueListExecutionStepHasIssue = em.merge(oldExecutionStepOfExecutionStepHasIssueListExecutionStepHasIssue); + } + } + for (ExecutionStepHasVmUser executionStepHasVmUserListExecutionStepHasVmUser : executionStep.getExecutionStepHasVmUserList()) { + ExecutionStep oldExecutionStepOfExecutionStepHasVmUserListExecutionStepHasVmUser = executionStepHasVmUserListExecutionStepHasVmUser.getExecutionStep(); + executionStepHasVmUserListExecutionStepHasVmUser.setExecutionStep(executionStep); + executionStepHasVmUserListExecutionStepHasVmUser = em.merge(executionStepHasVmUserListExecutionStepHasVmUser); + if (oldExecutionStepOfExecutionStepHasVmUserListExecutionStepHasVmUser != null) { + oldExecutionStepOfExecutionStepHasVmUserListExecutionStepHasVmUser.getExecutionStepHasVmUserList().remove(executionStepHasVmUserListExecutionStepHasVmUser); + oldExecutionStepOfExecutionStepHasVmUserListExecutionStepHasVmUser = em.merge(oldExecutionStepOfExecutionStepHasVmUserListExecutionStepHasVmUser); + } + } + for (History historyListHistory : executionStep.getHistoryList()) { + historyListHistory.getExecutionStepList().add(executionStep); + historyListHistory = em.merge(historyListHistory); + } + em.getTransaction().commit(); + } + catch (Exception ex) { + if (findExecutionStep(executionStep.getExecutionStepPK()) != null) { + throw new PreexistingEntityException("ExecutionStep " + executionStep + " already exists.", ex); + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(ExecutionStep executionStep) throws IllegalOrphanException, NonexistentEntityException, Exception { + executionStep.getExecutionStepPK().setTestCaseExecutionId(executionStep.getTestCaseExecution().getId()); + executionStep.getExecutionStepPK().setStepTestCaseId(executionStep.getStep().getStepPK().getTestCaseId()); + executionStep.getExecutionStepPK().setStepId(executionStep.getStep().getStepPK().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + ExecutionStep persistentExecutionStep = em.find(ExecutionStep.class, executionStep.getExecutionStepPK()); + ExecutionResult resultIdOld = persistentExecutionStep.getResultId(); + ExecutionResult resultIdNew = executionStep.getResultId(); + ReviewResult reviewResultIdOld = persistentExecutionStep.getReviewResultId(); + ReviewResult reviewResultIdNew = executionStep.getReviewResultId(); + VmUser assigneeOld = persistentExecutionStep.getAssignee(); + VmUser assigneeNew = executionStep.getAssignee(); + VmUser assignerOld = persistentExecutionStep.getAssigner(); + VmUser assignerNew = executionStep.getAssigner(); + Step stepOld = persistentExecutionStep.getStep(); + Step stepNew = executionStep.getStep(); + TestCaseExecution testCaseExecutionOld = persistentExecutionStep.getTestCaseExecution(); + TestCaseExecution testCaseExecutionNew = executionStep.getTestCaseExecution(); + VmUser reviewerOld = persistentExecutionStep.getReviewer(); + VmUser reviewerNew = executionStep.getReviewer(); + History stepHistoryOld = persistentExecutionStep.getStepHistory(); + History stepHistoryNew = executionStep.getStepHistory(); + List executionStepHasAttachmentListOld = persistentExecutionStep.getExecutionStepHasAttachmentList(); + List executionStepHasAttachmentListNew = executionStep.getExecutionStepHasAttachmentList(); + List executionStepHasIssueListOld = persistentExecutionStep.getExecutionStepHasIssueList(); + List executionStepHasIssueListNew = executionStep.getExecutionStepHasIssueList(); + List executionStepHasVmUserListOld = persistentExecutionStep.getExecutionStepHasVmUserList(); + List executionStepHasVmUserListNew = executionStep.getExecutionStepHasVmUserList(); + List historyListOld = persistentExecutionStep.getHistoryList(); + List historyListNew = executionStep.getHistoryList(); + List illegalOrphanMessages = null; + for (ExecutionStepHasAttachment executionStepHasAttachmentListOldExecutionStepHasAttachment : executionStepHasAttachmentListOld) { + if (!executionStepHasAttachmentListNew.contains(executionStepHasAttachmentListOldExecutionStepHasAttachment)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain ExecutionStepHasAttachment " + executionStepHasAttachmentListOldExecutionStepHasAttachment + " since its executionStep field is not nullable."); + } + } + for (ExecutionStepHasIssue executionStepHasIssueListOldExecutionStepHasIssue : executionStepHasIssueListOld) { + if (!executionStepHasIssueListNew.contains(executionStepHasIssueListOldExecutionStepHasIssue)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain ExecutionStepHasIssue " + executionStepHasIssueListOldExecutionStepHasIssue + " since its executionStep field is not nullable."); + } + } + for (ExecutionStepHasVmUser executionStepHasVmUserListOldExecutionStepHasVmUser : executionStepHasVmUserListOld) { + if (!executionStepHasVmUserListNew.contains(executionStepHasVmUserListOldExecutionStepHasVmUser)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain ExecutionStepHasVmUser " + executionStepHasVmUserListOldExecutionStepHasVmUser + " since its executionStep field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (resultIdNew != null) { + resultIdNew = em.getReference(resultIdNew.getClass(), resultIdNew.getId()); + executionStep.setResultId(resultIdNew); + } + if (reviewResultIdNew != null) { + reviewResultIdNew = em.getReference(reviewResultIdNew.getClass(), reviewResultIdNew.getId()); + executionStep.setReviewResultId(reviewResultIdNew); + } + if (assigneeNew != null) { + assigneeNew = em.getReference(assigneeNew.getClass(), assigneeNew.getId()); + executionStep.setAssignee(assigneeNew); + } + if (assignerNew != null) { + assignerNew = em.getReference(assignerNew.getClass(), assignerNew.getId()); + executionStep.setAssigner(assignerNew); + } + if (stepNew != null) { + stepNew = em.getReference(stepNew.getClass(), stepNew.getStepPK()); + executionStep.setStep(stepNew); + } + if (testCaseExecutionNew != null) { + testCaseExecutionNew = em.getReference(testCaseExecutionNew.getClass(), testCaseExecutionNew.getId()); + executionStep.setTestCaseExecution(testCaseExecutionNew); + } + if (reviewerNew != null) { + reviewerNew = em.getReference(reviewerNew.getClass(), reviewerNew.getId()); + executionStep.setReviewer(reviewerNew); + } + if (stepHistoryNew != null) { + stepHistoryNew = em.getReference(stepHistoryNew.getClass(), stepHistoryNew.getId()); + executionStep.setStepHistory(stepHistoryNew); + } + List attachedExecutionStepHasAttachmentListNew = new ArrayList<>(); + for (ExecutionStepHasAttachment executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach : executionStepHasAttachmentListNew) { + executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach = em.getReference(executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach.getClass(), executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach.getExecutionStepHasAttachmentPK()); + attachedExecutionStepHasAttachmentListNew.add(executionStepHasAttachmentListNewExecutionStepHasAttachmentToAttach); + } + executionStepHasAttachmentListNew = attachedExecutionStepHasAttachmentListNew; + executionStep.setExecutionStepHasAttachmentList(executionStepHasAttachmentListNew); + List attachedExecutionStepHasIssueListNew = new ArrayList<>(); + for (ExecutionStepHasIssue executionStepHasIssueListNewExecutionStepHasIssueToAttach : executionStepHasIssueListNew) { + executionStepHasIssueListNewExecutionStepHasIssueToAttach = em.getReference(executionStepHasIssueListNewExecutionStepHasIssueToAttach.getClass(), executionStepHasIssueListNewExecutionStepHasIssueToAttach.getExecutionStepHasIssuePK()); + attachedExecutionStepHasIssueListNew.add(executionStepHasIssueListNewExecutionStepHasIssueToAttach); + } + executionStepHasIssueListNew = attachedExecutionStepHasIssueListNew; + executionStep.setExecutionStepHasIssueList(executionStepHasIssueListNew); + List attachedExecutionStepHasVmUserListNew = new ArrayList<>(); + for (ExecutionStepHasVmUser executionStepHasVmUserListNewExecutionStepHasVmUserToAttach : executionStepHasVmUserListNew) { + executionStepHasVmUserListNewExecutionStepHasVmUserToAttach = em.getReference(executionStepHasVmUserListNewExecutionStepHasVmUserToAttach.getClass(), executionStepHasVmUserListNewExecutionStepHasVmUserToAttach.getExecutionStepHasVmUserPK()); + attachedExecutionStepHasVmUserListNew.add(executionStepHasVmUserListNewExecutionStepHasVmUserToAttach); + } + executionStepHasVmUserListNew = attachedExecutionStepHasVmUserListNew; + executionStep.setExecutionStepHasVmUserList(executionStepHasVmUserListNew); + List attachedHistoryListNew = new ArrayList<>(); + for (History historyListNewHistoryToAttach : historyListNew) { + historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); + attachedHistoryListNew.add(historyListNewHistoryToAttach); + } + historyListNew = attachedHistoryListNew; + executionStep.setHistoryList(historyListNew); + executionStep = em.merge(executionStep); + if (resultIdOld != null && !resultIdOld.equals(resultIdNew)) { + resultIdOld.getExecutionStepList().remove(executionStep); + resultIdOld = em.merge(resultIdOld); + } + if (resultIdNew != null && !resultIdNew.equals(resultIdOld)) { + resultIdNew.getExecutionStepList().add(executionStep); + resultIdNew = em.merge(resultIdNew); + } + if (reviewResultIdOld != null && !reviewResultIdOld.equals(reviewResultIdNew)) { + reviewResultIdOld.getExecutionStepList().remove(executionStep); + reviewResultIdOld = em.merge(reviewResultIdOld); + } + if (reviewResultIdNew != null && !reviewResultIdNew.equals(reviewResultIdOld)) { + reviewResultIdNew.getExecutionStepList().add(executionStep); + reviewResultIdNew = em.merge(reviewResultIdNew); + } + if (assigneeOld != null && !assigneeOld.equals(assigneeNew)) { + assigneeOld.getExecutionStepList().remove(executionStep); + assigneeOld = em.merge(assigneeOld); + } + if (assigneeNew != null && !assigneeNew.equals(assigneeOld)) { + assigneeNew.getExecutionStepList().add(executionStep); + assigneeNew = em.merge(assigneeNew); + } + if (assignerOld != null && !assignerOld.equals(assignerNew)) { + assignerOld.getExecutionStepList().remove(executionStep); + assignerOld = em.merge(assignerOld); + } + if (assignerNew != null && !assignerNew.equals(assignerOld)) { + assignerNew.getExecutionStepList().add(executionStep); + assignerNew = em.merge(assignerNew); + } + if (stepOld != null && !stepOld.equals(stepNew)) { + stepOld.getExecutionStepList().remove(executionStep); + stepOld = em.merge(stepOld); + } + if (stepNew != null && !stepNew.equals(stepOld)) { + stepNew.getExecutionStepList().add(executionStep); + stepNew = em.merge(stepNew); + } + if (testCaseExecutionOld != null && !testCaseExecutionOld.equals(testCaseExecutionNew)) { + testCaseExecutionOld.getExecutionStepList().remove(executionStep); + testCaseExecutionOld = em.merge(testCaseExecutionOld); + } + if (testCaseExecutionNew != null && !testCaseExecutionNew.equals(testCaseExecutionOld)) { + testCaseExecutionNew.getExecutionStepList().add(executionStep); + testCaseExecutionNew = em.merge(testCaseExecutionNew); + } + if (reviewerOld != null && !reviewerOld.equals(reviewerNew)) { + reviewerOld.getExecutionStepList().remove(executionStep); + reviewerOld = em.merge(reviewerOld); + } + if (reviewerNew != null && !reviewerNew.equals(reviewerOld)) { + reviewerNew.getExecutionStepList().add(executionStep); + reviewerNew = em.merge(reviewerNew); + } + if (stepHistoryOld != null && !stepHistoryOld.equals(stepHistoryNew)) { + stepHistoryOld.getExecutionStepList().remove(executionStep); + stepHistoryOld = em.merge(stepHistoryOld); + } + if (stepHistoryNew != null && !stepHistoryNew.equals(stepHistoryOld)) { + stepHistoryNew.getExecutionStepList().add(executionStep); + stepHistoryNew = em.merge(stepHistoryNew); + } + for (ExecutionStepHasAttachment executionStepHasAttachmentListNewExecutionStepHasAttachment : executionStepHasAttachmentListNew) { + if (!executionStepHasAttachmentListOld.contains(executionStepHasAttachmentListNewExecutionStepHasAttachment)) { + ExecutionStep oldExecutionStepOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment = executionStepHasAttachmentListNewExecutionStepHasAttachment.getExecutionStep(); + executionStepHasAttachmentListNewExecutionStepHasAttachment.setExecutionStep(executionStep); + executionStepHasAttachmentListNewExecutionStepHasAttachment = em.merge(executionStepHasAttachmentListNewExecutionStepHasAttachment); + if (oldExecutionStepOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment != null && !oldExecutionStepOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment.equals(executionStep)) { + oldExecutionStepOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment.getExecutionStepHasAttachmentList().remove(executionStepHasAttachmentListNewExecutionStepHasAttachment); + oldExecutionStepOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment = em.merge(oldExecutionStepOfExecutionStepHasAttachmentListNewExecutionStepHasAttachment); + } + } + } + for (ExecutionStepHasIssue executionStepHasIssueListNewExecutionStepHasIssue : executionStepHasIssueListNew) { + if (!executionStepHasIssueListOld.contains(executionStepHasIssueListNewExecutionStepHasIssue)) { + ExecutionStep oldExecutionStepOfExecutionStepHasIssueListNewExecutionStepHasIssue = executionStepHasIssueListNewExecutionStepHasIssue.getExecutionStep(); + executionStepHasIssueListNewExecutionStepHasIssue.setExecutionStep(executionStep); + executionStepHasIssueListNewExecutionStepHasIssue = em.merge(executionStepHasIssueListNewExecutionStepHasIssue); + if (oldExecutionStepOfExecutionStepHasIssueListNewExecutionStepHasIssue != null && !oldExecutionStepOfExecutionStepHasIssueListNewExecutionStepHasIssue.equals(executionStep)) { + oldExecutionStepOfExecutionStepHasIssueListNewExecutionStepHasIssue.getExecutionStepHasIssueList().remove(executionStepHasIssueListNewExecutionStepHasIssue); + oldExecutionStepOfExecutionStepHasIssueListNewExecutionStepHasIssue = em.merge(oldExecutionStepOfExecutionStepHasIssueListNewExecutionStepHasIssue); + } + } + } + for (ExecutionStepHasVmUser executionStepHasVmUserListNewExecutionStepHasVmUser : executionStepHasVmUserListNew) { + if (!executionStepHasVmUserListOld.contains(executionStepHasVmUserListNewExecutionStepHasVmUser)) { + ExecutionStep oldExecutionStepOfExecutionStepHasVmUserListNewExecutionStepHasVmUser = executionStepHasVmUserListNewExecutionStepHasVmUser.getExecutionStep(); + executionStepHasVmUserListNewExecutionStepHasVmUser.setExecutionStep(executionStep); + executionStepHasVmUserListNewExecutionStepHasVmUser = em.merge(executionStepHasVmUserListNewExecutionStepHasVmUser); + if (oldExecutionStepOfExecutionStepHasVmUserListNewExecutionStepHasVmUser != null && !oldExecutionStepOfExecutionStepHasVmUserListNewExecutionStepHasVmUser.equals(executionStep)) { + oldExecutionStepOfExecutionStepHasVmUserListNewExecutionStepHasVmUser.getExecutionStepHasVmUserList().remove(executionStepHasVmUserListNewExecutionStepHasVmUser); + oldExecutionStepOfExecutionStepHasVmUserListNewExecutionStepHasVmUser = em.merge(oldExecutionStepOfExecutionStepHasVmUserListNewExecutionStepHasVmUser); + } + } + } + for (History historyListOldHistory : historyListOld) { + if (!historyListNew.contains(historyListOldHistory)) { + historyListOldHistory.getExecutionStepList().remove(executionStep); + historyListOldHistory = em.merge(historyListOldHistory); + } + } + for (History historyListNewHistory : historyListNew) { + if (!historyListOld.contains(historyListNewHistory)) { + historyListNewHistory.getExecutionStepList().add(executionStep); + historyListNewHistory = em.merge(historyListNewHistory); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + ExecutionStepPK id = executionStep.getExecutionStepPK(); + if (findExecutionStep(id) == null) { + throw new NonexistentEntityException("The executionStep with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(ExecutionStepPK id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + ExecutionStep executionStep; + try { + executionStep = em.getReference(ExecutionStep.class, id); + executionStep.getExecutionStepPK(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The executionStep with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List executionStepHasAttachmentListOrphanCheck = executionStep.getExecutionStepHasAttachmentList(); + for (ExecutionStepHasAttachment executionStepHasAttachmentListOrphanCheckExecutionStepHasAttachment : executionStepHasAttachmentListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This ExecutionStep (" + executionStep + ") cannot be destroyed since the ExecutionStepHasAttachment " + executionStepHasAttachmentListOrphanCheckExecutionStepHasAttachment + " in its executionStepHasAttachmentList field has a non-nullable executionStep field."); + } + List executionStepHasIssueListOrphanCheck = executionStep.getExecutionStepHasIssueList(); + for (ExecutionStepHasIssue executionStepHasIssueListOrphanCheckExecutionStepHasIssue : executionStepHasIssueListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This ExecutionStep (" + executionStep + ") cannot be destroyed since the ExecutionStepHasIssue " + executionStepHasIssueListOrphanCheckExecutionStepHasIssue + " in its executionStepHasIssueList field has a non-nullable executionStep field."); + } + List executionStepHasVmUserListOrphanCheck = executionStep.getExecutionStepHasVmUserList(); + for (ExecutionStepHasVmUser executionStepHasVmUserListOrphanCheckExecutionStepHasVmUser : executionStepHasVmUserListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This ExecutionStep (" + executionStep + ") cannot be destroyed since the ExecutionStepHasVmUser " + executionStepHasVmUserListOrphanCheckExecutionStepHasVmUser + " in its executionStepHasVmUserList field has a non-nullable executionStep field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + ExecutionResult resultId = executionStep.getResultId(); + if (resultId != null) { + resultId.getExecutionStepList().remove(executionStep); + resultId = em.merge(resultId); + } + ReviewResult reviewResultId = executionStep.getReviewResultId(); + if (reviewResultId != null) { + reviewResultId.getExecutionStepList().remove(executionStep); + reviewResultId = em.merge(reviewResultId); + } + VmUser assignee = executionStep.getAssignee(); + if (assignee != null) { + assignee.getExecutionStepList().remove(executionStep); + assignee = em.merge(assignee); + } + VmUser assigner = executionStep.getAssigner(); + if (assigner != null) { + assigner.getExecutionStepList().remove(executionStep); + assigner = em.merge(assigner); + } + Step step = executionStep.getStep(); + if (step != null) { + step.getExecutionStepList().remove(executionStep); + step = em.merge(step); + } + TestCaseExecution testCaseExecution = executionStep.getTestCaseExecution(); + if (testCaseExecution != null) { + testCaseExecution.getExecutionStepList().remove(executionStep); + testCaseExecution = em.merge(testCaseExecution); + } + VmUser reviewer = executionStep.getReviewer(); + if (reviewer != null) { + reviewer.getExecutionStepList().remove(executionStep); + reviewer = em.merge(reviewer); + } + History stepHistory = executionStep.getStepHistory(); + if (stepHistory != null) { + stepHistory.getExecutionStepList().remove(executionStep); + stepHistory = em.merge(stepHistory); + } + List historyList = executionStep.getHistoryList(); + for (History historyListHistory : historyList) { + historyListHistory.getExecutionStepList().remove(executionStep); + historyListHistory = em.merge(historyListHistory); + } + em.remove(executionStep); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findExecutionStepEntities() { + return findExecutionStepEntities(true, -1, -1); + } + + public List findExecutionStepEntities(int maxResults, int firstResult) { + return findExecutionStepEntities(false, maxResults, firstResult); + } + + private List findExecutionStepEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(ExecutionStep.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public ExecutionStep findExecutionStep(ExecutionStepPK id) { + EntityManager em = getEntityManager(); + try { + return em.find(ExecutionStep.class, id); + } + finally { + em.close(); + } + } + + public int getExecutionStepCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(ExecutionStep.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/FailureModeJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/FailureModeJpaController.java index 43ab07c4..7298bf76 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/FailureModeJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/FailureModeJpaController.java @@ -13,186 +13,186 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.FailureMode; -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.RiskItem; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class FailureModeJpaController implements Serializable { - - public FailureModeJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(FailureMode failureMode) { - if (failureMode.getRiskItemList() == null) { - failureMode.setRiskItemList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedRiskItemList = new ArrayList(); - for (RiskItem riskItemListRiskItemToAttach : failureMode.getRiskItemList()) { - riskItemListRiskItemToAttach = em.getReference(riskItemListRiskItemToAttach.getClass(), riskItemListRiskItemToAttach.getRiskItemPK()); - attachedRiskItemList.add(riskItemListRiskItemToAttach); - } - failureMode.setRiskItemList(attachedRiskItemList); - em.persist(failureMode); - for (RiskItem riskItemListRiskItem : failureMode.getRiskItemList()) { - riskItemListRiskItem.getFailureModeList().add(failureMode); - riskItemListRiskItem = em.merge(riskItemListRiskItem); - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(FailureMode failureMode) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - FailureMode persistentFailureMode = em.find(FailureMode.class, failureMode.getId()); - List riskItemListOld = persistentFailureMode.getRiskItemList(); - List riskItemListNew = failureMode.getRiskItemList(); - List attachedRiskItemListNew = new ArrayList(); - for (RiskItem riskItemListNewRiskItemToAttach : riskItemListNew) { - riskItemListNewRiskItemToAttach = em.getReference(riskItemListNewRiskItemToAttach.getClass(), riskItemListNewRiskItemToAttach.getRiskItemPK()); - attachedRiskItemListNew.add(riskItemListNewRiskItemToAttach); - } - riskItemListNew = attachedRiskItemListNew; - failureMode.setRiskItemList(riskItemListNew); - failureMode = em.merge(failureMode); - for (RiskItem riskItemListOldRiskItem : riskItemListOld) { - if (!riskItemListNew.contains(riskItemListOldRiskItem)) { - riskItemListOldRiskItem.getFailureModeList().remove(failureMode); - riskItemListOldRiskItem = em.merge(riskItemListOldRiskItem); - } - } - for (RiskItem riskItemListNewRiskItem : riskItemListNew) { - if (!riskItemListOld.contains(riskItemListNewRiskItem)) { - riskItemListNewRiskItem.getFailureModeList().add(failureMode); - riskItemListNewRiskItem = em.merge(riskItemListNewRiskItem); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = failureMode.getId(); - if (findFailureMode(id) == null) { - throw new NonexistentEntityException("The failureMode with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - FailureMode failureMode; - try { - failureMode = em.getReference(FailureMode.class, id); - failureMode.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The failureMode with id " + id + " no longer exists.", enfe); - } - List riskItemList = failureMode.getRiskItemList(); - for (RiskItem riskItemListRiskItem : riskItemList) { - riskItemListRiskItem.getFailureModeList().remove(failureMode); - riskItemListRiskItem = em.merge(riskItemListRiskItem); - } - em.remove(failureMode); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findFailureModeEntities() { - return findFailureModeEntities(true, -1, -1); - } - - public List findFailureModeEntities(int maxResults, int firstResult) { - return findFailureModeEntities(false, maxResults, firstResult); - } - - private List findFailureModeEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(FailureMode.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public FailureMode findFailureMode(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(FailureMode.class, id); - } - finally { - em.close(); - } - } - - public int getFailureModeCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(FailureMode.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import com.validation.manager.core.db.FailureMode; +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.RiskItem; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class FailureModeJpaController implements Serializable { + + public FailureModeJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(FailureMode failureMode) { + if (failureMode.getRiskItemList() == null) { + failureMode.setRiskItemList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedRiskItemList = new ArrayList<>(); + for (RiskItem riskItemListRiskItemToAttach : failureMode.getRiskItemList()) { + riskItemListRiskItemToAttach = em.getReference(riskItemListRiskItemToAttach.getClass(), riskItemListRiskItemToAttach.getRiskItemPK()); + attachedRiskItemList.add(riskItemListRiskItemToAttach); + } + failureMode.setRiskItemList(attachedRiskItemList); + em.persist(failureMode); + for (RiskItem riskItemListRiskItem : failureMode.getRiskItemList()) { + riskItemListRiskItem.getFailureModeList().add(failureMode); + riskItemListRiskItem = em.merge(riskItemListRiskItem); + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(FailureMode failureMode) throws NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + FailureMode persistentFailureMode = em.find(FailureMode.class, failureMode.getId()); + List riskItemListOld = persistentFailureMode.getRiskItemList(); + List riskItemListNew = failureMode.getRiskItemList(); + List attachedRiskItemListNew = new ArrayList<>(); + for (RiskItem riskItemListNewRiskItemToAttach : riskItemListNew) { + riskItemListNewRiskItemToAttach = em.getReference(riskItemListNewRiskItemToAttach.getClass(), riskItemListNewRiskItemToAttach.getRiskItemPK()); + attachedRiskItemListNew.add(riskItemListNewRiskItemToAttach); + } + riskItemListNew = attachedRiskItemListNew; + failureMode.setRiskItemList(riskItemListNew); + failureMode = em.merge(failureMode); + for (RiskItem riskItemListOldRiskItem : riskItemListOld) { + if (!riskItemListNew.contains(riskItemListOldRiskItem)) { + riskItemListOldRiskItem.getFailureModeList().remove(failureMode); + riskItemListOldRiskItem = em.merge(riskItemListOldRiskItem); + } + } + for (RiskItem riskItemListNewRiskItem : riskItemListNew) { + if (!riskItemListOld.contains(riskItemListNewRiskItem)) { + riskItemListNewRiskItem.getFailureModeList().add(failureMode); + riskItemListNewRiskItem = em.merge(riskItemListNewRiskItem); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = failureMode.getId(); + if (findFailureMode(id) == null) { + throw new NonexistentEntityException("The failureMode with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + FailureMode failureMode; + try { + failureMode = em.getReference(FailureMode.class, id); + failureMode.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The failureMode with id " + id + " no longer exists.", enfe); + } + List riskItemList = failureMode.getRiskItemList(); + for (RiskItem riskItemListRiskItem : riskItemList) { + riskItemListRiskItem.getFailureModeList().remove(failureMode); + riskItemListRiskItem = em.merge(riskItemListRiskItem); + } + em.remove(failureMode); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findFailureModeEntities() { + return findFailureModeEntities(true, -1, -1); + } + + public List findFailureModeEntities(int maxResults, int firstResult) { + return findFailureModeEntities(false, maxResults, firstResult); + } + + private List findFailureModeEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(FailureMode.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public FailureMode findFailureMode(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(FailureMode.class, id); + } + finally { + em.close(); + } + } + + public int getFailureModeCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(FailureMode.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/FieldTypeJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/FieldTypeJpaController.java index 899ef9b7..11f5995a 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/FieldTypeJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/FieldTypeJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.FieldType; -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.HistoryField; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class FieldTypeJpaController implements Serializable { - - public FieldTypeJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(FieldType fieldType) { - if (fieldType.getHistoryFieldList() == null) { - fieldType.setHistoryFieldList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedHistoryFieldList = new ArrayList(); - for (HistoryField historyFieldListHistoryFieldToAttach : fieldType.getHistoryFieldList()) { - historyFieldListHistoryFieldToAttach = em.getReference(historyFieldListHistoryFieldToAttach.getClass(), historyFieldListHistoryFieldToAttach.getHistoryFieldPK()); - attachedHistoryFieldList.add(historyFieldListHistoryFieldToAttach); - } - fieldType.setHistoryFieldList(attachedHistoryFieldList); - em.persist(fieldType); - for (HistoryField historyFieldListHistoryField : fieldType.getHistoryFieldList()) { - FieldType oldFieldTypeOfHistoryFieldListHistoryField = historyFieldListHistoryField.getFieldType(); - historyFieldListHistoryField.setFieldType(fieldType); - historyFieldListHistoryField = em.merge(historyFieldListHistoryField); - if (oldFieldTypeOfHistoryFieldListHistoryField != null) { - oldFieldTypeOfHistoryFieldListHistoryField.getHistoryFieldList().remove(historyFieldListHistoryField); - oldFieldTypeOfHistoryFieldListHistoryField = em.merge(oldFieldTypeOfHistoryFieldListHistoryField); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(FieldType fieldType) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - FieldType persistentFieldType = em.find(FieldType.class, fieldType.getId()); - List historyFieldListOld = persistentFieldType.getHistoryFieldList(); - List historyFieldListNew = fieldType.getHistoryFieldList(); - List illegalOrphanMessages = null; - for (HistoryField historyFieldListOldHistoryField : historyFieldListOld) { - if (!historyFieldListNew.contains(historyFieldListOldHistoryField)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain HistoryField " + historyFieldListOldHistoryField + " since its fieldType field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedHistoryFieldListNew = new ArrayList(); - for (HistoryField historyFieldListNewHistoryFieldToAttach : historyFieldListNew) { - historyFieldListNewHistoryFieldToAttach = em.getReference(historyFieldListNewHistoryFieldToAttach.getClass(), historyFieldListNewHistoryFieldToAttach.getHistoryFieldPK()); - attachedHistoryFieldListNew.add(historyFieldListNewHistoryFieldToAttach); - } - historyFieldListNew = attachedHistoryFieldListNew; - fieldType.setHistoryFieldList(historyFieldListNew); - fieldType = em.merge(fieldType); - for (HistoryField historyFieldListNewHistoryField : historyFieldListNew) { - if (!historyFieldListOld.contains(historyFieldListNewHistoryField)) { - FieldType oldFieldTypeOfHistoryFieldListNewHistoryField = historyFieldListNewHistoryField.getFieldType(); - historyFieldListNewHistoryField.setFieldType(fieldType); - historyFieldListNewHistoryField = em.merge(historyFieldListNewHistoryField); - if (oldFieldTypeOfHistoryFieldListNewHistoryField != null && !oldFieldTypeOfHistoryFieldListNewHistoryField.equals(fieldType)) { - oldFieldTypeOfHistoryFieldListNewHistoryField.getHistoryFieldList().remove(historyFieldListNewHistoryField); - oldFieldTypeOfHistoryFieldListNewHistoryField = em.merge(oldFieldTypeOfHistoryFieldListNewHistoryField); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = fieldType.getId(); - if (findFieldType(id) == null) { - throw new NonexistentEntityException("The fieldType with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - FieldType fieldType; - try { - fieldType = em.getReference(FieldType.class, id); - fieldType.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The fieldType with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List historyFieldListOrphanCheck = fieldType.getHistoryFieldList(); - for (HistoryField historyFieldListOrphanCheckHistoryField : historyFieldListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This FieldType (" + fieldType + ") cannot be destroyed since the HistoryField " + historyFieldListOrphanCheckHistoryField + " in its historyFieldList field has a non-nullable fieldType field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(fieldType); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findFieldTypeEntities() { - return findFieldTypeEntities(true, -1, -1); - } - - public List findFieldTypeEntities(int maxResults, int firstResult) { - return findFieldTypeEntities(false, maxResults, firstResult); - } - - private List findFieldTypeEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(FieldType.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public FieldType findFieldType(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(FieldType.class, id); - } - finally { - em.close(); - } - } - - public int getFieldTypeCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(FieldType.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import com.validation.manager.core.db.FieldType; +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.HistoryField; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class FieldTypeJpaController implements Serializable { + + public FieldTypeJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(FieldType fieldType) { + if (fieldType.getHistoryFieldList() == null) { + fieldType.setHistoryFieldList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedHistoryFieldList = new ArrayList<>(); + for (HistoryField historyFieldListHistoryFieldToAttach : fieldType.getHistoryFieldList()) { + historyFieldListHistoryFieldToAttach = em.getReference(historyFieldListHistoryFieldToAttach.getClass(), historyFieldListHistoryFieldToAttach.getHistoryFieldPK()); + attachedHistoryFieldList.add(historyFieldListHistoryFieldToAttach); + } + fieldType.setHistoryFieldList(attachedHistoryFieldList); + em.persist(fieldType); + for (HistoryField historyFieldListHistoryField : fieldType.getHistoryFieldList()) { + FieldType oldFieldTypeOfHistoryFieldListHistoryField = historyFieldListHistoryField.getFieldType(); + historyFieldListHistoryField.setFieldType(fieldType); + historyFieldListHistoryField = em.merge(historyFieldListHistoryField); + if (oldFieldTypeOfHistoryFieldListHistoryField != null) { + oldFieldTypeOfHistoryFieldListHistoryField.getHistoryFieldList().remove(historyFieldListHistoryField); + oldFieldTypeOfHistoryFieldListHistoryField = em.merge(oldFieldTypeOfHistoryFieldListHistoryField); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(FieldType fieldType) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + FieldType persistentFieldType = em.find(FieldType.class, fieldType.getId()); + List historyFieldListOld = persistentFieldType.getHistoryFieldList(); + List historyFieldListNew = fieldType.getHistoryFieldList(); + List illegalOrphanMessages = null; + for (HistoryField historyFieldListOldHistoryField : historyFieldListOld) { + if (!historyFieldListNew.contains(historyFieldListOldHistoryField)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain HistoryField " + historyFieldListOldHistoryField + " since its fieldType field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedHistoryFieldListNew = new ArrayList<>(); + for (HistoryField historyFieldListNewHistoryFieldToAttach : historyFieldListNew) { + historyFieldListNewHistoryFieldToAttach = em.getReference(historyFieldListNewHistoryFieldToAttach.getClass(), historyFieldListNewHistoryFieldToAttach.getHistoryFieldPK()); + attachedHistoryFieldListNew.add(historyFieldListNewHistoryFieldToAttach); + } + historyFieldListNew = attachedHistoryFieldListNew; + fieldType.setHistoryFieldList(historyFieldListNew); + fieldType = em.merge(fieldType); + for (HistoryField historyFieldListNewHistoryField : historyFieldListNew) { + if (!historyFieldListOld.contains(historyFieldListNewHistoryField)) { + FieldType oldFieldTypeOfHistoryFieldListNewHistoryField = historyFieldListNewHistoryField.getFieldType(); + historyFieldListNewHistoryField.setFieldType(fieldType); + historyFieldListNewHistoryField = em.merge(historyFieldListNewHistoryField); + if (oldFieldTypeOfHistoryFieldListNewHistoryField != null && !oldFieldTypeOfHistoryFieldListNewHistoryField.equals(fieldType)) { + oldFieldTypeOfHistoryFieldListNewHistoryField.getHistoryFieldList().remove(historyFieldListNewHistoryField); + oldFieldTypeOfHistoryFieldListNewHistoryField = em.merge(oldFieldTypeOfHistoryFieldListNewHistoryField); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = fieldType.getId(); + if (findFieldType(id) == null) { + throw new NonexistentEntityException("The fieldType with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + FieldType fieldType; + try { + fieldType = em.getReference(FieldType.class, id); + fieldType.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The fieldType with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List historyFieldListOrphanCheck = fieldType.getHistoryFieldList(); + for (HistoryField historyFieldListOrphanCheckHistoryField : historyFieldListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This FieldType (" + fieldType + ") cannot be destroyed since the HistoryField " + historyFieldListOrphanCheckHistoryField + " in its historyFieldList field has a non-nullable fieldType field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(fieldType); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findFieldTypeEntities() { + return findFieldTypeEntities(true, -1, -1); + } + + public List findFieldTypeEntities(int maxResults, int firstResult) { + return findFieldTypeEntities(false, maxResults, firstResult); + } + + private List findFieldTypeEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(FieldType.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public FieldType findFieldType(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(FieldType.class, id); + } + finally { + em.close(); + } + } + + public int getFieldTypeCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(FieldType.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/FmeaJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/FmeaJpaController.java index 69733618..882f8859 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/FmeaJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/FmeaJpaController.java @@ -13,326 +13,326 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Fmea; -import com.validation.manager.core.db.RiskCategory; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.RiskItem; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class FmeaJpaController implements Serializable { - - public FmeaJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Fmea fmea) { - if (fmea.getRiskCategoryList() == null) { - fmea.setRiskCategoryList(new ArrayList()); - } - if (fmea.getRiskItemList() == null) { - fmea.setRiskItemList(new ArrayList()); - } - if (fmea.getFmeaList() == null) { - fmea.setFmeaList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Fmea parent = fmea.getParent(); - if (parent != null) { - parent = em.getReference(parent.getClass(), parent.getId()); - fmea.setParent(parent); - } - List attachedRiskCategoryList = new ArrayList(); - for (RiskCategory riskCategoryListRiskCategoryToAttach : fmea.getRiskCategoryList()) { - riskCategoryListRiskCategoryToAttach = em.getReference(riskCategoryListRiskCategoryToAttach.getClass(), riskCategoryListRiskCategoryToAttach.getId()); - attachedRiskCategoryList.add(riskCategoryListRiskCategoryToAttach); - } - fmea.setRiskCategoryList(attachedRiskCategoryList); - List attachedRiskItemList = new ArrayList(); - for (RiskItem riskItemListRiskItemToAttach : fmea.getRiskItemList()) { - riskItemListRiskItemToAttach = em.getReference(riskItemListRiskItemToAttach.getClass(), riskItemListRiskItemToAttach.getRiskItemPK()); - attachedRiskItemList.add(riskItemListRiskItemToAttach); - } - fmea.setRiskItemList(attachedRiskItemList); - List attachedFmeaList = new ArrayList(); - for (Fmea fmeaListFmeaToAttach : fmea.getFmeaList()) { - fmeaListFmeaToAttach = em.getReference(fmeaListFmeaToAttach.getClass(), fmeaListFmeaToAttach.getId()); - attachedFmeaList.add(fmeaListFmeaToAttach); - } - fmea.setFmeaList(attachedFmeaList); - em.persist(fmea); - if (parent != null) { - parent.getFmeaList().add(fmea); - parent = em.merge(parent); - } - for (RiskCategory riskCategoryListRiskCategory : fmea.getRiskCategoryList()) { - riskCategoryListRiskCategory.getFmeaList().add(fmea); - riskCategoryListRiskCategory = em.merge(riskCategoryListRiskCategory); - } - for (RiskItem riskItemListRiskItem : fmea.getRiskItemList()) { - Fmea oldFmeaOfRiskItemListRiskItem = riskItemListRiskItem.getFmea(); - riskItemListRiskItem.setFmea(fmea); - riskItemListRiskItem = em.merge(riskItemListRiskItem); - if (oldFmeaOfRiskItemListRiskItem != null) { - oldFmeaOfRiskItemListRiskItem.getRiskItemList().remove(riskItemListRiskItem); - oldFmeaOfRiskItemListRiskItem = em.merge(oldFmeaOfRiskItemListRiskItem); - } - } - for (Fmea fmeaListFmea : fmea.getFmeaList()) { - Fmea oldParentOfFmeaListFmea = fmeaListFmea.getParent(); - fmeaListFmea.setParent(fmea); - fmeaListFmea = em.merge(fmeaListFmea); - if (oldParentOfFmeaListFmea != null) { - oldParentOfFmeaListFmea.getFmeaList().remove(fmeaListFmea); - oldParentOfFmeaListFmea = em.merge(oldParentOfFmeaListFmea); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Fmea fmea) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Fmea persistentFmea = em.find(Fmea.class, fmea.getId()); - Fmea parentOld = persistentFmea.getParent(); - Fmea parentNew = fmea.getParent(); - List riskCategoryListOld = persistentFmea.getRiskCategoryList(); - List riskCategoryListNew = fmea.getRiskCategoryList(); - List riskItemListOld = persistentFmea.getRiskItemList(); - List riskItemListNew = fmea.getRiskItemList(); - List fmeaListOld = persistentFmea.getFmeaList(); - List fmeaListNew = fmea.getFmeaList(); - List illegalOrphanMessages = null; - for (RiskItem riskItemListOldRiskItem : riskItemListOld) { - if (!riskItemListNew.contains(riskItemListOldRiskItem)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain RiskItem " + riskItemListOldRiskItem + " since its fmea field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (parentNew != null) { - parentNew = em.getReference(parentNew.getClass(), parentNew.getId()); - fmea.setParent(parentNew); - } - List attachedRiskCategoryListNew = new ArrayList(); - for (RiskCategory riskCategoryListNewRiskCategoryToAttach : riskCategoryListNew) { - riskCategoryListNewRiskCategoryToAttach = em.getReference(riskCategoryListNewRiskCategoryToAttach.getClass(), riskCategoryListNewRiskCategoryToAttach.getId()); - attachedRiskCategoryListNew.add(riskCategoryListNewRiskCategoryToAttach); - } - riskCategoryListNew = attachedRiskCategoryListNew; - fmea.setRiskCategoryList(riskCategoryListNew); - List attachedRiskItemListNew = new ArrayList(); - for (RiskItem riskItemListNewRiskItemToAttach : riskItemListNew) { - riskItemListNewRiskItemToAttach = em.getReference(riskItemListNewRiskItemToAttach.getClass(), riskItemListNewRiskItemToAttach.getRiskItemPK()); - attachedRiskItemListNew.add(riskItemListNewRiskItemToAttach); - } - riskItemListNew = attachedRiskItemListNew; - fmea.setRiskItemList(riskItemListNew); - List attachedFmeaListNew = new ArrayList(); - for (Fmea fmeaListNewFmeaToAttach : fmeaListNew) { - fmeaListNewFmeaToAttach = em.getReference(fmeaListNewFmeaToAttach.getClass(), fmeaListNewFmeaToAttach.getId()); - attachedFmeaListNew.add(fmeaListNewFmeaToAttach); - } - fmeaListNew = attachedFmeaListNew; - fmea.setFmeaList(fmeaListNew); - fmea = em.merge(fmea); - if (parentOld != null && !parentOld.equals(parentNew)) { - parentOld.getFmeaList().remove(fmea); - parentOld = em.merge(parentOld); - } - if (parentNew != null && !parentNew.equals(parentOld)) { - parentNew.getFmeaList().add(fmea); - parentNew = em.merge(parentNew); - } - for (RiskCategory riskCategoryListOldRiskCategory : riskCategoryListOld) { - if (!riskCategoryListNew.contains(riskCategoryListOldRiskCategory)) { - riskCategoryListOldRiskCategory.getFmeaList().remove(fmea); - riskCategoryListOldRiskCategory = em.merge(riskCategoryListOldRiskCategory); - } - } - for (RiskCategory riskCategoryListNewRiskCategory : riskCategoryListNew) { - if (!riskCategoryListOld.contains(riskCategoryListNewRiskCategory)) { - riskCategoryListNewRiskCategory.getFmeaList().add(fmea); - riskCategoryListNewRiskCategory = em.merge(riskCategoryListNewRiskCategory); - } - } - for (RiskItem riskItemListNewRiskItem : riskItemListNew) { - if (!riskItemListOld.contains(riskItemListNewRiskItem)) { - Fmea oldFmeaOfRiskItemListNewRiskItem = riskItemListNewRiskItem.getFmea(); - riskItemListNewRiskItem.setFmea(fmea); - riskItemListNewRiskItem = em.merge(riskItemListNewRiskItem); - if (oldFmeaOfRiskItemListNewRiskItem != null && !oldFmeaOfRiskItemListNewRiskItem.equals(fmea)) { - oldFmeaOfRiskItemListNewRiskItem.getRiskItemList().remove(riskItemListNewRiskItem); - oldFmeaOfRiskItemListNewRiskItem = em.merge(oldFmeaOfRiskItemListNewRiskItem); - } - } - } - for (Fmea fmeaListOldFmea : fmeaListOld) { - if (!fmeaListNew.contains(fmeaListOldFmea)) { - fmeaListOldFmea.setParent(null); - fmeaListOldFmea = em.merge(fmeaListOldFmea); - } - } - for (Fmea fmeaListNewFmea : fmeaListNew) { - if (!fmeaListOld.contains(fmeaListNewFmea)) { - Fmea oldParentOfFmeaListNewFmea = fmeaListNewFmea.getParent(); - fmeaListNewFmea.setParent(fmea); - fmeaListNewFmea = em.merge(fmeaListNewFmea); - if (oldParentOfFmeaListNewFmea != null && !oldParentOfFmeaListNewFmea.equals(fmea)) { - oldParentOfFmeaListNewFmea.getFmeaList().remove(fmeaListNewFmea); - oldParentOfFmeaListNewFmea = em.merge(oldParentOfFmeaListNewFmea); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = fmea.getId(); - if (findFmea(id) == null) { - throw new NonexistentEntityException("The fmea with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Fmea fmea; - try { - fmea = em.getReference(Fmea.class, id); - fmea.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The fmea with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List riskItemListOrphanCheck = fmea.getRiskItemList(); - for (RiskItem riskItemListOrphanCheckRiskItem : riskItemListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Fmea (" + fmea + ") cannot be destroyed since the RiskItem " + riskItemListOrphanCheckRiskItem + " in its riskItemList field has a non-nullable fmea field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - Fmea parent = fmea.getParent(); - if (parent != null) { - parent.getFmeaList().remove(fmea); - parent = em.merge(parent); - } - List riskCategoryList = fmea.getRiskCategoryList(); - for (RiskCategory riskCategoryListRiskCategory : riskCategoryList) { - riskCategoryListRiskCategory.getFmeaList().remove(fmea); - riskCategoryListRiskCategory = em.merge(riskCategoryListRiskCategory); - } - List fmeaList = fmea.getFmeaList(); - for (Fmea fmeaListFmea : fmeaList) { - fmeaListFmea.setParent(null); - fmeaListFmea = em.merge(fmeaListFmea); - } - em.remove(fmea); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findFmeaEntities() { - return findFmeaEntities(true, -1, -1); - } - - public List findFmeaEntities(int maxResults, int firstResult) { - return findFmeaEntities(false, maxResults, firstResult); - } - - private List findFmeaEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Fmea.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public Fmea findFmea(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(Fmea.class, id); - } - finally { - em.close(); - } - } - - public int getFmeaCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(Fmea.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Fmea; +import com.validation.manager.core.db.RiskCategory; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.RiskItem; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class FmeaJpaController implements Serializable { + + public FmeaJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Fmea fmea) { + if (fmea.getRiskCategoryList() == null) { + fmea.setRiskCategoryList(new ArrayList<>()); + } + if (fmea.getRiskItemList() == null) { + fmea.setRiskItemList(new ArrayList<>()); + } + if (fmea.getFmeaList() == null) { + fmea.setFmeaList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Fmea parent = fmea.getParent(); + if (parent != null) { + parent = em.getReference(parent.getClass(), parent.getId()); + fmea.setParent(parent); + } + List attachedRiskCategoryList = new ArrayList<>(); + for (RiskCategory riskCategoryListRiskCategoryToAttach : fmea.getRiskCategoryList()) { + riskCategoryListRiskCategoryToAttach = em.getReference(riskCategoryListRiskCategoryToAttach.getClass(), riskCategoryListRiskCategoryToAttach.getId()); + attachedRiskCategoryList.add(riskCategoryListRiskCategoryToAttach); + } + fmea.setRiskCategoryList(attachedRiskCategoryList); + List attachedRiskItemList = new ArrayList<>(); + for (RiskItem riskItemListRiskItemToAttach : fmea.getRiskItemList()) { + riskItemListRiskItemToAttach = em.getReference(riskItemListRiskItemToAttach.getClass(), riskItemListRiskItemToAttach.getRiskItemPK()); + attachedRiskItemList.add(riskItemListRiskItemToAttach); + } + fmea.setRiskItemList(attachedRiskItemList); + List attachedFmeaList = new ArrayList<>(); + for (Fmea fmeaListFmeaToAttach : fmea.getFmeaList()) { + fmeaListFmeaToAttach = em.getReference(fmeaListFmeaToAttach.getClass(), fmeaListFmeaToAttach.getId()); + attachedFmeaList.add(fmeaListFmeaToAttach); + } + fmea.setFmeaList(attachedFmeaList); + em.persist(fmea); + if (parent != null) { + parent.getFmeaList().add(fmea); + parent = em.merge(parent); + } + for (RiskCategory riskCategoryListRiskCategory : fmea.getRiskCategoryList()) { + riskCategoryListRiskCategory.getFmeaList().add(fmea); + riskCategoryListRiskCategory = em.merge(riskCategoryListRiskCategory); + } + for (RiskItem riskItemListRiskItem : fmea.getRiskItemList()) { + Fmea oldFmeaOfRiskItemListRiskItem = riskItemListRiskItem.getFmea(); + riskItemListRiskItem.setFmea(fmea); + riskItemListRiskItem = em.merge(riskItemListRiskItem); + if (oldFmeaOfRiskItemListRiskItem != null) { + oldFmeaOfRiskItemListRiskItem.getRiskItemList().remove(riskItemListRiskItem); + oldFmeaOfRiskItemListRiskItem = em.merge(oldFmeaOfRiskItemListRiskItem); + } + } + for (Fmea fmeaListFmea : fmea.getFmeaList()) { + Fmea oldParentOfFmeaListFmea = fmeaListFmea.getParent(); + fmeaListFmea.setParent(fmea); + fmeaListFmea = em.merge(fmeaListFmea); + if (oldParentOfFmeaListFmea != null) { + oldParentOfFmeaListFmea.getFmeaList().remove(fmeaListFmea); + oldParentOfFmeaListFmea = em.merge(oldParentOfFmeaListFmea); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Fmea fmea) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Fmea persistentFmea = em.find(Fmea.class, fmea.getId()); + Fmea parentOld = persistentFmea.getParent(); + Fmea parentNew = fmea.getParent(); + List riskCategoryListOld = persistentFmea.getRiskCategoryList(); + List riskCategoryListNew = fmea.getRiskCategoryList(); + List riskItemListOld = persistentFmea.getRiskItemList(); + List riskItemListNew = fmea.getRiskItemList(); + List fmeaListOld = persistentFmea.getFmeaList(); + List fmeaListNew = fmea.getFmeaList(); + List illegalOrphanMessages = null; + for (RiskItem riskItemListOldRiskItem : riskItemListOld) { + if (!riskItemListNew.contains(riskItemListOldRiskItem)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain RiskItem " + riskItemListOldRiskItem + " since its fmea field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (parentNew != null) { + parentNew = em.getReference(parentNew.getClass(), parentNew.getId()); + fmea.setParent(parentNew); + } + List attachedRiskCategoryListNew = new ArrayList<>(); + for (RiskCategory riskCategoryListNewRiskCategoryToAttach : riskCategoryListNew) { + riskCategoryListNewRiskCategoryToAttach = em.getReference(riskCategoryListNewRiskCategoryToAttach.getClass(), riskCategoryListNewRiskCategoryToAttach.getId()); + attachedRiskCategoryListNew.add(riskCategoryListNewRiskCategoryToAttach); + } + riskCategoryListNew = attachedRiskCategoryListNew; + fmea.setRiskCategoryList(riskCategoryListNew); + List attachedRiskItemListNew = new ArrayList<>(); + for (RiskItem riskItemListNewRiskItemToAttach : riskItemListNew) { + riskItemListNewRiskItemToAttach = em.getReference(riskItemListNewRiskItemToAttach.getClass(), riskItemListNewRiskItemToAttach.getRiskItemPK()); + attachedRiskItemListNew.add(riskItemListNewRiskItemToAttach); + } + riskItemListNew = attachedRiskItemListNew; + fmea.setRiskItemList(riskItemListNew); + List attachedFmeaListNew = new ArrayList<>(); + for (Fmea fmeaListNewFmeaToAttach : fmeaListNew) { + fmeaListNewFmeaToAttach = em.getReference(fmeaListNewFmeaToAttach.getClass(), fmeaListNewFmeaToAttach.getId()); + attachedFmeaListNew.add(fmeaListNewFmeaToAttach); + } + fmeaListNew = attachedFmeaListNew; + fmea.setFmeaList(fmeaListNew); + fmea = em.merge(fmea); + if (parentOld != null && !parentOld.equals(parentNew)) { + parentOld.getFmeaList().remove(fmea); + parentOld = em.merge(parentOld); + } + if (parentNew != null && !parentNew.equals(parentOld)) { + parentNew.getFmeaList().add(fmea); + parentNew = em.merge(parentNew); + } + for (RiskCategory riskCategoryListOldRiskCategory : riskCategoryListOld) { + if (!riskCategoryListNew.contains(riskCategoryListOldRiskCategory)) { + riskCategoryListOldRiskCategory.getFmeaList().remove(fmea); + riskCategoryListOldRiskCategory = em.merge(riskCategoryListOldRiskCategory); + } + } + for (RiskCategory riskCategoryListNewRiskCategory : riskCategoryListNew) { + if (!riskCategoryListOld.contains(riskCategoryListNewRiskCategory)) { + riskCategoryListNewRiskCategory.getFmeaList().add(fmea); + riskCategoryListNewRiskCategory = em.merge(riskCategoryListNewRiskCategory); + } + } + for (RiskItem riskItemListNewRiskItem : riskItemListNew) { + if (!riskItemListOld.contains(riskItemListNewRiskItem)) { + Fmea oldFmeaOfRiskItemListNewRiskItem = riskItemListNewRiskItem.getFmea(); + riskItemListNewRiskItem.setFmea(fmea); + riskItemListNewRiskItem = em.merge(riskItemListNewRiskItem); + if (oldFmeaOfRiskItemListNewRiskItem != null && !oldFmeaOfRiskItemListNewRiskItem.equals(fmea)) { + oldFmeaOfRiskItemListNewRiskItem.getRiskItemList().remove(riskItemListNewRiskItem); + oldFmeaOfRiskItemListNewRiskItem = em.merge(oldFmeaOfRiskItemListNewRiskItem); + } + } + } + for (Fmea fmeaListOldFmea : fmeaListOld) { + if (!fmeaListNew.contains(fmeaListOldFmea)) { + fmeaListOldFmea.setParent(null); + fmeaListOldFmea = em.merge(fmeaListOldFmea); + } + } + for (Fmea fmeaListNewFmea : fmeaListNew) { + if (!fmeaListOld.contains(fmeaListNewFmea)) { + Fmea oldParentOfFmeaListNewFmea = fmeaListNewFmea.getParent(); + fmeaListNewFmea.setParent(fmea); + fmeaListNewFmea = em.merge(fmeaListNewFmea); + if (oldParentOfFmeaListNewFmea != null && !oldParentOfFmeaListNewFmea.equals(fmea)) { + oldParentOfFmeaListNewFmea.getFmeaList().remove(fmeaListNewFmea); + oldParentOfFmeaListNewFmea = em.merge(oldParentOfFmeaListNewFmea); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = fmea.getId(); + if (findFmea(id) == null) { + throw new NonexistentEntityException("The fmea with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Fmea fmea; + try { + fmea = em.getReference(Fmea.class, id); + fmea.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The fmea with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List riskItemListOrphanCheck = fmea.getRiskItemList(); + for (RiskItem riskItemListOrphanCheckRiskItem : riskItemListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Fmea (" + fmea + ") cannot be destroyed since the RiskItem " + riskItemListOrphanCheckRiskItem + " in its riskItemList field has a non-nullable fmea field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + Fmea parent = fmea.getParent(); + if (parent != null) { + parent.getFmeaList().remove(fmea); + parent = em.merge(parent); + } + List riskCategoryList = fmea.getRiskCategoryList(); + for (RiskCategory riskCategoryListRiskCategory : riskCategoryList) { + riskCategoryListRiskCategory.getFmeaList().remove(fmea); + riskCategoryListRiskCategory = em.merge(riskCategoryListRiskCategory); + } + List fmeaList = fmea.getFmeaList(); + for (Fmea fmeaListFmea : fmeaList) { + fmeaListFmea.setParent(null); + fmeaListFmea = em.merge(fmeaListFmea); + } + em.remove(fmea); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findFmeaEntities() { + return findFmeaEntities(true, -1, -1); + } + + public List findFmeaEntities(int maxResults, int firstResult) { + return findFmeaEntities(false, maxResults, firstResult); + } + + private List findFmeaEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Fmea.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public Fmea findFmea(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(Fmea.class, id); + } + finally { + em.close(); + } + } + + public int getFmeaCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Fmea.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/HazardJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/HazardJpaController.java index a0f03baf..0b28ec35 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/HazardJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/HazardJpaController.java @@ -13,186 +13,186 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.Hazard; -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.RiskItem; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class HazardJpaController implements Serializable { - - public HazardJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Hazard hazard) { - if (hazard.getRiskItemList() == null) { - hazard.setRiskItemList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedRiskItemList = new ArrayList(); - for (RiskItem riskItemListRiskItemToAttach : hazard.getRiskItemList()) { - riskItemListRiskItemToAttach = em.getReference(riskItemListRiskItemToAttach.getClass(), riskItemListRiskItemToAttach.getRiskItemPK()); - attachedRiskItemList.add(riskItemListRiskItemToAttach); - } - hazard.setRiskItemList(attachedRiskItemList); - em.persist(hazard); - for (RiskItem riskItemListRiskItem : hazard.getRiskItemList()) { - riskItemListRiskItem.getHazardList().add(hazard); - riskItemListRiskItem = em.merge(riskItemListRiskItem); - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Hazard hazard) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Hazard persistentHazard = em.find(Hazard.class, hazard.getId()); - List riskItemListOld = persistentHazard.getRiskItemList(); - List riskItemListNew = hazard.getRiskItemList(); - List attachedRiskItemListNew = new ArrayList(); - for (RiskItem riskItemListNewRiskItemToAttach : riskItemListNew) { - riskItemListNewRiskItemToAttach = em.getReference(riskItemListNewRiskItemToAttach.getClass(), riskItemListNewRiskItemToAttach.getRiskItemPK()); - attachedRiskItemListNew.add(riskItemListNewRiskItemToAttach); - } - riskItemListNew = attachedRiskItemListNew; - hazard.setRiskItemList(riskItemListNew); - hazard = em.merge(hazard); - for (RiskItem riskItemListOldRiskItem : riskItemListOld) { - if (!riskItemListNew.contains(riskItemListOldRiskItem)) { - riskItemListOldRiskItem.getHazardList().remove(hazard); - riskItemListOldRiskItem = em.merge(riskItemListOldRiskItem); - } - } - for (RiskItem riskItemListNewRiskItem : riskItemListNew) { - if (!riskItemListOld.contains(riskItemListNewRiskItem)) { - riskItemListNewRiskItem.getHazardList().add(hazard); - riskItemListNewRiskItem = em.merge(riskItemListNewRiskItem); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = hazard.getId(); - if (findHazard(id) == null) { - throw new NonexistentEntityException("The hazard with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Hazard hazard; - try { - hazard = em.getReference(Hazard.class, id); - hazard.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The hazard with id " + id + " no longer exists.", enfe); - } - List riskItemList = hazard.getRiskItemList(); - for (RiskItem riskItemListRiskItem : riskItemList) { - riskItemListRiskItem.getHazardList().remove(hazard); - riskItemListRiskItem = em.merge(riskItemListRiskItem); - } - em.remove(hazard); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findHazardEntities() { - return findHazardEntities(true, -1, -1); - } - - public List findHazardEntities(int maxResults, int firstResult) { - return findHazardEntities(false, maxResults, firstResult); - } - - private List findHazardEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Hazard.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public Hazard findHazard(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(Hazard.class, id); - } - finally { - em.close(); - } - } - - public int getHazardCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(Hazard.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import com.validation.manager.core.db.Hazard; +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.RiskItem; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class HazardJpaController implements Serializable { + + public HazardJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Hazard hazard) { + if (hazard.getRiskItemList() == null) { + hazard.setRiskItemList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedRiskItemList = new ArrayList<>(); + for (RiskItem riskItemListRiskItemToAttach : hazard.getRiskItemList()) { + riskItemListRiskItemToAttach = em.getReference(riskItemListRiskItemToAttach.getClass(), riskItemListRiskItemToAttach.getRiskItemPK()); + attachedRiskItemList.add(riskItemListRiskItemToAttach); + } + hazard.setRiskItemList(attachedRiskItemList); + em.persist(hazard); + for (RiskItem riskItemListRiskItem : hazard.getRiskItemList()) { + riskItemListRiskItem.getHazardList().add(hazard); + riskItemListRiskItem = em.merge(riskItemListRiskItem); + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Hazard hazard) throws NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Hazard persistentHazard = em.find(Hazard.class, hazard.getId()); + List riskItemListOld = persistentHazard.getRiskItemList(); + List riskItemListNew = hazard.getRiskItemList(); + List attachedRiskItemListNew = new ArrayList<>(); + for (RiskItem riskItemListNewRiskItemToAttach : riskItemListNew) { + riskItemListNewRiskItemToAttach = em.getReference(riskItemListNewRiskItemToAttach.getClass(), riskItemListNewRiskItemToAttach.getRiskItemPK()); + attachedRiskItemListNew.add(riskItemListNewRiskItemToAttach); + } + riskItemListNew = attachedRiskItemListNew; + hazard.setRiskItemList(riskItemListNew); + hazard = em.merge(hazard); + for (RiskItem riskItemListOldRiskItem : riskItemListOld) { + if (!riskItemListNew.contains(riskItemListOldRiskItem)) { + riskItemListOldRiskItem.getHazardList().remove(hazard); + riskItemListOldRiskItem = em.merge(riskItemListOldRiskItem); + } + } + for (RiskItem riskItemListNewRiskItem : riskItemListNew) { + if (!riskItemListOld.contains(riskItemListNewRiskItem)) { + riskItemListNewRiskItem.getHazardList().add(hazard); + riskItemListNewRiskItem = em.merge(riskItemListNewRiskItem); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = hazard.getId(); + if (findHazard(id) == null) { + throw new NonexistentEntityException("The hazard with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Hazard hazard; + try { + hazard = em.getReference(Hazard.class, id); + hazard.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The hazard with id " + id + " no longer exists.", enfe); + } + List riskItemList = hazard.getRiskItemList(); + for (RiskItem riskItemListRiskItem : riskItemList) { + riskItemListRiskItem.getHazardList().remove(hazard); + riskItemListRiskItem = em.merge(riskItemListRiskItem); + } + em.remove(hazard); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findHazardEntities() { + return findHazardEntities(true, -1, -1); + } + + public List findHazardEntities(int maxResults, int firstResult) { + return findHazardEntities(false, maxResults, firstResult); + } + + private List findHazardEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Hazard.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public Hazard findHazard(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(Hazard.class, id); + } + finally { + em.close(); + } + } + + public int getHazardCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Hazard.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/HistoryJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/HistoryJpaController.java index 8c3caa07..27ac154b 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/HistoryJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/HistoryJpaController.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,434 +13,462 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.Requirement; -import com.validation.manager.core.db.Project; -import com.validation.manager.core.db.Step; -import com.validation.manager.core.db.VmSetting; -import com.validation.manager.core.db.HistoryField; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.Baseline; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class HistoryJpaController implements Serializable { - - public HistoryJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(History history) { - if (history.getHistoryFieldList() == null) { - history.setHistoryFieldList(new ArrayList()); - } - if (history.getBaselineList() == null) { - history.setBaselineList(new ArrayList()); - } - if (history.getExecutionStepList() == null) { - history.setExecutionStepList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - VmUser modifierId = history.getModifierId(); - if (modifierId != null) { - modifierId = em.getReference(modifierId.getClass(), modifierId.getId()); - history.setModifierId(modifierId); - } - Requirement requirementId = history.getRequirementId(); - if (requirementId != null) { - requirementId = em.getReference(requirementId.getClass(), requirementId.getId()); - history.setRequirementId(requirementId); - } - Project projectId = history.getProjectId(); - if (projectId != null) { - projectId = em.getReference(projectId.getClass(), projectId.getId()); - history.setProjectId(projectId); - } - Step step = history.getStep(); - if (step != null) { - step = em.getReference(step.getClass(), step.getStepPK()); - history.setStep(step); - } - VmSetting vmSettingId = history.getVmSettingId(); - if (vmSettingId != null) { - vmSettingId = em.getReference(vmSettingId.getClass(), vmSettingId.getId()); - history.setVmSettingId(vmSettingId); - } - List attachedHistoryFieldList = new ArrayList(); - for (HistoryField historyFieldListHistoryFieldToAttach : history.getHistoryFieldList()) { - historyFieldListHistoryFieldToAttach = em.getReference(historyFieldListHistoryFieldToAttach.getClass(), historyFieldListHistoryFieldToAttach.getHistoryFieldPK()); - attachedHistoryFieldList.add(historyFieldListHistoryFieldToAttach); - } - history.setHistoryFieldList(attachedHistoryFieldList); - List attachedBaselineList = new ArrayList(); - for (Baseline baselineListBaselineToAttach : history.getBaselineList()) { - baselineListBaselineToAttach = em.getReference(baselineListBaselineToAttach.getClass(), baselineListBaselineToAttach.getId()); - attachedBaselineList.add(baselineListBaselineToAttach); - } - history.setBaselineList(attachedBaselineList); - List attachedExecutionStepList = new ArrayList(); - for (ExecutionStep executionStepListExecutionStepToAttach : history.getExecutionStepList()) { - executionStepListExecutionStepToAttach = em.getReference(executionStepListExecutionStepToAttach.getClass(), executionStepListExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepList.add(executionStepListExecutionStepToAttach); - } - history.setExecutionStepList(attachedExecutionStepList); - em.persist(history); - if (modifierId != null) { - modifierId.getHistoryModificationList().add(history); - modifierId = em.merge(modifierId); - } - if (requirementId != null) { - requirementId.getHistoryList().add(history); - requirementId = em.merge(requirementId); - } - if (projectId != null) { - projectId.getHistoryList().add(history); - projectId = em.merge(projectId); - } - if (step != null) { - step.getHistoryList().add(history); - step = em.merge(step); - } - if (vmSettingId != null) { - vmSettingId.getHistoryList().add(history); - vmSettingId = em.merge(vmSettingId); - } - for (HistoryField historyFieldListHistoryField : history.getHistoryFieldList()) { - History oldHistoryOfHistoryFieldListHistoryField = historyFieldListHistoryField.getHistory(); - historyFieldListHistoryField.setHistory(history); - historyFieldListHistoryField = em.merge(historyFieldListHistoryField); - if (oldHistoryOfHistoryFieldListHistoryField != null) { - oldHistoryOfHistoryFieldListHistoryField.getHistoryFieldList().remove(historyFieldListHistoryField); - oldHistoryOfHistoryFieldListHistoryField = em.merge(oldHistoryOfHistoryFieldListHistoryField); - } - } - for (Baseline baselineListBaseline : history.getBaselineList()) { - baselineListBaseline.getHistoryList().add(history); - baselineListBaseline = em.merge(baselineListBaseline); - } - for (ExecutionStep executionStepListExecutionStep : history.getExecutionStepList()) { - executionStepListExecutionStep.getHistoryList().add(history); - executionStepListExecutionStep = em.merge(executionStepListExecutionStep); - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(History history) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - History persistentHistory = em.find(History.class, history.getId()); - VmUser modifierIdOld = persistentHistory.getModifierId(); - VmUser modifierIdNew = history.getModifierId(); - Requirement requirementIdOld = persistentHistory.getRequirementId(); - Requirement requirementIdNew = history.getRequirementId(); - Project projectIdOld = persistentHistory.getProjectId(); - Project projectIdNew = history.getProjectId(); - Step stepOld = persistentHistory.getStep(); - Step stepNew = history.getStep(); - VmSetting vmSettingIdOld = persistentHistory.getVmSettingId(); - VmSetting vmSettingIdNew = history.getVmSettingId(); - List historyFieldListOld = persistentHistory.getHistoryFieldList(); - List historyFieldListNew = history.getHistoryFieldList(); - List baselineListOld = persistentHistory.getBaselineList(); - List baselineListNew = history.getBaselineList(); - List executionStepListOld = persistentHistory.getExecutionStepList(); - List executionStepListNew = history.getExecutionStepList(); - List illegalOrphanMessages = null; - for (HistoryField historyFieldListOldHistoryField : historyFieldListOld) { - if (!historyFieldListNew.contains(historyFieldListOldHistoryField)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain HistoryField " + historyFieldListOldHistoryField + " since its history field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (modifierIdNew != null) { - modifierIdNew = em.getReference(modifierIdNew.getClass(), modifierIdNew.getId()); - history.setModifierId(modifierIdNew); - } - if (requirementIdNew != null) { - requirementIdNew = em.getReference(requirementIdNew.getClass(), requirementIdNew.getId()); - history.setRequirementId(requirementIdNew); - } - if (projectIdNew != null) { - projectIdNew = em.getReference(projectIdNew.getClass(), projectIdNew.getId()); - history.setProjectId(projectIdNew); - } - if (stepNew != null) { - stepNew = em.getReference(stepNew.getClass(), stepNew.getStepPK()); - history.setStep(stepNew); - } - if (vmSettingIdNew != null) { - vmSettingIdNew = em.getReference(vmSettingIdNew.getClass(), vmSettingIdNew.getId()); - history.setVmSettingId(vmSettingIdNew); - } - List attachedHistoryFieldListNew = new ArrayList(); - for (HistoryField historyFieldListNewHistoryFieldToAttach : historyFieldListNew) { - historyFieldListNewHistoryFieldToAttach = em.getReference(historyFieldListNewHistoryFieldToAttach.getClass(), historyFieldListNewHistoryFieldToAttach.getHistoryFieldPK()); - attachedHistoryFieldListNew.add(historyFieldListNewHistoryFieldToAttach); - } - historyFieldListNew = attachedHistoryFieldListNew; - history.setHistoryFieldList(historyFieldListNew); - List attachedBaselineListNew = new ArrayList(); - for (Baseline baselineListNewBaselineToAttach : baselineListNew) { - baselineListNewBaselineToAttach = em.getReference(baselineListNewBaselineToAttach.getClass(), baselineListNewBaselineToAttach.getId()); - attachedBaselineListNew.add(baselineListNewBaselineToAttach); - } - baselineListNew = attachedBaselineListNew; - history.setBaselineList(baselineListNew); - List attachedExecutionStepListNew = new ArrayList(); - for (ExecutionStep executionStepListNewExecutionStepToAttach : executionStepListNew) { - executionStepListNewExecutionStepToAttach = em.getReference(executionStepListNewExecutionStepToAttach.getClass(), executionStepListNewExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepListNew.add(executionStepListNewExecutionStepToAttach); - } - executionStepListNew = attachedExecutionStepListNew; - history.setExecutionStepList(executionStepListNew); - history = em.merge(history); - if (modifierIdOld != null && !modifierIdOld.equals(modifierIdNew)) { - modifierIdOld.getHistoryModificationList().remove(history); - modifierIdOld = em.merge(modifierIdOld); - } - if (modifierIdNew != null && !modifierIdNew.equals(modifierIdOld)) { - modifierIdNew.getHistoryModificationList().add(history); - modifierIdNew = em.merge(modifierIdNew); - } - if (requirementIdOld != null && !requirementIdOld.equals(requirementIdNew)) { - requirementIdOld.getHistoryList().remove(history); - requirementIdOld = em.merge(requirementIdOld); - } - if (requirementIdNew != null && !requirementIdNew.equals(requirementIdOld)) { - requirementIdNew.getHistoryList().add(history); - requirementIdNew = em.merge(requirementIdNew); - } - if (projectIdOld != null && !projectIdOld.equals(projectIdNew)) { - projectIdOld.getHistoryList().remove(history); - projectIdOld = em.merge(projectIdOld); - } - if (projectIdNew != null && !projectIdNew.equals(projectIdOld)) { - projectIdNew.getHistoryList().add(history); - projectIdNew = em.merge(projectIdNew); - } - if (stepOld != null && !stepOld.equals(stepNew)) { - stepOld.getHistoryList().remove(history); - stepOld = em.merge(stepOld); - } - if (stepNew != null && !stepNew.equals(stepOld)) { - stepNew.getHistoryList().add(history); - stepNew = em.merge(stepNew); - } - if (vmSettingIdOld != null && !vmSettingIdOld.equals(vmSettingIdNew)) { - vmSettingIdOld.getHistoryList().remove(history); - vmSettingIdOld = em.merge(vmSettingIdOld); - } - if (vmSettingIdNew != null && !vmSettingIdNew.equals(vmSettingIdOld)) { - vmSettingIdNew.getHistoryList().add(history); - vmSettingIdNew = em.merge(vmSettingIdNew); - } - for (HistoryField historyFieldListNewHistoryField : historyFieldListNew) { - if (!historyFieldListOld.contains(historyFieldListNewHistoryField)) { - History oldHistoryOfHistoryFieldListNewHistoryField = historyFieldListNewHistoryField.getHistory(); - historyFieldListNewHistoryField.setHistory(history); - historyFieldListNewHistoryField = em.merge(historyFieldListNewHistoryField); - if (oldHistoryOfHistoryFieldListNewHistoryField != null && !oldHistoryOfHistoryFieldListNewHistoryField.equals(history)) { - oldHistoryOfHistoryFieldListNewHistoryField.getHistoryFieldList().remove(historyFieldListNewHistoryField); - oldHistoryOfHistoryFieldListNewHistoryField = em.merge(oldHistoryOfHistoryFieldListNewHistoryField); - } - } - } - for (Baseline baselineListOldBaseline : baselineListOld) { - if (!baselineListNew.contains(baselineListOldBaseline)) { - baselineListOldBaseline.getHistoryList().remove(history); - baselineListOldBaseline = em.merge(baselineListOldBaseline); - } - } - for (Baseline baselineListNewBaseline : baselineListNew) { - if (!baselineListOld.contains(baselineListNewBaseline)) { - baselineListNewBaseline.getHistoryList().add(history); - baselineListNewBaseline = em.merge(baselineListNewBaseline); - } - } - for (ExecutionStep executionStepListOldExecutionStep : executionStepListOld) { - if (!executionStepListNew.contains(executionStepListOldExecutionStep)) { - executionStepListOldExecutionStep.getHistoryList().remove(history); - executionStepListOldExecutionStep = em.merge(executionStepListOldExecutionStep); - } - } - for (ExecutionStep executionStepListNewExecutionStep : executionStepListNew) { - if (!executionStepListOld.contains(executionStepListNewExecutionStep)) { - executionStepListNewExecutionStep.getHistoryList().add(history); - executionStepListNewExecutionStep = em.merge(executionStepListNewExecutionStep); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = history.getId(); - if (findHistory(id) == null) { - throw new NonexistentEntityException("The history with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - History history; - try { - history = em.getReference(History.class, id); - history.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The history with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List historyFieldListOrphanCheck = history.getHistoryFieldList(); - for (HistoryField historyFieldListOrphanCheckHistoryField : historyFieldListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This History (" + history + ") cannot be destroyed since the HistoryField " + historyFieldListOrphanCheckHistoryField + " in its historyFieldList field has a non-nullable history field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - VmUser modifierId = history.getModifierId(); - if (modifierId != null) { - modifierId.getHistoryModificationList().remove(history); - modifierId = em.merge(modifierId); - } - Requirement requirementId = history.getRequirementId(); - if (requirementId != null) { - requirementId.getHistoryList().remove(history); - requirementId = em.merge(requirementId); - } - Project projectId = history.getProjectId(); - if (projectId != null) { - projectId.getHistoryList().remove(history); - projectId = em.merge(projectId); - } - Step step = history.getStep(); - if (step != null) { - step.getHistoryList().remove(history); - step = em.merge(step); - } - VmSetting vmSettingId = history.getVmSettingId(); - if (vmSettingId != null) { - vmSettingId.getHistoryList().remove(history); - vmSettingId = em.merge(vmSettingId); - } - List baselineList = history.getBaselineList(); - for (Baseline baselineListBaseline : baselineList) { - baselineListBaseline.getHistoryList().remove(history); - baselineListBaseline = em.merge(baselineListBaseline); - } - List executionStepList = history.getExecutionStepList(); - for (ExecutionStep executionStepListExecutionStep : executionStepList) { - executionStepListExecutionStep.getHistoryList().remove(history); - executionStepListExecutionStep = em.merge(executionStepListExecutionStep); - } - em.remove(history); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findHistoryEntities() { - return findHistoryEntities(true, -1, -1); - } - - public List findHistoryEntities(int maxResults, int firstResult) { - return findHistoryEntities(false, maxResults, firstResult); - } - - private List findHistoryEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(History.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public History findHistory(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(History.class, id); - } - finally { - em.close(); - } - } - - public int getHistoryCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(History.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.Requirement; +import com.validation.manager.core.db.Project; +import com.validation.manager.core.db.Step; +import com.validation.manager.core.db.VmSetting; +import com.validation.manager.core.db.HistoryField; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.Baseline; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class HistoryJpaController implements Serializable { + + public HistoryJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(History history) { + if (history.getHistoryFieldList() == null) { + history.setHistoryFieldList(new ArrayList<>()); + } + if (history.getBaselineList() == null) { + history.setBaselineList(new ArrayList<>()); + } + if (history.getExecutionStepList() == null) { + history.setExecutionStepList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + VmUser modifierId = history.getModifierId(); + if (modifierId != null) { + modifierId = em.getReference(modifierId.getClass(), modifierId.getId()); + history.setModifierId(modifierId); + } + Requirement requirementId = history.getRequirementId(); + if (requirementId != null) { + requirementId = em.getReference(requirementId.getClass(), requirementId.getId()); + history.setRequirementId(requirementId); + } + Project projectId = history.getProjectId(); + if (projectId != null) { + projectId = em.getReference(projectId.getClass(), projectId.getId()); + history.setProjectId(projectId); + } + Step step = history.getStep(); + if (step != null) { + step = em.getReference(step.getClass(), step.getStepPK()); + history.setStep(step); + } + VmSetting vmSettingId = history.getVmSettingId(); + if (vmSettingId != null) { + vmSettingId = em.getReference(vmSettingId.getClass(), vmSettingId.getId()); + history.setVmSettingId(vmSettingId); + } + VmUser vmUserId = history.getVmUserId(); + if (vmUserId != null) { + vmUserId = em.getReference(vmUserId.getClass(), vmUserId.getId()); + history.setVmUserId(vmUserId); + } + List attachedHistoryFieldList = new ArrayList<>(); + for (HistoryField historyFieldListHistoryFieldToAttach : history.getHistoryFieldList()) { + historyFieldListHistoryFieldToAttach = em.getReference(historyFieldListHistoryFieldToAttach.getClass(), historyFieldListHistoryFieldToAttach.getHistoryFieldPK()); + attachedHistoryFieldList.add(historyFieldListHistoryFieldToAttach); + } + history.setHistoryFieldList(attachedHistoryFieldList); + List attachedBaselineList = new ArrayList<>(); + for (Baseline baselineListBaselineToAttach : history.getBaselineList()) { + baselineListBaselineToAttach = em.getReference(baselineListBaselineToAttach.getClass(), baselineListBaselineToAttach.getId()); + attachedBaselineList.add(baselineListBaselineToAttach); + } + history.setBaselineList(attachedBaselineList); + List attachedExecutionStepList = new ArrayList<>(); + for (ExecutionStep executionStepListExecutionStepToAttach : history.getExecutionStepList()) { + executionStepListExecutionStepToAttach = em.getReference(executionStepListExecutionStepToAttach.getClass(), executionStepListExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepList.add(executionStepListExecutionStepToAttach); + } + history.setExecutionStepList(attachedExecutionStepList); + em.persist(history); + if (modifierId != null) { + modifierId.getHistoryModificationList().add(history); + modifierId = em.merge(modifierId); + } + if (requirementId != null) { + requirementId.getHistoryList().add(history); + requirementId = em.merge(requirementId); + } + if (projectId != null) { + projectId.getHistoryList().add(history); + projectId = em.merge(projectId); + } + if (step != null) { + step.getHistoryList().add(history); + step = em.merge(step); + } + if (vmSettingId != null) { + vmSettingId.getHistoryList().add(history); + vmSettingId = em.merge(vmSettingId); + } + if (vmUserId != null) { + vmUserId.getHistoryModificationList().add(history); + vmUserId = em.merge(vmUserId); + } + for (HistoryField historyFieldListHistoryField : history.getHistoryFieldList()) { + History oldHistoryOfHistoryFieldListHistoryField = historyFieldListHistoryField.getHistory(); + historyFieldListHistoryField.setHistory(history); + historyFieldListHistoryField = em.merge(historyFieldListHistoryField); + if (oldHistoryOfHistoryFieldListHistoryField != null) { + oldHistoryOfHistoryFieldListHistoryField.getHistoryFieldList().remove(historyFieldListHistoryField); + oldHistoryOfHistoryFieldListHistoryField = em.merge(oldHistoryOfHistoryFieldListHistoryField); + } + } + for (Baseline baselineListBaseline : history.getBaselineList()) { + baselineListBaseline.getHistoryList().add(history); + baselineListBaseline = em.merge(baselineListBaseline); + } + for (ExecutionStep executionStepListExecutionStep : history.getExecutionStepList()) { + executionStepListExecutionStep.getHistoryList().add(history); + executionStepListExecutionStep = em.merge(executionStepListExecutionStep); + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(History history) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + History persistentHistory = em.find(History.class, history.getId()); + VmUser modifierIdOld = persistentHistory.getModifierId(); + VmUser modifierIdNew = history.getModifierId(); + Requirement requirementIdOld = persistentHistory.getRequirementId(); + Requirement requirementIdNew = history.getRequirementId(); + Project projectIdOld = persistentHistory.getProjectId(); + Project projectIdNew = history.getProjectId(); + Step stepOld = persistentHistory.getStep(); + Step stepNew = history.getStep(); + VmSetting vmSettingIdOld = persistentHistory.getVmSettingId(); + VmSetting vmSettingIdNew = history.getVmSettingId(); + VmUser vmUserIdOld = persistentHistory.getVmUserId(); + VmUser vmUserIdNew = history.getVmUserId(); + List historyFieldListOld = persistentHistory.getHistoryFieldList(); + List historyFieldListNew = history.getHistoryFieldList(); + List baselineListOld = persistentHistory.getBaselineList(); + List baselineListNew = history.getBaselineList(); + List executionStepListOld = persistentHistory.getExecutionStepList(); + List executionStepListNew = history.getExecutionStepList(); + List illegalOrphanMessages = null; + for (HistoryField historyFieldListOldHistoryField : historyFieldListOld) { + if (!historyFieldListNew.contains(historyFieldListOldHistoryField)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain HistoryField " + historyFieldListOldHistoryField + " since its history field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (modifierIdNew != null) { + modifierIdNew = em.getReference(modifierIdNew.getClass(), modifierIdNew.getId()); + history.setModifierId(modifierIdNew); + } + if (requirementIdNew != null) { + requirementIdNew = em.getReference(requirementIdNew.getClass(), requirementIdNew.getId()); + history.setRequirementId(requirementIdNew); + } + if (projectIdNew != null) { + projectIdNew = em.getReference(projectIdNew.getClass(), projectIdNew.getId()); + history.setProjectId(projectIdNew); + } + if (stepNew != null) { + stepNew = em.getReference(stepNew.getClass(), stepNew.getStepPK()); + history.setStep(stepNew); + } + if (vmSettingIdNew != null) { + vmSettingIdNew = em.getReference(vmSettingIdNew.getClass(), vmSettingIdNew.getId()); + history.setVmSettingId(vmSettingIdNew); + } + if (vmUserIdNew != null) { + vmUserIdNew = em.getReference(vmUserIdNew.getClass(), vmUserIdNew.getId()); + history.setVmUserId(vmUserIdNew); + } + List attachedHistoryFieldListNew = new ArrayList<>(); + for (HistoryField historyFieldListNewHistoryFieldToAttach : historyFieldListNew) { + historyFieldListNewHistoryFieldToAttach = em.getReference(historyFieldListNewHistoryFieldToAttach.getClass(), historyFieldListNewHistoryFieldToAttach.getHistoryFieldPK()); + attachedHistoryFieldListNew.add(historyFieldListNewHistoryFieldToAttach); + } + historyFieldListNew = attachedHistoryFieldListNew; + history.setHistoryFieldList(historyFieldListNew); + List attachedBaselineListNew = new ArrayList<>(); + for (Baseline baselineListNewBaselineToAttach : baselineListNew) { + baselineListNewBaselineToAttach = em.getReference(baselineListNewBaselineToAttach.getClass(), baselineListNewBaselineToAttach.getId()); + attachedBaselineListNew.add(baselineListNewBaselineToAttach); + } + baselineListNew = attachedBaselineListNew; + history.setBaselineList(baselineListNew); + List attachedExecutionStepListNew = new ArrayList<>(); + for (ExecutionStep executionStepListNewExecutionStepToAttach : executionStepListNew) { + executionStepListNewExecutionStepToAttach = em.getReference(executionStepListNewExecutionStepToAttach.getClass(), executionStepListNewExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepListNew.add(executionStepListNewExecutionStepToAttach); + } + executionStepListNew = attachedExecutionStepListNew; + history.setExecutionStepList(executionStepListNew); + history = em.merge(history); + if (modifierIdOld != null && !modifierIdOld.equals(modifierIdNew)) { + modifierIdOld.getHistoryModificationList().remove(history); + modifierIdOld = em.merge(modifierIdOld); + } + if (modifierIdNew != null && !modifierIdNew.equals(modifierIdOld)) { + modifierIdNew.getHistoryModificationList().add(history); + modifierIdNew = em.merge(modifierIdNew); + } + if (requirementIdOld != null && !requirementIdOld.equals(requirementIdNew)) { + requirementIdOld.getHistoryList().remove(history); + requirementIdOld = em.merge(requirementIdOld); + } + if (requirementIdNew != null && !requirementIdNew.equals(requirementIdOld)) { + requirementIdNew.getHistoryList().add(history); + requirementIdNew = em.merge(requirementIdNew); + } + if (projectIdOld != null && !projectIdOld.equals(projectIdNew)) { + projectIdOld.getHistoryList().remove(history); + projectIdOld = em.merge(projectIdOld); + } + if (projectIdNew != null && !projectIdNew.equals(projectIdOld)) { + projectIdNew.getHistoryList().add(history); + projectIdNew = em.merge(projectIdNew); + } + if (stepOld != null && !stepOld.equals(stepNew)) { + stepOld.getHistoryList().remove(history); + stepOld = em.merge(stepOld); + } + if (stepNew != null && !stepNew.equals(stepOld)) { + stepNew.getHistoryList().add(history); + stepNew = em.merge(stepNew); + } + if (vmSettingIdOld != null && !vmSettingIdOld.equals(vmSettingIdNew)) { + vmSettingIdOld.getHistoryList().remove(history); + vmSettingIdOld = em.merge(vmSettingIdOld); + } + if (vmSettingIdNew != null && !vmSettingIdNew.equals(vmSettingIdOld)) { + vmSettingIdNew.getHistoryList().add(history); + vmSettingIdNew = em.merge(vmSettingIdNew); + } + if (vmUserIdOld != null && !vmUserIdOld.equals(vmUserIdNew)) { + vmUserIdOld.getHistoryModificationList().remove(history); + vmUserIdOld = em.merge(vmUserIdOld); + } + if (vmUserIdNew != null && !vmUserIdNew.equals(vmUserIdOld)) { + vmUserIdNew.getHistoryModificationList().add(history); + vmUserIdNew = em.merge(vmUserIdNew); + } + for (HistoryField historyFieldListNewHistoryField : historyFieldListNew) { + if (!historyFieldListOld.contains(historyFieldListNewHistoryField)) { + History oldHistoryOfHistoryFieldListNewHistoryField = historyFieldListNewHistoryField.getHistory(); + historyFieldListNewHistoryField.setHistory(history); + historyFieldListNewHistoryField = em.merge(historyFieldListNewHistoryField); + if (oldHistoryOfHistoryFieldListNewHistoryField != null && !oldHistoryOfHistoryFieldListNewHistoryField.equals(history)) { + oldHistoryOfHistoryFieldListNewHistoryField.getHistoryFieldList().remove(historyFieldListNewHistoryField); + oldHistoryOfHistoryFieldListNewHistoryField = em.merge(oldHistoryOfHistoryFieldListNewHistoryField); + } + } + } + for (Baseline baselineListOldBaseline : baselineListOld) { + if (!baselineListNew.contains(baselineListOldBaseline)) { + baselineListOldBaseline.getHistoryList().remove(history); + baselineListOldBaseline = em.merge(baselineListOldBaseline); + } + } + for (Baseline baselineListNewBaseline : baselineListNew) { + if (!baselineListOld.contains(baselineListNewBaseline)) { + baselineListNewBaseline.getHistoryList().add(history); + baselineListNewBaseline = em.merge(baselineListNewBaseline); + } + } + for (ExecutionStep executionStepListOldExecutionStep : executionStepListOld) { + if (!executionStepListNew.contains(executionStepListOldExecutionStep)) { + executionStepListOldExecutionStep.getHistoryList().remove(history); + executionStepListOldExecutionStep = em.merge(executionStepListOldExecutionStep); + } + } + for (ExecutionStep executionStepListNewExecutionStep : executionStepListNew) { + if (!executionStepListOld.contains(executionStepListNewExecutionStep)) { + executionStepListNewExecutionStep.getHistoryList().add(history); + executionStepListNewExecutionStep = em.merge(executionStepListNewExecutionStep); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = history.getId(); + if (findHistory(id) == null) { + throw new NonexistentEntityException("The history with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + History history; + try { + history = em.getReference(History.class, id); + history.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The history with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List historyFieldListOrphanCheck = history.getHistoryFieldList(); + for (HistoryField historyFieldListOrphanCheckHistoryField : historyFieldListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This History (" + history + ") cannot be destroyed since the HistoryField " + historyFieldListOrphanCheckHistoryField + " in its historyFieldList field has a non-nullable history field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + VmUser modifierId = history.getModifierId(); + if (modifierId != null) { + modifierId.getHistoryModificationList().remove(history); + modifierId = em.merge(modifierId); + } + Requirement requirementId = history.getRequirementId(); + if (requirementId != null) { + requirementId.getHistoryList().remove(history); + requirementId = em.merge(requirementId); + } + Project projectId = history.getProjectId(); + if (projectId != null) { + projectId.getHistoryList().remove(history); + projectId = em.merge(projectId); + } + Step step = history.getStep(); + if (step != null) { + step.getHistoryList().remove(history); + step = em.merge(step); + } + VmSetting vmSettingId = history.getVmSettingId(); + if (vmSettingId != null) { + vmSettingId.getHistoryList().remove(history); + vmSettingId = em.merge(vmSettingId); + } + VmUser vmUserId = history.getVmUserId(); + if (vmUserId != null) { + vmUserId.getHistoryModificationList().remove(history); + vmUserId = em.merge(vmUserId); + } + List baselineList = history.getBaselineList(); + for (Baseline baselineListBaseline : baselineList) { + baselineListBaseline.getHistoryList().remove(history); + baselineListBaseline = em.merge(baselineListBaseline); + } + List executionStepList = history.getExecutionStepList(); + for (ExecutionStep executionStepListExecutionStep : executionStepList) { + executionStepListExecutionStep.getHistoryList().remove(history); + executionStepListExecutionStep = em.merge(executionStepListExecutionStep); + } + em.remove(history); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findHistoryEntities() { + return findHistoryEntities(true, -1, -1); + } + + public List findHistoryEntities(int maxResults, int firstResult) { + return findHistoryEntities(false, maxResults, firstResult); + } + + private List findHistoryEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(History.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public History findHistory(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(History.class, id); + } + finally { + em.close(); + } + } + + public int getHistoryCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(History.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/InvestigationJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/InvestigationJpaController.java index 40d5a13b..16cf6165 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/InvestigationJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/InvestigationJpaController.java @@ -13,263 +13,263 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.UserHasInvestigation; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.ExceptionHasInvestigation; -import com.validation.manager.core.db.Investigation; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class InvestigationJpaController implements Serializable { - - public InvestigationJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Investigation investigation) { - if (investigation.getUserHasInvestigationList() == null) { - investigation.setUserHasInvestigationList(new ArrayList()); - } - if (investigation.getExceptionHasInvestigationList() == null) { - investigation.setExceptionHasInvestigationList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedUserHasInvestigationList = new ArrayList(); - for (UserHasInvestigation userHasInvestigationListUserHasInvestigationToAttach : investigation.getUserHasInvestigationList()) { - userHasInvestigationListUserHasInvestigationToAttach = em.getReference(userHasInvestigationListUserHasInvestigationToAttach.getClass(), userHasInvestigationListUserHasInvestigationToAttach.getUserHasInvestigationPK()); - attachedUserHasInvestigationList.add(userHasInvestigationListUserHasInvestigationToAttach); - } - investigation.setUserHasInvestigationList(attachedUserHasInvestigationList); - List attachedExceptionHasInvestigationList = new ArrayList(); - for (ExceptionHasInvestigation exceptionHasInvestigationListExceptionHasInvestigationToAttach : investigation.getExceptionHasInvestigationList()) { - exceptionHasInvestigationListExceptionHasInvestigationToAttach = em.getReference(exceptionHasInvestigationListExceptionHasInvestigationToAttach.getClass(), exceptionHasInvestigationListExceptionHasInvestigationToAttach.getExceptionHasInvestigationPK()); - attachedExceptionHasInvestigationList.add(exceptionHasInvestigationListExceptionHasInvestigationToAttach); - } - investigation.setExceptionHasInvestigationList(attachedExceptionHasInvestigationList); - em.persist(investigation); - for (UserHasInvestigation userHasInvestigationListUserHasInvestigation : investigation.getUserHasInvestigationList()) { - Investigation oldInvestigationOfUserHasInvestigationListUserHasInvestigation = userHasInvestigationListUserHasInvestigation.getInvestigation(); - userHasInvestigationListUserHasInvestigation.setInvestigation(investigation); - userHasInvestigationListUserHasInvestigation = em.merge(userHasInvestigationListUserHasInvestigation); - if (oldInvestigationOfUserHasInvestigationListUserHasInvestigation != null) { - oldInvestigationOfUserHasInvestigationListUserHasInvestigation.getUserHasInvestigationList().remove(userHasInvestigationListUserHasInvestigation); - oldInvestigationOfUserHasInvestigationListUserHasInvestigation = em.merge(oldInvestigationOfUserHasInvestigationListUserHasInvestigation); - } - } - for (ExceptionHasInvestigation exceptionHasInvestigationListExceptionHasInvestigation : investigation.getExceptionHasInvestigationList()) { - Investigation oldInvestigationOfExceptionHasInvestigationListExceptionHasInvestigation = exceptionHasInvestigationListExceptionHasInvestigation.getInvestigation(); - exceptionHasInvestigationListExceptionHasInvestigation.setInvestigation(investigation); - exceptionHasInvestigationListExceptionHasInvestigation = em.merge(exceptionHasInvestigationListExceptionHasInvestigation); - if (oldInvestigationOfExceptionHasInvestigationListExceptionHasInvestigation != null) { - oldInvestigationOfExceptionHasInvestigationListExceptionHasInvestigation.getExceptionHasInvestigationList().remove(exceptionHasInvestigationListExceptionHasInvestigation); - oldInvestigationOfExceptionHasInvestigationListExceptionHasInvestigation = em.merge(oldInvestigationOfExceptionHasInvestigationListExceptionHasInvestigation); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Investigation investigation) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Investigation persistentInvestigation = em.find(Investigation.class, investigation.getId()); - List userHasInvestigationListOld = persistentInvestigation.getUserHasInvestigationList(); - List userHasInvestigationListNew = investigation.getUserHasInvestigationList(); - List exceptionHasInvestigationListOld = persistentInvestigation.getExceptionHasInvestigationList(); - List exceptionHasInvestigationListNew = investigation.getExceptionHasInvestigationList(); - List illegalOrphanMessages = null; - for (UserHasInvestigation userHasInvestigationListOldUserHasInvestigation : userHasInvestigationListOld) { - if (!userHasInvestigationListNew.contains(userHasInvestigationListOldUserHasInvestigation)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserHasInvestigation " + userHasInvestigationListOldUserHasInvestigation + " since its investigation field is not nullable."); - } - } - for (ExceptionHasInvestigation exceptionHasInvestigationListOldExceptionHasInvestigation : exceptionHasInvestigationListOld) { - if (!exceptionHasInvestigationListNew.contains(exceptionHasInvestigationListOldExceptionHasInvestigation)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain ExceptionHasInvestigation " + exceptionHasInvestigationListOldExceptionHasInvestigation + " since its investigation field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedUserHasInvestigationListNew = new ArrayList(); - for (UserHasInvestigation userHasInvestigationListNewUserHasInvestigationToAttach : userHasInvestigationListNew) { - userHasInvestigationListNewUserHasInvestigationToAttach = em.getReference(userHasInvestigationListNewUserHasInvestigationToAttach.getClass(), userHasInvestigationListNewUserHasInvestigationToAttach.getUserHasInvestigationPK()); - attachedUserHasInvestigationListNew.add(userHasInvestigationListNewUserHasInvestigationToAttach); - } - userHasInvestigationListNew = attachedUserHasInvestigationListNew; - investigation.setUserHasInvestigationList(userHasInvestigationListNew); - List attachedExceptionHasInvestigationListNew = new ArrayList(); - for (ExceptionHasInvestigation exceptionHasInvestigationListNewExceptionHasInvestigationToAttach : exceptionHasInvestigationListNew) { - exceptionHasInvestigationListNewExceptionHasInvestigationToAttach = em.getReference(exceptionHasInvestigationListNewExceptionHasInvestigationToAttach.getClass(), exceptionHasInvestigationListNewExceptionHasInvestigationToAttach.getExceptionHasInvestigationPK()); - attachedExceptionHasInvestigationListNew.add(exceptionHasInvestigationListNewExceptionHasInvestigationToAttach); - } - exceptionHasInvestigationListNew = attachedExceptionHasInvestigationListNew; - investigation.setExceptionHasInvestigationList(exceptionHasInvestigationListNew); - investigation = em.merge(investigation); - for (UserHasInvestigation userHasInvestigationListNewUserHasInvestigation : userHasInvestigationListNew) { - if (!userHasInvestigationListOld.contains(userHasInvestigationListNewUserHasInvestigation)) { - Investigation oldInvestigationOfUserHasInvestigationListNewUserHasInvestigation = userHasInvestigationListNewUserHasInvestigation.getInvestigation(); - userHasInvestigationListNewUserHasInvestigation.setInvestigation(investigation); - userHasInvestigationListNewUserHasInvestigation = em.merge(userHasInvestigationListNewUserHasInvestigation); - if (oldInvestigationOfUserHasInvestigationListNewUserHasInvestigation != null && !oldInvestigationOfUserHasInvestigationListNewUserHasInvestigation.equals(investigation)) { - oldInvestigationOfUserHasInvestigationListNewUserHasInvestigation.getUserHasInvestigationList().remove(userHasInvestigationListNewUserHasInvestigation); - oldInvestigationOfUserHasInvestigationListNewUserHasInvestigation = em.merge(oldInvestigationOfUserHasInvestigationListNewUserHasInvestigation); - } - } - } - for (ExceptionHasInvestigation exceptionHasInvestigationListNewExceptionHasInvestigation : exceptionHasInvestigationListNew) { - if (!exceptionHasInvestigationListOld.contains(exceptionHasInvestigationListNewExceptionHasInvestigation)) { - Investigation oldInvestigationOfExceptionHasInvestigationListNewExceptionHasInvestigation = exceptionHasInvestigationListNewExceptionHasInvestigation.getInvestigation(); - exceptionHasInvestigationListNewExceptionHasInvestigation.setInvestigation(investigation); - exceptionHasInvestigationListNewExceptionHasInvestigation = em.merge(exceptionHasInvestigationListNewExceptionHasInvestigation); - if (oldInvestigationOfExceptionHasInvestigationListNewExceptionHasInvestigation != null && !oldInvestigationOfExceptionHasInvestigationListNewExceptionHasInvestigation.equals(investigation)) { - oldInvestigationOfExceptionHasInvestigationListNewExceptionHasInvestigation.getExceptionHasInvestigationList().remove(exceptionHasInvestigationListNewExceptionHasInvestigation); - oldInvestigationOfExceptionHasInvestigationListNewExceptionHasInvestigation = em.merge(oldInvestigationOfExceptionHasInvestigationListNewExceptionHasInvestigation); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = investigation.getId(); - if (findInvestigation(id) == null) { - throw new NonexistentEntityException("The investigation with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Investigation investigation; - try { - investigation = em.getReference(Investigation.class, id); - investigation.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The investigation with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List userHasInvestigationListOrphanCheck = investigation.getUserHasInvestigationList(); - for (UserHasInvestigation userHasInvestigationListOrphanCheckUserHasInvestigation : userHasInvestigationListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Investigation (" + investigation + ") cannot be destroyed since the UserHasInvestigation " + userHasInvestigationListOrphanCheckUserHasInvestigation + " in its userHasInvestigationList field has a non-nullable investigation field."); - } - List exceptionHasInvestigationListOrphanCheck = investigation.getExceptionHasInvestigationList(); - for (ExceptionHasInvestigation exceptionHasInvestigationListOrphanCheckExceptionHasInvestigation : exceptionHasInvestigationListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Investigation (" + investigation + ") cannot be destroyed since the ExceptionHasInvestigation " + exceptionHasInvestigationListOrphanCheckExceptionHasInvestigation + " in its exceptionHasInvestigationList field has a non-nullable investigation field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(investigation); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findInvestigationEntities() { - return findInvestigationEntities(true, -1, -1); - } - - public List findInvestigationEntities(int maxResults, int firstResult) { - return findInvestigationEntities(false, maxResults, firstResult); - } - - private List findInvestigationEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Investigation.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public Investigation findInvestigation(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(Investigation.class, id); - } - finally { - em.close(); - } - } - - public int getInvestigationCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(Investigation.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.UserHasInvestigation; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.ExceptionHasInvestigation; +import com.validation.manager.core.db.Investigation; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class InvestigationJpaController implements Serializable { + + public InvestigationJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Investigation investigation) { + if (investigation.getUserHasInvestigationList() == null) { + investigation.setUserHasInvestigationList(new ArrayList<>()); + } + if (investigation.getExceptionHasInvestigationList() == null) { + investigation.setExceptionHasInvestigationList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedUserHasInvestigationList = new ArrayList<>(); + for (UserHasInvestigation userHasInvestigationListUserHasInvestigationToAttach : investigation.getUserHasInvestigationList()) { + userHasInvestigationListUserHasInvestigationToAttach = em.getReference(userHasInvestigationListUserHasInvestigationToAttach.getClass(), userHasInvestigationListUserHasInvestigationToAttach.getUserHasInvestigationPK()); + attachedUserHasInvestigationList.add(userHasInvestigationListUserHasInvestigationToAttach); + } + investigation.setUserHasInvestigationList(attachedUserHasInvestigationList); + List attachedExceptionHasInvestigationList = new ArrayList<>(); + for (ExceptionHasInvestigation exceptionHasInvestigationListExceptionHasInvestigationToAttach : investigation.getExceptionHasInvestigationList()) { + exceptionHasInvestigationListExceptionHasInvestigationToAttach = em.getReference(exceptionHasInvestigationListExceptionHasInvestigationToAttach.getClass(), exceptionHasInvestigationListExceptionHasInvestigationToAttach.getExceptionHasInvestigationPK()); + attachedExceptionHasInvestigationList.add(exceptionHasInvestigationListExceptionHasInvestigationToAttach); + } + investigation.setExceptionHasInvestigationList(attachedExceptionHasInvestigationList); + em.persist(investigation); + for (UserHasInvestigation userHasInvestigationListUserHasInvestigation : investigation.getUserHasInvestigationList()) { + Investigation oldInvestigationOfUserHasInvestigationListUserHasInvestigation = userHasInvestigationListUserHasInvestigation.getInvestigation(); + userHasInvestigationListUserHasInvestigation.setInvestigation(investigation); + userHasInvestigationListUserHasInvestigation = em.merge(userHasInvestigationListUserHasInvestigation); + if (oldInvestigationOfUserHasInvestigationListUserHasInvestigation != null) { + oldInvestigationOfUserHasInvestigationListUserHasInvestigation.getUserHasInvestigationList().remove(userHasInvestigationListUserHasInvestigation); + oldInvestigationOfUserHasInvestigationListUserHasInvestigation = em.merge(oldInvestigationOfUserHasInvestigationListUserHasInvestigation); + } + } + for (ExceptionHasInvestigation exceptionHasInvestigationListExceptionHasInvestigation : investigation.getExceptionHasInvestigationList()) { + Investigation oldInvestigationOfExceptionHasInvestigationListExceptionHasInvestigation = exceptionHasInvestigationListExceptionHasInvestigation.getInvestigation(); + exceptionHasInvestigationListExceptionHasInvestigation.setInvestigation(investigation); + exceptionHasInvestigationListExceptionHasInvestigation = em.merge(exceptionHasInvestigationListExceptionHasInvestigation); + if (oldInvestigationOfExceptionHasInvestigationListExceptionHasInvestigation != null) { + oldInvestigationOfExceptionHasInvestigationListExceptionHasInvestigation.getExceptionHasInvestigationList().remove(exceptionHasInvestigationListExceptionHasInvestigation); + oldInvestigationOfExceptionHasInvestigationListExceptionHasInvestigation = em.merge(oldInvestigationOfExceptionHasInvestigationListExceptionHasInvestigation); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Investigation investigation) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Investigation persistentInvestigation = em.find(Investigation.class, investigation.getId()); + List userHasInvestigationListOld = persistentInvestigation.getUserHasInvestigationList(); + List userHasInvestigationListNew = investigation.getUserHasInvestigationList(); + List exceptionHasInvestigationListOld = persistentInvestigation.getExceptionHasInvestigationList(); + List exceptionHasInvestigationListNew = investigation.getExceptionHasInvestigationList(); + List illegalOrphanMessages = null; + for (UserHasInvestigation userHasInvestigationListOldUserHasInvestigation : userHasInvestigationListOld) { + if (!userHasInvestigationListNew.contains(userHasInvestigationListOldUserHasInvestigation)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserHasInvestigation " + userHasInvestigationListOldUserHasInvestigation + " since its investigation field is not nullable."); + } + } + for (ExceptionHasInvestigation exceptionHasInvestigationListOldExceptionHasInvestigation : exceptionHasInvestigationListOld) { + if (!exceptionHasInvestigationListNew.contains(exceptionHasInvestigationListOldExceptionHasInvestigation)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain ExceptionHasInvestigation " + exceptionHasInvestigationListOldExceptionHasInvestigation + " since its investigation field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedUserHasInvestigationListNew = new ArrayList<>(); + for (UserHasInvestigation userHasInvestigationListNewUserHasInvestigationToAttach : userHasInvestigationListNew) { + userHasInvestigationListNewUserHasInvestigationToAttach = em.getReference(userHasInvestigationListNewUserHasInvestigationToAttach.getClass(), userHasInvestigationListNewUserHasInvestigationToAttach.getUserHasInvestigationPK()); + attachedUserHasInvestigationListNew.add(userHasInvestigationListNewUserHasInvestigationToAttach); + } + userHasInvestigationListNew = attachedUserHasInvestigationListNew; + investigation.setUserHasInvestigationList(userHasInvestigationListNew); + List attachedExceptionHasInvestigationListNew = new ArrayList<>(); + for (ExceptionHasInvestigation exceptionHasInvestigationListNewExceptionHasInvestigationToAttach : exceptionHasInvestigationListNew) { + exceptionHasInvestigationListNewExceptionHasInvestigationToAttach = em.getReference(exceptionHasInvestigationListNewExceptionHasInvestigationToAttach.getClass(), exceptionHasInvestigationListNewExceptionHasInvestigationToAttach.getExceptionHasInvestigationPK()); + attachedExceptionHasInvestigationListNew.add(exceptionHasInvestigationListNewExceptionHasInvestigationToAttach); + } + exceptionHasInvestigationListNew = attachedExceptionHasInvestigationListNew; + investigation.setExceptionHasInvestigationList(exceptionHasInvestigationListNew); + investigation = em.merge(investigation); + for (UserHasInvestigation userHasInvestigationListNewUserHasInvestigation : userHasInvestigationListNew) { + if (!userHasInvestigationListOld.contains(userHasInvestigationListNewUserHasInvestigation)) { + Investigation oldInvestigationOfUserHasInvestigationListNewUserHasInvestigation = userHasInvestigationListNewUserHasInvestigation.getInvestigation(); + userHasInvestigationListNewUserHasInvestigation.setInvestigation(investigation); + userHasInvestigationListNewUserHasInvestigation = em.merge(userHasInvestigationListNewUserHasInvestigation); + if (oldInvestigationOfUserHasInvestigationListNewUserHasInvestigation != null && !oldInvestigationOfUserHasInvestigationListNewUserHasInvestigation.equals(investigation)) { + oldInvestigationOfUserHasInvestigationListNewUserHasInvestigation.getUserHasInvestigationList().remove(userHasInvestigationListNewUserHasInvestigation); + oldInvestigationOfUserHasInvestigationListNewUserHasInvestigation = em.merge(oldInvestigationOfUserHasInvestigationListNewUserHasInvestigation); + } + } + } + for (ExceptionHasInvestigation exceptionHasInvestigationListNewExceptionHasInvestigation : exceptionHasInvestigationListNew) { + if (!exceptionHasInvestigationListOld.contains(exceptionHasInvestigationListNewExceptionHasInvestigation)) { + Investigation oldInvestigationOfExceptionHasInvestigationListNewExceptionHasInvestigation = exceptionHasInvestigationListNewExceptionHasInvestigation.getInvestigation(); + exceptionHasInvestigationListNewExceptionHasInvestigation.setInvestigation(investigation); + exceptionHasInvestigationListNewExceptionHasInvestigation = em.merge(exceptionHasInvestigationListNewExceptionHasInvestigation); + if (oldInvestigationOfExceptionHasInvestigationListNewExceptionHasInvestigation != null && !oldInvestigationOfExceptionHasInvestigationListNewExceptionHasInvestigation.equals(investigation)) { + oldInvestigationOfExceptionHasInvestigationListNewExceptionHasInvestigation.getExceptionHasInvestigationList().remove(exceptionHasInvestigationListNewExceptionHasInvestigation); + oldInvestigationOfExceptionHasInvestigationListNewExceptionHasInvestigation = em.merge(oldInvestigationOfExceptionHasInvestigationListNewExceptionHasInvestigation); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = investigation.getId(); + if (findInvestigation(id) == null) { + throw new NonexistentEntityException("The investigation with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Investigation investigation; + try { + investigation = em.getReference(Investigation.class, id); + investigation.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The investigation with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List userHasInvestigationListOrphanCheck = investigation.getUserHasInvestigationList(); + for (UserHasInvestigation userHasInvestigationListOrphanCheckUserHasInvestigation : userHasInvestigationListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Investigation (" + investigation + ") cannot be destroyed since the UserHasInvestigation " + userHasInvestigationListOrphanCheckUserHasInvestigation + " in its userHasInvestigationList field has a non-nullable investigation field."); + } + List exceptionHasInvestigationListOrphanCheck = investigation.getExceptionHasInvestigationList(); + for (ExceptionHasInvestigation exceptionHasInvestigationListOrphanCheckExceptionHasInvestigation : exceptionHasInvestigationListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Investigation (" + investigation + ") cannot be destroyed since the ExceptionHasInvestigation " + exceptionHasInvestigationListOrphanCheckExceptionHasInvestigation + " in its exceptionHasInvestigationList field has a non-nullable investigation field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(investigation); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findInvestigationEntities() { + return findInvestigationEntities(true, -1, -1); + } + + public List findInvestigationEntities(int maxResults, int firstResult) { + return findInvestigationEntities(false, maxResults, firstResult); + } + + private List findInvestigationEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Investigation.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public Investigation findInvestigation(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(Investigation.class, id); + } + finally { + em.close(); + } + } + + public int getInvestigationCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Investigation.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/IssueJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/IssueJpaController.java index 1e1a39a2..7dd13592 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/IssueJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/IssueJpaController.java @@ -13,280 +13,280 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.IssueResolution; -import com.validation.manager.core.db.IssueType; -import com.validation.manager.core.db.ExecutionStepHasIssue; -import com.validation.manager.core.db.Issue; -import com.validation.manager.core.db.IssuePK; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class IssueJpaController implements Serializable { - - public IssueJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Issue issue) throws PreexistingEntityException, Exception { - if (issue.getIssuePK() == null) { - issue.setIssuePK(new IssuePK()); - } - if (issue.getExecutionStepHasIssueList() == null) { - issue.setExecutionStepHasIssueList(new ArrayList()); - } - issue.getIssuePK().setIssueTypeId(issue.getIssueType().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - IssueResolution issueResolutionId = issue.getIssueResolutionId(); - if (issueResolutionId != null) { - issueResolutionId = em.getReference(issueResolutionId.getClass(), issueResolutionId.getId()); - issue.setIssueResolutionId(issueResolutionId); - } - IssueType issueType = issue.getIssueType(); - if (issueType != null) { - issueType = em.getReference(issueType.getClass(), issueType.getId()); - issue.setIssueType(issueType); - } - List attachedExecutionStepHasIssueList = new ArrayList(); - for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssueToAttach : issue.getExecutionStepHasIssueList()) { - executionStepHasIssueListExecutionStepHasIssueToAttach = em.getReference(executionStepHasIssueListExecutionStepHasIssueToAttach.getClass(), executionStepHasIssueListExecutionStepHasIssueToAttach.getExecutionStepHasIssuePK()); - attachedExecutionStepHasIssueList.add(executionStepHasIssueListExecutionStepHasIssueToAttach); - } - issue.setExecutionStepHasIssueList(attachedExecutionStepHasIssueList); - em.persist(issue); - if (issueResolutionId != null) { - issueResolutionId.getIssueList().add(issue); - issueResolutionId = em.merge(issueResolutionId); - } - if (issueType != null) { - issueType.getIssueList().add(issue); - issueType = em.merge(issueType); - } - for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssue : issue.getExecutionStepHasIssueList()) { - Issue oldIssueOfExecutionStepHasIssueListExecutionStepHasIssue = executionStepHasIssueListExecutionStepHasIssue.getIssue(); - executionStepHasIssueListExecutionStepHasIssue.setIssue(issue); - executionStepHasIssueListExecutionStepHasIssue = em.merge(executionStepHasIssueListExecutionStepHasIssue); - if (oldIssueOfExecutionStepHasIssueListExecutionStepHasIssue != null) { - oldIssueOfExecutionStepHasIssueListExecutionStepHasIssue.getExecutionStepHasIssueList().remove(executionStepHasIssueListExecutionStepHasIssue); - oldIssueOfExecutionStepHasIssueListExecutionStepHasIssue = em.merge(oldIssueOfExecutionStepHasIssueListExecutionStepHasIssue); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - if (findIssue(issue.getIssuePK()) != null) { - throw new PreexistingEntityException("Issue " + issue + " already exists.", ex); - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Issue issue) throws IllegalOrphanException, NonexistentEntityException, Exception { - issue.getIssuePK().setIssueTypeId(issue.getIssueType().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Issue persistentIssue = em.find(Issue.class, issue.getIssuePK()); - IssueResolution issueResolutionIdOld = persistentIssue.getIssueResolutionId(); - IssueResolution issueResolutionIdNew = issue.getIssueResolutionId(); - IssueType issueTypeOld = persistentIssue.getIssueType(); - IssueType issueTypeNew = issue.getIssueType(); - List executionStepHasIssueListOld = persistentIssue.getExecutionStepHasIssueList(); - List executionStepHasIssueListNew = issue.getExecutionStepHasIssueList(); - List illegalOrphanMessages = null; - for (ExecutionStepHasIssue executionStepHasIssueListOldExecutionStepHasIssue : executionStepHasIssueListOld) { - if (!executionStepHasIssueListNew.contains(executionStepHasIssueListOldExecutionStepHasIssue)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain ExecutionStepHasIssue " + executionStepHasIssueListOldExecutionStepHasIssue + " since its issue field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (issueResolutionIdNew != null) { - issueResolutionIdNew = em.getReference(issueResolutionIdNew.getClass(), issueResolutionIdNew.getId()); - issue.setIssueResolutionId(issueResolutionIdNew); - } - if (issueTypeNew != null) { - issueTypeNew = em.getReference(issueTypeNew.getClass(), issueTypeNew.getId()); - issue.setIssueType(issueTypeNew); - } - List attachedExecutionStepHasIssueListNew = new ArrayList(); - for (ExecutionStepHasIssue executionStepHasIssueListNewExecutionStepHasIssueToAttach : executionStepHasIssueListNew) { - executionStepHasIssueListNewExecutionStepHasIssueToAttach = em.getReference(executionStepHasIssueListNewExecutionStepHasIssueToAttach.getClass(), executionStepHasIssueListNewExecutionStepHasIssueToAttach.getExecutionStepHasIssuePK()); - attachedExecutionStepHasIssueListNew.add(executionStepHasIssueListNewExecutionStepHasIssueToAttach); - } - executionStepHasIssueListNew = attachedExecutionStepHasIssueListNew; - issue.setExecutionStepHasIssueList(executionStepHasIssueListNew); - issue = em.merge(issue); - if (issueResolutionIdOld != null && !issueResolutionIdOld.equals(issueResolutionIdNew)) { - issueResolutionIdOld.getIssueList().remove(issue); - issueResolutionIdOld = em.merge(issueResolutionIdOld); - } - if (issueResolutionIdNew != null && !issueResolutionIdNew.equals(issueResolutionIdOld)) { - issueResolutionIdNew.getIssueList().add(issue); - issueResolutionIdNew = em.merge(issueResolutionIdNew); - } - if (issueTypeOld != null && !issueTypeOld.equals(issueTypeNew)) { - issueTypeOld.getIssueList().remove(issue); - issueTypeOld = em.merge(issueTypeOld); - } - if (issueTypeNew != null && !issueTypeNew.equals(issueTypeOld)) { - issueTypeNew.getIssueList().add(issue); - issueTypeNew = em.merge(issueTypeNew); - } - for (ExecutionStepHasIssue executionStepHasIssueListNewExecutionStepHasIssue : executionStepHasIssueListNew) { - if (!executionStepHasIssueListOld.contains(executionStepHasIssueListNewExecutionStepHasIssue)) { - Issue oldIssueOfExecutionStepHasIssueListNewExecutionStepHasIssue = executionStepHasIssueListNewExecutionStepHasIssue.getIssue(); - executionStepHasIssueListNewExecutionStepHasIssue.setIssue(issue); - executionStepHasIssueListNewExecutionStepHasIssue = em.merge(executionStepHasIssueListNewExecutionStepHasIssue); - if (oldIssueOfExecutionStepHasIssueListNewExecutionStepHasIssue != null && !oldIssueOfExecutionStepHasIssueListNewExecutionStepHasIssue.equals(issue)) { - oldIssueOfExecutionStepHasIssueListNewExecutionStepHasIssue.getExecutionStepHasIssueList().remove(executionStepHasIssueListNewExecutionStepHasIssue); - oldIssueOfExecutionStepHasIssueListNewExecutionStepHasIssue = em.merge(oldIssueOfExecutionStepHasIssueListNewExecutionStepHasIssue); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - IssuePK id = issue.getIssuePK(); - if (findIssue(id) == null) { - throw new NonexistentEntityException("The issue with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(IssuePK id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Issue issue; - try { - issue = em.getReference(Issue.class, id); - issue.getIssuePK(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The issue with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List executionStepHasIssueListOrphanCheck = issue.getExecutionStepHasIssueList(); - for (ExecutionStepHasIssue executionStepHasIssueListOrphanCheckExecutionStepHasIssue : executionStepHasIssueListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Issue (" + issue + ") cannot be destroyed since the ExecutionStepHasIssue " + executionStepHasIssueListOrphanCheckExecutionStepHasIssue + " in its executionStepHasIssueList field has a non-nullable issue field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - IssueResolution issueResolutionId = issue.getIssueResolutionId(); - if (issueResolutionId != null) { - issueResolutionId.getIssueList().remove(issue); - issueResolutionId = em.merge(issueResolutionId); - } - IssueType issueType = issue.getIssueType(); - if (issueType != null) { - issueType.getIssueList().remove(issue); - issueType = em.merge(issueType); - } - em.remove(issue); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findIssueEntities() { - return findIssueEntities(true, -1, -1); - } - - public List findIssueEntities(int maxResults, int firstResult) { - return findIssueEntities(false, maxResults, firstResult); - } - - private List findIssueEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Issue.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public Issue findIssue(IssuePK id) { - EntityManager em = getEntityManager(); - try { - return em.find(Issue.class, id); - } - finally { - em.close(); - } - } - - public int getIssueCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(Issue.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.IssueResolution; +import com.validation.manager.core.db.IssueType; +import com.validation.manager.core.db.ExecutionStepHasIssue; +import com.validation.manager.core.db.Issue; +import com.validation.manager.core.db.IssuePK; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class IssueJpaController implements Serializable { + + public IssueJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Issue issue) throws PreexistingEntityException, Exception { + if (issue.getIssuePK() == null) { + issue.setIssuePK(new IssuePK()); + } + if (issue.getExecutionStepHasIssueList() == null) { + issue.setExecutionStepHasIssueList(new ArrayList<>()); + } + issue.getIssuePK().setIssueTypeId(issue.getIssueType().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + IssueResolution issueResolutionId = issue.getIssueResolutionId(); + if (issueResolutionId != null) { + issueResolutionId = em.getReference(issueResolutionId.getClass(), issueResolutionId.getId()); + issue.setIssueResolutionId(issueResolutionId); + } + IssueType issueType = issue.getIssueType(); + if (issueType != null) { + issueType = em.getReference(issueType.getClass(), issueType.getId()); + issue.setIssueType(issueType); + } + List attachedExecutionStepHasIssueList = new ArrayList<>(); + for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssueToAttach : issue.getExecutionStepHasIssueList()) { + executionStepHasIssueListExecutionStepHasIssueToAttach = em.getReference(executionStepHasIssueListExecutionStepHasIssueToAttach.getClass(), executionStepHasIssueListExecutionStepHasIssueToAttach.getExecutionStepHasIssuePK()); + attachedExecutionStepHasIssueList.add(executionStepHasIssueListExecutionStepHasIssueToAttach); + } + issue.setExecutionStepHasIssueList(attachedExecutionStepHasIssueList); + em.persist(issue); + if (issueResolutionId != null) { + issueResolutionId.getIssueList().add(issue); + issueResolutionId = em.merge(issueResolutionId); + } + if (issueType != null) { + issueType.getIssueList().add(issue); + issueType = em.merge(issueType); + } + for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssue : issue.getExecutionStepHasIssueList()) { + Issue oldIssueOfExecutionStepHasIssueListExecutionStepHasIssue = executionStepHasIssueListExecutionStepHasIssue.getIssue(); + executionStepHasIssueListExecutionStepHasIssue.setIssue(issue); + executionStepHasIssueListExecutionStepHasIssue = em.merge(executionStepHasIssueListExecutionStepHasIssue); + if (oldIssueOfExecutionStepHasIssueListExecutionStepHasIssue != null) { + oldIssueOfExecutionStepHasIssueListExecutionStepHasIssue.getExecutionStepHasIssueList().remove(executionStepHasIssueListExecutionStepHasIssue); + oldIssueOfExecutionStepHasIssueListExecutionStepHasIssue = em.merge(oldIssueOfExecutionStepHasIssueListExecutionStepHasIssue); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + if (findIssue(issue.getIssuePK()) != null) { + throw new PreexistingEntityException("Issue " + issue + " already exists.", ex); + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Issue issue) throws IllegalOrphanException, NonexistentEntityException, Exception { + issue.getIssuePK().setIssueTypeId(issue.getIssueType().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Issue persistentIssue = em.find(Issue.class, issue.getIssuePK()); + IssueResolution issueResolutionIdOld = persistentIssue.getIssueResolutionId(); + IssueResolution issueResolutionIdNew = issue.getIssueResolutionId(); + IssueType issueTypeOld = persistentIssue.getIssueType(); + IssueType issueTypeNew = issue.getIssueType(); + List executionStepHasIssueListOld = persistentIssue.getExecutionStepHasIssueList(); + List executionStepHasIssueListNew = issue.getExecutionStepHasIssueList(); + List illegalOrphanMessages = null; + for (ExecutionStepHasIssue executionStepHasIssueListOldExecutionStepHasIssue : executionStepHasIssueListOld) { + if (!executionStepHasIssueListNew.contains(executionStepHasIssueListOldExecutionStepHasIssue)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain ExecutionStepHasIssue " + executionStepHasIssueListOldExecutionStepHasIssue + " since its issue field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (issueResolutionIdNew != null) { + issueResolutionIdNew = em.getReference(issueResolutionIdNew.getClass(), issueResolutionIdNew.getId()); + issue.setIssueResolutionId(issueResolutionIdNew); + } + if (issueTypeNew != null) { + issueTypeNew = em.getReference(issueTypeNew.getClass(), issueTypeNew.getId()); + issue.setIssueType(issueTypeNew); + } + List attachedExecutionStepHasIssueListNew = new ArrayList<>(); + for (ExecutionStepHasIssue executionStepHasIssueListNewExecutionStepHasIssueToAttach : executionStepHasIssueListNew) { + executionStepHasIssueListNewExecutionStepHasIssueToAttach = em.getReference(executionStepHasIssueListNewExecutionStepHasIssueToAttach.getClass(), executionStepHasIssueListNewExecutionStepHasIssueToAttach.getExecutionStepHasIssuePK()); + attachedExecutionStepHasIssueListNew.add(executionStepHasIssueListNewExecutionStepHasIssueToAttach); + } + executionStepHasIssueListNew = attachedExecutionStepHasIssueListNew; + issue.setExecutionStepHasIssueList(executionStepHasIssueListNew); + issue = em.merge(issue); + if (issueResolutionIdOld != null && !issueResolutionIdOld.equals(issueResolutionIdNew)) { + issueResolutionIdOld.getIssueList().remove(issue); + issueResolutionIdOld = em.merge(issueResolutionIdOld); + } + if (issueResolutionIdNew != null && !issueResolutionIdNew.equals(issueResolutionIdOld)) { + issueResolutionIdNew.getIssueList().add(issue); + issueResolutionIdNew = em.merge(issueResolutionIdNew); + } + if (issueTypeOld != null && !issueTypeOld.equals(issueTypeNew)) { + issueTypeOld.getIssueList().remove(issue); + issueTypeOld = em.merge(issueTypeOld); + } + if (issueTypeNew != null && !issueTypeNew.equals(issueTypeOld)) { + issueTypeNew.getIssueList().add(issue); + issueTypeNew = em.merge(issueTypeNew); + } + for (ExecutionStepHasIssue executionStepHasIssueListNewExecutionStepHasIssue : executionStepHasIssueListNew) { + if (!executionStepHasIssueListOld.contains(executionStepHasIssueListNewExecutionStepHasIssue)) { + Issue oldIssueOfExecutionStepHasIssueListNewExecutionStepHasIssue = executionStepHasIssueListNewExecutionStepHasIssue.getIssue(); + executionStepHasIssueListNewExecutionStepHasIssue.setIssue(issue); + executionStepHasIssueListNewExecutionStepHasIssue = em.merge(executionStepHasIssueListNewExecutionStepHasIssue); + if (oldIssueOfExecutionStepHasIssueListNewExecutionStepHasIssue != null && !oldIssueOfExecutionStepHasIssueListNewExecutionStepHasIssue.equals(issue)) { + oldIssueOfExecutionStepHasIssueListNewExecutionStepHasIssue.getExecutionStepHasIssueList().remove(executionStepHasIssueListNewExecutionStepHasIssue); + oldIssueOfExecutionStepHasIssueListNewExecutionStepHasIssue = em.merge(oldIssueOfExecutionStepHasIssueListNewExecutionStepHasIssue); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + IssuePK id = issue.getIssuePK(); + if (findIssue(id) == null) { + throw new NonexistentEntityException("The issue with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(IssuePK id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Issue issue; + try { + issue = em.getReference(Issue.class, id); + issue.getIssuePK(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The issue with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List executionStepHasIssueListOrphanCheck = issue.getExecutionStepHasIssueList(); + for (ExecutionStepHasIssue executionStepHasIssueListOrphanCheckExecutionStepHasIssue : executionStepHasIssueListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Issue (" + issue + ") cannot be destroyed since the ExecutionStepHasIssue " + executionStepHasIssueListOrphanCheckExecutionStepHasIssue + " in its executionStepHasIssueList field has a non-nullable issue field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + IssueResolution issueResolutionId = issue.getIssueResolutionId(); + if (issueResolutionId != null) { + issueResolutionId.getIssueList().remove(issue); + issueResolutionId = em.merge(issueResolutionId); + } + IssueType issueType = issue.getIssueType(); + if (issueType != null) { + issueType.getIssueList().remove(issue); + issueType = em.merge(issueType); + } + em.remove(issue); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findIssueEntities() { + return findIssueEntities(true, -1, -1); + } + + public List findIssueEntities(int maxResults, int firstResult) { + return findIssueEntities(false, maxResults, firstResult); + } + + private List findIssueEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Issue.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public Issue findIssue(IssuePK id) { + EntityManager em = getEntityManager(); + try { + return em.find(Issue.class, id); + } + finally { + em.close(); + } + } + + public int getIssueCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Issue.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/IssueResolutionJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/IssueResolutionJpaController.java index 261af4bf..9a959957 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/IssueResolutionJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/IssueResolutionJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Issue; -import com.validation.manager.core.db.IssueResolution; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class IssueResolutionJpaController implements Serializable { - - public IssueResolutionJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(IssueResolution issueResolution) { - if (issueResolution.getIssueList() == null) { - issueResolution.setIssueList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedIssueList = new ArrayList(); - for (Issue issueListIssueToAttach : issueResolution.getIssueList()) { - issueListIssueToAttach = em.getReference(issueListIssueToAttach.getClass(), issueListIssueToAttach.getIssuePK()); - attachedIssueList.add(issueListIssueToAttach); - } - issueResolution.setIssueList(attachedIssueList); - em.persist(issueResolution); - for (Issue issueListIssue : issueResolution.getIssueList()) { - IssueResolution oldIssueResolutionIdOfIssueListIssue = issueListIssue.getIssueResolutionId(); - issueListIssue.setIssueResolutionId(issueResolution); - issueListIssue = em.merge(issueListIssue); - if (oldIssueResolutionIdOfIssueListIssue != null) { - oldIssueResolutionIdOfIssueListIssue.getIssueList().remove(issueListIssue); - oldIssueResolutionIdOfIssueListIssue = em.merge(oldIssueResolutionIdOfIssueListIssue); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(IssueResolution issueResolution) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - IssueResolution persistentIssueResolution = em.find(IssueResolution.class, issueResolution.getId()); - List issueListOld = persistentIssueResolution.getIssueList(); - List issueListNew = issueResolution.getIssueList(); - List illegalOrphanMessages = null; - for (Issue issueListOldIssue : issueListOld) { - if (!issueListNew.contains(issueListOldIssue)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain Issue " + issueListOldIssue + " since its issueResolutionId field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedIssueListNew = new ArrayList(); - for (Issue issueListNewIssueToAttach : issueListNew) { - issueListNewIssueToAttach = em.getReference(issueListNewIssueToAttach.getClass(), issueListNewIssueToAttach.getIssuePK()); - attachedIssueListNew.add(issueListNewIssueToAttach); - } - issueListNew = attachedIssueListNew; - issueResolution.setIssueList(issueListNew); - issueResolution = em.merge(issueResolution); - for (Issue issueListNewIssue : issueListNew) { - if (!issueListOld.contains(issueListNewIssue)) { - IssueResolution oldIssueResolutionIdOfIssueListNewIssue = issueListNewIssue.getIssueResolutionId(); - issueListNewIssue.setIssueResolutionId(issueResolution); - issueListNewIssue = em.merge(issueListNewIssue); - if (oldIssueResolutionIdOfIssueListNewIssue != null && !oldIssueResolutionIdOfIssueListNewIssue.equals(issueResolution)) { - oldIssueResolutionIdOfIssueListNewIssue.getIssueList().remove(issueListNewIssue); - oldIssueResolutionIdOfIssueListNewIssue = em.merge(oldIssueResolutionIdOfIssueListNewIssue); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = issueResolution.getId(); - if (findIssueResolution(id) == null) { - throw new NonexistentEntityException("The issueResolution with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - IssueResolution issueResolution; - try { - issueResolution = em.getReference(IssueResolution.class, id); - issueResolution.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The issueResolution with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List issueListOrphanCheck = issueResolution.getIssueList(); - for (Issue issueListOrphanCheckIssue : issueListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This IssueResolution (" + issueResolution + ") cannot be destroyed since the Issue " + issueListOrphanCheckIssue + " in its issueList field has a non-nullable issueResolutionId field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(issueResolution); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findIssueResolutionEntities() { - return findIssueResolutionEntities(true, -1, -1); - } - - public List findIssueResolutionEntities(int maxResults, int firstResult) { - return findIssueResolutionEntities(false, maxResults, firstResult); - } - - private List findIssueResolutionEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(IssueResolution.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public IssueResolution findIssueResolution(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(IssueResolution.class, id); - } - finally { - em.close(); - } - } - - public int getIssueResolutionCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(IssueResolution.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Issue; +import com.validation.manager.core.db.IssueResolution; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class IssueResolutionJpaController implements Serializable { + + public IssueResolutionJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(IssueResolution issueResolution) { + if (issueResolution.getIssueList() == null) { + issueResolution.setIssueList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedIssueList = new ArrayList<>(); + for (Issue issueListIssueToAttach : issueResolution.getIssueList()) { + issueListIssueToAttach = em.getReference(issueListIssueToAttach.getClass(), issueListIssueToAttach.getIssuePK()); + attachedIssueList.add(issueListIssueToAttach); + } + issueResolution.setIssueList(attachedIssueList); + em.persist(issueResolution); + for (Issue issueListIssue : issueResolution.getIssueList()) { + IssueResolution oldIssueResolutionIdOfIssueListIssue = issueListIssue.getIssueResolutionId(); + issueListIssue.setIssueResolutionId(issueResolution); + issueListIssue = em.merge(issueListIssue); + if (oldIssueResolutionIdOfIssueListIssue != null) { + oldIssueResolutionIdOfIssueListIssue.getIssueList().remove(issueListIssue); + oldIssueResolutionIdOfIssueListIssue = em.merge(oldIssueResolutionIdOfIssueListIssue); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(IssueResolution issueResolution) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + IssueResolution persistentIssueResolution = em.find(IssueResolution.class, issueResolution.getId()); + List issueListOld = persistentIssueResolution.getIssueList(); + List issueListNew = issueResolution.getIssueList(); + List illegalOrphanMessages = null; + for (Issue issueListOldIssue : issueListOld) { + if (!issueListNew.contains(issueListOldIssue)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain Issue " + issueListOldIssue + " since its issueResolutionId field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedIssueListNew = new ArrayList<>(); + for (Issue issueListNewIssueToAttach : issueListNew) { + issueListNewIssueToAttach = em.getReference(issueListNewIssueToAttach.getClass(), issueListNewIssueToAttach.getIssuePK()); + attachedIssueListNew.add(issueListNewIssueToAttach); + } + issueListNew = attachedIssueListNew; + issueResolution.setIssueList(issueListNew); + issueResolution = em.merge(issueResolution); + for (Issue issueListNewIssue : issueListNew) { + if (!issueListOld.contains(issueListNewIssue)) { + IssueResolution oldIssueResolutionIdOfIssueListNewIssue = issueListNewIssue.getIssueResolutionId(); + issueListNewIssue.setIssueResolutionId(issueResolution); + issueListNewIssue = em.merge(issueListNewIssue); + if (oldIssueResolutionIdOfIssueListNewIssue != null && !oldIssueResolutionIdOfIssueListNewIssue.equals(issueResolution)) { + oldIssueResolutionIdOfIssueListNewIssue.getIssueList().remove(issueListNewIssue); + oldIssueResolutionIdOfIssueListNewIssue = em.merge(oldIssueResolutionIdOfIssueListNewIssue); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = issueResolution.getId(); + if (findIssueResolution(id) == null) { + throw new NonexistentEntityException("The issueResolution with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + IssueResolution issueResolution; + try { + issueResolution = em.getReference(IssueResolution.class, id); + issueResolution.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The issueResolution with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List issueListOrphanCheck = issueResolution.getIssueList(); + for (Issue issueListOrphanCheckIssue : issueListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This IssueResolution (" + issueResolution + ") cannot be destroyed since the Issue " + issueListOrphanCheckIssue + " in its issueList field has a non-nullable issueResolutionId field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(issueResolution); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findIssueResolutionEntities() { + return findIssueResolutionEntities(true, -1, -1); + } + + public List findIssueResolutionEntities(int maxResults, int firstResult) { + return findIssueResolutionEntities(false, maxResults, firstResult); + } + + private List findIssueResolutionEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(IssueResolution.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public IssueResolution findIssueResolution(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(IssueResolution.class, id); + } + finally { + em.close(); + } + } + + public int getIssueResolutionCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(IssueResolution.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/IssueTypeJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/IssueTypeJpaController.java index baadbdf6..194c050a 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/IssueTypeJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/IssueTypeJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Issue; -import com.validation.manager.core.db.IssueType; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class IssueTypeJpaController implements Serializable { - - public IssueTypeJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(IssueType issueType) { - if (issueType.getIssueList() == null) { - issueType.setIssueList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedIssueList = new ArrayList(); - for (Issue issueListIssueToAttach : issueType.getIssueList()) { - issueListIssueToAttach = em.getReference(issueListIssueToAttach.getClass(), issueListIssueToAttach.getIssuePK()); - attachedIssueList.add(issueListIssueToAttach); - } - issueType.setIssueList(attachedIssueList); - em.persist(issueType); - for (Issue issueListIssue : issueType.getIssueList()) { - IssueType oldIssueTypeOfIssueListIssue = issueListIssue.getIssueType(); - issueListIssue.setIssueType(issueType); - issueListIssue = em.merge(issueListIssue); - if (oldIssueTypeOfIssueListIssue != null) { - oldIssueTypeOfIssueListIssue.getIssueList().remove(issueListIssue); - oldIssueTypeOfIssueListIssue = em.merge(oldIssueTypeOfIssueListIssue); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(IssueType issueType) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - IssueType persistentIssueType = em.find(IssueType.class, issueType.getId()); - List issueListOld = persistentIssueType.getIssueList(); - List issueListNew = issueType.getIssueList(); - List illegalOrphanMessages = null; - for (Issue issueListOldIssue : issueListOld) { - if (!issueListNew.contains(issueListOldIssue)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain Issue " + issueListOldIssue + " since its issueType field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedIssueListNew = new ArrayList(); - for (Issue issueListNewIssueToAttach : issueListNew) { - issueListNewIssueToAttach = em.getReference(issueListNewIssueToAttach.getClass(), issueListNewIssueToAttach.getIssuePK()); - attachedIssueListNew.add(issueListNewIssueToAttach); - } - issueListNew = attachedIssueListNew; - issueType.setIssueList(issueListNew); - issueType = em.merge(issueType); - for (Issue issueListNewIssue : issueListNew) { - if (!issueListOld.contains(issueListNewIssue)) { - IssueType oldIssueTypeOfIssueListNewIssue = issueListNewIssue.getIssueType(); - issueListNewIssue.setIssueType(issueType); - issueListNewIssue = em.merge(issueListNewIssue); - if (oldIssueTypeOfIssueListNewIssue != null && !oldIssueTypeOfIssueListNewIssue.equals(issueType)) { - oldIssueTypeOfIssueListNewIssue.getIssueList().remove(issueListNewIssue); - oldIssueTypeOfIssueListNewIssue = em.merge(oldIssueTypeOfIssueListNewIssue); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = issueType.getId(); - if (findIssueType(id) == null) { - throw new NonexistentEntityException("The issueType with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - IssueType issueType; - try { - issueType = em.getReference(IssueType.class, id); - issueType.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The issueType with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List issueListOrphanCheck = issueType.getIssueList(); - for (Issue issueListOrphanCheckIssue : issueListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This IssueType (" + issueType + ") cannot be destroyed since the Issue " + issueListOrphanCheckIssue + " in its issueList field has a non-nullable issueType field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(issueType); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findIssueTypeEntities() { - return findIssueTypeEntities(true, -1, -1); - } - - public List findIssueTypeEntities(int maxResults, int firstResult) { - return findIssueTypeEntities(false, maxResults, firstResult); - } - - private List findIssueTypeEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(IssueType.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public IssueType findIssueType(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(IssueType.class, id); - } - finally { - em.close(); - } - } - - public int getIssueTypeCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(IssueType.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Issue; +import com.validation.manager.core.db.IssueType; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class IssueTypeJpaController implements Serializable { + + public IssueTypeJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(IssueType issueType) { + if (issueType.getIssueList() == null) { + issueType.setIssueList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedIssueList = new ArrayList<>(); + for (Issue issueListIssueToAttach : issueType.getIssueList()) { + issueListIssueToAttach = em.getReference(issueListIssueToAttach.getClass(), issueListIssueToAttach.getIssuePK()); + attachedIssueList.add(issueListIssueToAttach); + } + issueType.setIssueList(attachedIssueList); + em.persist(issueType); + for (Issue issueListIssue : issueType.getIssueList()) { + IssueType oldIssueTypeOfIssueListIssue = issueListIssue.getIssueType(); + issueListIssue.setIssueType(issueType); + issueListIssue = em.merge(issueListIssue); + if (oldIssueTypeOfIssueListIssue != null) { + oldIssueTypeOfIssueListIssue.getIssueList().remove(issueListIssue); + oldIssueTypeOfIssueListIssue = em.merge(oldIssueTypeOfIssueListIssue); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(IssueType issueType) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + IssueType persistentIssueType = em.find(IssueType.class, issueType.getId()); + List issueListOld = persistentIssueType.getIssueList(); + List issueListNew = issueType.getIssueList(); + List illegalOrphanMessages = null; + for (Issue issueListOldIssue : issueListOld) { + if (!issueListNew.contains(issueListOldIssue)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain Issue " + issueListOldIssue + " since its issueType field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedIssueListNew = new ArrayList<>(); + for (Issue issueListNewIssueToAttach : issueListNew) { + issueListNewIssueToAttach = em.getReference(issueListNewIssueToAttach.getClass(), issueListNewIssueToAttach.getIssuePK()); + attachedIssueListNew.add(issueListNewIssueToAttach); + } + issueListNew = attachedIssueListNew; + issueType.setIssueList(issueListNew); + issueType = em.merge(issueType); + for (Issue issueListNewIssue : issueListNew) { + if (!issueListOld.contains(issueListNewIssue)) { + IssueType oldIssueTypeOfIssueListNewIssue = issueListNewIssue.getIssueType(); + issueListNewIssue.setIssueType(issueType); + issueListNewIssue = em.merge(issueListNewIssue); + if (oldIssueTypeOfIssueListNewIssue != null && !oldIssueTypeOfIssueListNewIssue.equals(issueType)) { + oldIssueTypeOfIssueListNewIssue.getIssueList().remove(issueListNewIssue); + oldIssueTypeOfIssueListNewIssue = em.merge(oldIssueTypeOfIssueListNewIssue); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = issueType.getId(); + if (findIssueType(id) == null) { + throw new NonexistentEntityException("The issueType with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + IssueType issueType; + try { + issueType = em.getReference(IssueType.class, id); + issueType.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The issueType with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List issueListOrphanCheck = issueType.getIssueList(); + for (Issue issueListOrphanCheckIssue : issueListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This IssueType (" + issueType + ") cannot be destroyed since the Issue " + issueListOrphanCheckIssue + " in its issueList field has a non-nullable issueType field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(issueType); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findIssueTypeEntities() { + return findIssueTypeEntities(true, -1, -1); + } + + public List findIssueTypeEntities(int maxResults, int firstResult) { + return findIssueTypeEntities(false, maxResults, firstResult); + } + + private List findIssueTypeEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(IssueType.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public IssueType findIssueType(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(IssueType.class, id); + } + finally { + em.close(); + } + } + + public int getIssueTypeCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(IssueType.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/NotificationTypeJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/NotificationTypeJpaController.java index 9825606e..3efeea35 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/NotificationTypeJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/NotificationTypeJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Notification; -import com.validation.manager.core.db.NotificationType; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class NotificationTypeJpaController implements Serializable { - - public NotificationTypeJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(NotificationType notificationType) { - if (notificationType.getNotificationList() == null) { - notificationType.setNotificationList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedNotificationList = new ArrayList(); - for (Notification notificationListNotificationToAttach : notificationType.getNotificationList()) { - notificationListNotificationToAttach = em.getReference(notificationListNotificationToAttach.getClass(), notificationListNotificationToAttach.getNotificationPK()); - attachedNotificationList.add(notificationListNotificationToAttach); - } - notificationType.setNotificationList(attachedNotificationList); - em.persist(notificationType); - for (Notification notificationListNotification : notificationType.getNotificationList()) { - NotificationType oldNotificationTypeOfNotificationListNotification = notificationListNotification.getNotificationType(); - notificationListNotification.setNotificationType(notificationType); - notificationListNotification = em.merge(notificationListNotification); - if (oldNotificationTypeOfNotificationListNotification != null) { - oldNotificationTypeOfNotificationListNotification.getNotificationList().remove(notificationListNotification); - oldNotificationTypeOfNotificationListNotification = em.merge(oldNotificationTypeOfNotificationListNotification); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(NotificationType notificationType) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - NotificationType persistentNotificationType = em.find(NotificationType.class, notificationType.getId()); - List notificationListOld = persistentNotificationType.getNotificationList(); - List notificationListNew = notificationType.getNotificationList(); - List illegalOrphanMessages = null; - for (Notification notificationListOldNotification : notificationListOld) { - if (!notificationListNew.contains(notificationListOldNotification)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain Notification " + notificationListOldNotification + " since its notificationType field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedNotificationListNew = new ArrayList(); - for (Notification notificationListNewNotificationToAttach : notificationListNew) { - notificationListNewNotificationToAttach = em.getReference(notificationListNewNotificationToAttach.getClass(), notificationListNewNotificationToAttach.getNotificationPK()); - attachedNotificationListNew.add(notificationListNewNotificationToAttach); - } - notificationListNew = attachedNotificationListNew; - notificationType.setNotificationList(notificationListNew); - notificationType = em.merge(notificationType); - for (Notification notificationListNewNotification : notificationListNew) { - if (!notificationListOld.contains(notificationListNewNotification)) { - NotificationType oldNotificationTypeOfNotificationListNewNotification = notificationListNewNotification.getNotificationType(); - notificationListNewNotification.setNotificationType(notificationType); - notificationListNewNotification = em.merge(notificationListNewNotification); - if (oldNotificationTypeOfNotificationListNewNotification != null && !oldNotificationTypeOfNotificationListNewNotification.equals(notificationType)) { - oldNotificationTypeOfNotificationListNewNotification.getNotificationList().remove(notificationListNewNotification); - oldNotificationTypeOfNotificationListNewNotification = em.merge(oldNotificationTypeOfNotificationListNewNotification); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = notificationType.getId(); - if (findNotificationType(id) == null) { - throw new NonexistentEntityException("The notificationType with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - NotificationType notificationType; - try { - notificationType = em.getReference(NotificationType.class, id); - notificationType.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The notificationType with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List notificationListOrphanCheck = notificationType.getNotificationList(); - for (Notification notificationListOrphanCheckNotification : notificationListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This NotificationType (" + notificationType + ") cannot be destroyed since the Notification " + notificationListOrphanCheckNotification + " in its notificationList field has a non-nullable notificationType field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(notificationType); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findNotificationTypeEntities() { - return findNotificationTypeEntities(true, -1, -1); - } - - public List findNotificationTypeEntities(int maxResults, int firstResult) { - return findNotificationTypeEntities(false, maxResults, firstResult); - } - - private List findNotificationTypeEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(NotificationType.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public NotificationType findNotificationType(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(NotificationType.class, id); - } - finally { - em.close(); - } - } - - public int getNotificationTypeCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(NotificationType.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Notification; +import com.validation.manager.core.db.NotificationType; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class NotificationTypeJpaController implements Serializable { + + public NotificationTypeJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(NotificationType notificationType) { + if (notificationType.getNotificationList() == null) { + notificationType.setNotificationList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedNotificationList = new ArrayList<>(); + for (Notification notificationListNotificationToAttach : notificationType.getNotificationList()) { + notificationListNotificationToAttach = em.getReference(notificationListNotificationToAttach.getClass(), notificationListNotificationToAttach.getNotificationPK()); + attachedNotificationList.add(notificationListNotificationToAttach); + } + notificationType.setNotificationList(attachedNotificationList); + em.persist(notificationType); + for (Notification notificationListNotification : notificationType.getNotificationList()) { + NotificationType oldNotificationTypeOfNotificationListNotification = notificationListNotification.getNotificationType(); + notificationListNotification.setNotificationType(notificationType); + notificationListNotification = em.merge(notificationListNotification); + if (oldNotificationTypeOfNotificationListNotification != null) { + oldNotificationTypeOfNotificationListNotification.getNotificationList().remove(notificationListNotification); + oldNotificationTypeOfNotificationListNotification = em.merge(oldNotificationTypeOfNotificationListNotification); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(NotificationType notificationType) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + NotificationType persistentNotificationType = em.find(NotificationType.class, notificationType.getId()); + List notificationListOld = persistentNotificationType.getNotificationList(); + List notificationListNew = notificationType.getNotificationList(); + List illegalOrphanMessages = null; + for (Notification notificationListOldNotification : notificationListOld) { + if (!notificationListNew.contains(notificationListOldNotification)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain Notification " + notificationListOldNotification + " since its notificationType field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedNotificationListNew = new ArrayList<>(); + for (Notification notificationListNewNotificationToAttach : notificationListNew) { + notificationListNewNotificationToAttach = em.getReference(notificationListNewNotificationToAttach.getClass(), notificationListNewNotificationToAttach.getNotificationPK()); + attachedNotificationListNew.add(notificationListNewNotificationToAttach); + } + notificationListNew = attachedNotificationListNew; + notificationType.setNotificationList(notificationListNew); + notificationType = em.merge(notificationType); + for (Notification notificationListNewNotification : notificationListNew) { + if (!notificationListOld.contains(notificationListNewNotification)) { + NotificationType oldNotificationTypeOfNotificationListNewNotification = notificationListNewNotification.getNotificationType(); + notificationListNewNotification.setNotificationType(notificationType); + notificationListNewNotification = em.merge(notificationListNewNotification); + if (oldNotificationTypeOfNotificationListNewNotification != null && !oldNotificationTypeOfNotificationListNewNotification.equals(notificationType)) { + oldNotificationTypeOfNotificationListNewNotification.getNotificationList().remove(notificationListNewNotification); + oldNotificationTypeOfNotificationListNewNotification = em.merge(oldNotificationTypeOfNotificationListNewNotification); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = notificationType.getId(); + if (findNotificationType(id) == null) { + throw new NonexistentEntityException("The notificationType with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + NotificationType notificationType; + try { + notificationType = em.getReference(NotificationType.class, id); + notificationType.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The notificationType with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List notificationListOrphanCheck = notificationType.getNotificationList(); + for (Notification notificationListOrphanCheckNotification : notificationListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This NotificationType (" + notificationType + ") cannot be destroyed since the Notification " + notificationListOrphanCheckNotification + " in its notificationList field has a non-nullable notificationType field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(notificationType); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findNotificationTypeEntities() { + return findNotificationTypeEntities(true, -1, -1); + } + + public List findNotificationTypeEntities(int maxResults, int firstResult) { + return findNotificationTypeEntities(false, maxResults, firstResult); + } + + private List findNotificationTypeEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(NotificationType.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public NotificationType findNotificationType(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(NotificationType.class, id); + } + finally { + em.close(); + } + } + + public int getNotificationTypeCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(NotificationType.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/ProjectJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/ProjectJpaController.java index 4940e117..87928c3a 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/ProjectJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/ProjectJpaController.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,380 +13,380 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Project; -import com.validation.manager.core.db.TestProject; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.RequirementSpec; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class ProjectJpaController implements Serializable { - - public ProjectJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Project project) { - if (project.getTestProjectList() == null) { - project.setTestProjectList(new ArrayList()); - } - if (project.getProjectList() == null) { - project.setProjectList(new ArrayList()); - } - if (project.getRequirementSpecList() == null) { - project.setRequirementSpecList(new ArrayList()); - } - if (project.getHistoryList() == null) { - project.setHistoryList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Project parentProjectId = project.getParentProjectId(); - if (parentProjectId != null) { - parentProjectId = em.getReference(parentProjectId.getClass(), parentProjectId.getId()); - project.setParentProjectId(parentProjectId); - } - List attachedTestProjectList = new ArrayList(); - for (TestProject testProjectListTestProjectToAttach : project.getTestProjectList()) { - testProjectListTestProjectToAttach = em.getReference(testProjectListTestProjectToAttach.getClass(), testProjectListTestProjectToAttach.getId()); - attachedTestProjectList.add(testProjectListTestProjectToAttach); - } - project.setTestProjectList(attachedTestProjectList); - List attachedProjectList = new ArrayList(); - for (Project projectListProjectToAttach : project.getProjectList()) { - projectListProjectToAttach = em.getReference(projectListProjectToAttach.getClass(), projectListProjectToAttach.getId()); - attachedProjectList.add(projectListProjectToAttach); - } - project.setProjectList(attachedProjectList); - List attachedRequirementSpecList = new ArrayList(); - for (RequirementSpec requirementSpecListRequirementSpecToAttach : project.getRequirementSpecList()) { - requirementSpecListRequirementSpecToAttach = em.getReference(requirementSpecListRequirementSpecToAttach.getClass(), requirementSpecListRequirementSpecToAttach.getRequirementSpecPK()); - attachedRequirementSpecList.add(requirementSpecListRequirementSpecToAttach); - } - project.setRequirementSpecList(attachedRequirementSpecList); - List attachedHistoryList = new ArrayList(); - for (History historyListHistoryToAttach : project.getHistoryList()) { - historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); - attachedHistoryList.add(historyListHistoryToAttach); - } - project.setHistoryList(attachedHistoryList); - em.persist(project); - if (parentProjectId != null) { - parentProjectId.getProjectList().add(project); - parentProjectId = em.merge(parentProjectId); - } - for (TestProject testProjectListTestProject : project.getTestProjectList()) { - testProjectListTestProject.getProjectList().add(project); - testProjectListTestProject = em.merge(testProjectListTestProject); - } - for (Project projectListProject : project.getProjectList()) { - Project oldParentProjectIdOfProjectListProject = projectListProject.getParentProjectId(); - projectListProject.setParentProjectId(project); - projectListProject = em.merge(projectListProject); - if (oldParentProjectIdOfProjectListProject != null) { - oldParentProjectIdOfProjectListProject.getProjectList().remove(projectListProject); - oldParentProjectIdOfProjectListProject = em.merge(oldParentProjectIdOfProjectListProject); - } - } - for (RequirementSpec requirementSpecListRequirementSpec : project.getRequirementSpecList()) { - Project oldProjectOfRequirementSpecListRequirementSpec = requirementSpecListRequirementSpec.getProject(); - requirementSpecListRequirementSpec.setProject(project); - requirementSpecListRequirementSpec = em.merge(requirementSpecListRequirementSpec); - if (oldProjectOfRequirementSpecListRequirementSpec != null) { - oldProjectOfRequirementSpecListRequirementSpec.getRequirementSpecList().remove(requirementSpecListRequirementSpec); - oldProjectOfRequirementSpecListRequirementSpec = em.merge(oldProjectOfRequirementSpecListRequirementSpec); - } - } - for (History historyListHistory : project.getHistoryList()) { - Project oldProjectIdOfHistoryListHistory = historyListHistory.getProjectId(); - historyListHistory.setProjectId(project); - historyListHistory = em.merge(historyListHistory); - if (oldProjectIdOfHistoryListHistory != null) { - oldProjectIdOfHistoryListHistory.getHistoryList().remove(historyListHistory); - oldProjectIdOfHistoryListHistory = em.merge(oldProjectIdOfHistoryListHistory); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Project project) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Project persistentProject = em.find(Project.class, project.getId()); - Project parentProjectIdOld = persistentProject.getParentProjectId(); - Project parentProjectIdNew = project.getParentProjectId(); - List testProjectListOld = persistentProject.getTestProjectList(); - List testProjectListNew = project.getTestProjectList(); - List projectListOld = persistentProject.getProjectList(); - List projectListNew = project.getProjectList(); - List requirementSpecListOld = persistentProject.getRequirementSpecList(); - List requirementSpecListNew = project.getRequirementSpecList(); - List historyListOld = persistentProject.getHistoryList(); - List historyListNew = project.getHistoryList(); - List illegalOrphanMessages = null; - for (RequirementSpec requirementSpecListOldRequirementSpec : requirementSpecListOld) { - if (!requirementSpecListNew.contains(requirementSpecListOldRequirementSpec)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain RequirementSpec " + requirementSpecListOldRequirementSpec + " since its project field is not nullable."); - } - } - for (History historyListOldHistory : historyListOld) { - if (!historyListNew.contains(historyListOldHistory)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain History " + historyListOldHistory + " since its projectId field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (parentProjectIdNew != null) { - parentProjectIdNew = em.getReference(parentProjectIdNew.getClass(), parentProjectIdNew.getId()); - project.setParentProjectId(parentProjectIdNew); - } - List attachedTestProjectListNew = new ArrayList(); - for (TestProject testProjectListNewTestProjectToAttach : testProjectListNew) { - testProjectListNewTestProjectToAttach = em.getReference(testProjectListNewTestProjectToAttach.getClass(), testProjectListNewTestProjectToAttach.getId()); - attachedTestProjectListNew.add(testProjectListNewTestProjectToAttach); - } - testProjectListNew = attachedTestProjectListNew; - project.setTestProjectList(testProjectListNew); - List attachedProjectListNew = new ArrayList(); - for (Project projectListNewProjectToAttach : projectListNew) { - projectListNewProjectToAttach = em.getReference(projectListNewProjectToAttach.getClass(), projectListNewProjectToAttach.getId()); - attachedProjectListNew.add(projectListNewProjectToAttach); - } - projectListNew = attachedProjectListNew; - project.setProjectList(projectListNew); - List attachedRequirementSpecListNew = new ArrayList(); - for (RequirementSpec requirementSpecListNewRequirementSpecToAttach : requirementSpecListNew) { - requirementSpecListNewRequirementSpecToAttach = em.getReference(requirementSpecListNewRequirementSpecToAttach.getClass(), requirementSpecListNewRequirementSpecToAttach.getRequirementSpecPK()); - attachedRequirementSpecListNew.add(requirementSpecListNewRequirementSpecToAttach); - } - requirementSpecListNew = attachedRequirementSpecListNew; - project.setRequirementSpecList(requirementSpecListNew); - List attachedHistoryListNew = new ArrayList(); - for (History historyListNewHistoryToAttach : historyListNew) { - historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); - attachedHistoryListNew.add(historyListNewHistoryToAttach); - } - historyListNew = attachedHistoryListNew; - project.setHistoryList(historyListNew); - project = em.merge(project); - if (parentProjectIdOld != null && !parentProjectIdOld.equals(parentProjectIdNew)) { - parentProjectIdOld.getProjectList().remove(project); - parentProjectIdOld = em.merge(parentProjectIdOld); - } - if (parentProjectIdNew != null && !parentProjectIdNew.equals(parentProjectIdOld)) { - parentProjectIdNew.getProjectList().add(project); - parentProjectIdNew = em.merge(parentProjectIdNew); - } - for (TestProject testProjectListOldTestProject : testProjectListOld) { - if (!testProjectListNew.contains(testProjectListOldTestProject)) { - testProjectListOldTestProject.getProjectList().remove(project); - testProjectListOldTestProject = em.merge(testProjectListOldTestProject); - } - } - for (TestProject testProjectListNewTestProject : testProjectListNew) { - if (!testProjectListOld.contains(testProjectListNewTestProject)) { - testProjectListNewTestProject.getProjectList().add(project); - testProjectListNewTestProject = em.merge(testProjectListNewTestProject); - } - } - for (Project projectListOldProject : projectListOld) { - if (!projectListNew.contains(projectListOldProject)) { - projectListOldProject.setParentProjectId(null); - projectListOldProject = em.merge(projectListOldProject); - } - } - for (Project projectListNewProject : projectListNew) { - if (!projectListOld.contains(projectListNewProject)) { - Project oldParentProjectIdOfProjectListNewProject = projectListNewProject.getParentProjectId(); - projectListNewProject.setParentProjectId(project); - projectListNewProject = em.merge(projectListNewProject); - if (oldParentProjectIdOfProjectListNewProject != null && !oldParentProjectIdOfProjectListNewProject.equals(project)) { - oldParentProjectIdOfProjectListNewProject.getProjectList().remove(projectListNewProject); - oldParentProjectIdOfProjectListNewProject = em.merge(oldParentProjectIdOfProjectListNewProject); - } - } - } - for (RequirementSpec requirementSpecListNewRequirementSpec : requirementSpecListNew) { - if (!requirementSpecListOld.contains(requirementSpecListNewRequirementSpec)) { - Project oldProjectOfRequirementSpecListNewRequirementSpec = requirementSpecListNewRequirementSpec.getProject(); - requirementSpecListNewRequirementSpec.setProject(project); - requirementSpecListNewRequirementSpec = em.merge(requirementSpecListNewRequirementSpec); - if (oldProjectOfRequirementSpecListNewRequirementSpec != null && !oldProjectOfRequirementSpecListNewRequirementSpec.equals(project)) { - oldProjectOfRequirementSpecListNewRequirementSpec.getRequirementSpecList().remove(requirementSpecListNewRequirementSpec); - oldProjectOfRequirementSpecListNewRequirementSpec = em.merge(oldProjectOfRequirementSpecListNewRequirementSpec); - } - } - } - for (History historyListNewHistory : historyListNew) { - if (!historyListOld.contains(historyListNewHistory)) { - Project oldProjectIdOfHistoryListNewHistory = historyListNewHistory.getProjectId(); - historyListNewHistory.setProjectId(project); - historyListNewHistory = em.merge(historyListNewHistory); - if (oldProjectIdOfHistoryListNewHistory != null && !oldProjectIdOfHistoryListNewHistory.equals(project)) { - oldProjectIdOfHistoryListNewHistory.getHistoryList().remove(historyListNewHistory); - oldProjectIdOfHistoryListNewHistory = em.merge(oldProjectIdOfHistoryListNewHistory); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = project.getId(); - if (findProject(id) == null) { - throw new NonexistentEntityException("The project with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Project project; - try { - project = em.getReference(Project.class, id); - project.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The project with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List requirementSpecListOrphanCheck = project.getRequirementSpecList(); - for (RequirementSpec requirementSpecListOrphanCheckRequirementSpec : requirementSpecListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Project (" + project + ") cannot be destroyed since the RequirementSpec " + requirementSpecListOrphanCheckRequirementSpec + " in its requirementSpecList field has a non-nullable project field."); - } - List historyListOrphanCheck = project.getHistoryList(); - for (History historyListOrphanCheckHistory : historyListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Project (" + project + ") cannot be destroyed since the History " + historyListOrphanCheckHistory + " in its historyList field has a non-nullable projectId field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - Project parentProjectId = project.getParentProjectId(); - if (parentProjectId != null) { - parentProjectId.getProjectList().remove(project); - parentProjectId = em.merge(parentProjectId); - } - List testProjectList = project.getTestProjectList(); - for (TestProject testProjectListTestProject : testProjectList) { - testProjectListTestProject.getProjectList().remove(project); - testProjectListTestProject = em.merge(testProjectListTestProject); - } - List projectList = project.getProjectList(); - for (Project projectListProject : projectList) { - projectListProject.setParentProjectId(null); - projectListProject = em.merge(projectListProject); - } - em.remove(project); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findProjectEntities() { - return findProjectEntities(true, -1, -1); - } - - public List findProjectEntities(int maxResults, int firstResult) { - return findProjectEntities(false, maxResults, firstResult); - } - - private List findProjectEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Project.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public Project findProject(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(Project.class, id); - } - finally { - em.close(); - } - } - - public int getProjectCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(Project.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Project; +import com.validation.manager.core.db.TestProject; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.RequirementSpec; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ProjectJpaController implements Serializable { + + public ProjectJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Project project) { + if (project.getTestProjectList() == null) { + project.setTestProjectList(new ArrayList<>()); + } + if (project.getProjectList() == null) { + project.setProjectList(new ArrayList<>()); + } + if (project.getRequirementSpecList() == null) { + project.setRequirementSpecList(new ArrayList<>()); + } + if (project.getHistoryList() == null) { + project.setHistoryList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Project parentProjectId = project.getParentProjectId(); + if (parentProjectId != null) { + parentProjectId = em.getReference(parentProjectId.getClass(), parentProjectId.getId()); + project.setParentProjectId(parentProjectId); + } + List attachedTestProjectList = new ArrayList<>(); + for (TestProject testProjectListTestProjectToAttach : project.getTestProjectList()) { + testProjectListTestProjectToAttach = em.getReference(testProjectListTestProjectToAttach.getClass(), testProjectListTestProjectToAttach.getId()); + attachedTestProjectList.add(testProjectListTestProjectToAttach); + } + project.setTestProjectList(attachedTestProjectList); + List attachedProjectList = new ArrayList<>(); + for (Project projectListProjectToAttach : project.getProjectList()) { + projectListProjectToAttach = em.getReference(projectListProjectToAttach.getClass(), projectListProjectToAttach.getId()); + attachedProjectList.add(projectListProjectToAttach); + } + project.setProjectList(attachedProjectList); + List attachedRequirementSpecList = new ArrayList<>(); + for (RequirementSpec requirementSpecListRequirementSpecToAttach : project.getRequirementSpecList()) { + requirementSpecListRequirementSpecToAttach = em.getReference(requirementSpecListRequirementSpecToAttach.getClass(), requirementSpecListRequirementSpecToAttach.getRequirementSpecPK()); + attachedRequirementSpecList.add(requirementSpecListRequirementSpecToAttach); + } + project.setRequirementSpecList(attachedRequirementSpecList); + List attachedHistoryList = new ArrayList<>(); + for (History historyListHistoryToAttach : project.getHistoryList()) { + historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); + attachedHistoryList.add(historyListHistoryToAttach); + } + project.setHistoryList(attachedHistoryList); + em.persist(project); + if (parentProjectId != null) { + parentProjectId.getProjectList().add(project); + parentProjectId = em.merge(parentProjectId); + } + for (TestProject testProjectListTestProject : project.getTestProjectList()) { + testProjectListTestProject.getProjectList().add(project); + testProjectListTestProject = em.merge(testProjectListTestProject); + } + for (Project projectListProject : project.getProjectList()) { + Project oldParentProjectIdOfProjectListProject = projectListProject.getParentProjectId(); + projectListProject.setParentProjectId(project); + projectListProject = em.merge(projectListProject); + if (oldParentProjectIdOfProjectListProject != null) { + oldParentProjectIdOfProjectListProject.getProjectList().remove(projectListProject); + oldParentProjectIdOfProjectListProject = em.merge(oldParentProjectIdOfProjectListProject); + } + } + for (RequirementSpec requirementSpecListRequirementSpec : project.getRequirementSpecList()) { + Project oldProjectOfRequirementSpecListRequirementSpec = requirementSpecListRequirementSpec.getProject(); + requirementSpecListRequirementSpec.setProject(project); + requirementSpecListRequirementSpec = em.merge(requirementSpecListRequirementSpec); + if (oldProjectOfRequirementSpecListRequirementSpec != null) { + oldProjectOfRequirementSpecListRequirementSpec.getRequirementSpecList().remove(requirementSpecListRequirementSpec); + oldProjectOfRequirementSpecListRequirementSpec = em.merge(oldProjectOfRequirementSpecListRequirementSpec); + } + } + for (History historyListHistory : project.getHistoryList()) { + Project oldProjectIdOfHistoryListHistory = historyListHistory.getProjectId(); + historyListHistory.setProjectId(project); + historyListHistory = em.merge(historyListHistory); + if (oldProjectIdOfHistoryListHistory != null) { + oldProjectIdOfHistoryListHistory.getHistoryList().remove(historyListHistory); + oldProjectIdOfHistoryListHistory = em.merge(oldProjectIdOfHistoryListHistory); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Project project) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Project persistentProject = em.find(Project.class, project.getId()); + Project parentProjectIdOld = persistentProject.getParentProjectId(); + Project parentProjectIdNew = project.getParentProjectId(); + List testProjectListOld = persistentProject.getTestProjectList(); + List testProjectListNew = project.getTestProjectList(); + List projectListOld = persistentProject.getProjectList(); + List projectListNew = project.getProjectList(); + List requirementSpecListOld = persistentProject.getRequirementSpecList(); + List requirementSpecListNew = project.getRequirementSpecList(); + List historyListOld = persistentProject.getHistoryList(); + List historyListNew = project.getHistoryList(); + List illegalOrphanMessages = null; + for (RequirementSpec requirementSpecListOldRequirementSpec : requirementSpecListOld) { + if (!requirementSpecListNew.contains(requirementSpecListOldRequirementSpec)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain RequirementSpec " + requirementSpecListOldRequirementSpec + " since its project field is not nullable."); + } + } + for (History historyListOldHistory : historyListOld) { + if (!historyListNew.contains(historyListOldHistory)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain History " + historyListOldHistory + " since its projectId field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (parentProjectIdNew != null) { + parentProjectIdNew = em.getReference(parentProjectIdNew.getClass(), parentProjectIdNew.getId()); + project.setParentProjectId(parentProjectIdNew); + } + List attachedTestProjectListNew = new ArrayList<>(); + for (TestProject testProjectListNewTestProjectToAttach : testProjectListNew) { + testProjectListNewTestProjectToAttach = em.getReference(testProjectListNewTestProjectToAttach.getClass(), testProjectListNewTestProjectToAttach.getId()); + attachedTestProjectListNew.add(testProjectListNewTestProjectToAttach); + } + testProjectListNew = attachedTestProjectListNew; + project.setTestProjectList(testProjectListNew); + List attachedProjectListNew = new ArrayList<>(); + for (Project projectListNewProjectToAttach : projectListNew) { + projectListNewProjectToAttach = em.getReference(projectListNewProjectToAttach.getClass(), projectListNewProjectToAttach.getId()); + attachedProjectListNew.add(projectListNewProjectToAttach); + } + projectListNew = attachedProjectListNew; + project.setProjectList(projectListNew); + List attachedRequirementSpecListNew = new ArrayList<>(); + for (RequirementSpec requirementSpecListNewRequirementSpecToAttach : requirementSpecListNew) { + requirementSpecListNewRequirementSpecToAttach = em.getReference(requirementSpecListNewRequirementSpecToAttach.getClass(), requirementSpecListNewRequirementSpecToAttach.getRequirementSpecPK()); + attachedRequirementSpecListNew.add(requirementSpecListNewRequirementSpecToAttach); + } + requirementSpecListNew = attachedRequirementSpecListNew; + project.setRequirementSpecList(requirementSpecListNew); + List attachedHistoryListNew = new ArrayList<>(); + for (History historyListNewHistoryToAttach : historyListNew) { + historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); + attachedHistoryListNew.add(historyListNewHistoryToAttach); + } + historyListNew = attachedHistoryListNew; + project.setHistoryList(historyListNew); + project = em.merge(project); + if (parentProjectIdOld != null && !parentProjectIdOld.equals(parentProjectIdNew)) { + parentProjectIdOld.getProjectList().remove(project); + parentProjectIdOld = em.merge(parentProjectIdOld); + } + if (parentProjectIdNew != null && !parentProjectIdNew.equals(parentProjectIdOld)) { + parentProjectIdNew.getProjectList().add(project); + parentProjectIdNew = em.merge(parentProjectIdNew); + } + for (TestProject testProjectListOldTestProject : testProjectListOld) { + if (!testProjectListNew.contains(testProjectListOldTestProject)) { + testProjectListOldTestProject.getProjectList().remove(project); + testProjectListOldTestProject = em.merge(testProjectListOldTestProject); + } + } + for (TestProject testProjectListNewTestProject : testProjectListNew) { + if (!testProjectListOld.contains(testProjectListNewTestProject)) { + testProjectListNewTestProject.getProjectList().add(project); + testProjectListNewTestProject = em.merge(testProjectListNewTestProject); + } + } + for (Project projectListOldProject : projectListOld) { + if (!projectListNew.contains(projectListOldProject)) { + projectListOldProject.setParentProjectId(null); + projectListOldProject = em.merge(projectListOldProject); + } + } + for (Project projectListNewProject : projectListNew) { + if (!projectListOld.contains(projectListNewProject)) { + Project oldParentProjectIdOfProjectListNewProject = projectListNewProject.getParentProjectId(); + projectListNewProject.setParentProjectId(project); + projectListNewProject = em.merge(projectListNewProject); + if (oldParentProjectIdOfProjectListNewProject != null && !oldParentProjectIdOfProjectListNewProject.equals(project)) { + oldParentProjectIdOfProjectListNewProject.getProjectList().remove(projectListNewProject); + oldParentProjectIdOfProjectListNewProject = em.merge(oldParentProjectIdOfProjectListNewProject); + } + } + } + for (RequirementSpec requirementSpecListNewRequirementSpec : requirementSpecListNew) { + if (!requirementSpecListOld.contains(requirementSpecListNewRequirementSpec)) { + Project oldProjectOfRequirementSpecListNewRequirementSpec = requirementSpecListNewRequirementSpec.getProject(); + requirementSpecListNewRequirementSpec.setProject(project); + requirementSpecListNewRequirementSpec = em.merge(requirementSpecListNewRequirementSpec); + if (oldProjectOfRequirementSpecListNewRequirementSpec != null && !oldProjectOfRequirementSpecListNewRequirementSpec.equals(project)) { + oldProjectOfRequirementSpecListNewRequirementSpec.getRequirementSpecList().remove(requirementSpecListNewRequirementSpec); + oldProjectOfRequirementSpecListNewRequirementSpec = em.merge(oldProjectOfRequirementSpecListNewRequirementSpec); + } + } + } + for (History historyListNewHistory : historyListNew) { + if (!historyListOld.contains(historyListNewHistory)) { + Project oldProjectIdOfHistoryListNewHistory = historyListNewHistory.getProjectId(); + historyListNewHistory.setProjectId(project); + historyListNewHistory = em.merge(historyListNewHistory); + if (oldProjectIdOfHistoryListNewHistory != null && !oldProjectIdOfHistoryListNewHistory.equals(project)) { + oldProjectIdOfHistoryListNewHistory.getHistoryList().remove(historyListNewHistory); + oldProjectIdOfHistoryListNewHistory = em.merge(oldProjectIdOfHistoryListNewHistory); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = project.getId(); + if (findProject(id) == null) { + throw new NonexistentEntityException("The project with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Project project; + try { + project = em.getReference(Project.class, id); + project.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The project with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List requirementSpecListOrphanCheck = project.getRequirementSpecList(); + for (RequirementSpec requirementSpecListOrphanCheckRequirementSpec : requirementSpecListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Project (" + project + ") cannot be destroyed since the RequirementSpec " + requirementSpecListOrphanCheckRequirementSpec + " in its requirementSpecList field has a non-nullable project field."); + } + List historyListOrphanCheck = project.getHistoryList(); + for (History historyListOrphanCheckHistory : historyListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Project (" + project + ") cannot be destroyed since the History " + historyListOrphanCheckHistory + " in its historyList field has a non-nullable projectId field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + Project parentProjectId = project.getParentProjectId(); + if (parentProjectId != null) { + parentProjectId.getProjectList().remove(project); + parentProjectId = em.merge(parentProjectId); + } + List testProjectList = project.getTestProjectList(); + for (TestProject testProjectListTestProject : testProjectList) { + testProjectListTestProject.getProjectList().remove(project); + testProjectListTestProject = em.merge(testProjectListTestProject); + } + List projectList = project.getProjectList(); + for (Project projectListProject : projectList) { + projectListProject.setParentProjectId(null); + projectListProject = em.merge(projectListProject); + } + em.remove(project); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findProjectEntities() { + return findProjectEntities(true, -1, -1); + } + + public List findProjectEntities(int maxResults, int firstResult) { + return findProjectEntities(false, maxResults, firstResult); + } + + private List findProjectEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Project.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public Project findProject(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(Project.class, id); + } + finally { + em.close(); + } + } + + public int getProjectCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Project.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementJpaController.java index c18f7889..4e95c09a 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementJpaController.java @@ -13,463 +13,463 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Requirement; -import com.validation.manager.core.db.RequirementSpecNode; -import com.validation.manager.core.db.RequirementStatus; -import com.validation.manager.core.db.RequirementType; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.Step; -import com.validation.manager.core.db.RiskControlHasRequirement; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RequirementJpaController implements Serializable { - - public RequirementJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Requirement requirement) { - if (requirement.getRequirementList() == null) { - requirement.setRequirementList(new ArrayList()); - } - if (requirement.getStepList() == null) { - requirement.setStepList(new ArrayList()); - } - if (requirement.getRiskControlHasRequirementList() == null) { - requirement.setRiskControlHasRequirementList(new ArrayList()); - } - if (requirement.getHistoryList() == null) { - requirement.setHistoryList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Requirement parentRequirementId = requirement.getParentRequirementId(); - if (parentRequirementId != null) { - parentRequirementId = em.getReference(parentRequirementId.getClass(), parentRequirementId.getId()); - requirement.setParentRequirementId(parentRequirementId); - } - RequirementSpecNode requirementSpecNode = requirement.getRequirementSpecNode(); - if (requirementSpecNode != null) { - requirementSpecNode = em.getReference(requirementSpecNode.getClass(), requirementSpecNode.getRequirementSpecNodePK()); - requirement.setRequirementSpecNode(requirementSpecNode); - } - RequirementStatus requirementStatusId = requirement.getRequirementStatusId(); - if (requirementStatusId != null) { - requirementStatusId = em.getReference(requirementStatusId.getClass(), requirementStatusId.getId()); - requirement.setRequirementStatusId(requirementStatusId); - } - RequirementType requirementTypeId = requirement.getRequirementTypeId(); - if (requirementTypeId != null) { - requirementTypeId = em.getReference(requirementTypeId.getClass(), requirementTypeId.getId()); - requirement.setRequirementTypeId(requirementTypeId); - } - List attachedRequirementList = new ArrayList(); - for (Requirement requirementListRequirementToAttach : requirement.getRequirementList()) { - requirementListRequirementToAttach = em.getReference(requirementListRequirementToAttach.getClass(), requirementListRequirementToAttach.getId()); - attachedRequirementList.add(requirementListRequirementToAttach); - } - requirement.setRequirementList(attachedRequirementList); - List attachedStepList = new ArrayList(); - for (Step stepListStepToAttach : requirement.getStepList()) { - stepListStepToAttach = em.getReference(stepListStepToAttach.getClass(), stepListStepToAttach.getStepPK()); - attachedStepList.add(stepListStepToAttach); - } - requirement.setStepList(attachedStepList); - List attachedRiskControlHasRequirementList = new ArrayList(); - for (RiskControlHasRequirement riskControlHasRequirementListRiskControlHasRequirementToAttach : requirement.getRiskControlHasRequirementList()) { - riskControlHasRequirementListRiskControlHasRequirementToAttach = em.getReference(riskControlHasRequirementListRiskControlHasRequirementToAttach.getClass(), riskControlHasRequirementListRiskControlHasRequirementToAttach.getRiskControlHasRequirementPK()); - attachedRiskControlHasRequirementList.add(riskControlHasRequirementListRiskControlHasRequirementToAttach); - } - requirement.setRiskControlHasRequirementList(attachedRiskControlHasRequirementList); - List attachedHistoryList = new ArrayList(); - for (History historyListHistoryToAttach : requirement.getHistoryList()) { - historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); - attachedHistoryList.add(historyListHistoryToAttach); - } - requirement.setHistoryList(attachedHistoryList); - em.persist(requirement); - if (parentRequirementId != null) { - parentRequirementId.getRequirementList().add(requirement); - parentRequirementId = em.merge(parentRequirementId); - } - if (requirementSpecNode != null) { - requirementSpecNode.getRequirementList().add(requirement); - requirementSpecNode = em.merge(requirementSpecNode); - } - if (requirementStatusId != null) { - requirementStatusId.getRequirementList().add(requirement); - requirementStatusId = em.merge(requirementStatusId); - } - if (requirementTypeId != null) { - requirementTypeId.getRequirementList().add(requirement); - requirementTypeId = em.merge(requirementTypeId); - } - for (Requirement requirementListRequirement : requirement.getRequirementList()) { - Requirement oldParentRequirementIdOfRequirementListRequirement = requirementListRequirement.getParentRequirementId(); - requirementListRequirement.setParentRequirementId(requirement); - requirementListRequirement = em.merge(requirementListRequirement); - if (oldParentRequirementIdOfRequirementListRequirement != null) { - oldParentRequirementIdOfRequirementListRequirement.getRequirementList().remove(requirementListRequirement); - oldParentRequirementIdOfRequirementListRequirement = em.merge(oldParentRequirementIdOfRequirementListRequirement); - } - } - for (Step stepListStep : requirement.getStepList()) { - stepListStep.getRequirementList().add(requirement); - stepListStep = em.merge(stepListStep); - } - for (RiskControlHasRequirement riskControlHasRequirementListRiskControlHasRequirement : requirement.getRiskControlHasRequirementList()) { - Requirement oldRequirementOfRiskControlHasRequirementListRiskControlHasRequirement = riskControlHasRequirementListRiskControlHasRequirement.getRequirement(); - riskControlHasRequirementListRiskControlHasRequirement.setRequirement(requirement); - riskControlHasRequirementListRiskControlHasRequirement = em.merge(riskControlHasRequirementListRiskControlHasRequirement); - if (oldRequirementOfRiskControlHasRequirementListRiskControlHasRequirement != null) { - oldRequirementOfRiskControlHasRequirementListRiskControlHasRequirement.getRiskControlHasRequirementList().remove(riskControlHasRequirementListRiskControlHasRequirement); - oldRequirementOfRiskControlHasRequirementListRiskControlHasRequirement = em.merge(oldRequirementOfRiskControlHasRequirementListRiskControlHasRequirement); - } - } - for (History historyListHistory : requirement.getHistoryList()) { - Requirement oldRequirementIdOfHistoryListHistory = historyListHistory.getRequirementId(); - historyListHistory.setRequirementId(requirement); - historyListHistory = em.merge(historyListHistory); - if (oldRequirementIdOfHistoryListHistory != null) { - oldRequirementIdOfHistoryListHistory.getHistoryList().remove(historyListHistory); - oldRequirementIdOfHistoryListHistory = em.merge(oldRequirementIdOfHistoryListHistory); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Requirement requirement) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Requirement persistentRequirement = em.find(Requirement.class, requirement.getId()); - Requirement parentRequirementIdOld = persistentRequirement.getParentRequirementId(); - Requirement parentRequirementIdNew = requirement.getParentRequirementId(); - RequirementSpecNode requirementSpecNodeOld = persistentRequirement.getRequirementSpecNode(); - RequirementSpecNode requirementSpecNodeNew = requirement.getRequirementSpecNode(); - RequirementStatus requirementStatusIdOld = persistentRequirement.getRequirementStatusId(); - RequirementStatus requirementStatusIdNew = requirement.getRequirementStatusId(); - RequirementType requirementTypeIdOld = persistentRequirement.getRequirementTypeId(); - RequirementType requirementTypeIdNew = requirement.getRequirementTypeId(); - List requirementListOld = persistentRequirement.getRequirementList(); - List requirementListNew = requirement.getRequirementList(); - List stepListOld = persistentRequirement.getStepList(); - List stepListNew = requirement.getStepList(); - List riskControlHasRequirementListOld = persistentRequirement.getRiskControlHasRequirementList(); - List riskControlHasRequirementListNew = requirement.getRiskControlHasRequirementList(); - List historyListOld = persistentRequirement.getHistoryList(); - List historyListNew = requirement.getHistoryList(); - List illegalOrphanMessages = null; - for (RiskControlHasRequirement riskControlHasRequirementListOldRiskControlHasRequirement : riskControlHasRequirementListOld) { - if (!riskControlHasRequirementListNew.contains(riskControlHasRequirementListOldRiskControlHasRequirement)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain RiskControlHasRequirement " + riskControlHasRequirementListOldRiskControlHasRequirement + " since its requirement field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (parentRequirementIdNew != null) { - parentRequirementIdNew = em.getReference(parentRequirementIdNew.getClass(), parentRequirementIdNew.getId()); - requirement.setParentRequirementId(parentRequirementIdNew); - } - if (requirementSpecNodeNew != null) { - requirementSpecNodeNew = em.getReference(requirementSpecNodeNew.getClass(), requirementSpecNodeNew.getRequirementSpecNodePK()); - requirement.setRequirementSpecNode(requirementSpecNodeNew); - } - if (requirementStatusIdNew != null) { - requirementStatusIdNew = em.getReference(requirementStatusIdNew.getClass(), requirementStatusIdNew.getId()); - requirement.setRequirementStatusId(requirementStatusIdNew); - } - if (requirementTypeIdNew != null) { - requirementTypeIdNew = em.getReference(requirementTypeIdNew.getClass(), requirementTypeIdNew.getId()); - requirement.setRequirementTypeId(requirementTypeIdNew); - } - List attachedRequirementListNew = new ArrayList(); - for (Requirement requirementListNewRequirementToAttach : requirementListNew) { - requirementListNewRequirementToAttach = em.getReference(requirementListNewRequirementToAttach.getClass(), requirementListNewRequirementToAttach.getId()); - attachedRequirementListNew.add(requirementListNewRequirementToAttach); - } - requirementListNew = attachedRequirementListNew; - requirement.setRequirementList(requirementListNew); - List attachedStepListNew = new ArrayList(); - for (Step stepListNewStepToAttach : stepListNew) { - stepListNewStepToAttach = em.getReference(stepListNewStepToAttach.getClass(), stepListNewStepToAttach.getStepPK()); - attachedStepListNew.add(stepListNewStepToAttach); - } - stepListNew = attachedStepListNew; - requirement.setStepList(stepListNew); - List attachedRiskControlHasRequirementListNew = new ArrayList(); - for (RiskControlHasRequirement riskControlHasRequirementListNewRiskControlHasRequirementToAttach : riskControlHasRequirementListNew) { - riskControlHasRequirementListNewRiskControlHasRequirementToAttach = em.getReference(riskControlHasRequirementListNewRiskControlHasRequirementToAttach.getClass(), riskControlHasRequirementListNewRiskControlHasRequirementToAttach.getRiskControlHasRequirementPK()); - attachedRiskControlHasRequirementListNew.add(riskControlHasRequirementListNewRiskControlHasRequirementToAttach); - } - riskControlHasRequirementListNew = attachedRiskControlHasRequirementListNew; - requirement.setRiskControlHasRequirementList(riskControlHasRequirementListNew); - List attachedHistoryListNew = new ArrayList(); - for (History historyListNewHistoryToAttach : historyListNew) { - historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); - attachedHistoryListNew.add(historyListNewHistoryToAttach); - } - historyListNew = attachedHistoryListNew; - requirement.setHistoryList(historyListNew); - requirement = em.merge(requirement); - if (parentRequirementIdOld != null && !parentRequirementIdOld.equals(parentRequirementIdNew)) { - parentRequirementIdOld.getRequirementList().remove(requirement); - parentRequirementIdOld = em.merge(parentRequirementIdOld); - } - if (parentRequirementIdNew != null && !parentRequirementIdNew.equals(parentRequirementIdOld)) { - parentRequirementIdNew.getRequirementList().add(requirement); - parentRequirementIdNew = em.merge(parentRequirementIdNew); - } - if (requirementSpecNodeOld != null && !requirementSpecNodeOld.equals(requirementSpecNodeNew)) { - requirementSpecNodeOld.getRequirementList().remove(requirement); - requirementSpecNodeOld = em.merge(requirementSpecNodeOld); - } - if (requirementSpecNodeNew != null && !requirementSpecNodeNew.equals(requirementSpecNodeOld)) { - requirementSpecNodeNew.getRequirementList().add(requirement); - requirementSpecNodeNew = em.merge(requirementSpecNodeNew); - } - if (requirementStatusIdOld != null && !requirementStatusIdOld.equals(requirementStatusIdNew)) { - requirementStatusIdOld.getRequirementList().remove(requirement); - requirementStatusIdOld = em.merge(requirementStatusIdOld); - } - if (requirementStatusIdNew != null && !requirementStatusIdNew.equals(requirementStatusIdOld)) { - requirementStatusIdNew.getRequirementList().add(requirement); - requirementStatusIdNew = em.merge(requirementStatusIdNew); - } - if (requirementTypeIdOld != null && !requirementTypeIdOld.equals(requirementTypeIdNew)) { - requirementTypeIdOld.getRequirementList().remove(requirement); - requirementTypeIdOld = em.merge(requirementTypeIdOld); - } - if (requirementTypeIdNew != null && !requirementTypeIdNew.equals(requirementTypeIdOld)) { - requirementTypeIdNew.getRequirementList().add(requirement); - requirementTypeIdNew = em.merge(requirementTypeIdNew); - } - for (Requirement requirementListOldRequirement : requirementListOld) { - if (!requirementListNew.contains(requirementListOldRequirement)) { - requirementListOldRequirement.setParentRequirementId(null); - requirementListOldRequirement = em.merge(requirementListOldRequirement); - } - } - for (Requirement requirementListNewRequirement : requirementListNew) { - if (!requirementListOld.contains(requirementListNewRequirement)) { - Requirement oldParentRequirementIdOfRequirementListNewRequirement = requirementListNewRequirement.getParentRequirementId(); - requirementListNewRequirement.setParentRequirementId(requirement); - requirementListNewRequirement = em.merge(requirementListNewRequirement); - if (oldParentRequirementIdOfRequirementListNewRequirement != null && !oldParentRequirementIdOfRequirementListNewRequirement.equals(requirement)) { - oldParentRequirementIdOfRequirementListNewRequirement.getRequirementList().remove(requirementListNewRequirement); - oldParentRequirementIdOfRequirementListNewRequirement = em.merge(oldParentRequirementIdOfRequirementListNewRequirement); - } - } - } - for (Step stepListOldStep : stepListOld) { - if (!stepListNew.contains(stepListOldStep)) { - stepListOldStep.getRequirementList().remove(requirement); - stepListOldStep = em.merge(stepListOldStep); - } - } - for (Step stepListNewStep : stepListNew) { - if (!stepListOld.contains(stepListNewStep)) { - stepListNewStep.getRequirementList().add(requirement); - stepListNewStep = em.merge(stepListNewStep); - } - } - for (RiskControlHasRequirement riskControlHasRequirementListNewRiskControlHasRequirement : riskControlHasRequirementListNew) { - if (!riskControlHasRequirementListOld.contains(riskControlHasRequirementListNewRiskControlHasRequirement)) { - Requirement oldRequirementOfRiskControlHasRequirementListNewRiskControlHasRequirement = riskControlHasRequirementListNewRiskControlHasRequirement.getRequirement(); - riskControlHasRequirementListNewRiskControlHasRequirement.setRequirement(requirement); - riskControlHasRequirementListNewRiskControlHasRequirement = em.merge(riskControlHasRequirementListNewRiskControlHasRequirement); - if (oldRequirementOfRiskControlHasRequirementListNewRiskControlHasRequirement != null && !oldRequirementOfRiskControlHasRequirementListNewRiskControlHasRequirement.equals(requirement)) { - oldRequirementOfRiskControlHasRequirementListNewRiskControlHasRequirement.getRiskControlHasRequirementList().remove(riskControlHasRequirementListNewRiskControlHasRequirement); - oldRequirementOfRiskControlHasRequirementListNewRiskControlHasRequirement = em.merge(oldRequirementOfRiskControlHasRequirementListNewRiskControlHasRequirement); - } - } - } - for (History historyListOldHistory : historyListOld) { - if (!historyListNew.contains(historyListOldHistory)) { - historyListOldHistory.setRequirementId(null); - historyListOldHistory = em.merge(historyListOldHistory); - } - } - for (History historyListNewHistory : historyListNew) { - if (!historyListOld.contains(historyListNewHistory)) { - Requirement oldRequirementIdOfHistoryListNewHistory = historyListNewHistory.getRequirementId(); - historyListNewHistory.setRequirementId(requirement); - historyListNewHistory = em.merge(historyListNewHistory); - if (oldRequirementIdOfHistoryListNewHistory != null && !oldRequirementIdOfHistoryListNewHistory.equals(requirement)) { - oldRequirementIdOfHistoryListNewHistory.getHistoryList().remove(historyListNewHistory); - oldRequirementIdOfHistoryListNewHistory = em.merge(oldRequirementIdOfHistoryListNewHistory); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = requirement.getId(); - if (findRequirement(id) == null) { - throw new NonexistentEntityException("The requirement with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Requirement requirement; - try { - requirement = em.getReference(Requirement.class, id); - requirement.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The requirement with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List riskControlHasRequirementListOrphanCheck = requirement.getRiskControlHasRequirementList(); - for (RiskControlHasRequirement riskControlHasRequirementListOrphanCheckRiskControlHasRequirement : riskControlHasRequirementListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Requirement (" + requirement + ") cannot be destroyed since the RiskControlHasRequirement " + riskControlHasRequirementListOrphanCheckRiskControlHasRequirement + " in its riskControlHasRequirementList field has a non-nullable requirement field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - Requirement parentRequirementId = requirement.getParentRequirementId(); - if (parentRequirementId != null) { - parentRequirementId.getRequirementList().remove(requirement); - parentRequirementId = em.merge(parentRequirementId); - } - RequirementSpecNode requirementSpecNode = requirement.getRequirementSpecNode(); - if (requirementSpecNode != null) { - requirementSpecNode.getRequirementList().remove(requirement); - requirementSpecNode = em.merge(requirementSpecNode); - } - RequirementStatus requirementStatusId = requirement.getRequirementStatusId(); - if (requirementStatusId != null) { - requirementStatusId.getRequirementList().remove(requirement); - requirementStatusId = em.merge(requirementStatusId); - } - RequirementType requirementTypeId = requirement.getRequirementTypeId(); - if (requirementTypeId != null) { - requirementTypeId.getRequirementList().remove(requirement); - requirementTypeId = em.merge(requirementTypeId); - } - List requirementList = requirement.getRequirementList(); - for (Requirement requirementListRequirement : requirementList) { - requirementListRequirement.setParentRequirementId(null); - requirementListRequirement = em.merge(requirementListRequirement); - } - List stepList = requirement.getStepList(); - for (Step stepListStep : stepList) { - stepListStep.getRequirementList().remove(requirement); - stepListStep = em.merge(stepListStep); - } - List historyList = requirement.getHistoryList(); - for (History historyListHistory : historyList) { - historyListHistory.setRequirementId(null); - historyListHistory = em.merge(historyListHistory); - } - em.remove(requirement); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findRequirementEntities() { - return findRequirementEntities(true, -1, -1); - } - - public List findRequirementEntities(int maxResults, int firstResult) { - return findRequirementEntities(false, maxResults, firstResult); - } - - private List findRequirementEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Requirement.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public Requirement findRequirement(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(Requirement.class, id); - } - finally { - em.close(); - } - } - - public int getRequirementCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(Requirement.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Requirement; +import com.validation.manager.core.db.RequirementSpecNode; +import com.validation.manager.core.db.RequirementStatus; +import com.validation.manager.core.db.RequirementType; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.Step; +import com.validation.manager.core.db.RiskControlHasRequirement; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RequirementJpaController implements Serializable { + + public RequirementJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Requirement requirement) { + if (requirement.getRequirementList() == null) { + requirement.setRequirementList(new ArrayList<>()); + } + if (requirement.getStepList() == null) { + requirement.setStepList(new ArrayList<>()); + } + if (requirement.getRiskControlHasRequirementList() == null) { + requirement.setRiskControlHasRequirementList(new ArrayList<>()); + } + if (requirement.getHistoryList() == null) { + requirement.setHistoryList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Requirement parentRequirementId = requirement.getParentRequirementId(); + if (parentRequirementId != null) { + parentRequirementId = em.getReference(parentRequirementId.getClass(), parentRequirementId.getId()); + requirement.setParentRequirementId(parentRequirementId); + } + RequirementSpecNode requirementSpecNode = requirement.getRequirementSpecNode(); + if (requirementSpecNode != null) { + requirementSpecNode = em.getReference(requirementSpecNode.getClass(), requirementSpecNode.getRequirementSpecNodePK()); + requirement.setRequirementSpecNode(requirementSpecNode); + } + RequirementStatus requirementStatusId = requirement.getRequirementStatusId(); + if (requirementStatusId != null) { + requirementStatusId = em.getReference(requirementStatusId.getClass(), requirementStatusId.getId()); + requirement.setRequirementStatusId(requirementStatusId); + } + RequirementType requirementTypeId = requirement.getRequirementTypeId(); + if (requirementTypeId != null) { + requirementTypeId = em.getReference(requirementTypeId.getClass(), requirementTypeId.getId()); + requirement.setRequirementTypeId(requirementTypeId); + } + List attachedRequirementList = new ArrayList<>(); + for (Requirement requirementListRequirementToAttach : requirement.getRequirementList()) { + requirementListRequirementToAttach = em.getReference(requirementListRequirementToAttach.getClass(), requirementListRequirementToAttach.getId()); + attachedRequirementList.add(requirementListRequirementToAttach); + } + requirement.setRequirementList(attachedRequirementList); + List attachedStepList = new ArrayList<>(); + for (Step stepListStepToAttach : requirement.getStepList()) { + stepListStepToAttach = em.getReference(stepListStepToAttach.getClass(), stepListStepToAttach.getStepPK()); + attachedStepList.add(stepListStepToAttach); + } + requirement.setStepList(attachedStepList); + List attachedRiskControlHasRequirementList = new ArrayList<>(); + for (RiskControlHasRequirement riskControlHasRequirementListRiskControlHasRequirementToAttach : requirement.getRiskControlHasRequirementList()) { + riskControlHasRequirementListRiskControlHasRequirementToAttach = em.getReference(riskControlHasRequirementListRiskControlHasRequirementToAttach.getClass(), riskControlHasRequirementListRiskControlHasRequirementToAttach.getRiskControlHasRequirementPK()); + attachedRiskControlHasRequirementList.add(riskControlHasRequirementListRiskControlHasRequirementToAttach); + } + requirement.setRiskControlHasRequirementList(attachedRiskControlHasRequirementList); + List attachedHistoryList = new ArrayList<>(); + for (History historyListHistoryToAttach : requirement.getHistoryList()) { + historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); + attachedHistoryList.add(historyListHistoryToAttach); + } + requirement.setHistoryList(attachedHistoryList); + em.persist(requirement); + if (parentRequirementId != null) { + parentRequirementId.getRequirementList().add(requirement); + parentRequirementId = em.merge(parentRequirementId); + } + if (requirementSpecNode != null) { + requirementSpecNode.getRequirementList().add(requirement); + requirementSpecNode = em.merge(requirementSpecNode); + } + if (requirementStatusId != null) { + requirementStatusId.getRequirementList().add(requirement); + requirementStatusId = em.merge(requirementStatusId); + } + if (requirementTypeId != null) { + requirementTypeId.getRequirementList().add(requirement); + requirementTypeId = em.merge(requirementTypeId); + } + for (Requirement requirementListRequirement : requirement.getRequirementList()) { + Requirement oldParentRequirementIdOfRequirementListRequirement = requirementListRequirement.getParentRequirementId(); + requirementListRequirement.setParentRequirementId(requirement); + requirementListRequirement = em.merge(requirementListRequirement); + if (oldParentRequirementIdOfRequirementListRequirement != null) { + oldParentRequirementIdOfRequirementListRequirement.getRequirementList().remove(requirementListRequirement); + oldParentRequirementIdOfRequirementListRequirement = em.merge(oldParentRequirementIdOfRequirementListRequirement); + } + } + for (Step stepListStep : requirement.getStepList()) { + stepListStep.getRequirementList().add(requirement); + stepListStep = em.merge(stepListStep); + } + for (RiskControlHasRequirement riskControlHasRequirementListRiskControlHasRequirement : requirement.getRiskControlHasRequirementList()) { + Requirement oldRequirementOfRiskControlHasRequirementListRiskControlHasRequirement = riskControlHasRequirementListRiskControlHasRequirement.getRequirement(); + riskControlHasRequirementListRiskControlHasRequirement.setRequirement(requirement); + riskControlHasRequirementListRiskControlHasRequirement = em.merge(riskControlHasRequirementListRiskControlHasRequirement); + if (oldRequirementOfRiskControlHasRequirementListRiskControlHasRequirement != null) { + oldRequirementOfRiskControlHasRequirementListRiskControlHasRequirement.getRiskControlHasRequirementList().remove(riskControlHasRequirementListRiskControlHasRequirement); + oldRequirementOfRiskControlHasRequirementListRiskControlHasRequirement = em.merge(oldRequirementOfRiskControlHasRequirementListRiskControlHasRequirement); + } + } + for (History historyListHistory : requirement.getHistoryList()) { + Requirement oldRequirementIdOfHistoryListHistory = historyListHistory.getRequirementId(); + historyListHistory.setRequirementId(requirement); + historyListHistory = em.merge(historyListHistory); + if (oldRequirementIdOfHistoryListHistory != null) { + oldRequirementIdOfHistoryListHistory.getHistoryList().remove(historyListHistory); + oldRequirementIdOfHistoryListHistory = em.merge(oldRequirementIdOfHistoryListHistory); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Requirement requirement) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Requirement persistentRequirement = em.find(Requirement.class, requirement.getId()); + Requirement parentRequirementIdOld = persistentRequirement.getParentRequirementId(); + Requirement parentRequirementIdNew = requirement.getParentRequirementId(); + RequirementSpecNode requirementSpecNodeOld = persistentRequirement.getRequirementSpecNode(); + RequirementSpecNode requirementSpecNodeNew = requirement.getRequirementSpecNode(); + RequirementStatus requirementStatusIdOld = persistentRequirement.getRequirementStatusId(); + RequirementStatus requirementStatusIdNew = requirement.getRequirementStatusId(); + RequirementType requirementTypeIdOld = persistentRequirement.getRequirementTypeId(); + RequirementType requirementTypeIdNew = requirement.getRequirementTypeId(); + List requirementListOld = persistentRequirement.getRequirementList(); + List requirementListNew = requirement.getRequirementList(); + List stepListOld = persistentRequirement.getStepList(); + List stepListNew = requirement.getStepList(); + List riskControlHasRequirementListOld = persistentRequirement.getRiskControlHasRequirementList(); + List riskControlHasRequirementListNew = requirement.getRiskControlHasRequirementList(); + List historyListOld = persistentRequirement.getHistoryList(); + List historyListNew = requirement.getHistoryList(); + List illegalOrphanMessages = null; + for (RiskControlHasRequirement riskControlHasRequirementListOldRiskControlHasRequirement : riskControlHasRequirementListOld) { + if (!riskControlHasRequirementListNew.contains(riskControlHasRequirementListOldRiskControlHasRequirement)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain RiskControlHasRequirement " + riskControlHasRequirementListOldRiskControlHasRequirement + " since its requirement field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (parentRequirementIdNew != null) { + parentRequirementIdNew = em.getReference(parentRequirementIdNew.getClass(), parentRequirementIdNew.getId()); + requirement.setParentRequirementId(parentRequirementIdNew); + } + if (requirementSpecNodeNew != null) { + requirementSpecNodeNew = em.getReference(requirementSpecNodeNew.getClass(), requirementSpecNodeNew.getRequirementSpecNodePK()); + requirement.setRequirementSpecNode(requirementSpecNodeNew); + } + if (requirementStatusIdNew != null) { + requirementStatusIdNew = em.getReference(requirementStatusIdNew.getClass(), requirementStatusIdNew.getId()); + requirement.setRequirementStatusId(requirementStatusIdNew); + } + if (requirementTypeIdNew != null) { + requirementTypeIdNew = em.getReference(requirementTypeIdNew.getClass(), requirementTypeIdNew.getId()); + requirement.setRequirementTypeId(requirementTypeIdNew); + } + List attachedRequirementListNew = new ArrayList<>(); + for (Requirement requirementListNewRequirementToAttach : requirementListNew) { + requirementListNewRequirementToAttach = em.getReference(requirementListNewRequirementToAttach.getClass(), requirementListNewRequirementToAttach.getId()); + attachedRequirementListNew.add(requirementListNewRequirementToAttach); + } + requirementListNew = attachedRequirementListNew; + requirement.setRequirementList(requirementListNew); + List attachedStepListNew = new ArrayList<>(); + for (Step stepListNewStepToAttach : stepListNew) { + stepListNewStepToAttach = em.getReference(stepListNewStepToAttach.getClass(), stepListNewStepToAttach.getStepPK()); + attachedStepListNew.add(stepListNewStepToAttach); + } + stepListNew = attachedStepListNew; + requirement.setStepList(stepListNew); + List attachedRiskControlHasRequirementListNew = new ArrayList<>(); + for (RiskControlHasRequirement riskControlHasRequirementListNewRiskControlHasRequirementToAttach : riskControlHasRequirementListNew) { + riskControlHasRequirementListNewRiskControlHasRequirementToAttach = em.getReference(riskControlHasRequirementListNewRiskControlHasRequirementToAttach.getClass(), riskControlHasRequirementListNewRiskControlHasRequirementToAttach.getRiskControlHasRequirementPK()); + attachedRiskControlHasRequirementListNew.add(riskControlHasRequirementListNewRiskControlHasRequirementToAttach); + } + riskControlHasRequirementListNew = attachedRiskControlHasRequirementListNew; + requirement.setRiskControlHasRequirementList(riskControlHasRequirementListNew); + List attachedHistoryListNew = new ArrayList<>(); + for (History historyListNewHistoryToAttach : historyListNew) { + historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); + attachedHistoryListNew.add(historyListNewHistoryToAttach); + } + historyListNew = attachedHistoryListNew; + requirement.setHistoryList(historyListNew); + requirement = em.merge(requirement); + if (parentRequirementIdOld != null && !parentRequirementIdOld.equals(parentRequirementIdNew)) { + parentRequirementIdOld.getRequirementList().remove(requirement); + parentRequirementIdOld = em.merge(parentRequirementIdOld); + } + if (parentRequirementIdNew != null && !parentRequirementIdNew.equals(parentRequirementIdOld)) { + parentRequirementIdNew.getRequirementList().add(requirement); + parentRequirementIdNew = em.merge(parentRequirementIdNew); + } + if (requirementSpecNodeOld != null && !requirementSpecNodeOld.equals(requirementSpecNodeNew)) { + requirementSpecNodeOld.getRequirementList().remove(requirement); + requirementSpecNodeOld = em.merge(requirementSpecNodeOld); + } + if (requirementSpecNodeNew != null && !requirementSpecNodeNew.equals(requirementSpecNodeOld)) { + requirementSpecNodeNew.getRequirementList().add(requirement); + requirementSpecNodeNew = em.merge(requirementSpecNodeNew); + } + if (requirementStatusIdOld != null && !requirementStatusIdOld.equals(requirementStatusIdNew)) { + requirementStatusIdOld.getRequirementList().remove(requirement); + requirementStatusIdOld = em.merge(requirementStatusIdOld); + } + if (requirementStatusIdNew != null && !requirementStatusIdNew.equals(requirementStatusIdOld)) { + requirementStatusIdNew.getRequirementList().add(requirement); + requirementStatusIdNew = em.merge(requirementStatusIdNew); + } + if (requirementTypeIdOld != null && !requirementTypeIdOld.equals(requirementTypeIdNew)) { + requirementTypeIdOld.getRequirementList().remove(requirement); + requirementTypeIdOld = em.merge(requirementTypeIdOld); + } + if (requirementTypeIdNew != null && !requirementTypeIdNew.equals(requirementTypeIdOld)) { + requirementTypeIdNew.getRequirementList().add(requirement); + requirementTypeIdNew = em.merge(requirementTypeIdNew); + } + for (Requirement requirementListOldRequirement : requirementListOld) { + if (!requirementListNew.contains(requirementListOldRequirement)) { + requirementListOldRequirement.setParentRequirementId(null); + requirementListOldRequirement = em.merge(requirementListOldRequirement); + } + } + for (Requirement requirementListNewRequirement : requirementListNew) { + if (!requirementListOld.contains(requirementListNewRequirement)) { + Requirement oldParentRequirementIdOfRequirementListNewRequirement = requirementListNewRequirement.getParentRequirementId(); + requirementListNewRequirement.setParentRequirementId(requirement); + requirementListNewRequirement = em.merge(requirementListNewRequirement); + if (oldParentRequirementIdOfRequirementListNewRequirement != null && !oldParentRequirementIdOfRequirementListNewRequirement.equals(requirement)) { + oldParentRequirementIdOfRequirementListNewRequirement.getRequirementList().remove(requirementListNewRequirement); + oldParentRequirementIdOfRequirementListNewRequirement = em.merge(oldParentRequirementIdOfRequirementListNewRequirement); + } + } + } + for (Step stepListOldStep : stepListOld) { + if (!stepListNew.contains(stepListOldStep)) { + stepListOldStep.getRequirementList().remove(requirement); + stepListOldStep = em.merge(stepListOldStep); + } + } + for (Step stepListNewStep : stepListNew) { + if (!stepListOld.contains(stepListNewStep)) { + stepListNewStep.getRequirementList().add(requirement); + stepListNewStep = em.merge(stepListNewStep); + } + } + for (RiskControlHasRequirement riskControlHasRequirementListNewRiskControlHasRequirement : riskControlHasRequirementListNew) { + if (!riskControlHasRequirementListOld.contains(riskControlHasRequirementListNewRiskControlHasRequirement)) { + Requirement oldRequirementOfRiskControlHasRequirementListNewRiskControlHasRequirement = riskControlHasRequirementListNewRiskControlHasRequirement.getRequirement(); + riskControlHasRequirementListNewRiskControlHasRequirement.setRequirement(requirement); + riskControlHasRequirementListNewRiskControlHasRequirement = em.merge(riskControlHasRequirementListNewRiskControlHasRequirement); + if (oldRequirementOfRiskControlHasRequirementListNewRiskControlHasRequirement != null && !oldRequirementOfRiskControlHasRequirementListNewRiskControlHasRequirement.equals(requirement)) { + oldRequirementOfRiskControlHasRequirementListNewRiskControlHasRequirement.getRiskControlHasRequirementList().remove(riskControlHasRequirementListNewRiskControlHasRequirement); + oldRequirementOfRiskControlHasRequirementListNewRiskControlHasRequirement = em.merge(oldRequirementOfRiskControlHasRequirementListNewRiskControlHasRequirement); + } + } + } + for (History historyListOldHistory : historyListOld) { + if (!historyListNew.contains(historyListOldHistory)) { + historyListOldHistory.setRequirementId(null); + historyListOldHistory = em.merge(historyListOldHistory); + } + } + for (History historyListNewHistory : historyListNew) { + if (!historyListOld.contains(historyListNewHistory)) { + Requirement oldRequirementIdOfHistoryListNewHistory = historyListNewHistory.getRequirementId(); + historyListNewHistory.setRequirementId(requirement); + historyListNewHistory = em.merge(historyListNewHistory); + if (oldRequirementIdOfHistoryListNewHistory != null && !oldRequirementIdOfHistoryListNewHistory.equals(requirement)) { + oldRequirementIdOfHistoryListNewHistory.getHistoryList().remove(historyListNewHistory); + oldRequirementIdOfHistoryListNewHistory = em.merge(oldRequirementIdOfHistoryListNewHistory); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = requirement.getId(); + if (findRequirement(id) == null) { + throw new NonexistentEntityException("The requirement with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Requirement requirement; + try { + requirement = em.getReference(Requirement.class, id); + requirement.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The requirement with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List riskControlHasRequirementListOrphanCheck = requirement.getRiskControlHasRequirementList(); + for (RiskControlHasRequirement riskControlHasRequirementListOrphanCheckRiskControlHasRequirement : riskControlHasRequirementListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Requirement (" + requirement + ") cannot be destroyed since the RiskControlHasRequirement " + riskControlHasRequirementListOrphanCheckRiskControlHasRequirement + " in its riskControlHasRequirementList field has a non-nullable requirement field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + Requirement parentRequirementId = requirement.getParentRequirementId(); + if (parentRequirementId != null) { + parentRequirementId.getRequirementList().remove(requirement); + parentRequirementId = em.merge(parentRequirementId); + } + RequirementSpecNode requirementSpecNode = requirement.getRequirementSpecNode(); + if (requirementSpecNode != null) { + requirementSpecNode.getRequirementList().remove(requirement); + requirementSpecNode = em.merge(requirementSpecNode); + } + RequirementStatus requirementStatusId = requirement.getRequirementStatusId(); + if (requirementStatusId != null) { + requirementStatusId.getRequirementList().remove(requirement); + requirementStatusId = em.merge(requirementStatusId); + } + RequirementType requirementTypeId = requirement.getRequirementTypeId(); + if (requirementTypeId != null) { + requirementTypeId.getRequirementList().remove(requirement); + requirementTypeId = em.merge(requirementTypeId); + } + List requirementList = requirement.getRequirementList(); + for (Requirement requirementListRequirement : requirementList) { + requirementListRequirement.setParentRequirementId(null); + requirementListRequirement = em.merge(requirementListRequirement); + } + List stepList = requirement.getStepList(); + for (Step stepListStep : stepList) { + stepListStep.getRequirementList().remove(requirement); + stepListStep = em.merge(stepListStep); + } + List historyList = requirement.getHistoryList(); + for (History historyListHistory : historyList) { + historyListHistory.setRequirementId(null); + historyListHistory = em.merge(historyListHistory); + } + em.remove(requirement); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findRequirementEntities() { + return findRequirementEntities(true, -1, -1); + } + + public List findRequirementEntities(int maxResults, int firstResult) { + return findRequirementEntities(false, maxResults, firstResult); + } + + private List findRequirementEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Requirement.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public Requirement findRequirement(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(Requirement.class, id); + } + finally { + em.close(); + } + } + + public int getRequirementCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Requirement.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementSpecJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementSpecJpaController.java index bcb1d522..47160912 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementSpecJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementSpecJpaController.java @@ -13,336 +13,336 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Project; -import com.validation.manager.core.db.SpecLevel; -import com.validation.manager.core.db.RequirementSpecNode; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.Baseline; -import com.validation.manager.core.db.RequirementSpec; -import com.validation.manager.core.db.RequirementSpecPK; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RequirementSpecJpaController implements Serializable { - - public RequirementSpecJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(RequirementSpec requirementSpec) throws PreexistingEntityException, Exception { - if (requirementSpec.getRequirementSpecPK() == null) { - requirementSpec.setRequirementSpecPK(new RequirementSpecPK()); - } - if (requirementSpec.getRequirementSpecNodeList() == null) { - requirementSpec.setRequirementSpecNodeList(new ArrayList()); - } - if (requirementSpec.getBaselineList() == null) { - requirementSpec.setBaselineList(new ArrayList()); - } - requirementSpec.getRequirementSpecPK().setSpecLevelId(requirementSpec.getSpecLevel().getId()); - requirementSpec.getRequirementSpecPK().setProjectId(requirementSpec.getProject().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Project project = requirementSpec.getProject(); - if (project != null) { - project = em.getReference(project.getClass(), project.getId()); - requirementSpec.setProject(project); - } - SpecLevel specLevel = requirementSpec.getSpecLevel(); - if (specLevel != null) { - specLevel = em.getReference(specLevel.getClass(), specLevel.getId()); - requirementSpec.setSpecLevel(specLevel); - } - List attachedRequirementSpecNodeList = new ArrayList(); - for (RequirementSpecNode requirementSpecNodeListRequirementSpecNodeToAttach : requirementSpec.getRequirementSpecNodeList()) { - requirementSpecNodeListRequirementSpecNodeToAttach = em.getReference(requirementSpecNodeListRequirementSpecNodeToAttach.getClass(), requirementSpecNodeListRequirementSpecNodeToAttach.getRequirementSpecNodePK()); - attachedRequirementSpecNodeList.add(requirementSpecNodeListRequirementSpecNodeToAttach); - } - requirementSpec.setRequirementSpecNodeList(attachedRequirementSpecNodeList); - List attachedBaselineList = new ArrayList(); - for (Baseline baselineListBaselineToAttach : requirementSpec.getBaselineList()) { - baselineListBaselineToAttach = em.getReference(baselineListBaselineToAttach.getClass(), baselineListBaselineToAttach.getId()); - attachedBaselineList.add(baselineListBaselineToAttach); - } - requirementSpec.setBaselineList(attachedBaselineList); - em.persist(requirementSpec); - if (project != null) { - project.getRequirementSpecList().add(requirementSpec); - project = em.merge(project); - } - if (specLevel != null) { - specLevel.getRequirementSpecList().add(requirementSpec); - specLevel = em.merge(specLevel); - } - for (RequirementSpecNode requirementSpecNodeListRequirementSpecNode : requirementSpec.getRequirementSpecNodeList()) { - RequirementSpec oldRequirementSpecOfRequirementSpecNodeListRequirementSpecNode = requirementSpecNodeListRequirementSpecNode.getRequirementSpec(); - requirementSpecNodeListRequirementSpecNode.setRequirementSpec(requirementSpec); - requirementSpecNodeListRequirementSpecNode = em.merge(requirementSpecNodeListRequirementSpecNode); - if (oldRequirementSpecOfRequirementSpecNodeListRequirementSpecNode != null) { - oldRequirementSpecOfRequirementSpecNodeListRequirementSpecNode.getRequirementSpecNodeList().remove(requirementSpecNodeListRequirementSpecNode); - oldRequirementSpecOfRequirementSpecNodeListRequirementSpecNode = em.merge(oldRequirementSpecOfRequirementSpecNodeListRequirementSpecNode); - } - } - for (Baseline baselineListBaseline : requirementSpec.getBaselineList()) { - RequirementSpec oldRequirementSpecOfBaselineListBaseline = baselineListBaseline.getRequirementSpec(); - baselineListBaseline.setRequirementSpec(requirementSpec); - baselineListBaseline = em.merge(baselineListBaseline); - if (oldRequirementSpecOfBaselineListBaseline != null) { - oldRequirementSpecOfBaselineListBaseline.getBaselineList().remove(baselineListBaseline); - oldRequirementSpecOfBaselineListBaseline = em.merge(oldRequirementSpecOfBaselineListBaseline); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - if (findRequirementSpec(requirementSpec.getRequirementSpecPK()) != null) { - throw new PreexistingEntityException("RequirementSpec " + requirementSpec + " already exists.", ex); - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(RequirementSpec requirementSpec) throws IllegalOrphanException, NonexistentEntityException, Exception { - requirementSpec.getRequirementSpecPK().setSpecLevelId(requirementSpec.getSpecLevel().getId()); - requirementSpec.getRequirementSpecPK().setProjectId(requirementSpec.getProject().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RequirementSpec persistentRequirementSpec = em.find(RequirementSpec.class, requirementSpec.getRequirementSpecPK()); - Project projectOld = persistentRequirementSpec.getProject(); - Project projectNew = requirementSpec.getProject(); - SpecLevel specLevelOld = persistentRequirementSpec.getSpecLevel(); - SpecLevel specLevelNew = requirementSpec.getSpecLevel(); - List requirementSpecNodeListOld = persistentRequirementSpec.getRequirementSpecNodeList(); - List requirementSpecNodeListNew = requirementSpec.getRequirementSpecNodeList(); - List baselineListOld = persistentRequirementSpec.getBaselineList(); - List baselineListNew = requirementSpec.getBaselineList(); - List illegalOrphanMessages = null; - for (RequirementSpecNode requirementSpecNodeListOldRequirementSpecNode : requirementSpecNodeListOld) { - if (!requirementSpecNodeListNew.contains(requirementSpecNodeListOldRequirementSpecNode)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain RequirementSpecNode " + requirementSpecNodeListOldRequirementSpecNode + " since its requirementSpec field is not nullable."); - } - } - for (Baseline baselineListOldBaseline : baselineListOld) { - if (!baselineListNew.contains(baselineListOldBaseline)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain Baseline " + baselineListOldBaseline + " since its requirementSpec field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (projectNew != null) { - projectNew = em.getReference(projectNew.getClass(), projectNew.getId()); - requirementSpec.setProject(projectNew); - } - if (specLevelNew != null) { - specLevelNew = em.getReference(specLevelNew.getClass(), specLevelNew.getId()); - requirementSpec.setSpecLevel(specLevelNew); - } - List attachedRequirementSpecNodeListNew = new ArrayList(); - for (RequirementSpecNode requirementSpecNodeListNewRequirementSpecNodeToAttach : requirementSpecNodeListNew) { - requirementSpecNodeListNewRequirementSpecNodeToAttach = em.getReference(requirementSpecNodeListNewRequirementSpecNodeToAttach.getClass(), requirementSpecNodeListNewRequirementSpecNodeToAttach.getRequirementSpecNodePK()); - attachedRequirementSpecNodeListNew.add(requirementSpecNodeListNewRequirementSpecNodeToAttach); - } - requirementSpecNodeListNew = attachedRequirementSpecNodeListNew; - requirementSpec.setRequirementSpecNodeList(requirementSpecNodeListNew); - List attachedBaselineListNew = new ArrayList(); - for (Baseline baselineListNewBaselineToAttach : baselineListNew) { - baselineListNewBaselineToAttach = em.getReference(baselineListNewBaselineToAttach.getClass(), baselineListNewBaselineToAttach.getId()); - attachedBaselineListNew.add(baselineListNewBaselineToAttach); - } - baselineListNew = attachedBaselineListNew; - requirementSpec.setBaselineList(baselineListNew); - requirementSpec = em.merge(requirementSpec); - if (projectOld != null && !projectOld.equals(projectNew)) { - projectOld.getRequirementSpecList().remove(requirementSpec); - projectOld = em.merge(projectOld); - } - if (projectNew != null && !projectNew.equals(projectOld)) { - projectNew.getRequirementSpecList().add(requirementSpec); - projectNew = em.merge(projectNew); - } - if (specLevelOld != null && !specLevelOld.equals(specLevelNew)) { - specLevelOld.getRequirementSpecList().remove(requirementSpec); - specLevelOld = em.merge(specLevelOld); - } - if (specLevelNew != null && !specLevelNew.equals(specLevelOld)) { - specLevelNew.getRequirementSpecList().add(requirementSpec); - specLevelNew = em.merge(specLevelNew); - } - for (RequirementSpecNode requirementSpecNodeListNewRequirementSpecNode : requirementSpecNodeListNew) { - if (!requirementSpecNodeListOld.contains(requirementSpecNodeListNewRequirementSpecNode)) { - RequirementSpec oldRequirementSpecOfRequirementSpecNodeListNewRequirementSpecNode = requirementSpecNodeListNewRequirementSpecNode.getRequirementSpec(); - requirementSpecNodeListNewRequirementSpecNode.setRequirementSpec(requirementSpec); - requirementSpecNodeListNewRequirementSpecNode = em.merge(requirementSpecNodeListNewRequirementSpecNode); - if (oldRequirementSpecOfRequirementSpecNodeListNewRequirementSpecNode != null && !oldRequirementSpecOfRequirementSpecNodeListNewRequirementSpecNode.equals(requirementSpec)) { - oldRequirementSpecOfRequirementSpecNodeListNewRequirementSpecNode.getRequirementSpecNodeList().remove(requirementSpecNodeListNewRequirementSpecNode); - oldRequirementSpecOfRequirementSpecNodeListNewRequirementSpecNode = em.merge(oldRequirementSpecOfRequirementSpecNodeListNewRequirementSpecNode); - } - } - } - for (Baseline baselineListNewBaseline : baselineListNew) { - if (!baselineListOld.contains(baselineListNewBaseline)) { - RequirementSpec oldRequirementSpecOfBaselineListNewBaseline = baselineListNewBaseline.getRequirementSpec(); - baselineListNewBaseline.setRequirementSpec(requirementSpec); - baselineListNewBaseline = em.merge(baselineListNewBaseline); - if (oldRequirementSpecOfBaselineListNewBaseline != null && !oldRequirementSpecOfBaselineListNewBaseline.equals(requirementSpec)) { - oldRequirementSpecOfBaselineListNewBaseline.getBaselineList().remove(baselineListNewBaseline); - oldRequirementSpecOfBaselineListNewBaseline = em.merge(oldRequirementSpecOfBaselineListNewBaseline); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - RequirementSpecPK id = requirementSpec.getRequirementSpecPK(); - if (findRequirementSpec(id) == null) { - throw new NonexistentEntityException("The requirementSpec with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(RequirementSpecPK id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RequirementSpec requirementSpec; - try { - requirementSpec = em.getReference(RequirementSpec.class, id); - requirementSpec.getRequirementSpecPK(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The requirementSpec with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List requirementSpecNodeListOrphanCheck = requirementSpec.getRequirementSpecNodeList(); - for (RequirementSpecNode requirementSpecNodeListOrphanCheckRequirementSpecNode : requirementSpecNodeListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This RequirementSpec (" + requirementSpec + ") cannot be destroyed since the RequirementSpecNode " + requirementSpecNodeListOrphanCheckRequirementSpecNode + " in its requirementSpecNodeList field has a non-nullable requirementSpec field."); - } - List baselineListOrphanCheck = requirementSpec.getBaselineList(); - for (Baseline baselineListOrphanCheckBaseline : baselineListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This RequirementSpec (" + requirementSpec + ") cannot be destroyed since the Baseline " + baselineListOrphanCheckBaseline + " in its baselineList field has a non-nullable requirementSpec field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - Project project = requirementSpec.getProject(); - if (project != null) { - project.getRequirementSpecList().remove(requirementSpec); - project = em.merge(project); - } - SpecLevel specLevel = requirementSpec.getSpecLevel(); - if (specLevel != null) { - specLevel.getRequirementSpecList().remove(requirementSpec); - specLevel = em.merge(specLevel); - } - em.remove(requirementSpec); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findRequirementSpecEntities() { - return findRequirementSpecEntities(true, -1, -1); - } - - public List findRequirementSpecEntities(int maxResults, int firstResult) { - return findRequirementSpecEntities(false, maxResults, firstResult); - } - - private List findRequirementSpecEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(RequirementSpec.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public RequirementSpec findRequirementSpec(RequirementSpecPK id) { - EntityManager em = getEntityManager(); - try { - return em.find(RequirementSpec.class, id); - } - finally { - em.close(); - } - } - - public int getRequirementSpecCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(RequirementSpec.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Project; +import com.validation.manager.core.db.SpecLevel; +import com.validation.manager.core.db.RequirementSpecNode; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.Baseline; +import com.validation.manager.core.db.RequirementSpec; +import com.validation.manager.core.db.RequirementSpecPK; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RequirementSpecJpaController implements Serializable { + + public RequirementSpecJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(RequirementSpec requirementSpec) throws PreexistingEntityException, Exception { + if (requirementSpec.getRequirementSpecPK() == null) { + requirementSpec.setRequirementSpecPK(new RequirementSpecPK()); + } + if (requirementSpec.getRequirementSpecNodeList() == null) { + requirementSpec.setRequirementSpecNodeList(new ArrayList<>()); + } + if (requirementSpec.getBaselineList() == null) { + requirementSpec.setBaselineList(new ArrayList<>()); + } + requirementSpec.getRequirementSpecPK().setSpecLevelId(requirementSpec.getSpecLevel().getId()); + requirementSpec.getRequirementSpecPK().setProjectId(requirementSpec.getProject().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Project project = requirementSpec.getProject(); + if (project != null) { + project = em.getReference(project.getClass(), project.getId()); + requirementSpec.setProject(project); + } + SpecLevel specLevel = requirementSpec.getSpecLevel(); + if (specLevel != null) { + specLevel = em.getReference(specLevel.getClass(), specLevel.getId()); + requirementSpec.setSpecLevel(specLevel); + } + List attachedRequirementSpecNodeList = new ArrayList<>(); + for (RequirementSpecNode requirementSpecNodeListRequirementSpecNodeToAttach : requirementSpec.getRequirementSpecNodeList()) { + requirementSpecNodeListRequirementSpecNodeToAttach = em.getReference(requirementSpecNodeListRequirementSpecNodeToAttach.getClass(), requirementSpecNodeListRequirementSpecNodeToAttach.getRequirementSpecNodePK()); + attachedRequirementSpecNodeList.add(requirementSpecNodeListRequirementSpecNodeToAttach); + } + requirementSpec.setRequirementSpecNodeList(attachedRequirementSpecNodeList); + List attachedBaselineList = new ArrayList<>(); + for (Baseline baselineListBaselineToAttach : requirementSpec.getBaselineList()) { + baselineListBaselineToAttach = em.getReference(baselineListBaselineToAttach.getClass(), baselineListBaselineToAttach.getId()); + attachedBaselineList.add(baselineListBaselineToAttach); + } + requirementSpec.setBaselineList(attachedBaselineList); + em.persist(requirementSpec); + if (project != null) { + project.getRequirementSpecList().add(requirementSpec); + project = em.merge(project); + } + if (specLevel != null) { + specLevel.getRequirementSpecList().add(requirementSpec); + specLevel = em.merge(specLevel); + } + for (RequirementSpecNode requirementSpecNodeListRequirementSpecNode : requirementSpec.getRequirementSpecNodeList()) { + RequirementSpec oldRequirementSpecOfRequirementSpecNodeListRequirementSpecNode = requirementSpecNodeListRequirementSpecNode.getRequirementSpec(); + requirementSpecNodeListRequirementSpecNode.setRequirementSpec(requirementSpec); + requirementSpecNodeListRequirementSpecNode = em.merge(requirementSpecNodeListRequirementSpecNode); + if (oldRequirementSpecOfRequirementSpecNodeListRequirementSpecNode != null) { + oldRequirementSpecOfRequirementSpecNodeListRequirementSpecNode.getRequirementSpecNodeList().remove(requirementSpecNodeListRequirementSpecNode); + oldRequirementSpecOfRequirementSpecNodeListRequirementSpecNode = em.merge(oldRequirementSpecOfRequirementSpecNodeListRequirementSpecNode); + } + } + for (Baseline baselineListBaseline : requirementSpec.getBaselineList()) { + RequirementSpec oldRequirementSpecOfBaselineListBaseline = baselineListBaseline.getRequirementSpec(); + baselineListBaseline.setRequirementSpec(requirementSpec); + baselineListBaseline = em.merge(baselineListBaseline); + if (oldRequirementSpecOfBaselineListBaseline != null) { + oldRequirementSpecOfBaselineListBaseline.getBaselineList().remove(baselineListBaseline); + oldRequirementSpecOfBaselineListBaseline = em.merge(oldRequirementSpecOfBaselineListBaseline); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + if (findRequirementSpec(requirementSpec.getRequirementSpecPK()) != null) { + throw new PreexistingEntityException("RequirementSpec " + requirementSpec + " already exists.", ex); + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(RequirementSpec requirementSpec) throws IllegalOrphanException, NonexistentEntityException, Exception { + requirementSpec.getRequirementSpecPK().setSpecLevelId(requirementSpec.getSpecLevel().getId()); + requirementSpec.getRequirementSpecPK().setProjectId(requirementSpec.getProject().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RequirementSpec persistentRequirementSpec = em.find(RequirementSpec.class, requirementSpec.getRequirementSpecPK()); + Project projectOld = persistentRequirementSpec.getProject(); + Project projectNew = requirementSpec.getProject(); + SpecLevel specLevelOld = persistentRequirementSpec.getSpecLevel(); + SpecLevel specLevelNew = requirementSpec.getSpecLevel(); + List requirementSpecNodeListOld = persistentRequirementSpec.getRequirementSpecNodeList(); + List requirementSpecNodeListNew = requirementSpec.getRequirementSpecNodeList(); + List baselineListOld = persistentRequirementSpec.getBaselineList(); + List baselineListNew = requirementSpec.getBaselineList(); + List illegalOrphanMessages = null; + for (RequirementSpecNode requirementSpecNodeListOldRequirementSpecNode : requirementSpecNodeListOld) { + if (!requirementSpecNodeListNew.contains(requirementSpecNodeListOldRequirementSpecNode)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain RequirementSpecNode " + requirementSpecNodeListOldRequirementSpecNode + " since its requirementSpec field is not nullable."); + } + } + for (Baseline baselineListOldBaseline : baselineListOld) { + if (!baselineListNew.contains(baselineListOldBaseline)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain Baseline " + baselineListOldBaseline + " since its requirementSpec field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (projectNew != null) { + projectNew = em.getReference(projectNew.getClass(), projectNew.getId()); + requirementSpec.setProject(projectNew); + } + if (specLevelNew != null) { + specLevelNew = em.getReference(specLevelNew.getClass(), specLevelNew.getId()); + requirementSpec.setSpecLevel(specLevelNew); + } + List attachedRequirementSpecNodeListNew = new ArrayList<>(); + for (RequirementSpecNode requirementSpecNodeListNewRequirementSpecNodeToAttach : requirementSpecNodeListNew) { + requirementSpecNodeListNewRequirementSpecNodeToAttach = em.getReference(requirementSpecNodeListNewRequirementSpecNodeToAttach.getClass(), requirementSpecNodeListNewRequirementSpecNodeToAttach.getRequirementSpecNodePK()); + attachedRequirementSpecNodeListNew.add(requirementSpecNodeListNewRequirementSpecNodeToAttach); + } + requirementSpecNodeListNew = attachedRequirementSpecNodeListNew; + requirementSpec.setRequirementSpecNodeList(requirementSpecNodeListNew); + List attachedBaselineListNew = new ArrayList<>(); + for (Baseline baselineListNewBaselineToAttach : baselineListNew) { + baselineListNewBaselineToAttach = em.getReference(baselineListNewBaselineToAttach.getClass(), baselineListNewBaselineToAttach.getId()); + attachedBaselineListNew.add(baselineListNewBaselineToAttach); + } + baselineListNew = attachedBaselineListNew; + requirementSpec.setBaselineList(baselineListNew); + requirementSpec = em.merge(requirementSpec); + if (projectOld != null && !projectOld.equals(projectNew)) { + projectOld.getRequirementSpecList().remove(requirementSpec); + projectOld = em.merge(projectOld); + } + if (projectNew != null && !projectNew.equals(projectOld)) { + projectNew.getRequirementSpecList().add(requirementSpec); + projectNew = em.merge(projectNew); + } + if (specLevelOld != null && !specLevelOld.equals(specLevelNew)) { + specLevelOld.getRequirementSpecList().remove(requirementSpec); + specLevelOld = em.merge(specLevelOld); + } + if (specLevelNew != null && !specLevelNew.equals(specLevelOld)) { + specLevelNew.getRequirementSpecList().add(requirementSpec); + specLevelNew = em.merge(specLevelNew); + } + for (RequirementSpecNode requirementSpecNodeListNewRequirementSpecNode : requirementSpecNodeListNew) { + if (!requirementSpecNodeListOld.contains(requirementSpecNodeListNewRequirementSpecNode)) { + RequirementSpec oldRequirementSpecOfRequirementSpecNodeListNewRequirementSpecNode = requirementSpecNodeListNewRequirementSpecNode.getRequirementSpec(); + requirementSpecNodeListNewRequirementSpecNode.setRequirementSpec(requirementSpec); + requirementSpecNodeListNewRequirementSpecNode = em.merge(requirementSpecNodeListNewRequirementSpecNode); + if (oldRequirementSpecOfRequirementSpecNodeListNewRequirementSpecNode != null && !oldRequirementSpecOfRequirementSpecNodeListNewRequirementSpecNode.equals(requirementSpec)) { + oldRequirementSpecOfRequirementSpecNodeListNewRequirementSpecNode.getRequirementSpecNodeList().remove(requirementSpecNodeListNewRequirementSpecNode); + oldRequirementSpecOfRequirementSpecNodeListNewRequirementSpecNode = em.merge(oldRequirementSpecOfRequirementSpecNodeListNewRequirementSpecNode); + } + } + } + for (Baseline baselineListNewBaseline : baselineListNew) { + if (!baselineListOld.contains(baselineListNewBaseline)) { + RequirementSpec oldRequirementSpecOfBaselineListNewBaseline = baselineListNewBaseline.getRequirementSpec(); + baselineListNewBaseline.setRequirementSpec(requirementSpec); + baselineListNewBaseline = em.merge(baselineListNewBaseline); + if (oldRequirementSpecOfBaselineListNewBaseline != null && !oldRequirementSpecOfBaselineListNewBaseline.equals(requirementSpec)) { + oldRequirementSpecOfBaselineListNewBaseline.getBaselineList().remove(baselineListNewBaseline); + oldRequirementSpecOfBaselineListNewBaseline = em.merge(oldRequirementSpecOfBaselineListNewBaseline); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + RequirementSpecPK id = requirementSpec.getRequirementSpecPK(); + if (findRequirementSpec(id) == null) { + throw new NonexistentEntityException("The requirementSpec with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(RequirementSpecPK id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RequirementSpec requirementSpec; + try { + requirementSpec = em.getReference(RequirementSpec.class, id); + requirementSpec.getRequirementSpecPK(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The requirementSpec with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List requirementSpecNodeListOrphanCheck = requirementSpec.getRequirementSpecNodeList(); + for (RequirementSpecNode requirementSpecNodeListOrphanCheckRequirementSpecNode : requirementSpecNodeListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This RequirementSpec (" + requirementSpec + ") cannot be destroyed since the RequirementSpecNode " + requirementSpecNodeListOrphanCheckRequirementSpecNode + " in its requirementSpecNodeList field has a non-nullable requirementSpec field."); + } + List baselineListOrphanCheck = requirementSpec.getBaselineList(); + for (Baseline baselineListOrphanCheckBaseline : baselineListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This RequirementSpec (" + requirementSpec + ") cannot be destroyed since the Baseline " + baselineListOrphanCheckBaseline + " in its baselineList field has a non-nullable requirementSpec field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + Project project = requirementSpec.getProject(); + if (project != null) { + project.getRequirementSpecList().remove(requirementSpec); + project = em.merge(project); + } + SpecLevel specLevel = requirementSpec.getSpecLevel(); + if (specLevel != null) { + specLevel.getRequirementSpecList().remove(requirementSpec); + specLevel = em.merge(specLevel); + } + em.remove(requirementSpec); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findRequirementSpecEntities() { + return findRequirementSpecEntities(true, -1, -1); + } + + public List findRequirementSpecEntities(int maxResults, int firstResult) { + return findRequirementSpecEntities(false, maxResults, firstResult); + } + + private List findRequirementSpecEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(RequirementSpec.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public RequirementSpec findRequirementSpec(RequirementSpecPK id) { + EntityManager em = getEntityManager(); + try { + return em.find(RequirementSpec.class, id); + } + finally { + em.close(); + } + } + + public int getRequirementSpecCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(RequirementSpec.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementSpecNodeJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementSpecNodeJpaController.java index bb85a9ad..07511bb7 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementSpecNodeJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementSpecNodeJpaController.java @@ -13,332 +13,332 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.RequirementSpec; -import com.validation.manager.core.db.RequirementSpecNode; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.Requirement; -import com.validation.manager.core.db.RequirementSpecNodePK; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RequirementSpecNodeJpaController implements Serializable { - - public RequirementSpecNodeJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(RequirementSpecNode requirementSpecNode) throws PreexistingEntityException, Exception { - if (requirementSpecNode.getRequirementSpecNodePK() == null) { - requirementSpecNode.setRequirementSpecNodePK(new RequirementSpecNodePK()); - } - if (requirementSpecNode.getRequirementSpecNodeList() == null) { - requirementSpecNode.setRequirementSpecNodeList(new ArrayList()); - } - if (requirementSpecNode.getRequirementList() == null) { - requirementSpecNode.setRequirementList(new ArrayList()); - } - requirementSpecNode.getRequirementSpecNodePK().setRequirementSpecId(requirementSpecNode.getRequirementSpec().getRequirementSpecPK().getId()); - requirementSpecNode.getRequirementSpecNodePK().setRequirementSpecProjectId(requirementSpecNode.getRequirementSpec().getRequirementSpecPK().getProjectId()); - requirementSpecNode.getRequirementSpecNodePK().setRequirementSpecSpecLevelId(requirementSpecNode.getRequirementSpec().getRequirementSpecPK().getSpecLevelId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RequirementSpec requirementSpec = requirementSpecNode.getRequirementSpec(); - if (requirementSpec != null) { - requirementSpec = em.getReference(requirementSpec.getClass(), requirementSpec.getRequirementSpecPK()); - requirementSpecNode.setRequirementSpec(requirementSpec); - } - RequirementSpecNode requirementSpecNodeRel = requirementSpecNode.getRequirementSpecNode(); - if (requirementSpecNodeRel != null) { - requirementSpecNodeRel = em.getReference(requirementSpecNodeRel.getClass(), requirementSpecNodeRel.getRequirementSpecNodePK()); - requirementSpecNode.setRequirementSpecNode(requirementSpecNodeRel); - } - List attachedRequirementSpecNodeList = new ArrayList(); - for (RequirementSpecNode requirementSpecNodeListRequirementSpecNodeToAttach : requirementSpecNode.getRequirementSpecNodeList()) { - requirementSpecNodeListRequirementSpecNodeToAttach = em.getReference(requirementSpecNodeListRequirementSpecNodeToAttach.getClass(), requirementSpecNodeListRequirementSpecNodeToAttach.getRequirementSpecNodePK()); - attachedRequirementSpecNodeList.add(requirementSpecNodeListRequirementSpecNodeToAttach); - } - requirementSpecNode.setRequirementSpecNodeList(attachedRequirementSpecNodeList); - List attachedRequirementList = new ArrayList(); - for (Requirement requirementListRequirementToAttach : requirementSpecNode.getRequirementList()) { - requirementListRequirementToAttach = em.getReference(requirementListRequirementToAttach.getClass(), requirementListRequirementToAttach.getId()); - attachedRequirementList.add(requirementListRequirementToAttach); - } - requirementSpecNode.setRequirementList(attachedRequirementList); - em.persist(requirementSpecNode); - if (requirementSpec != null) { - requirementSpec.getRequirementSpecNodeList().add(requirementSpecNode); - requirementSpec = em.merge(requirementSpec); - } - if (requirementSpecNodeRel != null) { - requirementSpecNodeRel.getRequirementSpecNodeList().add(requirementSpecNode); - requirementSpecNodeRel = em.merge(requirementSpecNodeRel); - } - for (RequirementSpecNode requirementSpecNodeListRequirementSpecNode : requirementSpecNode.getRequirementSpecNodeList()) { - RequirementSpecNode oldRequirementSpecNodeOfRequirementSpecNodeListRequirementSpecNode = requirementSpecNodeListRequirementSpecNode.getRequirementSpecNode(); - requirementSpecNodeListRequirementSpecNode.setRequirementSpecNode(requirementSpecNode); - requirementSpecNodeListRequirementSpecNode = em.merge(requirementSpecNodeListRequirementSpecNode); - if (oldRequirementSpecNodeOfRequirementSpecNodeListRequirementSpecNode != null) { - oldRequirementSpecNodeOfRequirementSpecNodeListRequirementSpecNode.getRequirementSpecNodeList().remove(requirementSpecNodeListRequirementSpecNode); - oldRequirementSpecNodeOfRequirementSpecNodeListRequirementSpecNode = em.merge(oldRequirementSpecNodeOfRequirementSpecNodeListRequirementSpecNode); - } - } - for (Requirement requirementListRequirement : requirementSpecNode.getRequirementList()) { - RequirementSpecNode oldRequirementSpecNodeOfRequirementListRequirement = requirementListRequirement.getRequirementSpecNode(); - requirementListRequirement.setRequirementSpecNode(requirementSpecNode); - requirementListRequirement = em.merge(requirementListRequirement); - if (oldRequirementSpecNodeOfRequirementListRequirement != null) { - oldRequirementSpecNodeOfRequirementListRequirement.getRequirementList().remove(requirementListRequirement); - oldRequirementSpecNodeOfRequirementListRequirement = em.merge(oldRequirementSpecNodeOfRequirementListRequirement); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - if (findRequirementSpecNode(requirementSpecNode.getRequirementSpecNodePK()) != null) { - throw new PreexistingEntityException("RequirementSpecNode " + requirementSpecNode + " already exists.", ex); - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(RequirementSpecNode requirementSpecNode) throws IllegalOrphanException, NonexistentEntityException, Exception { - requirementSpecNode.getRequirementSpecNodePK().setRequirementSpecId(requirementSpecNode.getRequirementSpec().getRequirementSpecPK().getId()); - requirementSpecNode.getRequirementSpecNodePK().setRequirementSpecProjectId(requirementSpecNode.getRequirementSpec().getRequirementSpecPK().getProjectId()); - requirementSpecNode.getRequirementSpecNodePK().setRequirementSpecSpecLevelId(requirementSpecNode.getRequirementSpec().getRequirementSpecPK().getSpecLevelId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RequirementSpecNode persistentRequirementSpecNode = em.find(RequirementSpecNode.class, requirementSpecNode.getRequirementSpecNodePK()); - RequirementSpec requirementSpecOld = persistentRequirementSpecNode.getRequirementSpec(); - RequirementSpec requirementSpecNew = requirementSpecNode.getRequirementSpec(); - RequirementSpecNode requirementSpecNodeRelOld = persistentRequirementSpecNode.getRequirementSpecNode(); - RequirementSpecNode requirementSpecNodeRelNew = requirementSpecNode.getRequirementSpecNode(); - List requirementSpecNodeListOld = persistentRequirementSpecNode.getRequirementSpecNodeList(); - List requirementSpecNodeListNew = requirementSpecNode.getRequirementSpecNodeList(); - List requirementListOld = persistentRequirementSpecNode.getRequirementList(); - List requirementListNew = requirementSpecNode.getRequirementList(); - List illegalOrphanMessages = null; - for (Requirement requirementListOldRequirement : requirementListOld) { - if (!requirementListNew.contains(requirementListOldRequirement)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain Requirement " + requirementListOldRequirement + " since its requirementSpecNode field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (requirementSpecNew != null) { - requirementSpecNew = em.getReference(requirementSpecNew.getClass(), requirementSpecNew.getRequirementSpecPK()); - requirementSpecNode.setRequirementSpec(requirementSpecNew); - } - if (requirementSpecNodeRelNew != null) { - requirementSpecNodeRelNew = em.getReference(requirementSpecNodeRelNew.getClass(), requirementSpecNodeRelNew.getRequirementSpecNodePK()); - requirementSpecNode.setRequirementSpecNode(requirementSpecNodeRelNew); - } - List attachedRequirementSpecNodeListNew = new ArrayList(); - for (RequirementSpecNode requirementSpecNodeListNewRequirementSpecNodeToAttach : requirementSpecNodeListNew) { - requirementSpecNodeListNewRequirementSpecNodeToAttach = em.getReference(requirementSpecNodeListNewRequirementSpecNodeToAttach.getClass(), requirementSpecNodeListNewRequirementSpecNodeToAttach.getRequirementSpecNodePK()); - attachedRequirementSpecNodeListNew.add(requirementSpecNodeListNewRequirementSpecNodeToAttach); - } - requirementSpecNodeListNew = attachedRequirementSpecNodeListNew; - requirementSpecNode.setRequirementSpecNodeList(requirementSpecNodeListNew); - List attachedRequirementListNew = new ArrayList(); - for (Requirement requirementListNewRequirementToAttach : requirementListNew) { - requirementListNewRequirementToAttach = em.getReference(requirementListNewRequirementToAttach.getClass(), requirementListNewRequirementToAttach.getId()); - attachedRequirementListNew.add(requirementListNewRequirementToAttach); - } - requirementListNew = attachedRequirementListNew; - requirementSpecNode.setRequirementList(requirementListNew); - requirementSpecNode = em.merge(requirementSpecNode); - if (requirementSpecOld != null && !requirementSpecOld.equals(requirementSpecNew)) { - requirementSpecOld.getRequirementSpecNodeList().remove(requirementSpecNode); - requirementSpecOld = em.merge(requirementSpecOld); - } - if (requirementSpecNew != null && !requirementSpecNew.equals(requirementSpecOld)) { - requirementSpecNew.getRequirementSpecNodeList().add(requirementSpecNode); - requirementSpecNew = em.merge(requirementSpecNew); - } - if (requirementSpecNodeRelOld != null && !requirementSpecNodeRelOld.equals(requirementSpecNodeRelNew)) { - requirementSpecNodeRelOld.getRequirementSpecNodeList().remove(requirementSpecNode); - requirementSpecNodeRelOld = em.merge(requirementSpecNodeRelOld); - } - if (requirementSpecNodeRelNew != null && !requirementSpecNodeRelNew.equals(requirementSpecNodeRelOld)) { - requirementSpecNodeRelNew.getRequirementSpecNodeList().add(requirementSpecNode); - requirementSpecNodeRelNew = em.merge(requirementSpecNodeRelNew); - } - for (RequirementSpecNode requirementSpecNodeListOldRequirementSpecNode : requirementSpecNodeListOld) { - if (!requirementSpecNodeListNew.contains(requirementSpecNodeListOldRequirementSpecNode)) { - requirementSpecNodeListOldRequirementSpecNode.setRequirementSpecNode(null); - requirementSpecNodeListOldRequirementSpecNode = em.merge(requirementSpecNodeListOldRequirementSpecNode); - } - } - for (RequirementSpecNode requirementSpecNodeListNewRequirementSpecNode : requirementSpecNodeListNew) { - if (!requirementSpecNodeListOld.contains(requirementSpecNodeListNewRequirementSpecNode)) { - RequirementSpecNode oldRequirementSpecNodeOfRequirementSpecNodeListNewRequirementSpecNode = requirementSpecNodeListNewRequirementSpecNode.getRequirementSpecNode(); - requirementSpecNodeListNewRequirementSpecNode.setRequirementSpecNode(requirementSpecNode); - requirementSpecNodeListNewRequirementSpecNode = em.merge(requirementSpecNodeListNewRequirementSpecNode); - if (oldRequirementSpecNodeOfRequirementSpecNodeListNewRequirementSpecNode != null && !oldRequirementSpecNodeOfRequirementSpecNodeListNewRequirementSpecNode.equals(requirementSpecNode)) { - oldRequirementSpecNodeOfRequirementSpecNodeListNewRequirementSpecNode.getRequirementSpecNodeList().remove(requirementSpecNodeListNewRequirementSpecNode); - oldRequirementSpecNodeOfRequirementSpecNodeListNewRequirementSpecNode = em.merge(oldRequirementSpecNodeOfRequirementSpecNodeListNewRequirementSpecNode); - } - } - } - for (Requirement requirementListNewRequirement : requirementListNew) { - if (!requirementListOld.contains(requirementListNewRequirement)) { - RequirementSpecNode oldRequirementSpecNodeOfRequirementListNewRequirement = requirementListNewRequirement.getRequirementSpecNode(); - requirementListNewRequirement.setRequirementSpecNode(requirementSpecNode); - requirementListNewRequirement = em.merge(requirementListNewRequirement); - if (oldRequirementSpecNodeOfRequirementListNewRequirement != null && !oldRequirementSpecNodeOfRequirementListNewRequirement.equals(requirementSpecNode)) { - oldRequirementSpecNodeOfRequirementListNewRequirement.getRequirementList().remove(requirementListNewRequirement); - oldRequirementSpecNodeOfRequirementListNewRequirement = em.merge(oldRequirementSpecNodeOfRequirementListNewRequirement); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - RequirementSpecNodePK id = requirementSpecNode.getRequirementSpecNodePK(); - if (findRequirementSpecNode(id) == null) { - throw new NonexistentEntityException("The requirementSpecNode with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(RequirementSpecNodePK id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RequirementSpecNode requirementSpecNode; - try { - requirementSpecNode = em.getReference(RequirementSpecNode.class, id); - requirementSpecNode.getRequirementSpecNodePK(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The requirementSpecNode with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List requirementListOrphanCheck = requirementSpecNode.getRequirementList(); - for (Requirement requirementListOrphanCheckRequirement : requirementListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This RequirementSpecNode (" + requirementSpecNode + ") cannot be destroyed since the Requirement " + requirementListOrphanCheckRequirement + " in its requirementList field has a non-nullable requirementSpecNode field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - RequirementSpec requirementSpec = requirementSpecNode.getRequirementSpec(); - if (requirementSpec != null) { - requirementSpec.getRequirementSpecNodeList().remove(requirementSpecNode); - requirementSpec = em.merge(requirementSpec); - } - RequirementSpecNode requirementSpecNodeRel = requirementSpecNode.getRequirementSpecNode(); - if (requirementSpecNodeRel != null) { - requirementSpecNodeRel.getRequirementSpecNodeList().remove(requirementSpecNode); - requirementSpecNodeRel = em.merge(requirementSpecNodeRel); - } - List requirementSpecNodeList = requirementSpecNode.getRequirementSpecNodeList(); - for (RequirementSpecNode requirementSpecNodeListRequirementSpecNode : requirementSpecNodeList) { - requirementSpecNodeListRequirementSpecNode.setRequirementSpecNode(null); - requirementSpecNodeListRequirementSpecNode = em.merge(requirementSpecNodeListRequirementSpecNode); - } - em.remove(requirementSpecNode); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findRequirementSpecNodeEntities() { - return findRequirementSpecNodeEntities(true, -1, -1); - } - - public List findRequirementSpecNodeEntities(int maxResults, int firstResult) { - return findRequirementSpecNodeEntities(false, maxResults, firstResult); - } - - private List findRequirementSpecNodeEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(RequirementSpecNode.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public RequirementSpecNode findRequirementSpecNode(RequirementSpecNodePK id) { - EntityManager em = getEntityManager(); - try { - return em.find(RequirementSpecNode.class, id); - } - finally { - em.close(); - } - } - - public int getRequirementSpecNodeCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(RequirementSpecNode.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.RequirementSpec; +import com.validation.manager.core.db.RequirementSpecNode; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.Requirement; +import com.validation.manager.core.db.RequirementSpecNodePK; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RequirementSpecNodeJpaController implements Serializable { + + public RequirementSpecNodeJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(RequirementSpecNode requirementSpecNode) throws PreexistingEntityException, Exception { + if (requirementSpecNode.getRequirementSpecNodePK() == null) { + requirementSpecNode.setRequirementSpecNodePK(new RequirementSpecNodePK()); + } + if (requirementSpecNode.getRequirementSpecNodeList() == null) { + requirementSpecNode.setRequirementSpecNodeList(new ArrayList<>()); + } + if (requirementSpecNode.getRequirementList() == null) { + requirementSpecNode.setRequirementList(new ArrayList<>()); + } + requirementSpecNode.getRequirementSpecNodePK().setRequirementSpecId(requirementSpecNode.getRequirementSpec().getRequirementSpecPK().getId()); + requirementSpecNode.getRequirementSpecNodePK().setRequirementSpecProjectId(requirementSpecNode.getRequirementSpec().getRequirementSpecPK().getProjectId()); + requirementSpecNode.getRequirementSpecNodePK().setRequirementSpecSpecLevelId(requirementSpecNode.getRequirementSpec().getRequirementSpecPK().getSpecLevelId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RequirementSpec requirementSpec = requirementSpecNode.getRequirementSpec(); + if (requirementSpec != null) { + requirementSpec = em.getReference(requirementSpec.getClass(), requirementSpec.getRequirementSpecPK()); + requirementSpecNode.setRequirementSpec(requirementSpec); + } + RequirementSpecNode requirementSpecNodeRel = requirementSpecNode.getRequirementSpecNode(); + if (requirementSpecNodeRel != null) { + requirementSpecNodeRel = em.getReference(requirementSpecNodeRel.getClass(), requirementSpecNodeRel.getRequirementSpecNodePK()); + requirementSpecNode.setRequirementSpecNode(requirementSpecNodeRel); + } + List attachedRequirementSpecNodeList = new ArrayList<>(); + for (RequirementSpecNode requirementSpecNodeListRequirementSpecNodeToAttach : requirementSpecNode.getRequirementSpecNodeList()) { + requirementSpecNodeListRequirementSpecNodeToAttach = em.getReference(requirementSpecNodeListRequirementSpecNodeToAttach.getClass(), requirementSpecNodeListRequirementSpecNodeToAttach.getRequirementSpecNodePK()); + attachedRequirementSpecNodeList.add(requirementSpecNodeListRequirementSpecNodeToAttach); + } + requirementSpecNode.setRequirementSpecNodeList(attachedRequirementSpecNodeList); + List attachedRequirementList = new ArrayList<>(); + for (Requirement requirementListRequirementToAttach : requirementSpecNode.getRequirementList()) { + requirementListRequirementToAttach = em.getReference(requirementListRequirementToAttach.getClass(), requirementListRequirementToAttach.getId()); + attachedRequirementList.add(requirementListRequirementToAttach); + } + requirementSpecNode.setRequirementList(attachedRequirementList); + em.persist(requirementSpecNode); + if (requirementSpec != null) { + requirementSpec.getRequirementSpecNodeList().add(requirementSpecNode); + requirementSpec = em.merge(requirementSpec); + } + if (requirementSpecNodeRel != null) { + requirementSpecNodeRel.getRequirementSpecNodeList().add(requirementSpecNode); + requirementSpecNodeRel = em.merge(requirementSpecNodeRel); + } + for (RequirementSpecNode requirementSpecNodeListRequirementSpecNode : requirementSpecNode.getRequirementSpecNodeList()) { + RequirementSpecNode oldRequirementSpecNodeOfRequirementSpecNodeListRequirementSpecNode = requirementSpecNodeListRequirementSpecNode.getRequirementSpecNode(); + requirementSpecNodeListRequirementSpecNode.setRequirementSpecNode(requirementSpecNode); + requirementSpecNodeListRequirementSpecNode = em.merge(requirementSpecNodeListRequirementSpecNode); + if (oldRequirementSpecNodeOfRequirementSpecNodeListRequirementSpecNode != null) { + oldRequirementSpecNodeOfRequirementSpecNodeListRequirementSpecNode.getRequirementSpecNodeList().remove(requirementSpecNodeListRequirementSpecNode); + oldRequirementSpecNodeOfRequirementSpecNodeListRequirementSpecNode = em.merge(oldRequirementSpecNodeOfRequirementSpecNodeListRequirementSpecNode); + } + } + for (Requirement requirementListRequirement : requirementSpecNode.getRequirementList()) { + RequirementSpecNode oldRequirementSpecNodeOfRequirementListRequirement = requirementListRequirement.getRequirementSpecNode(); + requirementListRequirement.setRequirementSpecNode(requirementSpecNode); + requirementListRequirement = em.merge(requirementListRequirement); + if (oldRequirementSpecNodeOfRequirementListRequirement != null) { + oldRequirementSpecNodeOfRequirementListRequirement.getRequirementList().remove(requirementListRequirement); + oldRequirementSpecNodeOfRequirementListRequirement = em.merge(oldRequirementSpecNodeOfRequirementListRequirement); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + if (findRequirementSpecNode(requirementSpecNode.getRequirementSpecNodePK()) != null) { + throw new PreexistingEntityException("RequirementSpecNode " + requirementSpecNode + " already exists.", ex); + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(RequirementSpecNode requirementSpecNode) throws IllegalOrphanException, NonexistentEntityException, Exception { + requirementSpecNode.getRequirementSpecNodePK().setRequirementSpecId(requirementSpecNode.getRequirementSpec().getRequirementSpecPK().getId()); + requirementSpecNode.getRequirementSpecNodePK().setRequirementSpecProjectId(requirementSpecNode.getRequirementSpec().getRequirementSpecPK().getProjectId()); + requirementSpecNode.getRequirementSpecNodePK().setRequirementSpecSpecLevelId(requirementSpecNode.getRequirementSpec().getRequirementSpecPK().getSpecLevelId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RequirementSpecNode persistentRequirementSpecNode = em.find(RequirementSpecNode.class, requirementSpecNode.getRequirementSpecNodePK()); + RequirementSpec requirementSpecOld = persistentRequirementSpecNode.getRequirementSpec(); + RequirementSpec requirementSpecNew = requirementSpecNode.getRequirementSpec(); + RequirementSpecNode requirementSpecNodeRelOld = persistentRequirementSpecNode.getRequirementSpecNode(); + RequirementSpecNode requirementSpecNodeRelNew = requirementSpecNode.getRequirementSpecNode(); + List requirementSpecNodeListOld = persistentRequirementSpecNode.getRequirementSpecNodeList(); + List requirementSpecNodeListNew = requirementSpecNode.getRequirementSpecNodeList(); + List requirementListOld = persistentRequirementSpecNode.getRequirementList(); + List requirementListNew = requirementSpecNode.getRequirementList(); + List illegalOrphanMessages = null; + for (Requirement requirementListOldRequirement : requirementListOld) { + if (!requirementListNew.contains(requirementListOldRequirement)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain Requirement " + requirementListOldRequirement + " since its requirementSpecNode field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (requirementSpecNew != null) { + requirementSpecNew = em.getReference(requirementSpecNew.getClass(), requirementSpecNew.getRequirementSpecPK()); + requirementSpecNode.setRequirementSpec(requirementSpecNew); + } + if (requirementSpecNodeRelNew != null) { + requirementSpecNodeRelNew = em.getReference(requirementSpecNodeRelNew.getClass(), requirementSpecNodeRelNew.getRequirementSpecNodePK()); + requirementSpecNode.setRequirementSpecNode(requirementSpecNodeRelNew); + } + List attachedRequirementSpecNodeListNew = new ArrayList<>(); + for (RequirementSpecNode requirementSpecNodeListNewRequirementSpecNodeToAttach : requirementSpecNodeListNew) { + requirementSpecNodeListNewRequirementSpecNodeToAttach = em.getReference(requirementSpecNodeListNewRequirementSpecNodeToAttach.getClass(), requirementSpecNodeListNewRequirementSpecNodeToAttach.getRequirementSpecNodePK()); + attachedRequirementSpecNodeListNew.add(requirementSpecNodeListNewRequirementSpecNodeToAttach); + } + requirementSpecNodeListNew = attachedRequirementSpecNodeListNew; + requirementSpecNode.setRequirementSpecNodeList(requirementSpecNodeListNew); + List attachedRequirementListNew = new ArrayList<>(); + for (Requirement requirementListNewRequirementToAttach : requirementListNew) { + requirementListNewRequirementToAttach = em.getReference(requirementListNewRequirementToAttach.getClass(), requirementListNewRequirementToAttach.getId()); + attachedRequirementListNew.add(requirementListNewRequirementToAttach); + } + requirementListNew = attachedRequirementListNew; + requirementSpecNode.setRequirementList(requirementListNew); + requirementSpecNode = em.merge(requirementSpecNode); + if (requirementSpecOld != null && !requirementSpecOld.equals(requirementSpecNew)) { + requirementSpecOld.getRequirementSpecNodeList().remove(requirementSpecNode); + requirementSpecOld = em.merge(requirementSpecOld); + } + if (requirementSpecNew != null && !requirementSpecNew.equals(requirementSpecOld)) { + requirementSpecNew.getRequirementSpecNodeList().add(requirementSpecNode); + requirementSpecNew = em.merge(requirementSpecNew); + } + if (requirementSpecNodeRelOld != null && !requirementSpecNodeRelOld.equals(requirementSpecNodeRelNew)) { + requirementSpecNodeRelOld.getRequirementSpecNodeList().remove(requirementSpecNode); + requirementSpecNodeRelOld = em.merge(requirementSpecNodeRelOld); + } + if (requirementSpecNodeRelNew != null && !requirementSpecNodeRelNew.equals(requirementSpecNodeRelOld)) { + requirementSpecNodeRelNew.getRequirementSpecNodeList().add(requirementSpecNode); + requirementSpecNodeRelNew = em.merge(requirementSpecNodeRelNew); + } + for (RequirementSpecNode requirementSpecNodeListOldRequirementSpecNode : requirementSpecNodeListOld) { + if (!requirementSpecNodeListNew.contains(requirementSpecNodeListOldRequirementSpecNode)) { + requirementSpecNodeListOldRequirementSpecNode.setRequirementSpecNode(null); + requirementSpecNodeListOldRequirementSpecNode = em.merge(requirementSpecNodeListOldRequirementSpecNode); + } + } + for (RequirementSpecNode requirementSpecNodeListNewRequirementSpecNode : requirementSpecNodeListNew) { + if (!requirementSpecNodeListOld.contains(requirementSpecNodeListNewRequirementSpecNode)) { + RequirementSpecNode oldRequirementSpecNodeOfRequirementSpecNodeListNewRequirementSpecNode = requirementSpecNodeListNewRequirementSpecNode.getRequirementSpecNode(); + requirementSpecNodeListNewRequirementSpecNode.setRequirementSpecNode(requirementSpecNode); + requirementSpecNodeListNewRequirementSpecNode = em.merge(requirementSpecNodeListNewRequirementSpecNode); + if (oldRequirementSpecNodeOfRequirementSpecNodeListNewRequirementSpecNode != null && !oldRequirementSpecNodeOfRequirementSpecNodeListNewRequirementSpecNode.equals(requirementSpecNode)) { + oldRequirementSpecNodeOfRequirementSpecNodeListNewRequirementSpecNode.getRequirementSpecNodeList().remove(requirementSpecNodeListNewRequirementSpecNode); + oldRequirementSpecNodeOfRequirementSpecNodeListNewRequirementSpecNode = em.merge(oldRequirementSpecNodeOfRequirementSpecNodeListNewRequirementSpecNode); + } + } + } + for (Requirement requirementListNewRequirement : requirementListNew) { + if (!requirementListOld.contains(requirementListNewRequirement)) { + RequirementSpecNode oldRequirementSpecNodeOfRequirementListNewRequirement = requirementListNewRequirement.getRequirementSpecNode(); + requirementListNewRequirement.setRequirementSpecNode(requirementSpecNode); + requirementListNewRequirement = em.merge(requirementListNewRequirement); + if (oldRequirementSpecNodeOfRequirementListNewRequirement != null && !oldRequirementSpecNodeOfRequirementListNewRequirement.equals(requirementSpecNode)) { + oldRequirementSpecNodeOfRequirementListNewRequirement.getRequirementList().remove(requirementListNewRequirement); + oldRequirementSpecNodeOfRequirementListNewRequirement = em.merge(oldRequirementSpecNodeOfRequirementListNewRequirement); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + RequirementSpecNodePK id = requirementSpecNode.getRequirementSpecNodePK(); + if (findRequirementSpecNode(id) == null) { + throw new NonexistentEntityException("The requirementSpecNode with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(RequirementSpecNodePK id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RequirementSpecNode requirementSpecNode; + try { + requirementSpecNode = em.getReference(RequirementSpecNode.class, id); + requirementSpecNode.getRequirementSpecNodePK(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The requirementSpecNode with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List requirementListOrphanCheck = requirementSpecNode.getRequirementList(); + for (Requirement requirementListOrphanCheckRequirement : requirementListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This RequirementSpecNode (" + requirementSpecNode + ") cannot be destroyed since the Requirement " + requirementListOrphanCheckRequirement + " in its requirementList field has a non-nullable requirementSpecNode field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + RequirementSpec requirementSpec = requirementSpecNode.getRequirementSpec(); + if (requirementSpec != null) { + requirementSpec.getRequirementSpecNodeList().remove(requirementSpecNode); + requirementSpec = em.merge(requirementSpec); + } + RequirementSpecNode requirementSpecNodeRel = requirementSpecNode.getRequirementSpecNode(); + if (requirementSpecNodeRel != null) { + requirementSpecNodeRel.getRequirementSpecNodeList().remove(requirementSpecNode); + requirementSpecNodeRel = em.merge(requirementSpecNodeRel); + } + List requirementSpecNodeList = requirementSpecNode.getRequirementSpecNodeList(); + for (RequirementSpecNode requirementSpecNodeListRequirementSpecNode : requirementSpecNodeList) { + requirementSpecNodeListRequirementSpecNode.setRequirementSpecNode(null); + requirementSpecNodeListRequirementSpecNode = em.merge(requirementSpecNodeListRequirementSpecNode); + } + em.remove(requirementSpecNode); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findRequirementSpecNodeEntities() { + return findRequirementSpecNodeEntities(true, -1, -1); + } + + public List findRequirementSpecNodeEntities(int maxResults, int firstResult) { + return findRequirementSpecNodeEntities(false, maxResults, firstResult); + } + + private List findRequirementSpecNodeEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(RequirementSpecNode.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public RequirementSpecNode findRequirementSpecNode(RequirementSpecNodePK id) { + EntityManager em = getEntityManager(); + try { + return em.find(RequirementSpecNode.class, id); + } + finally { + em.close(); + } + } + + public int getRequirementSpecNodeCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(RequirementSpecNode.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementStatusJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementStatusJpaController.java index 0c4879a9..a06633dd 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementStatusJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementStatusJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Requirement; -import com.validation.manager.core.db.RequirementStatus; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RequirementStatusJpaController implements Serializable { - - public RequirementStatusJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(RequirementStatus requirementStatus) { - if (requirementStatus.getRequirementList() == null) { - requirementStatus.setRequirementList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedRequirementList = new ArrayList(); - for (Requirement requirementListRequirementToAttach : requirementStatus.getRequirementList()) { - requirementListRequirementToAttach = em.getReference(requirementListRequirementToAttach.getClass(), requirementListRequirementToAttach.getId()); - attachedRequirementList.add(requirementListRequirementToAttach); - } - requirementStatus.setRequirementList(attachedRequirementList); - em.persist(requirementStatus); - for (Requirement requirementListRequirement : requirementStatus.getRequirementList()) { - RequirementStatus oldRequirementStatusIdOfRequirementListRequirement = requirementListRequirement.getRequirementStatusId(); - requirementListRequirement.setRequirementStatusId(requirementStatus); - requirementListRequirement = em.merge(requirementListRequirement); - if (oldRequirementStatusIdOfRequirementListRequirement != null) { - oldRequirementStatusIdOfRequirementListRequirement.getRequirementList().remove(requirementListRequirement); - oldRequirementStatusIdOfRequirementListRequirement = em.merge(oldRequirementStatusIdOfRequirementListRequirement); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(RequirementStatus requirementStatus) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RequirementStatus persistentRequirementStatus = em.find(RequirementStatus.class, requirementStatus.getId()); - List requirementListOld = persistentRequirementStatus.getRequirementList(); - List requirementListNew = requirementStatus.getRequirementList(); - List illegalOrphanMessages = null; - for (Requirement requirementListOldRequirement : requirementListOld) { - if (!requirementListNew.contains(requirementListOldRequirement)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain Requirement " + requirementListOldRequirement + " since its requirementStatusId field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedRequirementListNew = new ArrayList(); - for (Requirement requirementListNewRequirementToAttach : requirementListNew) { - requirementListNewRequirementToAttach = em.getReference(requirementListNewRequirementToAttach.getClass(), requirementListNewRequirementToAttach.getId()); - attachedRequirementListNew.add(requirementListNewRequirementToAttach); - } - requirementListNew = attachedRequirementListNew; - requirementStatus.setRequirementList(requirementListNew); - requirementStatus = em.merge(requirementStatus); - for (Requirement requirementListNewRequirement : requirementListNew) { - if (!requirementListOld.contains(requirementListNewRequirement)) { - RequirementStatus oldRequirementStatusIdOfRequirementListNewRequirement = requirementListNewRequirement.getRequirementStatusId(); - requirementListNewRequirement.setRequirementStatusId(requirementStatus); - requirementListNewRequirement = em.merge(requirementListNewRequirement); - if (oldRequirementStatusIdOfRequirementListNewRequirement != null && !oldRequirementStatusIdOfRequirementListNewRequirement.equals(requirementStatus)) { - oldRequirementStatusIdOfRequirementListNewRequirement.getRequirementList().remove(requirementListNewRequirement); - oldRequirementStatusIdOfRequirementListNewRequirement = em.merge(oldRequirementStatusIdOfRequirementListNewRequirement); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = requirementStatus.getId(); - if (findRequirementStatus(id) == null) { - throw new NonexistentEntityException("The requirementStatus with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RequirementStatus requirementStatus; - try { - requirementStatus = em.getReference(RequirementStatus.class, id); - requirementStatus.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The requirementStatus with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List requirementListOrphanCheck = requirementStatus.getRequirementList(); - for (Requirement requirementListOrphanCheckRequirement : requirementListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This RequirementStatus (" + requirementStatus + ") cannot be destroyed since the Requirement " + requirementListOrphanCheckRequirement + " in its requirementList field has a non-nullable requirementStatusId field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(requirementStatus); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findRequirementStatusEntities() { - return findRequirementStatusEntities(true, -1, -1); - } - - public List findRequirementStatusEntities(int maxResults, int firstResult) { - return findRequirementStatusEntities(false, maxResults, firstResult); - } - - private List findRequirementStatusEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(RequirementStatus.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public RequirementStatus findRequirementStatus(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(RequirementStatus.class, id); - } - finally { - em.close(); - } - } - - public int getRequirementStatusCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(RequirementStatus.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Requirement; +import com.validation.manager.core.db.RequirementStatus; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RequirementStatusJpaController implements Serializable { + + public RequirementStatusJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(RequirementStatus requirementStatus) { + if (requirementStatus.getRequirementList() == null) { + requirementStatus.setRequirementList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedRequirementList = new ArrayList<>(); + for (Requirement requirementListRequirementToAttach : requirementStatus.getRequirementList()) { + requirementListRequirementToAttach = em.getReference(requirementListRequirementToAttach.getClass(), requirementListRequirementToAttach.getId()); + attachedRequirementList.add(requirementListRequirementToAttach); + } + requirementStatus.setRequirementList(attachedRequirementList); + em.persist(requirementStatus); + for (Requirement requirementListRequirement : requirementStatus.getRequirementList()) { + RequirementStatus oldRequirementStatusIdOfRequirementListRequirement = requirementListRequirement.getRequirementStatusId(); + requirementListRequirement.setRequirementStatusId(requirementStatus); + requirementListRequirement = em.merge(requirementListRequirement); + if (oldRequirementStatusIdOfRequirementListRequirement != null) { + oldRequirementStatusIdOfRequirementListRequirement.getRequirementList().remove(requirementListRequirement); + oldRequirementStatusIdOfRequirementListRequirement = em.merge(oldRequirementStatusIdOfRequirementListRequirement); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(RequirementStatus requirementStatus) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RequirementStatus persistentRequirementStatus = em.find(RequirementStatus.class, requirementStatus.getId()); + List requirementListOld = persistentRequirementStatus.getRequirementList(); + List requirementListNew = requirementStatus.getRequirementList(); + List illegalOrphanMessages = null; + for (Requirement requirementListOldRequirement : requirementListOld) { + if (!requirementListNew.contains(requirementListOldRequirement)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain Requirement " + requirementListOldRequirement + " since its requirementStatusId field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedRequirementListNew = new ArrayList<>(); + for (Requirement requirementListNewRequirementToAttach : requirementListNew) { + requirementListNewRequirementToAttach = em.getReference(requirementListNewRequirementToAttach.getClass(), requirementListNewRequirementToAttach.getId()); + attachedRequirementListNew.add(requirementListNewRequirementToAttach); + } + requirementListNew = attachedRequirementListNew; + requirementStatus.setRequirementList(requirementListNew); + requirementStatus = em.merge(requirementStatus); + for (Requirement requirementListNewRequirement : requirementListNew) { + if (!requirementListOld.contains(requirementListNewRequirement)) { + RequirementStatus oldRequirementStatusIdOfRequirementListNewRequirement = requirementListNewRequirement.getRequirementStatusId(); + requirementListNewRequirement.setRequirementStatusId(requirementStatus); + requirementListNewRequirement = em.merge(requirementListNewRequirement); + if (oldRequirementStatusIdOfRequirementListNewRequirement != null && !oldRequirementStatusIdOfRequirementListNewRequirement.equals(requirementStatus)) { + oldRequirementStatusIdOfRequirementListNewRequirement.getRequirementList().remove(requirementListNewRequirement); + oldRequirementStatusIdOfRequirementListNewRequirement = em.merge(oldRequirementStatusIdOfRequirementListNewRequirement); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = requirementStatus.getId(); + if (findRequirementStatus(id) == null) { + throw new NonexistentEntityException("The requirementStatus with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RequirementStatus requirementStatus; + try { + requirementStatus = em.getReference(RequirementStatus.class, id); + requirementStatus.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The requirementStatus with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List requirementListOrphanCheck = requirementStatus.getRequirementList(); + for (Requirement requirementListOrphanCheckRequirement : requirementListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This RequirementStatus (" + requirementStatus + ") cannot be destroyed since the Requirement " + requirementListOrphanCheckRequirement + " in its requirementList field has a non-nullable requirementStatusId field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(requirementStatus); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findRequirementStatusEntities() { + return findRequirementStatusEntities(true, -1, -1); + } + + public List findRequirementStatusEntities(int maxResults, int firstResult) { + return findRequirementStatusEntities(false, maxResults, firstResult); + } + + private List findRequirementStatusEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(RequirementStatus.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public RequirementStatus findRequirementStatus(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(RequirementStatus.class, id); + } + finally { + em.close(); + } + } + + public int getRequirementStatusCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(RequirementStatus.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementTypeJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementTypeJpaController.java index fbf4cff6..d07cc7a4 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementTypeJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RequirementTypeJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Requirement; -import com.validation.manager.core.db.RequirementType; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RequirementTypeJpaController implements Serializable { - - public RequirementTypeJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(RequirementType requirementType) { - if (requirementType.getRequirementList() == null) { - requirementType.setRequirementList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedRequirementList = new ArrayList(); - for (Requirement requirementListRequirementToAttach : requirementType.getRequirementList()) { - requirementListRequirementToAttach = em.getReference(requirementListRequirementToAttach.getClass(), requirementListRequirementToAttach.getId()); - attachedRequirementList.add(requirementListRequirementToAttach); - } - requirementType.setRequirementList(attachedRequirementList); - em.persist(requirementType); - for (Requirement requirementListRequirement : requirementType.getRequirementList()) { - RequirementType oldRequirementTypeIdOfRequirementListRequirement = requirementListRequirement.getRequirementTypeId(); - requirementListRequirement.setRequirementTypeId(requirementType); - requirementListRequirement = em.merge(requirementListRequirement); - if (oldRequirementTypeIdOfRequirementListRequirement != null) { - oldRequirementTypeIdOfRequirementListRequirement.getRequirementList().remove(requirementListRequirement); - oldRequirementTypeIdOfRequirementListRequirement = em.merge(oldRequirementTypeIdOfRequirementListRequirement); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(RequirementType requirementType) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RequirementType persistentRequirementType = em.find(RequirementType.class, requirementType.getId()); - List requirementListOld = persistentRequirementType.getRequirementList(); - List requirementListNew = requirementType.getRequirementList(); - List illegalOrphanMessages = null; - for (Requirement requirementListOldRequirement : requirementListOld) { - if (!requirementListNew.contains(requirementListOldRequirement)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain Requirement " + requirementListOldRequirement + " since its requirementTypeId field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedRequirementListNew = new ArrayList(); - for (Requirement requirementListNewRequirementToAttach : requirementListNew) { - requirementListNewRequirementToAttach = em.getReference(requirementListNewRequirementToAttach.getClass(), requirementListNewRequirementToAttach.getId()); - attachedRequirementListNew.add(requirementListNewRequirementToAttach); - } - requirementListNew = attachedRequirementListNew; - requirementType.setRequirementList(requirementListNew); - requirementType = em.merge(requirementType); - for (Requirement requirementListNewRequirement : requirementListNew) { - if (!requirementListOld.contains(requirementListNewRequirement)) { - RequirementType oldRequirementTypeIdOfRequirementListNewRequirement = requirementListNewRequirement.getRequirementTypeId(); - requirementListNewRequirement.setRequirementTypeId(requirementType); - requirementListNewRequirement = em.merge(requirementListNewRequirement); - if (oldRequirementTypeIdOfRequirementListNewRequirement != null && !oldRequirementTypeIdOfRequirementListNewRequirement.equals(requirementType)) { - oldRequirementTypeIdOfRequirementListNewRequirement.getRequirementList().remove(requirementListNewRequirement); - oldRequirementTypeIdOfRequirementListNewRequirement = em.merge(oldRequirementTypeIdOfRequirementListNewRequirement); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = requirementType.getId(); - if (findRequirementType(id) == null) { - throw new NonexistentEntityException("The requirementType with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RequirementType requirementType; - try { - requirementType = em.getReference(RequirementType.class, id); - requirementType.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The requirementType with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List requirementListOrphanCheck = requirementType.getRequirementList(); - for (Requirement requirementListOrphanCheckRequirement : requirementListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This RequirementType (" + requirementType + ") cannot be destroyed since the Requirement " + requirementListOrphanCheckRequirement + " in its requirementList field has a non-nullable requirementTypeId field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(requirementType); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findRequirementTypeEntities() { - return findRequirementTypeEntities(true, -1, -1); - } - - public List findRequirementTypeEntities(int maxResults, int firstResult) { - return findRequirementTypeEntities(false, maxResults, firstResult); - } - - private List findRequirementTypeEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(RequirementType.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public RequirementType findRequirementType(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(RequirementType.class, id); - } - finally { - em.close(); - } - } - - public int getRequirementTypeCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(RequirementType.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Requirement; +import com.validation.manager.core.db.RequirementType; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RequirementTypeJpaController implements Serializable { + + public RequirementTypeJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(RequirementType requirementType) { + if (requirementType.getRequirementList() == null) { + requirementType.setRequirementList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedRequirementList = new ArrayList<>(); + for (Requirement requirementListRequirementToAttach : requirementType.getRequirementList()) { + requirementListRequirementToAttach = em.getReference(requirementListRequirementToAttach.getClass(), requirementListRequirementToAttach.getId()); + attachedRequirementList.add(requirementListRequirementToAttach); + } + requirementType.setRequirementList(attachedRequirementList); + em.persist(requirementType); + for (Requirement requirementListRequirement : requirementType.getRequirementList()) { + RequirementType oldRequirementTypeIdOfRequirementListRequirement = requirementListRequirement.getRequirementTypeId(); + requirementListRequirement.setRequirementTypeId(requirementType); + requirementListRequirement = em.merge(requirementListRequirement); + if (oldRequirementTypeIdOfRequirementListRequirement != null) { + oldRequirementTypeIdOfRequirementListRequirement.getRequirementList().remove(requirementListRequirement); + oldRequirementTypeIdOfRequirementListRequirement = em.merge(oldRequirementTypeIdOfRequirementListRequirement); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(RequirementType requirementType) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RequirementType persistentRequirementType = em.find(RequirementType.class, requirementType.getId()); + List requirementListOld = persistentRequirementType.getRequirementList(); + List requirementListNew = requirementType.getRequirementList(); + List illegalOrphanMessages = null; + for (Requirement requirementListOldRequirement : requirementListOld) { + if (!requirementListNew.contains(requirementListOldRequirement)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain Requirement " + requirementListOldRequirement + " since its requirementTypeId field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedRequirementListNew = new ArrayList<>(); + for (Requirement requirementListNewRequirementToAttach : requirementListNew) { + requirementListNewRequirementToAttach = em.getReference(requirementListNewRequirementToAttach.getClass(), requirementListNewRequirementToAttach.getId()); + attachedRequirementListNew.add(requirementListNewRequirementToAttach); + } + requirementListNew = attachedRequirementListNew; + requirementType.setRequirementList(requirementListNew); + requirementType = em.merge(requirementType); + for (Requirement requirementListNewRequirement : requirementListNew) { + if (!requirementListOld.contains(requirementListNewRequirement)) { + RequirementType oldRequirementTypeIdOfRequirementListNewRequirement = requirementListNewRequirement.getRequirementTypeId(); + requirementListNewRequirement.setRequirementTypeId(requirementType); + requirementListNewRequirement = em.merge(requirementListNewRequirement); + if (oldRequirementTypeIdOfRequirementListNewRequirement != null && !oldRequirementTypeIdOfRequirementListNewRequirement.equals(requirementType)) { + oldRequirementTypeIdOfRequirementListNewRequirement.getRequirementList().remove(requirementListNewRequirement); + oldRequirementTypeIdOfRequirementListNewRequirement = em.merge(oldRequirementTypeIdOfRequirementListNewRequirement); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = requirementType.getId(); + if (findRequirementType(id) == null) { + throw new NonexistentEntityException("The requirementType with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RequirementType requirementType; + try { + requirementType = em.getReference(RequirementType.class, id); + requirementType.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The requirementType with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List requirementListOrphanCheck = requirementType.getRequirementList(); + for (Requirement requirementListOrphanCheckRequirement : requirementListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This RequirementType (" + requirementType + ") cannot be destroyed since the Requirement " + requirementListOrphanCheckRequirement + " in its requirementList field has a non-nullable requirementTypeId field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(requirementType); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findRequirementTypeEntities() { + return findRequirementTypeEntities(true, -1, -1); + } + + public List findRequirementTypeEntities(int maxResults, int firstResult) { + return findRequirementTypeEntities(false, maxResults, firstResult); + } + + private List findRequirementTypeEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(RequirementType.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public RequirementType findRequirementType(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(RequirementType.class, id); + } + finally { + em.close(); + } + } + + public int getRequirementTypeCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(RequirementType.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/ReviewResultJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/ReviewResultJpaController.java index 58a61f66..b84cf788 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/ReviewResultJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/ReviewResultJpaController.java @@ -13,196 +13,196 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.ReviewResult; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class ReviewResultJpaController implements Serializable { - - public ReviewResultJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(ReviewResult reviewResult) { - if (reviewResult.getExecutionStepList() == null) { - reviewResult.setExecutionStepList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedExecutionStepList = new ArrayList(); - for (ExecutionStep executionStepListExecutionStepToAttach : reviewResult.getExecutionStepList()) { - executionStepListExecutionStepToAttach = em.getReference(executionStepListExecutionStepToAttach.getClass(), executionStepListExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepList.add(executionStepListExecutionStepToAttach); - } - reviewResult.setExecutionStepList(attachedExecutionStepList); - em.persist(reviewResult); - for (ExecutionStep executionStepListExecutionStep : reviewResult.getExecutionStepList()) { - ReviewResult oldReviewResultIdOfExecutionStepListExecutionStep = executionStepListExecutionStep.getReviewResultId(); - executionStepListExecutionStep.setReviewResultId(reviewResult); - executionStepListExecutionStep = em.merge(executionStepListExecutionStep); - if (oldReviewResultIdOfExecutionStepListExecutionStep != null) { - oldReviewResultIdOfExecutionStepListExecutionStep.getExecutionStepList().remove(executionStepListExecutionStep); - oldReviewResultIdOfExecutionStepListExecutionStep = em.merge(oldReviewResultIdOfExecutionStepListExecutionStep); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(ReviewResult reviewResult) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - ReviewResult persistentReviewResult = em.find(ReviewResult.class, reviewResult.getId()); - List executionStepListOld = persistentReviewResult.getExecutionStepList(); - List executionStepListNew = reviewResult.getExecutionStepList(); - List attachedExecutionStepListNew = new ArrayList(); - for (ExecutionStep executionStepListNewExecutionStepToAttach : executionStepListNew) { - executionStepListNewExecutionStepToAttach = em.getReference(executionStepListNewExecutionStepToAttach.getClass(), executionStepListNewExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepListNew.add(executionStepListNewExecutionStepToAttach); - } - executionStepListNew = attachedExecutionStepListNew; - reviewResult.setExecutionStepList(executionStepListNew); - reviewResult = em.merge(reviewResult); - for (ExecutionStep executionStepListOldExecutionStep : executionStepListOld) { - if (!executionStepListNew.contains(executionStepListOldExecutionStep)) { - executionStepListOldExecutionStep.setReviewResultId(null); - executionStepListOldExecutionStep = em.merge(executionStepListOldExecutionStep); - } - } - for (ExecutionStep executionStepListNewExecutionStep : executionStepListNew) { - if (!executionStepListOld.contains(executionStepListNewExecutionStep)) { - ReviewResult oldReviewResultIdOfExecutionStepListNewExecutionStep = executionStepListNewExecutionStep.getReviewResultId(); - executionStepListNewExecutionStep.setReviewResultId(reviewResult); - executionStepListNewExecutionStep = em.merge(executionStepListNewExecutionStep); - if (oldReviewResultIdOfExecutionStepListNewExecutionStep != null && !oldReviewResultIdOfExecutionStepListNewExecutionStep.equals(reviewResult)) { - oldReviewResultIdOfExecutionStepListNewExecutionStep.getExecutionStepList().remove(executionStepListNewExecutionStep); - oldReviewResultIdOfExecutionStepListNewExecutionStep = em.merge(oldReviewResultIdOfExecutionStepListNewExecutionStep); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = reviewResult.getId(); - if (findReviewResult(id) == null) { - throw new NonexistentEntityException("The reviewResult with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - ReviewResult reviewResult; - try { - reviewResult = em.getReference(ReviewResult.class, id); - reviewResult.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The reviewResult with id " + id + " no longer exists.", enfe); - } - List executionStepList = reviewResult.getExecutionStepList(); - for (ExecutionStep executionStepListExecutionStep : executionStepList) { - executionStepListExecutionStep.setReviewResultId(null); - executionStepListExecutionStep = em.merge(executionStepListExecutionStep); - } - em.remove(reviewResult); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findReviewResultEntities() { - return findReviewResultEntities(true, -1, -1); - } - - public List findReviewResultEntities(int maxResults, int firstResult) { - return findReviewResultEntities(false, maxResults, firstResult); - } - - private List findReviewResultEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(ReviewResult.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public ReviewResult findReviewResult(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(ReviewResult.class, id); - } - finally { - em.close(); - } - } - - public int getReviewResultCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(ReviewResult.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.ReviewResult; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ReviewResultJpaController implements Serializable { + + public ReviewResultJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(ReviewResult reviewResult) { + if (reviewResult.getExecutionStepList() == null) { + reviewResult.setExecutionStepList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedExecutionStepList = new ArrayList<>(); + for (ExecutionStep executionStepListExecutionStepToAttach : reviewResult.getExecutionStepList()) { + executionStepListExecutionStepToAttach = em.getReference(executionStepListExecutionStepToAttach.getClass(), executionStepListExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepList.add(executionStepListExecutionStepToAttach); + } + reviewResult.setExecutionStepList(attachedExecutionStepList); + em.persist(reviewResult); + for (ExecutionStep executionStepListExecutionStep : reviewResult.getExecutionStepList()) { + ReviewResult oldReviewResultIdOfExecutionStepListExecutionStep = executionStepListExecutionStep.getReviewResultId(); + executionStepListExecutionStep.setReviewResultId(reviewResult); + executionStepListExecutionStep = em.merge(executionStepListExecutionStep); + if (oldReviewResultIdOfExecutionStepListExecutionStep != null) { + oldReviewResultIdOfExecutionStepListExecutionStep.getExecutionStepList().remove(executionStepListExecutionStep); + oldReviewResultIdOfExecutionStepListExecutionStep = em.merge(oldReviewResultIdOfExecutionStepListExecutionStep); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(ReviewResult reviewResult) throws NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + ReviewResult persistentReviewResult = em.find(ReviewResult.class, reviewResult.getId()); + List executionStepListOld = persistentReviewResult.getExecutionStepList(); + List executionStepListNew = reviewResult.getExecutionStepList(); + List attachedExecutionStepListNew = new ArrayList<>(); + for (ExecutionStep executionStepListNewExecutionStepToAttach : executionStepListNew) { + executionStepListNewExecutionStepToAttach = em.getReference(executionStepListNewExecutionStepToAttach.getClass(), executionStepListNewExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepListNew.add(executionStepListNewExecutionStepToAttach); + } + executionStepListNew = attachedExecutionStepListNew; + reviewResult.setExecutionStepList(executionStepListNew); + reviewResult = em.merge(reviewResult); + for (ExecutionStep executionStepListOldExecutionStep : executionStepListOld) { + if (!executionStepListNew.contains(executionStepListOldExecutionStep)) { + executionStepListOldExecutionStep.setReviewResultId(null); + executionStepListOldExecutionStep = em.merge(executionStepListOldExecutionStep); + } + } + for (ExecutionStep executionStepListNewExecutionStep : executionStepListNew) { + if (!executionStepListOld.contains(executionStepListNewExecutionStep)) { + ReviewResult oldReviewResultIdOfExecutionStepListNewExecutionStep = executionStepListNewExecutionStep.getReviewResultId(); + executionStepListNewExecutionStep.setReviewResultId(reviewResult); + executionStepListNewExecutionStep = em.merge(executionStepListNewExecutionStep); + if (oldReviewResultIdOfExecutionStepListNewExecutionStep != null && !oldReviewResultIdOfExecutionStepListNewExecutionStep.equals(reviewResult)) { + oldReviewResultIdOfExecutionStepListNewExecutionStep.getExecutionStepList().remove(executionStepListNewExecutionStep); + oldReviewResultIdOfExecutionStepListNewExecutionStep = em.merge(oldReviewResultIdOfExecutionStepListNewExecutionStep); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = reviewResult.getId(); + if (findReviewResult(id) == null) { + throw new NonexistentEntityException("The reviewResult with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + ReviewResult reviewResult; + try { + reviewResult = em.getReference(ReviewResult.class, id); + reviewResult.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The reviewResult with id " + id + " no longer exists.", enfe); + } + List executionStepList = reviewResult.getExecutionStepList(); + for (ExecutionStep executionStepListExecutionStep : executionStepList) { + executionStepListExecutionStep.setReviewResultId(null); + executionStepListExecutionStep = em.merge(executionStepListExecutionStep); + } + em.remove(reviewResult); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findReviewResultEntities() { + return findReviewResultEntities(true, -1, -1); + } + + public List findReviewResultEntities(int maxResults, int firstResult) { + return findReviewResultEntities(false, maxResults, firstResult); + } + + private List findReviewResultEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(ReviewResult.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public ReviewResult findReviewResult(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(ReviewResult.class, id); + } + finally { + em.close(); + } + } + + public int getReviewResultCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(ReviewResult.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskCategoryJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskCategoryJpaController.java index 0c3af823..51bdb7a9 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskCategoryJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskCategoryJpaController.java @@ -13,249 +13,249 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Fmea; -import com.validation.manager.core.db.RiskCategory; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.RiskItemHasRiskCategory; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RiskCategoryJpaController implements Serializable { - - public RiskCategoryJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(RiskCategory riskCategory) { - if (riskCategory.getFmeaList() == null) { - riskCategory.setFmeaList(new ArrayList()); - } - if (riskCategory.getRiskItemHasRiskCategoryList() == null) { - riskCategory.setRiskItemHasRiskCategoryList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedFmeaList = new ArrayList(); - for (Fmea fmeaListFmeaToAttach : riskCategory.getFmeaList()) { - fmeaListFmeaToAttach = em.getReference(fmeaListFmeaToAttach.getClass(), fmeaListFmeaToAttach.getId()); - attachedFmeaList.add(fmeaListFmeaToAttach); - } - riskCategory.setFmeaList(attachedFmeaList); - List attachedRiskItemHasRiskCategoryList = new ArrayList(); - for (RiskItemHasRiskCategory riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach : riskCategory.getRiskItemHasRiskCategoryList()) { - riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach = em.getReference(riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach.getClass(), riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach.getRiskItemHasRiskCategoryPK()); - attachedRiskItemHasRiskCategoryList.add(riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach); - } - riskCategory.setRiskItemHasRiskCategoryList(attachedRiskItemHasRiskCategoryList); - em.persist(riskCategory); - for (Fmea fmeaListFmea : riskCategory.getFmeaList()) { - fmeaListFmea.getRiskCategoryList().add(riskCategory); - fmeaListFmea = em.merge(fmeaListFmea); - } - for (RiskItemHasRiskCategory riskItemHasRiskCategoryListRiskItemHasRiskCategory : riskCategory.getRiskItemHasRiskCategoryList()) { - RiskCategory oldRiskCategoryOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory = riskItemHasRiskCategoryListRiskItemHasRiskCategory.getRiskCategory(); - riskItemHasRiskCategoryListRiskItemHasRiskCategory.setRiskCategory(riskCategory); - riskItemHasRiskCategoryListRiskItemHasRiskCategory = em.merge(riskItemHasRiskCategoryListRiskItemHasRiskCategory); - if (oldRiskCategoryOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory != null) { - oldRiskCategoryOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory.getRiskItemHasRiskCategoryList().remove(riskItemHasRiskCategoryListRiskItemHasRiskCategory); - oldRiskCategoryOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory = em.merge(oldRiskCategoryOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(RiskCategory riskCategory) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RiskCategory persistentRiskCategory = em.find(RiskCategory.class, riskCategory.getId()); - List fmeaListOld = persistentRiskCategory.getFmeaList(); - List fmeaListNew = riskCategory.getFmeaList(); - List riskItemHasRiskCategoryListOld = persistentRiskCategory.getRiskItemHasRiskCategoryList(); - List riskItemHasRiskCategoryListNew = riskCategory.getRiskItemHasRiskCategoryList(); - List illegalOrphanMessages = null; - for (RiskItemHasRiskCategory riskItemHasRiskCategoryListOldRiskItemHasRiskCategory : riskItemHasRiskCategoryListOld) { - if (!riskItemHasRiskCategoryListNew.contains(riskItemHasRiskCategoryListOldRiskItemHasRiskCategory)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain RiskItemHasRiskCategory " + riskItemHasRiskCategoryListOldRiskItemHasRiskCategory + " since its riskCategory field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedFmeaListNew = new ArrayList(); - for (Fmea fmeaListNewFmeaToAttach : fmeaListNew) { - fmeaListNewFmeaToAttach = em.getReference(fmeaListNewFmeaToAttach.getClass(), fmeaListNewFmeaToAttach.getId()); - attachedFmeaListNew.add(fmeaListNewFmeaToAttach); - } - fmeaListNew = attachedFmeaListNew; - riskCategory.setFmeaList(fmeaListNew); - List attachedRiskItemHasRiskCategoryListNew = new ArrayList(); - for (RiskItemHasRiskCategory riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach : riskItemHasRiskCategoryListNew) { - riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach = em.getReference(riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach.getClass(), riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach.getRiskItemHasRiskCategoryPK()); - attachedRiskItemHasRiskCategoryListNew.add(riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach); - } - riskItemHasRiskCategoryListNew = attachedRiskItemHasRiskCategoryListNew; - riskCategory.setRiskItemHasRiskCategoryList(riskItemHasRiskCategoryListNew); - riskCategory = em.merge(riskCategory); - for (Fmea fmeaListOldFmea : fmeaListOld) { - if (!fmeaListNew.contains(fmeaListOldFmea)) { - fmeaListOldFmea.getRiskCategoryList().remove(riskCategory); - fmeaListOldFmea = em.merge(fmeaListOldFmea); - } - } - for (Fmea fmeaListNewFmea : fmeaListNew) { - if (!fmeaListOld.contains(fmeaListNewFmea)) { - fmeaListNewFmea.getRiskCategoryList().add(riskCategory); - fmeaListNewFmea = em.merge(fmeaListNewFmea); - } - } - for (RiskItemHasRiskCategory riskItemHasRiskCategoryListNewRiskItemHasRiskCategory : riskItemHasRiskCategoryListNew) { - if (!riskItemHasRiskCategoryListOld.contains(riskItemHasRiskCategoryListNewRiskItemHasRiskCategory)) { - RiskCategory oldRiskCategoryOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory = riskItemHasRiskCategoryListNewRiskItemHasRiskCategory.getRiskCategory(); - riskItemHasRiskCategoryListNewRiskItemHasRiskCategory.setRiskCategory(riskCategory); - riskItemHasRiskCategoryListNewRiskItemHasRiskCategory = em.merge(riskItemHasRiskCategoryListNewRiskItemHasRiskCategory); - if (oldRiskCategoryOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory != null && !oldRiskCategoryOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory.equals(riskCategory)) { - oldRiskCategoryOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory.getRiskItemHasRiskCategoryList().remove(riskItemHasRiskCategoryListNewRiskItemHasRiskCategory); - oldRiskCategoryOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory = em.merge(oldRiskCategoryOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = riskCategory.getId(); - if (findRiskCategory(id) == null) { - throw new NonexistentEntityException("The riskCategory with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RiskCategory riskCategory; - try { - riskCategory = em.getReference(RiskCategory.class, id); - riskCategory.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The riskCategory with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List riskItemHasRiskCategoryListOrphanCheck = riskCategory.getRiskItemHasRiskCategoryList(); - for (RiskItemHasRiskCategory riskItemHasRiskCategoryListOrphanCheckRiskItemHasRiskCategory : riskItemHasRiskCategoryListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This RiskCategory (" + riskCategory + ") cannot be destroyed since the RiskItemHasRiskCategory " + riskItemHasRiskCategoryListOrphanCheckRiskItemHasRiskCategory + " in its riskItemHasRiskCategoryList field has a non-nullable riskCategory field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List fmeaList = riskCategory.getFmeaList(); - for (Fmea fmeaListFmea : fmeaList) { - fmeaListFmea.getRiskCategoryList().remove(riskCategory); - fmeaListFmea = em.merge(fmeaListFmea); - } - em.remove(riskCategory); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findRiskCategoryEntities() { - return findRiskCategoryEntities(true, -1, -1); - } - - public List findRiskCategoryEntities(int maxResults, int firstResult) { - return findRiskCategoryEntities(false, maxResults, firstResult); - } - - private List findRiskCategoryEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(RiskCategory.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public RiskCategory findRiskCategory(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(RiskCategory.class, id); - } - finally { - em.close(); - } - } - - public int getRiskCategoryCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(RiskCategory.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Fmea; +import com.validation.manager.core.db.RiskCategory; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.RiskItemHasRiskCategory; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RiskCategoryJpaController implements Serializable { + + public RiskCategoryJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(RiskCategory riskCategory) { + if (riskCategory.getFmeaList() == null) { + riskCategory.setFmeaList(new ArrayList<>()); + } + if (riskCategory.getRiskItemHasRiskCategoryList() == null) { + riskCategory.setRiskItemHasRiskCategoryList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedFmeaList = new ArrayList<>(); + for (Fmea fmeaListFmeaToAttach : riskCategory.getFmeaList()) { + fmeaListFmeaToAttach = em.getReference(fmeaListFmeaToAttach.getClass(), fmeaListFmeaToAttach.getId()); + attachedFmeaList.add(fmeaListFmeaToAttach); + } + riskCategory.setFmeaList(attachedFmeaList); + List attachedRiskItemHasRiskCategoryList = new ArrayList<>(); + for (RiskItemHasRiskCategory riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach : riskCategory.getRiskItemHasRiskCategoryList()) { + riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach = em.getReference(riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach.getClass(), riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach.getRiskItemHasRiskCategoryPK()); + attachedRiskItemHasRiskCategoryList.add(riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach); + } + riskCategory.setRiskItemHasRiskCategoryList(attachedRiskItemHasRiskCategoryList); + em.persist(riskCategory); + for (Fmea fmeaListFmea : riskCategory.getFmeaList()) { + fmeaListFmea.getRiskCategoryList().add(riskCategory); + fmeaListFmea = em.merge(fmeaListFmea); + } + for (RiskItemHasRiskCategory riskItemHasRiskCategoryListRiskItemHasRiskCategory : riskCategory.getRiskItemHasRiskCategoryList()) { + RiskCategory oldRiskCategoryOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory = riskItemHasRiskCategoryListRiskItemHasRiskCategory.getRiskCategory(); + riskItemHasRiskCategoryListRiskItemHasRiskCategory.setRiskCategory(riskCategory); + riskItemHasRiskCategoryListRiskItemHasRiskCategory = em.merge(riskItemHasRiskCategoryListRiskItemHasRiskCategory); + if (oldRiskCategoryOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory != null) { + oldRiskCategoryOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory.getRiskItemHasRiskCategoryList().remove(riskItemHasRiskCategoryListRiskItemHasRiskCategory); + oldRiskCategoryOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory = em.merge(oldRiskCategoryOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(RiskCategory riskCategory) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RiskCategory persistentRiskCategory = em.find(RiskCategory.class, riskCategory.getId()); + List fmeaListOld = persistentRiskCategory.getFmeaList(); + List fmeaListNew = riskCategory.getFmeaList(); + List riskItemHasRiskCategoryListOld = persistentRiskCategory.getRiskItemHasRiskCategoryList(); + List riskItemHasRiskCategoryListNew = riskCategory.getRiskItemHasRiskCategoryList(); + List illegalOrphanMessages = null; + for (RiskItemHasRiskCategory riskItemHasRiskCategoryListOldRiskItemHasRiskCategory : riskItemHasRiskCategoryListOld) { + if (!riskItemHasRiskCategoryListNew.contains(riskItemHasRiskCategoryListOldRiskItemHasRiskCategory)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain RiskItemHasRiskCategory " + riskItemHasRiskCategoryListOldRiskItemHasRiskCategory + " since its riskCategory field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedFmeaListNew = new ArrayList<>(); + for (Fmea fmeaListNewFmeaToAttach : fmeaListNew) { + fmeaListNewFmeaToAttach = em.getReference(fmeaListNewFmeaToAttach.getClass(), fmeaListNewFmeaToAttach.getId()); + attachedFmeaListNew.add(fmeaListNewFmeaToAttach); + } + fmeaListNew = attachedFmeaListNew; + riskCategory.setFmeaList(fmeaListNew); + List attachedRiskItemHasRiskCategoryListNew = new ArrayList<>(); + for (RiskItemHasRiskCategory riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach : riskItemHasRiskCategoryListNew) { + riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach = em.getReference(riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach.getClass(), riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach.getRiskItemHasRiskCategoryPK()); + attachedRiskItemHasRiskCategoryListNew.add(riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach); + } + riskItemHasRiskCategoryListNew = attachedRiskItemHasRiskCategoryListNew; + riskCategory.setRiskItemHasRiskCategoryList(riskItemHasRiskCategoryListNew); + riskCategory = em.merge(riskCategory); + for (Fmea fmeaListOldFmea : fmeaListOld) { + if (!fmeaListNew.contains(fmeaListOldFmea)) { + fmeaListOldFmea.getRiskCategoryList().remove(riskCategory); + fmeaListOldFmea = em.merge(fmeaListOldFmea); + } + } + for (Fmea fmeaListNewFmea : fmeaListNew) { + if (!fmeaListOld.contains(fmeaListNewFmea)) { + fmeaListNewFmea.getRiskCategoryList().add(riskCategory); + fmeaListNewFmea = em.merge(fmeaListNewFmea); + } + } + for (RiskItemHasRiskCategory riskItemHasRiskCategoryListNewRiskItemHasRiskCategory : riskItemHasRiskCategoryListNew) { + if (!riskItemHasRiskCategoryListOld.contains(riskItemHasRiskCategoryListNewRiskItemHasRiskCategory)) { + RiskCategory oldRiskCategoryOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory = riskItemHasRiskCategoryListNewRiskItemHasRiskCategory.getRiskCategory(); + riskItemHasRiskCategoryListNewRiskItemHasRiskCategory.setRiskCategory(riskCategory); + riskItemHasRiskCategoryListNewRiskItemHasRiskCategory = em.merge(riskItemHasRiskCategoryListNewRiskItemHasRiskCategory); + if (oldRiskCategoryOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory != null && !oldRiskCategoryOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory.equals(riskCategory)) { + oldRiskCategoryOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory.getRiskItemHasRiskCategoryList().remove(riskItemHasRiskCategoryListNewRiskItemHasRiskCategory); + oldRiskCategoryOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory = em.merge(oldRiskCategoryOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = riskCategory.getId(); + if (findRiskCategory(id) == null) { + throw new NonexistentEntityException("The riskCategory with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RiskCategory riskCategory; + try { + riskCategory = em.getReference(RiskCategory.class, id); + riskCategory.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The riskCategory with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List riskItemHasRiskCategoryListOrphanCheck = riskCategory.getRiskItemHasRiskCategoryList(); + for (RiskItemHasRiskCategory riskItemHasRiskCategoryListOrphanCheckRiskItemHasRiskCategory : riskItemHasRiskCategoryListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This RiskCategory (" + riskCategory + ") cannot be destroyed since the RiskItemHasRiskCategory " + riskItemHasRiskCategoryListOrphanCheckRiskItemHasRiskCategory + " in its riskItemHasRiskCategoryList field has a non-nullable riskCategory field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List fmeaList = riskCategory.getFmeaList(); + for (Fmea fmeaListFmea : fmeaList) { + fmeaListFmea.getRiskCategoryList().remove(riskCategory); + fmeaListFmea = em.merge(fmeaListFmea); + } + em.remove(riskCategory); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findRiskCategoryEntities() { + return findRiskCategoryEntities(true, -1, -1); + } + + public List findRiskCategoryEntities(int maxResults, int firstResult) { + return findRiskCategoryEntities(false, maxResults, firstResult); + } + + private List findRiskCategoryEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(RiskCategory.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public RiskCategory findRiskCategory(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(RiskCategory.class, id); + } + finally { + em.close(); + } + } + + public int getRiskCategoryCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(RiskCategory.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskControlJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskControlJpaController.java index 1313ca87..6b41812b 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskControlJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskControlJpaController.java @@ -13,384 +13,384 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.RiskControl; -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.RiskControlType; -import com.validation.manager.core.db.RiskItem; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.RiskControlHasTestCase; -import com.validation.manager.core.db.RiskControlHasRequirement; -import com.validation.manager.core.db.RiskControlPK; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RiskControlJpaController implements Serializable { - - public RiskControlJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(RiskControl riskControl) throws PreexistingEntityException, Exception { - if (riskControl.getRiskControlPK() == null) { - riskControl.setRiskControlPK(new RiskControlPK()); - } - if (riskControl.getRiskItemList() == null) { - riskControl.setRiskItemList(new ArrayList()); - } - if (riskControl.getRiskItemList1() == null) { - riskControl.setRiskItemList1(new ArrayList()); - } - if (riskControl.getRiskControlHasTestCaseList() == null) { - riskControl.setRiskControlHasTestCaseList(new ArrayList()); - } - if (riskControl.getRiskControlHasRequirementList() == null) { - riskControl.setRiskControlHasRequirementList(new ArrayList()); - } - riskControl.getRiskControlPK().setRiskControlTypeId(riskControl.getRiskControlType().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RiskControlType riskControlType = riskControl.getRiskControlType(); - if (riskControlType != null) { - riskControlType = em.getReference(riskControlType.getClass(), riskControlType.getId()); - riskControl.setRiskControlType(riskControlType); - } - List attachedRiskItemList = new ArrayList(); - for (RiskItem riskItemListRiskItemToAttach : riskControl.getRiskItemList()) { - riskItemListRiskItemToAttach = em.getReference(riskItemListRiskItemToAttach.getClass(), riskItemListRiskItemToAttach.getRiskItemPK()); - attachedRiskItemList.add(riskItemListRiskItemToAttach); - } - riskControl.setRiskItemList(attachedRiskItemList); - List attachedRiskItemList1 = new ArrayList(); - for (RiskItem riskItemList1RiskItemToAttach : riskControl.getRiskItemList1()) { - riskItemList1RiskItemToAttach = em.getReference(riskItemList1RiskItemToAttach.getClass(), riskItemList1RiskItemToAttach.getRiskItemPK()); - attachedRiskItemList1.add(riskItemList1RiskItemToAttach); - } - riskControl.setRiskItemList1(attachedRiskItemList1); - List attachedRiskControlHasTestCaseList = new ArrayList(); - for (RiskControlHasTestCase riskControlHasTestCaseListRiskControlHasTestCaseToAttach : riskControl.getRiskControlHasTestCaseList()) { - riskControlHasTestCaseListRiskControlHasTestCaseToAttach = em.getReference(riskControlHasTestCaseListRiskControlHasTestCaseToAttach.getClass(), riskControlHasTestCaseListRiskControlHasTestCaseToAttach.getRiskControlHasTestCasePK()); - attachedRiskControlHasTestCaseList.add(riskControlHasTestCaseListRiskControlHasTestCaseToAttach); - } - riskControl.setRiskControlHasTestCaseList(attachedRiskControlHasTestCaseList); - List attachedRiskControlHasRequirementList = new ArrayList(); - for (RiskControlHasRequirement riskControlHasRequirementListRiskControlHasRequirementToAttach : riskControl.getRiskControlHasRequirementList()) { - riskControlHasRequirementListRiskControlHasRequirementToAttach = em.getReference(riskControlHasRequirementListRiskControlHasRequirementToAttach.getClass(), riskControlHasRequirementListRiskControlHasRequirementToAttach.getRiskControlHasRequirementPK()); - attachedRiskControlHasRequirementList.add(riskControlHasRequirementListRiskControlHasRequirementToAttach); - } - riskControl.setRiskControlHasRequirementList(attachedRiskControlHasRequirementList); - em.persist(riskControl); - if (riskControlType != null) { - riskControlType.getRiskControlList().add(riskControl); - riskControlType = em.merge(riskControlType); - } - for (RiskItem riskItemListRiskItem : riskControl.getRiskItemList()) { - riskItemListRiskItem.getRiskControlList().add(riskControl); - riskItemListRiskItem = em.merge(riskItemListRiskItem); - } - for (RiskItem riskItemList1RiskItem : riskControl.getRiskItemList1()) { - riskItemList1RiskItem.getRiskControlList().add(riskControl); - riskItemList1RiskItem = em.merge(riskItemList1RiskItem); - } - for (RiskControlHasTestCase riskControlHasTestCaseListRiskControlHasTestCase : riskControl.getRiskControlHasTestCaseList()) { - RiskControl oldRiskControlOfRiskControlHasTestCaseListRiskControlHasTestCase = riskControlHasTestCaseListRiskControlHasTestCase.getRiskControl(); - riskControlHasTestCaseListRiskControlHasTestCase.setRiskControl(riskControl); - riskControlHasTestCaseListRiskControlHasTestCase = em.merge(riskControlHasTestCaseListRiskControlHasTestCase); - if (oldRiskControlOfRiskControlHasTestCaseListRiskControlHasTestCase != null) { - oldRiskControlOfRiskControlHasTestCaseListRiskControlHasTestCase.getRiskControlHasTestCaseList().remove(riskControlHasTestCaseListRiskControlHasTestCase); - oldRiskControlOfRiskControlHasTestCaseListRiskControlHasTestCase = em.merge(oldRiskControlOfRiskControlHasTestCaseListRiskControlHasTestCase); - } - } - for (RiskControlHasRequirement riskControlHasRequirementListRiskControlHasRequirement : riskControl.getRiskControlHasRequirementList()) { - RiskControl oldRiskControlOfRiskControlHasRequirementListRiskControlHasRequirement = riskControlHasRequirementListRiskControlHasRequirement.getRiskControl(); - riskControlHasRequirementListRiskControlHasRequirement.setRiskControl(riskControl); - riskControlHasRequirementListRiskControlHasRequirement = em.merge(riskControlHasRequirementListRiskControlHasRequirement); - if (oldRiskControlOfRiskControlHasRequirementListRiskControlHasRequirement != null) { - oldRiskControlOfRiskControlHasRequirementListRiskControlHasRequirement.getRiskControlHasRequirementList().remove(riskControlHasRequirementListRiskControlHasRequirement); - oldRiskControlOfRiskControlHasRequirementListRiskControlHasRequirement = em.merge(oldRiskControlOfRiskControlHasRequirementListRiskControlHasRequirement); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - if (findRiskControl(riskControl.getRiskControlPK()) != null) { - throw new PreexistingEntityException("RiskControl " + riskControl + " already exists.", ex); - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(RiskControl riskControl) throws IllegalOrphanException, NonexistentEntityException, Exception { - riskControl.getRiskControlPK().setRiskControlTypeId(riskControl.getRiskControlType().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RiskControl persistentRiskControl = em.find(RiskControl.class, riskControl.getRiskControlPK()); - RiskControlType riskControlTypeOld = persistentRiskControl.getRiskControlType(); - RiskControlType riskControlTypeNew = riskControl.getRiskControlType(); - List riskItemListOld = persistentRiskControl.getRiskItemList(); - List riskItemListNew = riskControl.getRiskItemList(); - List riskItemList1Old = persistentRiskControl.getRiskItemList1(); - List riskItemList1New = riskControl.getRiskItemList1(); - List riskControlHasTestCaseListOld = persistentRiskControl.getRiskControlHasTestCaseList(); - List riskControlHasTestCaseListNew = riskControl.getRiskControlHasTestCaseList(); - List riskControlHasRequirementListOld = persistentRiskControl.getRiskControlHasRequirementList(); - List riskControlHasRequirementListNew = riskControl.getRiskControlHasRequirementList(); - List illegalOrphanMessages = null; - for (RiskControlHasTestCase riskControlHasTestCaseListOldRiskControlHasTestCase : riskControlHasTestCaseListOld) { - if (!riskControlHasTestCaseListNew.contains(riskControlHasTestCaseListOldRiskControlHasTestCase)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain RiskControlHasTestCase " + riskControlHasTestCaseListOldRiskControlHasTestCase + " since its riskControl field is not nullable."); - } - } - for (RiskControlHasRequirement riskControlHasRequirementListOldRiskControlHasRequirement : riskControlHasRequirementListOld) { - if (!riskControlHasRequirementListNew.contains(riskControlHasRequirementListOldRiskControlHasRequirement)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain RiskControlHasRequirement " + riskControlHasRequirementListOldRiskControlHasRequirement + " since its riskControl field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (riskControlTypeNew != null) { - riskControlTypeNew = em.getReference(riskControlTypeNew.getClass(), riskControlTypeNew.getId()); - riskControl.setRiskControlType(riskControlTypeNew); - } - List attachedRiskItemListNew = new ArrayList(); - for (RiskItem riskItemListNewRiskItemToAttach : riskItemListNew) { - riskItemListNewRiskItemToAttach = em.getReference(riskItemListNewRiskItemToAttach.getClass(), riskItemListNewRiskItemToAttach.getRiskItemPK()); - attachedRiskItemListNew.add(riskItemListNewRiskItemToAttach); - } - riskItemListNew = attachedRiskItemListNew; - riskControl.setRiskItemList(riskItemListNew); - List attachedRiskItemList1New = new ArrayList(); - for (RiskItem riskItemList1NewRiskItemToAttach : riskItemList1New) { - riskItemList1NewRiskItemToAttach = em.getReference(riskItemList1NewRiskItemToAttach.getClass(), riskItemList1NewRiskItemToAttach.getRiskItemPK()); - attachedRiskItemList1New.add(riskItemList1NewRiskItemToAttach); - } - riskItemList1New = attachedRiskItemList1New; - riskControl.setRiskItemList1(riskItemList1New); - List attachedRiskControlHasTestCaseListNew = new ArrayList(); - for (RiskControlHasTestCase riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach : riskControlHasTestCaseListNew) { - riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach = em.getReference(riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach.getClass(), riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach.getRiskControlHasTestCasePK()); - attachedRiskControlHasTestCaseListNew.add(riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach); - } - riskControlHasTestCaseListNew = attachedRiskControlHasTestCaseListNew; - riskControl.setRiskControlHasTestCaseList(riskControlHasTestCaseListNew); - List attachedRiskControlHasRequirementListNew = new ArrayList(); - for (RiskControlHasRequirement riskControlHasRequirementListNewRiskControlHasRequirementToAttach : riskControlHasRequirementListNew) { - riskControlHasRequirementListNewRiskControlHasRequirementToAttach = em.getReference(riskControlHasRequirementListNewRiskControlHasRequirementToAttach.getClass(), riskControlHasRequirementListNewRiskControlHasRequirementToAttach.getRiskControlHasRequirementPK()); - attachedRiskControlHasRequirementListNew.add(riskControlHasRequirementListNewRiskControlHasRequirementToAttach); - } - riskControlHasRequirementListNew = attachedRiskControlHasRequirementListNew; - riskControl.setRiskControlHasRequirementList(riskControlHasRequirementListNew); - riskControl = em.merge(riskControl); - if (riskControlTypeOld != null && !riskControlTypeOld.equals(riskControlTypeNew)) { - riskControlTypeOld.getRiskControlList().remove(riskControl); - riskControlTypeOld = em.merge(riskControlTypeOld); - } - if (riskControlTypeNew != null && !riskControlTypeNew.equals(riskControlTypeOld)) { - riskControlTypeNew.getRiskControlList().add(riskControl); - riskControlTypeNew = em.merge(riskControlTypeNew); - } - for (RiskItem riskItemListOldRiskItem : riskItemListOld) { - if (!riskItemListNew.contains(riskItemListOldRiskItem)) { - riskItemListOldRiskItem.getRiskControlList().remove(riskControl); - riskItemListOldRiskItem = em.merge(riskItemListOldRiskItem); - } - } - for (RiskItem riskItemListNewRiskItem : riskItemListNew) { - if (!riskItemListOld.contains(riskItemListNewRiskItem)) { - riskItemListNewRiskItem.getRiskControlList().add(riskControl); - riskItemListNewRiskItem = em.merge(riskItemListNewRiskItem); - } - } - for (RiskItem riskItemList1OldRiskItem : riskItemList1Old) { - if (!riskItemList1New.contains(riskItemList1OldRiskItem)) { - riskItemList1OldRiskItem.getRiskControlList().remove(riskControl); - riskItemList1OldRiskItem = em.merge(riskItemList1OldRiskItem); - } - } - for (RiskItem riskItemList1NewRiskItem : riskItemList1New) { - if (!riskItemList1Old.contains(riskItemList1NewRiskItem)) { - riskItemList1NewRiskItem.getRiskControlList().add(riskControl); - riskItemList1NewRiskItem = em.merge(riskItemList1NewRiskItem); - } - } - for (RiskControlHasTestCase riskControlHasTestCaseListNewRiskControlHasTestCase : riskControlHasTestCaseListNew) { - if (!riskControlHasTestCaseListOld.contains(riskControlHasTestCaseListNewRiskControlHasTestCase)) { - RiskControl oldRiskControlOfRiskControlHasTestCaseListNewRiskControlHasTestCase = riskControlHasTestCaseListNewRiskControlHasTestCase.getRiskControl(); - riskControlHasTestCaseListNewRiskControlHasTestCase.setRiskControl(riskControl); - riskControlHasTestCaseListNewRiskControlHasTestCase = em.merge(riskControlHasTestCaseListNewRiskControlHasTestCase); - if (oldRiskControlOfRiskControlHasTestCaseListNewRiskControlHasTestCase != null && !oldRiskControlOfRiskControlHasTestCaseListNewRiskControlHasTestCase.equals(riskControl)) { - oldRiskControlOfRiskControlHasTestCaseListNewRiskControlHasTestCase.getRiskControlHasTestCaseList().remove(riskControlHasTestCaseListNewRiskControlHasTestCase); - oldRiskControlOfRiskControlHasTestCaseListNewRiskControlHasTestCase = em.merge(oldRiskControlOfRiskControlHasTestCaseListNewRiskControlHasTestCase); - } - } - } - for (RiskControlHasRequirement riskControlHasRequirementListNewRiskControlHasRequirement : riskControlHasRequirementListNew) { - if (!riskControlHasRequirementListOld.contains(riskControlHasRequirementListNewRiskControlHasRequirement)) { - RiskControl oldRiskControlOfRiskControlHasRequirementListNewRiskControlHasRequirement = riskControlHasRequirementListNewRiskControlHasRequirement.getRiskControl(); - riskControlHasRequirementListNewRiskControlHasRequirement.setRiskControl(riskControl); - riskControlHasRequirementListNewRiskControlHasRequirement = em.merge(riskControlHasRequirementListNewRiskControlHasRequirement); - if (oldRiskControlOfRiskControlHasRequirementListNewRiskControlHasRequirement != null && !oldRiskControlOfRiskControlHasRequirementListNewRiskControlHasRequirement.equals(riskControl)) { - oldRiskControlOfRiskControlHasRequirementListNewRiskControlHasRequirement.getRiskControlHasRequirementList().remove(riskControlHasRequirementListNewRiskControlHasRequirement); - oldRiskControlOfRiskControlHasRequirementListNewRiskControlHasRequirement = em.merge(oldRiskControlOfRiskControlHasRequirementListNewRiskControlHasRequirement); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - RiskControlPK id = riskControl.getRiskControlPK(); - if (findRiskControl(id) == null) { - throw new NonexistentEntityException("The riskControl with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(RiskControlPK id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RiskControl riskControl; - try { - riskControl = em.getReference(RiskControl.class, id); - riskControl.getRiskControlPK(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The riskControl with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List riskControlHasTestCaseListOrphanCheck = riskControl.getRiskControlHasTestCaseList(); - for (RiskControlHasTestCase riskControlHasTestCaseListOrphanCheckRiskControlHasTestCase : riskControlHasTestCaseListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This RiskControl (" + riskControl + ") cannot be destroyed since the RiskControlHasTestCase " + riskControlHasTestCaseListOrphanCheckRiskControlHasTestCase + " in its riskControlHasTestCaseList field has a non-nullable riskControl field."); - } - List riskControlHasRequirementListOrphanCheck = riskControl.getRiskControlHasRequirementList(); - for (RiskControlHasRequirement riskControlHasRequirementListOrphanCheckRiskControlHasRequirement : riskControlHasRequirementListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This RiskControl (" + riskControl + ") cannot be destroyed since the RiskControlHasRequirement " + riskControlHasRequirementListOrphanCheckRiskControlHasRequirement + " in its riskControlHasRequirementList field has a non-nullable riskControl field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - RiskControlType riskControlType = riskControl.getRiskControlType(); - if (riskControlType != null) { - riskControlType.getRiskControlList().remove(riskControl); - riskControlType = em.merge(riskControlType); - } - List riskItemList = riskControl.getRiskItemList(); - for (RiskItem riskItemListRiskItem : riskItemList) { - riskItemListRiskItem.getRiskControlList().remove(riskControl); - riskItemListRiskItem = em.merge(riskItemListRiskItem); - } - List riskItemList1 = riskControl.getRiskItemList1(); - for (RiskItem riskItemList1RiskItem : riskItemList1) { - riskItemList1RiskItem.getRiskControlList().remove(riskControl); - riskItemList1RiskItem = em.merge(riskItemList1RiskItem); - } - em.remove(riskControl); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findRiskControlEntities() { - return findRiskControlEntities(true, -1, -1); - } - - public List findRiskControlEntities(int maxResults, int firstResult) { - return findRiskControlEntities(false, maxResults, firstResult); - } - - private List findRiskControlEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(RiskControl.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public RiskControl findRiskControl(RiskControlPK id) { - EntityManager em = getEntityManager(); - try { - return em.find(RiskControl.class, id); - } - finally { - em.close(); - } - } - - public int getRiskControlCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(RiskControl.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import com.validation.manager.core.db.RiskControl; +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.RiskControlType; +import com.validation.manager.core.db.RiskItem; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.RiskControlHasTestCase; +import com.validation.manager.core.db.RiskControlHasRequirement; +import com.validation.manager.core.db.RiskControlPK; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RiskControlJpaController implements Serializable { + + public RiskControlJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(RiskControl riskControl) throws PreexistingEntityException, Exception { + if (riskControl.getRiskControlPK() == null) { + riskControl.setRiskControlPK(new RiskControlPK()); + } + if (riskControl.getRiskItemList() == null) { + riskControl.setRiskItemList(new ArrayList<>()); + } + if (riskControl.getRiskItemList1() == null) { + riskControl.setRiskItemList1(new ArrayList<>()); + } + if (riskControl.getRiskControlHasTestCaseList() == null) { + riskControl.setRiskControlHasTestCaseList(new ArrayList<>()); + } + if (riskControl.getRiskControlHasRequirementList() == null) { + riskControl.setRiskControlHasRequirementList(new ArrayList<>()); + } + riskControl.getRiskControlPK().setRiskControlTypeId(riskControl.getRiskControlType().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RiskControlType riskControlType = riskControl.getRiskControlType(); + if (riskControlType != null) { + riskControlType = em.getReference(riskControlType.getClass(), riskControlType.getId()); + riskControl.setRiskControlType(riskControlType); + } + List attachedRiskItemList = new ArrayList<>(); + for (RiskItem riskItemListRiskItemToAttach : riskControl.getRiskItemList()) { + riskItemListRiskItemToAttach = em.getReference(riskItemListRiskItemToAttach.getClass(), riskItemListRiskItemToAttach.getRiskItemPK()); + attachedRiskItemList.add(riskItemListRiskItemToAttach); + } + riskControl.setRiskItemList(attachedRiskItemList); + List attachedRiskItemList1 = new ArrayList<>(); + for (RiskItem riskItemList1RiskItemToAttach : riskControl.getRiskItemList1()) { + riskItemList1RiskItemToAttach = em.getReference(riskItemList1RiskItemToAttach.getClass(), riskItemList1RiskItemToAttach.getRiskItemPK()); + attachedRiskItemList1.add(riskItemList1RiskItemToAttach); + } + riskControl.setRiskItemList1(attachedRiskItemList1); + List attachedRiskControlHasTestCaseList = new ArrayList<>(); + for (RiskControlHasTestCase riskControlHasTestCaseListRiskControlHasTestCaseToAttach : riskControl.getRiskControlHasTestCaseList()) { + riskControlHasTestCaseListRiskControlHasTestCaseToAttach = em.getReference(riskControlHasTestCaseListRiskControlHasTestCaseToAttach.getClass(), riskControlHasTestCaseListRiskControlHasTestCaseToAttach.getRiskControlHasTestCasePK()); + attachedRiskControlHasTestCaseList.add(riskControlHasTestCaseListRiskControlHasTestCaseToAttach); + } + riskControl.setRiskControlHasTestCaseList(attachedRiskControlHasTestCaseList); + List attachedRiskControlHasRequirementList = new ArrayList<>(); + for (RiskControlHasRequirement riskControlHasRequirementListRiskControlHasRequirementToAttach : riskControl.getRiskControlHasRequirementList()) { + riskControlHasRequirementListRiskControlHasRequirementToAttach = em.getReference(riskControlHasRequirementListRiskControlHasRequirementToAttach.getClass(), riskControlHasRequirementListRiskControlHasRequirementToAttach.getRiskControlHasRequirementPK()); + attachedRiskControlHasRequirementList.add(riskControlHasRequirementListRiskControlHasRequirementToAttach); + } + riskControl.setRiskControlHasRequirementList(attachedRiskControlHasRequirementList); + em.persist(riskControl); + if (riskControlType != null) { + riskControlType.getRiskControlList().add(riskControl); + riskControlType = em.merge(riskControlType); + } + for (RiskItem riskItemListRiskItem : riskControl.getRiskItemList()) { + riskItemListRiskItem.getRiskControlList().add(riskControl); + riskItemListRiskItem = em.merge(riskItemListRiskItem); + } + for (RiskItem riskItemList1RiskItem : riskControl.getRiskItemList1()) { + riskItemList1RiskItem.getRiskControlList().add(riskControl); + riskItemList1RiskItem = em.merge(riskItemList1RiskItem); + } + for (RiskControlHasTestCase riskControlHasTestCaseListRiskControlHasTestCase : riskControl.getRiskControlHasTestCaseList()) { + RiskControl oldRiskControlOfRiskControlHasTestCaseListRiskControlHasTestCase = riskControlHasTestCaseListRiskControlHasTestCase.getRiskControl(); + riskControlHasTestCaseListRiskControlHasTestCase.setRiskControl(riskControl); + riskControlHasTestCaseListRiskControlHasTestCase = em.merge(riskControlHasTestCaseListRiskControlHasTestCase); + if (oldRiskControlOfRiskControlHasTestCaseListRiskControlHasTestCase != null) { + oldRiskControlOfRiskControlHasTestCaseListRiskControlHasTestCase.getRiskControlHasTestCaseList().remove(riskControlHasTestCaseListRiskControlHasTestCase); + oldRiskControlOfRiskControlHasTestCaseListRiskControlHasTestCase = em.merge(oldRiskControlOfRiskControlHasTestCaseListRiskControlHasTestCase); + } + } + for (RiskControlHasRequirement riskControlHasRequirementListRiskControlHasRequirement : riskControl.getRiskControlHasRequirementList()) { + RiskControl oldRiskControlOfRiskControlHasRequirementListRiskControlHasRequirement = riskControlHasRequirementListRiskControlHasRequirement.getRiskControl(); + riskControlHasRequirementListRiskControlHasRequirement.setRiskControl(riskControl); + riskControlHasRequirementListRiskControlHasRequirement = em.merge(riskControlHasRequirementListRiskControlHasRequirement); + if (oldRiskControlOfRiskControlHasRequirementListRiskControlHasRequirement != null) { + oldRiskControlOfRiskControlHasRequirementListRiskControlHasRequirement.getRiskControlHasRequirementList().remove(riskControlHasRequirementListRiskControlHasRequirement); + oldRiskControlOfRiskControlHasRequirementListRiskControlHasRequirement = em.merge(oldRiskControlOfRiskControlHasRequirementListRiskControlHasRequirement); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + if (findRiskControl(riskControl.getRiskControlPK()) != null) { + throw new PreexistingEntityException("RiskControl " + riskControl + " already exists.", ex); + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(RiskControl riskControl) throws IllegalOrphanException, NonexistentEntityException, Exception { + riskControl.getRiskControlPK().setRiskControlTypeId(riskControl.getRiskControlType().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RiskControl persistentRiskControl = em.find(RiskControl.class, riskControl.getRiskControlPK()); + RiskControlType riskControlTypeOld = persistentRiskControl.getRiskControlType(); + RiskControlType riskControlTypeNew = riskControl.getRiskControlType(); + List riskItemListOld = persistentRiskControl.getRiskItemList(); + List riskItemListNew = riskControl.getRiskItemList(); + List riskItemList1Old = persistentRiskControl.getRiskItemList1(); + List riskItemList1New = riskControl.getRiskItemList1(); + List riskControlHasTestCaseListOld = persistentRiskControl.getRiskControlHasTestCaseList(); + List riskControlHasTestCaseListNew = riskControl.getRiskControlHasTestCaseList(); + List riskControlHasRequirementListOld = persistentRiskControl.getRiskControlHasRequirementList(); + List riskControlHasRequirementListNew = riskControl.getRiskControlHasRequirementList(); + List illegalOrphanMessages = null; + for (RiskControlHasTestCase riskControlHasTestCaseListOldRiskControlHasTestCase : riskControlHasTestCaseListOld) { + if (!riskControlHasTestCaseListNew.contains(riskControlHasTestCaseListOldRiskControlHasTestCase)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain RiskControlHasTestCase " + riskControlHasTestCaseListOldRiskControlHasTestCase + " since its riskControl field is not nullable."); + } + } + for (RiskControlHasRequirement riskControlHasRequirementListOldRiskControlHasRequirement : riskControlHasRequirementListOld) { + if (!riskControlHasRequirementListNew.contains(riskControlHasRequirementListOldRiskControlHasRequirement)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain RiskControlHasRequirement " + riskControlHasRequirementListOldRiskControlHasRequirement + " since its riskControl field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (riskControlTypeNew != null) { + riskControlTypeNew = em.getReference(riskControlTypeNew.getClass(), riskControlTypeNew.getId()); + riskControl.setRiskControlType(riskControlTypeNew); + } + List attachedRiskItemListNew = new ArrayList<>(); + for (RiskItem riskItemListNewRiskItemToAttach : riskItemListNew) { + riskItemListNewRiskItemToAttach = em.getReference(riskItemListNewRiskItemToAttach.getClass(), riskItemListNewRiskItemToAttach.getRiskItemPK()); + attachedRiskItemListNew.add(riskItemListNewRiskItemToAttach); + } + riskItemListNew = attachedRiskItemListNew; + riskControl.setRiskItemList(riskItemListNew); + List attachedRiskItemList1New = new ArrayList<>(); + for (RiskItem riskItemList1NewRiskItemToAttach : riskItemList1New) { + riskItemList1NewRiskItemToAttach = em.getReference(riskItemList1NewRiskItemToAttach.getClass(), riskItemList1NewRiskItemToAttach.getRiskItemPK()); + attachedRiskItemList1New.add(riskItemList1NewRiskItemToAttach); + } + riskItemList1New = attachedRiskItemList1New; + riskControl.setRiskItemList1(riskItemList1New); + List attachedRiskControlHasTestCaseListNew = new ArrayList<>(); + for (RiskControlHasTestCase riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach : riskControlHasTestCaseListNew) { + riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach = em.getReference(riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach.getClass(), riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach.getRiskControlHasTestCasePK()); + attachedRiskControlHasTestCaseListNew.add(riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach); + } + riskControlHasTestCaseListNew = attachedRiskControlHasTestCaseListNew; + riskControl.setRiskControlHasTestCaseList(riskControlHasTestCaseListNew); + List attachedRiskControlHasRequirementListNew = new ArrayList<>(); + for (RiskControlHasRequirement riskControlHasRequirementListNewRiskControlHasRequirementToAttach : riskControlHasRequirementListNew) { + riskControlHasRequirementListNewRiskControlHasRequirementToAttach = em.getReference(riskControlHasRequirementListNewRiskControlHasRequirementToAttach.getClass(), riskControlHasRequirementListNewRiskControlHasRequirementToAttach.getRiskControlHasRequirementPK()); + attachedRiskControlHasRequirementListNew.add(riskControlHasRequirementListNewRiskControlHasRequirementToAttach); + } + riskControlHasRequirementListNew = attachedRiskControlHasRequirementListNew; + riskControl.setRiskControlHasRequirementList(riskControlHasRequirementListNew); + riskControl = em.merge(riskControl); + if (riskControlTypeOld != null && !riskControlTypeOld.equals(riskControlTypeNew)) { + riskControlTypeOld.getRiskControlList().remove(riskControl); + riskControlTypeOld = em.merge(riskControlTypeOld); + } + if (riskControlTypeNew != null && !riskControlTypeNew.equals(riskControlTypeOld)) { + riskControlTypeNew.getRiskControlList().add(riskControl); + riskControlTypeNew = em.merge(riskControlTypeNew); + } + for (RiskItem riskItemListOldRiskItem : riskItemListOld) { + if (!riskItemListNew.contains(riskItemListOldRiskItem)) { + riskItemListOldRiskItem.getRiskControlList().remove(riskControl); + riskItemListOldRiskItem = em.merge(riskItemListOldRiskItem); + } + } + for (RiskItem riskItemListNewRiskItem : riskItemListNew) { + if (!riskItemListOld.contains(riskItemListNewRiskItem)) { + riskItemListNewRiskItem.getRiskControlList().add(riskControl); + riskItemListNewRiskItem = em.merge(riskItemListNewRiskItem); + } + } + for (RiskItem riskItemList1OldRiskItem : riskItemList1Old) { + if (!riskItemList1New.contains(riskItemList1OldRiskItem)) { + riskItemList1OldRiskItem.getRiskControlList().remove(riskControl); + riskItemList1OldRiskItem = em.merge(riskItemList1OldRiskItem); + } + } + for (RiskItem riskItemList1NewRiskItem : riskItemList1New) { + if (!riskItemList1Old.contains(riskItemList1NewRiskItem)) { + riskItemList1NewRiskItem.getRiskControlList().add(riskControl); + riskItemList1NewRiskItem = em.merge(riskItemList1NewRiskItem); + } + } + for (RiskControlHasTestCase riskControlHasTestCaseListNewRiskControlHasTestCase : riskControlHasTestCaseListNew) { + if (!riskControlHasTestCaseListOld.contains(riskControlHasTestCaseListNewRiskControlHasTestCase)) { + RiskControl oldRiskControlOfRiskControlHasTestCaseListNewRiskControlHasTestCase = riskControlHasTestCaseListNewRiskControlHasTestCase.getRiskControl(); + riskControlHasTestCaseListNewRiskControlHasTestCase.setRiskControl(riskControl); + riskControlHasTestCaseListNewRiskControlHasTestCase = em.merge(riskControlHasTestCaseListNewRiskControlHasTestCase); + if (oldRiskControlOfRiskControlHasTestCaseListNewRiskControlHasTestCase != null && !oldRiskControlOfRiskControlHasTestCaseListNewRiskControlHasTestCase.equals(riskControl)) { + oldRiskControlOfRiskControlHasTestCaseListNewRiskControlHasTestCase.getRiskControlHasTestCaseList().remove(riskControlHasTestCaseListNewRiskControlHasTestCase); + oldRiskControlOfRiskControlHasTestCaseListNewRiskControlHasTestCase = em.merge(oldRiskControlOfRiskControlHasTestCaseListNewRiskControlHasTestCase); + } + } + } + for (RiskControlHasRequirement riskControlHasRequirementListNewRiskControlHasRequirement : riskControlHasRequirementListNew) { + if (!riskControlHasRequirementListOld.contains(riskControlHasRequirementListNewRiskControlHasRequirement)) { + RiskControl oldRiskControlOfRiskControlHasRequirementListNewRiskControlHasRequirement = riskControlHasRequirementListNewRiskControlHasRequirement.getRiskControl(); + riskControlHasRequirementListNewRiskControlHasRequirement.setRiskControl(riskControl); + riskControlHasRequirementListNewRiskControlHasRequirement = em.merge(riskControlHasRequirementListNewRiskControlHasRequirement); + if (oldRiskControlOfRiskControlHasRequirementListNewRiskControlHasRequirement != null && !oldRiskControlOfRiskControlHasRequirementListNewRiskControlHasRequirement.equals(riskControl)) { + oldRiskControlOfRiskControlHasRequirementListNewRiskControlHasRequirement.getRiskControlHasRequirementList().remove(riskControlHasRequirementListNewRiskControlHasRequirement); + oldRiskControlOfRiskControlHasRequirementListNewRiskControlHasRequirement = em.merge(oldRiskControlOfRiskControlHasRequirementListNewRiskControlHasRequirement); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + RiskControlPK id = riskControl.getRiskControlPK(); + if (findRiskControl(id) == null) { + throw new NonexistentEntityException("The riskControl with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(RiskControlPK id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RiskControl riskControl; + try { + riskControl = em.getReference(RiskControl.class, id); + riskControl.getRiskControlPK(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The riskControl with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List riskControlHasTestCaseListOrphanCheck = riskControl.getRiskControlHasTestCaseList(); + for (RiskControlHasTestCase riskControlHasTestCaseListOrphanCheckRiskControlHasTestCase : riskControlHasTestCaseListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This RiskControl (" + riskControl + ") cannot be destroyed since the RiskControlHasTestCase " + riskControlHasTestCaseListOrphanCheckRiskControlHasTestCase + " in its riskControlHasTestCaseList field has a non-nullable riskControl field."); + } + List riskControlHasRequirementListOrphanCheck = riskControl.getRiskControlHasRequirementList(); + for (RiskControlHasRequirement riskControlHasRequirementListOrphanCheckRiskControlHasRequirement : riskControlHasRequirementListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This RiskControl (" + riskControl + ") cannot be destroyed since the RiskControlHasRequirement " + riskControlHasRequirementListOrphanCheckRiskControlHasRequirement + " in its riskControlHasRequirementList field has a non-nullable riskControl field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + RiskControlType riskControlType = riskControl.getRiskControlType(); + if (riskControlType != null) { + riskControlType.getRiskControlList().remove(riskControl); + riskControlType = em.merge(riskControlType); + } + List riskItemList = riskControl.getRiskItemList(); + for (RiskItem riskItemListRiskItem : riskItemList) { + riskItemListRiskItem.getRiskControlList().remove(riskControl); + riskItemListRiskItem = em.merge(riskItemListRiskItem); + } + List riskItemList1 = riskControl.getRiskItemList1(); + for (RiskItem riskItemList1RiskItem : riskItemList1) { + riskItemList1RiskItem.getRiskControlList().remove(riskControl); + riskItemList1RiskItem = em.merge(riskItemList1RiskItem); + } + em.remove(riskControl); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findRiskControlEntities() { + return findRiskControlEntities(true, -1, -1); + } + + public List findRiskControlEntities(int maxResults, int firstResult) { + return findRiskControlEntities(false, maxResults, firstResult); + } + + private List findRiskControlEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(RiskControl.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public RiskControl findRiskControl(RiskControlPK id) { + EntityManager em = getEntityManager(); + try { + return em.find(RiskControl.class, id); + } + finally { + em.close(); + } + } + + public int getRiskControlCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(RiskControl.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskControlTypeJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskControlTypeJpaController.java index 859776db..a0b0f18e 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskControlTypeJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskControlTypeJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.RiskControl; -import com.validation.manager.core.db.RiskControlType; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RiskControlTypeJpaController implements Serializable { - - public RiskControlTypeJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(RiskControlType riskControlType) { - if (riskControlType.getRiskControlList() == null) { - riskControlType.setRiskControlList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedRiskControlList = new ArrayList(); - for (RiskControl riskControlListRiskControlToAttach : riskControlType.getRiskControlList()) { - riskControlListRiskControlToAttach = em.getReference(riskControlListRiskControlToAttach.getClass(), riskControlListRiskControlToAttach.getRiskControlPK()); - attachedRiskControlList.add(riskControlListRiskControlToAttach); - } - riskControlType.setRiskControlList(attachedRiskControlList); - em.persist(riskControlType); - for (RiskControl riskControlListRiskControl : riskControlType.getRiskControlList()) { - RiskControlType oldRiskControlTypeOfRiskControlListRiskControl = riskControlListRiskControl.getRiskControlType(); - riskControlListRiskControl.setRiskControlType(riskControlType); - riskControlListRiskControl = em.merge(riskControlListRiskControl); - if (oldRiskControlTypeOfRiskControlListRiskControl != null) { - oldRiskControlTypeOfRiskControlListRiskControl.getRiskControlList().remove(riskControlListRiskControl); - oldRiskControlTypeOfRiskControlListRiskControl = em.merge(oldRiskControlTypeOfRiskControlListRiskControl); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(RiskControlType riskControlType) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RiskControlType persistentRiskControlType = em.find(RiskControlType.class, riskControlType.getId()); - List riskControlListOld = persistentRiskControlType.getRiskControlList(); - List riskControlListNew = riskControlType.getRiskControlList(); - List illegalOrphanMessages = null; - for (RiskControl riskControlListOldRiskControl : riskControlListOld) { - if (!riskControlListNew.contains(riskControlListOldRiskControl)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain RiskControl " + riskControlListOldRiskControl + " since its riskControlType field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedRiskControlListNew = new ArrayList(); - for (RiskControl riskControlListNewRiskControlToAttach : riskControlListNew) { - riskControlListNewRiskControlToAttach = em.getReference(riskControlListNewRiskControlToAttach.getClass(), riskControlListNewRiskControlToAttach.getRiskControlPK()); - attachedRiskControlListNew.add(riskControlListNewRiskControlToAttach); - } - riskControlListNew = attachedRiskControlListNew; - riskControlType.setRiskControlList(riskControlListNew); - riskControlType = em.merge(riskControlType); - for (RiskControl riskControlListNewRiskControl : riskControlListNew) { - if (!riskControlListOld.contains(riskControlListNewRiskControl)) { - RiskControlType oldRiskControlTypeOfRiskControlListNewRiskControl = riskControlListNewRiskControl.getRiskControlType(); - riskControlListNewRiskControl.setRiskControlType(riskControlType); - riskControlListNewRiskControl = em.merge(riskControlListNewRiskControl); - if (oldRiskControlTypeOfRiskControlListNewRiskControl != null && !oldRiskControlTypeOfRiskControlListNewRiskControl.equals(riskControlType)) { - oldRiskControlTypeOfRiskControlListNewRiskControl.getRiskControlList().remove(riskControlListNewRiskControl); - oldRiskControlTypeOfRiskControlListNewRiskControl = em.merge(oldRiskControlTypeOfRiskControlListNewRiskControl); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = riskControlType.getId(); - if (findRiskControlType(id) == null) { - throw new NonexistentEntityException("The riskControlType with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RiskControlType riskControlType; - try { - riskControlType = em.getReference(RiskControlType.class, id); - riskControlType.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The riskControlType with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List riskControlListOrphanCheck = riskControlType.getRiskControlList(); - for (RiskControl riskControlListOrphanCheckRiskControl : riskControlListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This RiskControlType (" + riskControlType + ") cannot be destroyed since the RiskControl " + riskControlListOrphanCheckRiskControl + " in its riskControlList field has a non-nullable riskControlType field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(riskControlType); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findRiskControlTypeEntities() { - return findRiskControlTypeEntities(true, -1, -1); - } - - public List findRiskControlTypeEntities(int maxResults, int firstResult) { - return findRiskControlTypeEntities(false, maxResults, firstResult); - } - - private List findRiskControlTypeEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(RiskControlType.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public RiskControlType findRiskControlType(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(RiskControlType.class, id); - } - finally { - em.close(); - } - } - - public int getRiskControlTypeCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(RiskControlType.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.RiskControl; +import com.validation.manager.core.db.RiskControlType; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RiskControlTypeJpaController implements Serializable { + + public RiskControlTypeJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(RiskControlType riskControlType) { + if (riskControlType.getRiskControlList() == null) { + riskControlType.setRiskControlList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedRiskControlList = new ArrayList<>(); + for (RiskControl riskControlListRiskControlToAttach : riskControlType.getRiskControlList()) { + riskControlListRiskControlToAttach = em.getReference(riskControlListRiskControlToAttach.getClass(), riskControlListRiskControlToAttach.getRiskControlPK()); + attachedRiskControlList.add(riskControlListRiskControlToAttach); + } + riskControlType.setRiskControlList(attachedRiskControlList); + em.persist(riskControlType); + for (RiskControl riskControlListRiskControl : riskControlType.getRiskControlList()) { + RiskControlType oldRiskControlTypeOfRiskControlListRiskControl = riskControlListRiskControl.getRiskControlType(); + riskControlListRiskControl.setRiskControlType(riskControlType); + riskControlListRiskControl = em.merge(riskControlListRiskControl); + if (oldRiskControlTypeOfRiskControlListRiskControl != null) { + oldRiskControlTypeOfRiskControlListRiskControl.getRiskControlList().remove(riskControlListRiskControl); + oldRiskControlTypeOfRiskControlListRiskControl = em.merge(oldRiskControlTypeOfRiskControlListRiskControl); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(RiskControlType riskControlType) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RiskControlType persistentRiskControlType = em.find(RiskControlType.class, riskControlType.getId()); + List riskControlListOld = persistentRiskControlType.getRiskControlList(); + List riskControlListNew = riskControlType.getRiskControlList(); + List illegalOrphanMessages = null; + for (RiskControl riskControlListOldRiskControl : riskControlListOld) { + if (!riskControlListNew.contains(riskControlListOldRiskControl)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain RiskControl " + riskControlListOldRiskControl + " since its riskControlType field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedRiskControlListNew = new ArrayList<>(); + for (RiskControl riskControlListNewRiskControlToAttach : riskControlListNew) { + riskControlListNewRiskControlToAttach = em.getReference(riskControlListNewRiskControlToAttach.getClass(), riskControlListNewRiskControlToAttach.getRiskControlPK()); + attachedRiskControlListNew.add(riskControlListNewRiskControlToAttach); + } + riskControlListNew = attachedRiskControlListNew; + riskControlType.setRiskControlList(riskControlListNew); + riskControlType = em.merge(riskControlType); + for (RiskControl riskControlListNewRiskControl : riskControlListNew) { + if (!riskControlListOld.contains(riskControlListNewRiskControl)) { + RiskControlType oldRiskControlTypeOfRiskControlListNewRiskControl = riskControlListNewRiskControl.getRiskControlType(); + riskControlListNewRiskControl.setRiskControlType(riskControlType); + riskControlListNewRiskControl = em.merge(riskControlListNewRiskControl); + if (oldRiskControlTypeOfRiskControlListNewRiskControl != null && !oldRiskControlTypeOfRiskControlListNewRiskControl.equals(riskControlType)) { + oldRiskControlTypeOfRiskControlListNewRiskControl.getRiskControlList().remove(riskControlListNewRiskControl); + oldRiskControlTypeOfRiskControlListNewRiskControl = em.merge(oldRiskControlTypeOfRiskControlListNewRiskControl); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = riskControlType.getId(); + if (findRiskControlType(id) == null) { + throw new NonexistentEntityException("The riskControlType with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RiskControlType riskControlType; + try { + riskControlType = em.getReference(RiskControlType.class, id); + riskControlType.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The riskControlType with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List riskControlListOrphanCheck = riskControlType.getRiskControlList(); + for (RiskControl riskControlListOrphanCheckRiskControl : riskControlListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This RiskControlType (" + riskControlType + ") cannot be destroyed since the RiskControl " + riskControlListOrphanCheckRiskControl + " in its riskControlList field has a non-nullable riskControlType field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(riskControlType); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findRiskControlTypeEntities() { + return findRiskControlTypeEntities(true, -1, -1); + } + + public List findRiskControlTypeEntities(int maxResults, int firstResult) { + return findRiskControlTypeEntities(false, maxResults, firstResult); + } + + private List findRiskControlTypeEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(RiskControlType.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public RiskControlType findRiskControlType(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(RiskControlType.class, id); + } + finally { + em.close(); + } + } + + public int getRiskControlTypeCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(RiskControlType.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskItemJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskItemJpaController.java index 71e5fdc3..6e09afa5 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskItemJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RiskItemJpaController.java @@ -13,450 +13,450 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Fmea; -import com.validation.manager.core.db.FailureMode; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.Hazard; -import com.validation.manager.core.db.RiskControl; -import com.validation.manager.core.db.Cause; -import com.validation.manager.core.db.RiskItem; -import com.validation.manager.core.db.RiskItemHasRiskCategory; -import com.validation.manager.core.db.RiskItemPK; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RiskItemJpaController implements Serializable { - - public RiskItemJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(RiskItem riskItem) throws PreexistingEntityException, Exception { - if (riskItem.getRiskItemPK() == null) { - riskItem.setRiskItemPK(new RiskItemPK()); - } - if (riskItem.getFailureModeList() == null) { - riskItem.setFailureModeList(new ArrayList()); - } - if (riskItem.getHazardList() == null) { - riskItem.setHazardList(new ArrayList()); - } - if (riskItem.getRiskControlList() == null) { - riskItem.setRiskControlList(new ArrayList()); - } - if (riskItem.getRiskControlList1() == null) { - riskItem.setRiskControlList1(new ArrayList()); - } - if (riskItem.getCauseList() == null) { - riskItem.setCauseList(new ArrayList()); - } - if (riskItem.getRiskItemHasRiskCategoryList() == null) { - riskItem.setRiskItemHasRiskCategoryList(new ArrayList()); - } - riskItem.getRiskItemPK().setFMEAid(riskItem.getFmea().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Fmea fmea = riskItem.getFmea(); - if (fmea != null) { - fmea = em.getReference(fmea.getClass(), fmea.getId()); - riskItem.setFmea(fmea); - } - List attachedFailureModeList = new ArrayList(); - for (FailureMode failureModeListFailureModeToAttach : riskItem.getFailureModeList()) { - failureModeListFailureModeToAttach = em.getReference(failureModeListFailureModeToAttach.getClass(), failureModeListFailureModeToAttach.getId()); - attachedFailureModeList.add(failureModeListFailureModeToAttach); - } - riskItem.setFailureModeList(attachedFailureModeList); - List attachedHazardList = new ArrayList(); - for (Hazard hazardListHazardToAttach : riskItem.getHazardList()) { - hazardListHazardToAttach = em.getReference(hazardListHazardToAttach.getClass(), hazardListHazardToAttach.getId()); - attachedHazardList.add(hazardListHazardToAttach); - } - riskItem.setHazardList(attachedHazardList); - List attachedRiskControlList = new ArrayList(); - for (RiskControl riskControlListRiskControlToAttach : riskItem.getRiskControlList()) { - riskControlListRiskControlToAttach = em.getReference(riskControlListRiskControlToAttach.getClass(), riskControlListRiskControlToAttach.getRiskControlPK()); - attachedRiskControlList.add(riskControlListRiskControlToAttach); - } - riskItem.setRiskControlList(attachedRiskControlList); - List attachedRiskControlList1 = new ArrayList(); - for (RiskControl riskControlList1RiskControlToAttach : riskItem.getRiskControlList1()) { - riskControlList1RiskControlToAttach = em.getReference(riskControlList1RiskControlToAttach.getClass(), riskControlList1RiskControlToAttach.getRiskControlPK()); - attachedRiskControlList1.add(riskControlList1RiskControlToAttach); - } - riskItem.setRiskControlList1(attachedRiskControlList1); - List attachedCauseList = new ArrayList(); - for (Cause causeListCauseToAttach : riskItem.getCauseList()) { - causeListCauseToAttach = em.getReference(causeListCauseToAttach.getClass(), causeListCauseToAttach.getId()); - attachedCauseList.add(causeListCauseToAttach); - } - riskItem.setCauseList(attachedCauseList); - List attachedRiskItemHasRiskCategoryList = new ArrayList(); - for (RiskItemHasRiskCategory riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach : riskItem.getRiskItemHasRiskCategoryList()) { - riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach = em.getReference(riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach.getClass(), riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach.getRiskItemHasRiskCategoryPK()); - attachedRiskItemHasRiskCategoryList.add(riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach); - } - riskItem.setRiskItemHasRiskCategoryList(attachedRiskItemHasRiskCategoryList); - em.persist(riskItem); - if (fmea != null) { - fmea.getRiskItemList().add(riskItem); - fmea = em.merge(fmea); - } - for (FailureMode failureModeListFailureMode : riskItem.getFailureModeList()) { - failureModeListFailureMode.getRiskItemList().add(riskItem); - failureModeListFailureMode = em.merge(failureModeListFailureMode); - } - for (Hazard hazardListHazard : riskItem.getHazardList()) { - hazardListHazard.getRiskItemList().add(riskItem); - hazardListHazard = em.merge(hazardListHazard); - } - for (RiskControl riskControlListRiskControl : riskItem.getRiskControlList()) { - riskControlListRiskControl.getRiskItemList().add(riskItem); - riskControlListRiskControl = em.merge(riskControlListRiskControl); - } - for (RiskControl riskControlList1RiskControl : riskItem.getRiskControlList1()) { - riskControlList1RiskControl.getRiskItemList1().add(riskItem); - riskControlList1RiskControl = em.merge(riskControlList1RiskControl); - } - for (Cause causeListCause : riskItem.getCauseList()) { - causeListCause.getRiskItemList().add(riskItem); - causeListCause = em.merge(causeListCause); - } - for (RiskItemHasRiskCategory riskItemHasRiskCategoryListRiskItemHasRiskCategory : riskItem.getRiskItemHasRiskCategoryList()) { - RiskItem oldRiskItemOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory = riskItemHasRiskCategoryListRiskItemHasRiskCategory.getRiskItem(); - riskItemHasRiskCategoryListRiskItemHasRiskCategory.setRiskItem(riskItem); - riskItemHasRiskCategoryListRiskItemHasRiskCategory = em.merge(riskItemHasRiskCategoryListRiskItemHasRiskCategory); - if (oldRiskItemOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory != null) { - oldRiskItemOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory.getRiskItemHasRiskCategoryList().remove(riskItemHasRiskCategoryListRiskItemHasRiskCategory); - oldRiskItemOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory = em.merge(oldRiskItemOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - if (findRiskItem(riskItem.getRiskItemPK()) != null) { - throw new PreexistingEntityException("RiskItem " + riskItem + " already exists.", ex); - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(RiskItem riskItem) throws IllegalOrphanException, NonexistentEntityException, Exception { - riskItem.getRiskItemPK().setFMEAid(riskItem.getFmea().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RiskItem persistentRiskItem = em.find(RiskItem.class, riskItem.getRiskItemPK()); - Fmea fmeaOld = persistentRiskItem.getFmea(); - Fmea fmeaNew = riskItem.getFmea(); - List failureModeListOld = persistentRiskItem.getFailureModeList(); - List failureModeListNew = riskItem.getFailureModeList(); - List hazardListOld = persistentRiskItem.getHazardList(); - List hazardListNew = riskItem.getHazardList(); - List riskControlListOld = persistentRiskItem.getRiskControlList(); - List riskControlListNew = riskItem.getRiskControlList(); - List riskControlList1Old = persistentRiskItem.getRiskControlList1(); - List riskControlList1New = riskItem.getRiskControlList1(); - List causeListOld = persistentRiskItem.getCauseList(); - List causeListNew = riskItem.getCauseList(); - List riskItemHasRiskCategoryListOld = persistentRiskItem.getRiskItemHasRiskCategoryList(); - List riskItemHasRiskCategoryListNew = riskItem.getRiskItemHasRiskCategoryList(); - List illegalOrphanMessages = null; - for (RiskItemHasRiskCategory riskItemHasRiskCategoryListOldRiskItemHasRiskCategory : riskItemHasRiskCategoryListOld) { - if (!riskItemHasRiskCategoryListNew.contains(riskItemHasRiskCategoryListOldRiskItemHasRiskCategory)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain RiskItemHasRiskCategory " + riskItemHasRiskCategoryListOldRiskItemHasRiskCategory + " since its riskItem field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (fmeaNew != null) { - fmeaNew = em.getReference(fmeaNew.getClass(), fmeaNew.getId()); - riskItem.setFmea(fmeaNew); - } - List attachedFailureModeListNew = new ArrayList(); - for (FailureMode failureModeListNewFailureModeToAttach : failureModeListNew) { - failureModeListNewFailureModeToAttach = em.getReference(failureModeListNewFailureModeToAttach.getClass(), failureModeListNewFailureModeToAttach.getId()); - attachedFailureModeListNew.add(failureModeListNewFailureModeToAttach); - } - failureModeListNew = attachedFailureModeListNew; - riskItem.setFailureModeList(failureModeListNew); - List attachedHazardListNew = new ArrayList(); - for (Hazard hazardListNewHazardToAttach : hazardListNew) { - hazardListNewHazardToAttach = em.getReference(hazardListNewHazardToAttach.getClass(), hazardListNewHazardToAttach.getId()); - attachedHazardListNew.add(hazardListNewHazardToAttach); - } - hazardListNew = attachedHazardListNew; - riskItem.setHazardList(hazardListNew); - List attachedRiskControlListNew = new ArrayList(); - for (RiskControl riskControlListNewRiskControlToAttach : riskControlListNew) { - riskControlListNewRiskControlToAttach = em.getReference(riskControlListNewRiskControlToAttach.getClass(), riskControlListNewRiskControlToAttach.getRiskControlPK()); - attachedRiskControlListNew.add(riskControlListNewRiskControlToAttach); - } - riskControlListNew = attachedRiskControlListNew; - riskItem.setRiskControlList(riskControlListNew); - List attachedRiskControlList1New = new ArrayList(); - for (RiskControl riskControlList1NewRiskControlToAttach : riskControlList1New) { - riskControlList1NewRiskControlToAttach = em.getReference(riskControlList1NewRiskControlToAttach.getClass(), riskControlList1NewRiskControlToAttach.getRiskControlPK()); - attachedRiskControlList1New.add(riskControlList1NewRiskControlToAttach); - } - riskControlList1New = attachedRiskControlList1New; - riskItem.setRiskControlList1(riskControlList1New); - List attachedCauseListNew = new ArrayList(); - for (Cause causeListNewCauseToAttach : causeListNew) { - causeListNewCauseToAttach = em.getReference(causeListNewCauseToAttach.getClass(), causeListNewCauseToAttach.getId()); - attachedCauseListNew.add(causeListNewCauseToAttach); - } - causeListNew = attachedCauseListNew; - riskItem.setCauseList(causeListNew); - List attachedRiskItemHasRiskCategoryListNew = new ArrayList(); - for (RiskItemHasRiskCategory riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach : riskItemHasRiskCategoryListNew) { - riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach = em.getReference(riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach.getClass(), riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach.getRiskItemHasRiskCategoryPK()); - attachedRiskItemHasRiskCategoryListNew.add(riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach); - } - riskItemHasRiskCategoryListNew = attachedRiskItemHasRiskCategoryListNew; - riskItem.setRiskItemHasRiskCategoryList(riskItemHasRiskCategoryListNew); - riskItem = em.merge(riskItem); - if (fmeaOld != null && !fmeaOld.equals(fmeaNew)) { - fmeaOld.getRiskItemList().remove(riskItem); - fmeaOld = em.merge(fmeaOld); - } - if (fmeaNew != null && !fmeaNew.equals(fmeaOld)) { - fmeaNew.getRiskItemList().add(riskItem); - fmeaNew = em.merge(fmeaNew); - } - for (FailureMode failureModeListOldFailureMode : failureModeListOld) { - if (!failureModeListNew.contains(failureModeListOldFailureMode)) { - failureModeListOldFailureMode.getRiskItemList().remove(riskItem); - failureModeListOldFailureMode = em.merge(failureModeListOldFailureMode); - } - } - for (FailureMode failureModeListNewFailureMode : failureModeListNew) { - if (!failureModeListOld.contains(failureModeListNewFailureMode)) { - failureModeListNewFailureMode.getRiskItemList().add(riskItem); - failureModeListNewFailureMode = em.merge(failureModeListNewFailureMode); - } - } - for (Hazard hazardListOldHazard : hazardListOld) { - if (!hazardListNew.contains(hazardListOldHazard)) { - hazardListOldHazard.getRiskItemList().remove(riskItem); - hazardListOldHazard = em.merge(hazardListOldHazard); - } - } - for (Hazard hazardListNewHazard : hazardListNew) { - if (!hazardListOld.contains(hazardListNewHazard)) { - hazardListNewHazard.getRiskItemList().add(riskItem); - hazardListNewHazard = em.merge(hazardListNewHazard); - } - } - for (RiskControl riskControlListOldRiskControl : riskControlListOld) { - if (!riskControlListNew.contains(riskControlListOldRiskControl)) { - riskControlListOldRiskControl.getRiskItemList().remove(riskItem); - riskControlListOldRiskControl = em.merge(riskControlListOldRiskControl); - } - } - for (RiskControl riskControlListNewRiskControl : riskControlListNew) { - if (!riskControlListOld.contains(riskControlListNewRiskControl)) { - riskControlListNewRiskControl.getRiskItemList().add(riskItem); - riskControlListNewRiskControl = em.merge(riskControlListNewRiskControl); - } - } - for (RiskControl riskControlList1OldRiskControl : riskControlList1Old) { - if (!riskControlList1New.contains(riskControlList1OldRiskControl)) { - riskControlList1OldRiskControl.getRiskItemList1().remove(riskItem); - riskControlList1OldRiskControl = em.merge(riskControlList1OldRiskControl); - } - } - for (RiskControl riskControlList1NewRiskControl : riskControlList1New) { - if (!riskControlList1Old.contains(riskControlList1NewRiskControl)) { - riskControlList1NewRiskControl.getRiskItemList1().add(riskItem); - riskControlList1NewRiskControl = em.merge(riskControlList1NewRiskControl); - } - } - for (Cause causeListOldCause : causeListOld) { - if (!causeListNew.contains(causeListOldCause)) { - causeListOldCause.getRiskItemList().remove(riskItem); - causeListOldCause = em.merge(causeListOldCause); - } - } - for (Cause causeListNewCause : causeListNew) { - if (!causeListOld.contains(causeListNewCause)) { - causeListNewCause.getRiskItemList().add(riskItem); - causeListNewCause = em.merge(causeListNewCause); - } - } - for (RiskItemHasRiskCategory riskItemHasRiskCategoryListNewRiskItemHasRiskCategory : riskItemHasRiskCategoryListNew) { - if (!riskItemHasRiskCategoryListOld.contains(riskItemHasRiskCategoryListNewRiskItemHasRiskCategory)) { - RiskItem oldRiskItemOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory = riskItemHasRiskCategoryListNewRiskItemHasRiskCategory.getRiskItem(); - riskItemHasRiskCategoryListNewRiskItemHasRiskCategory.setRiskItem(riskItem); - riskItemHasRiskCategoryListNewRiskItemHasRiskCategory = em.merge(riskItemHasRiskCategoryListNewRiskItemHasRiskCategory); - if (oldRiskItemOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory != null && !oldRiskItemOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory.equals(riskItem)) { - oldRiskItemOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory.getRiskItemHasRiskCategoryList().remove(riskItemHasRiskCategoryListNewRiskItemHasRiskCategory); - oldRiskItemOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory = em.merge(oldRiskItemOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - RiskItemPK id = riskItem.getRiskItemPK(); - if (findRiskItem(id) == null) { - throw new NonexistentEntityException("The riskItem with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(RiskItemPK id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RiskItem riskItem; - try { - riskItem = em.getReference(RiskItem.class, id); - riskItem.getRiskItemPK(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The riskItem with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List riskItemHasRiskCategoryListOrphanCheck = riskItem.getRiskItemHasRiskCategoryList(); - for (RiskItemHasRiskCategory riskItemHasRiskCategoryListOrphanCheckRiskItemHasRiskCategory : riskItemHasRiskCategoryListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This RiskItem (" + riskItem + ") cannot be destroyed since the RiskItemHasRiskCategory " + riskItemHasRiskCategoryListOrphanCheckRiskItemHasRiskCategory + " in its riskItemHasRiskCategoryList field has a non-nullable riskItem field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - Fmea fmea = riskItem.getFmea(); - if (fmea != null) { - fmea.getRiskItemList().remove(riskItem); - fmea = em.merge(fmea); - } - List failureModeList = riskItem.getFailureModeList(); - for (FailureMode failureModeListFailureMode : failureModeList) { - failureModeListFailureMode.getRiskItemList().remove(riskItem); - failureModeListFailureMode = em.merge(failureModeListFailureMode); - } - List hazardList = riskItem.getHazardList(); - for (Hazard hazardListHazard : hazardList) { - hazardListHazard.getRiskItemList().remove(riskItem); - hazardListHazard = em.merge(hazardListHazard); - } - List riskControlList = riskItem.getRiskControlList(); - for (RiskControl riskControlListRiskControl : riskControlList) { - riskControlListRiskControl.getRiskItemList().remove(riskItem); - riskControlListRiskControl = em.merge(riskControlListRiskControl); - } - List riskControlList1 = riskItem.getRiskControlList1(); - for (RiskControl riskControlList1RiskControl : riskControlList1) { - riskControlList1RiskControl.getRiskItemList1().remove(riskItem); - riskControlList1RiskControl = em.merge(riskControlList1RiskControl); - } - List causeList = riskItem.getCauseList(); - for (Cause causeListCause : causeList) { - causeListCause.getRiskItemList().remove(riskItem); - causeListCause = em.merge(causeListCause); - } - em.remove(riskItem); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findRiskItemEntities() { - return findRiskItemEntities(true, -1, -1); - } - - public List findRiskItemEntities(int maxResults, int firstResult) { - return findRiskItemEntities(false, maxResults, firstResult); - } - - private List findRiskItemEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(RiskItem.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public RiskItem findRiskItem(RiskItemPK id) { - EntityManager em = getEntityManager(); - try { - return em.find(RiskItem.class, id); - } - finally { - em.close(); - } - } - - public int getRiskItemCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(RiskItem.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Fmea; +import com.validation.manager.core.db.FailureMode; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.Hazard; +import com.validation.manager.core.db.RiskControl; +import com.validation.manager.core.db.Cause; +import com.validation.manager.core.db.RiskItem; +import com.validation.manager.core.db.RiskItemHasRiskCategory; +import com.validation.manager.core.db.RiskItemPK; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RiskItemJpaController implements Serializable { + + public RiskItemJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(RiskItem riskItem) throws PreexistingEntityException, Exception { + if (riskItem.getRiskItemPK() == null) { + riskItem.setRiskItemPK(new RiskItemPK()); + } + if (riskItem.getFailureModeList() == null) { + riskItem.setFailureModeList(new ArrayList<>()); + } + if (riskItem.getHazardList() == null) { + riskItem.setHazardList(new ArrayList<>()); + } + if (riskItem.getRiskControlList() == null) { + riskItem.setRiskControlList(new ArrayList<>()); + } + if (riskItem.getRiskControlList1() == null) { + riskItem.setRiskControlList1(new ArrayList<>()); + } + if (riskItem.getCauseList() == null) { + riskItem.setCauseList(new ArrayList<>()); + } + if (riskItem.getRiskItemHasRiskCategoryList() == null) { + riskItem.setRiskItemHasRiskCategoryList(new ArrayList<>()); + } + riskItem.getRiskItemPK().setFMEAid(riskItem.getFmea().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Fmea fmea = riskItem.getFmea(); + if (fmea != null) { + fmea = em.getReference(fmea.getClass(), fmea.getId()); + riskItem.setFmea(fmea); + } + List attachedFailureModeList = new ArrayList<>(); + for (FailureMode failureModeListFailureModeToAttach : riskItem.getFailureModeList()) { + failureModeListFailureModeToAttach = em.getReference(failureModeListFailureModeToAttach.getClass(), failureModeListFailureModeToAttach.getId()); + attachedFailureModeList.add(failureModeListFailureModeToAttach); + } + riskItem.setFailureModeList(attachedFailureModeList); + List attachedHazardList = new ArrayList<>(); + for (Hazard hazardListHazardToAttach : riskItem.getHazardList()) { + hazardListHazardToAttach = em.getReference(hazardListHazardToAttach.getClass(), hazardListHazardToAttach.getId()); + attachedHazardList.add(hazardListHazardToAttach); + } + riskItem.setHazardList(attachedHazardList); + List attachedRiskControlList = new ArrayList<>(); + for (RiskControl riskControlListRiskControlToAttach : riskItem.getRiskControlList()) { + riskControlListRiskControlToAttach = em.getReference(riskControlListRiskControlToAttach.getClass(), riskControlListRiskControlToAttach.getRiskControlPK()); + attachedRiskControlList.add(riskControlListRiskControlToAttach); + } + riskItem.setRiskControlList(attachedRiskControlList); + List attachedRiskControlList1 = new ArrayList<>(); + for (RiskControl riskControlList1RiskControlToAttach : riskItem.getRiskControlList1()) { + riskControlList1RiskControlToAttach = em.getReference(riskControlList1RiskControlToAttach.getClass(), riskControlList1RiskControlToAttach.getRiskControlPK()); + attachedRiskControlList1.add(riskControlList1RiskControlToAttach); + } + riskItem.setRiskControlList1(attachedRiskControlList1); + List attachedCauseList = new ArrayList<>(); + for (Cause causeListCauseToAttach : riskItem.getCauseList()) { + causeListCauseToAttach = em.getReference(causeListCauseToAttach.getClass(), causeListCauseToAttach.getId()); + attachedCauseList.add(causeListCauseToAttach); + } + riskItem.setCauseList(attachedCauseList); + List attachedRiskItemHasRiskCategoryList = new ArrayList<>(); + for (RiskItemHasRiskCategory riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach : riskItem.getRiskItemHasRiskCategoryList()) { + riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach = em.getReference(riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach.getClass(), riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach.getRiskItemHasRiskCategoryPK()); + attachedRiskItemHasRiskCategoryList.add(riskItemHasRiskCategoryListRiskItemHasRiskCategoryToAttach); + } + riskItem.setRiskItemHasRiskCategoryList(attachedRiskItemHasRiskCategoryList); + em.persist(riskItem); + if (fmea != null) { + fmea.getRiskItemList().add(riskItem); + fmea = em.merge(fmea); + } + for (FailureMode failureModeListFailureMode : riskItem.getFailureModeList()) { + failureModeListFailureMode.getRiskItemList().add(riskItem); + failureModeListFailureMode = em.merge(failureModeListFailureMode); + } + for (Hazard hazardListHazard : riskItem.getHazardList()) { + hazardListHazard.getRiskItemList().add(riskItem); + hazardListHazard = em.merge(hazardListHazard); + } + for (RiskControl riskControlListRiskControl : riskItem.getRiskControlList()) { + riskControlListRiskControl.getRiskItemList().add(riskItem); + riskControlListRiskControl = em.merge(riskControlListRiskControl); + } + for (RiskControl riskControlList1RiskControl : riskItem.getRiskControlList1()) { + riskControlList1RiskControl.getRiskItemList1().add(riskItem); + riskControlList1RiskControl = em.merge(riskControlList1RiskControl); + } + for (Cause causeListCause : riskItem.getCauseList()) { + causeListCause.getRiskItemList().add(riskItem); + causeListCause = em.merge(causeListCause); + } + for (RiskItemHasRiskCategory riskItemHasRiskCategoryListRiskItemHasRiskCategory : riskItem.getRiskItemHasRiskCategoryList()) { + RiskItem oldRiskItemOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory = riskItemHasRiskCategoryListRiskItemHasRiskCategory.getRiskItem(); + riskItemHasRiskCategoryListRiskItemHasRiskCategory.setRiskItem(riskItem); + riskItemHasRiskCategoryListRiskItemHasRiskCategory = em.merge(riskItemHasRiskCategoryListRiskItemHasRiskCategory); + if (oldRiskItemOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory != null) { + oldRiskItemOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory.getRiskItemHasRiskCategoryList().remove(riskItemHasRiskCategoryListRiskItemHasRiskCategory); + oldRiskItemOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory = em.merge(oldRiskItemOfRiskItemHasRiskCategoryListRiskItemHasRiskCategory); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + if (findRiskItem(riskItem.getRiskItemPK()) != null) { + throw new PreexistingEntityException("RiskItem " + riskItem + " already exists.", ex); + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(RiskItem riskItem) throws IllegalOrphanException, NonexistentEntityException, Exception { + riskItem.getRiskItemPK().setFMEAid(riskItem.getFmea().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RiskItem persistentRiskItem = em.find(RiskItem.class, riskItem.getRiskItemPK()); + Fmea fmeaOld = persistentRiskItem.getFmea(); + Fmea fmeaNew = riskItem.getFmea(); + List failureModeListOld = persistentRiskItem.getFailureModeList(); + List failureModeListNew = riskItem.getFailureModeList(); + List hazardListOld = persistentRiskItem.getHazardList(); + List hazardListNew = riskItem.getHazardList(); + List riskControlListOld = persistentRiskItem.getRiskControlList(); + List riskControlListNew = riskItem.getRiskControlList(); + List riskControlList1Old = persistentRiskItem.getRiskControlList1(); + List riskControlList1New = riskItem.getRiskControlList1(); + List causeListOld = persistentRiskItem.getCauseList(); + List causeListNew = riskItem.getCauseList(); + List riskItemHasRiskCategoryListOld = persistentRiskItem.getRiskItemHasRiskCategoryList(); + List riskItemHasRiskCategoryListNew = riskItem.getRiskItemHasRiskCategoryList(); + List illegalOrphanMessages = null; + for (RiskItemHasRiskCategory riskItemHasRiskCategoryListOldRiskItemHasRiskCategory : riskItemHasRiskCategoryListOld) { + if (!riskItemHasRiskCategoryListNew.contains(riskItemHasRiskCategoryListOldRiskItemHasRiskCategory)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain RiskItemHasRiskCategory " + riskItemHasRiskCategoryListOldRiskItemHasRiskCategory + " since its riskItem field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (fmeaNew != null) { + fmeaNew = em.getReference(fmeaNew.getClass(), fmeaNew.getId()); + riskItem.setFmea(fmeaNew); + } + List attachedFailureModeListNew = new ArrayList<>(); + for (FailureMode failureModeListNewFailureModeToAttach : failureModeListNew) { + failureModeListNewFailureModeToAttach = em.getReference(failureModeListNewFailureModeToAttach.getClass(), failureModeListNewFailureModeToAttach.getId()); + attachedFailureModeListNew.add(failureModeListNewFailureModeToAttach); + } + failureModeListNew = attachedFailureModeListNew; + riskItem.setFailureModeList(failureModeListNew); + List attachedHazardListNew = new ArrayList<>(); + for (Hazard hazardListNewHazardToAttach : hazardListNew) { + hazardListNewHazardToAttach = em.getReference(hazardListNewHazardToAttach.getClass(), hazardListNewHazardToAttach.getId()); + attachedHazardListNew.add(hazardListNewHazardToAttach); + } + hazardListNew = attachedHazardListNew; + riskItem.setHazardList(hazardListNew); + List attachedRiskControlListNew = new ArrayList<>(); + for (RiskControl riskControlListNewRiskControlToAttach : riskControlListNew) { + riskControlListNewRiskControlToAttach = em.getReference(riskControlListNewRiskControlToAttach.getClass(), riskControlListNewRiskControlToAttach.getRiskControlPK()); + attachedRiskControlListNew.add(riskControlListNewRiskControlToAttach); + } + riskControlListNew = attachedRiskControlListNew; + riskItem.setRiskControlList(riskControlListNew); + List attachedRiskControlList1New = new ArrayList<>(); + for (RiskControl riskControlList1NewRiskControlToAttach : riskControlList1New) { + riskControlList1NewRiskControlToAttach = em.getReference(riskControlList1NewRiskControlToAttach.getClass(), riskControlList1NewRiskControlToAttach.getRiskControlPK()); + attachedRiskControlList1New.add(riskControlList1NewRiskControlToAttach); + } + riskControlList1New = attachedRiskControlList1New; + riskItem.setRiskControlList1(riskControlList1New); + List attachedCauseListNew = new ArrayList<>(); + for (Cause causeListNewCauseToAttach : causeListNew) { + causeListNewCauseToAttach = em.getReference(causeListNewCauseToAttach.getClass(), causeListNewCauseToAttach.getId()); + attachedCauseListNew.add(causeListNewCauseToAttach); + } + causeListNew = attachedCauseListNew; + riskItem.setCauseList(causeListNew); + List attachedRiskItemHasRiskCategoryListNew = new ArrayList<>(); + for (RiskItemHasRiskCategory riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach : riskItemHasRiskCategoryListNew) { + riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach = em.getReference(riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach.getClass(), riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach.getRiskItemHasRiskCategoryPK()); + attachedRiskItemHasRiskCategoryListNew.add(riskItemHasRiskCategoryListNewRiskItemHasRiskCategoryToAttach); + } + riskItemHasRiskCategoryListNew = attachedRiskItemHasRiskCategoryListNew; + riskItem.setRiskItemHasRiskCategoryList(riskItemHasRiskCategoryListNew); + riskItem = em.merge(riskItem); + if (fmeaOld != null && !fmeaOld.equals(fmeaNew)) { + fmeaOld.getRiskItemList().remove(riskItem); + fmeaOld = em.merge(fmeaOld); + } + if (fmeaNew != null && !fmeaNew.equals(fmeaOld)) { + fmeaNew.getRiskItemList().add(riskItem); + fmeaNew = em.merge(fmeaNew); + } + for (FailureMode failureModeListOldFailureMode : failureModeListOld) { + if (!failureModeListNew.contains(failureModeListOldFailureMode)) { + failureModeListOldFailureMode.getRiskItemList().remove(riskItem); + failureModeListOldFailureMode = em.merge(failureModeListOldFailureMode); + } + } + for (FailureMode failureModeListNewFailureMode : failureModeListNew) { + if (!failureModeListOld.contains(failureModeListNewFailureMode)) { + failureModeListNewFailureMode.getRiskItemList().add(riskItem); + failureModeListNewFailureMode = em.merge(failureModeListNewFailureMode); + } + } + for (Hazard hazardListOldHazard : hazardListOld) { + if (!hazardListNew.contains(hazardListOldHazard)) { + hazardListOldHazard.getRiskItemList().remove(riskItem); + hazardListOldHazard = em.merge(hazardListOldHazard); + } + } + for (Hazard hazardListNewHazard : hazardListNew) { + if (!hazardListOld.contains(hazardListNewHazard)) { + hazardListNewHazard.getRiskItemList().add(riskItem); + hazardListNewHazard = em.merge(hazardListNewHazard); + } + } + for (RiskControl riskControlListOldRiskControl : riskControlListOld) { + if (!riskControlListNew.contains(riskControlListOldRiskControl)) { + riskControlListOldRiskControl.getRiskItemList().remove(riskItem); + riskControlListOldRiskControl = em.merge(riskControlListOldRiskControl); + } + } + for (RiskControl riskControlListNewRiskControl : riskControlListNew) { + if (!riskControlListOld.contains(riskControlListNewRiskControl)) { + riskControlListNewRiskControl.getRiskItemList().add(riskItem); + riskControlListNewRiskControl = em.merge(riskControlListNewRiskControl); + } + } + for (RiskControl riskControlList1OldRiskControl : riskControlList1Old) { + if (!riskControlList1New.contains(riskControlList1OldRiskControl)) { + riskControlList1OldRiskControl.getRiskItemList1().remove(riskItem); + riskControlList1OldRiskControl = em.merge(riskControlList1OldRiskControl); + } + } + for (RiskControl riskControlList1NewRiskControl : riskControlList1New) { + if (!riskControlList1Old.contains(riskControlList1NewRiskControl)) { + riskControlList1NewRiskControl.getRiskItemList1().add(riskItem); + riskControlList1NewRiskControl = em.merge(riskControlList1NewRiskControl); + } + } + for (Cause causeListOldCause : causeListOld) { + if (!causeListNew.contains(causeListOldCause)) { + causeListOldCause.getRiskItemList().remove(riskItem); + causeListOldCause = em.merge(causeListOldCause); + } + } + for (Cause causeListNewCause : causeListNew) { + if (!causeListOld.contains(causeListNewCause)) { + causeListNewCause.getRiskItemList().add(riskItem); + causeListNewCause = em.merge(causeListNewCause); + } + } + for (RiskItemHasRiskCategory riskItemHasRiskCategoryListNewRiskItemHasRiskCategory : riskItemHasRiskCategoryListNew) { + if (!riskItemHasRiskCategoryListOld.contains(riskItemHasRiskCategoryListNewRiskItemHasRiskCategory)) { + RiskItem oldRiskItemOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory = riskItemHasRiskCategoryListNewRiskItemHasRiskCategory.getRiskItem(); + riskItemHasRiskCategoryListNewRiskItemHasRiskCategory.setRiskItem(riskItem); + riskItemHasRiskCategoryListNewRiskItemHasRiskCategory = em.merge(riskItemHasRiskCategoryListNewRiskItemHasRiskCategory); + if (oldRiskItemOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory != null && !oldRiskItemOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory.equals(riskItem)) { + oldRiskItemOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory.getRiskItemHasRiskCategoryList().remove(riskItemHasRiskCategoryListNewRiskItemHasRiskCategory); + oldRiskItemOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory = em.merge(oldRiskItemOfRiskItemHasRiskCategoryListNewRiskItemHasRiskCategory); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + RiskItemPK id = riskItem.getRiskItemPK(); + if (findRiskItem(id) == null) { + throw new NonexistentEntityException("The riskItem with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(RiskItemPK id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RiskItem riskItem; + try { + riskItem = em.getReference(RiskItem.class, id); + riskItem.getRiskItemPK(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The riskItem with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List riskItemHasRiskCategoryListOrphanCheck = riskItem.getRiskItemHasRiskCategoryList(); + for (RiskItemHasRiskCategory riskItemHasRiskCategoryListOrphanCheckRiskItemHasRiskCategory : riskItemHasRiskCategoryListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This RiskItem (" + riskItem + ") cannot be destroyed since the RiskItemHasRiskCategory " + riskItemHasRiskCategoryListOrphanCheckRiskItemHasRiskCategory + " in its riskItemHasRiskCategoryList field has a non-nullable riskItem field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + Fmea fmea = riskItem.getFmea(); + if (fmea != null) { + fmea.getRiskItemList().remove(riskItem); + fmea = em.merge(fmea); + } + List failureModeList = riskItem.getFailureModeList(); + for (FailureMode failureModeListFailureMode : failureModeList) { + failureModeListFailureMode.getRiskItemList().remove(riskItem); + failureModeListFailureMode = em.merge(failureModeListFailureMode); + } + List hazardList = riskItem.getHazardList(); + for (Hazard hazardListHazard : hazardList) { + hazardListHazard.getRiskItemList().remove(riskItem); + hazardListHazard = em.merge(hazardListHazard); + } + List riskControlList = riskItem.getRiskControlList(); + for (RiskControl riskControlListRiskControl : riskControlList) { + riskControlListRiskControl.getRiskItemList().remove(riskItem); + riskControlListRiskControl = em.merge(riskControlListRiskControl); + } + List riskControlList1 = riskItem.getRiskControlList1(); + for (RiskControl riskControlList1RiskControl : riskControlList1) { + riskControlList1RiskControl.getRiskItemList1().remove(riskItem); + riskControlList1RiskControl = em.merge(riskControlList1RiskControl); + } + List causeList = riskItem.getCauseList(); + for (Cause causeListCause : causeList) { + causeListCause.getRiskItemList().remove(riskItem); + causeListCause = em.merge(causeListCause); + } + em.remove(riskItem); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findRiskItemEntities() { + return findRiskItemEntities(true, -1, -1); + } + + public List findRiskItemEntities(int maxResults, int firstResult) { + return findRiskItemEntities(false, maxResults, firstResult); + } + + private List findRiskItemEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(RiskItem.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public RiskItem findRiskItem(RiskItemPK id) { + EntityManager em = getEntityManager(); + try { + return em.find(RiskItem.class, id); + } + finally { + em.close(); + } + } + + public int getRiskItemCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(RiskItem.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RoleJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RoleJpaController.java index 28bb8041..98469f13 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RoleJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RoleJpaController.java @@ -13,397 +13,397 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.VmUser; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.UserRight; -import com.validation.manager.core.db.UserTestProjectRole; -import com.validation.manager.core.db.UserTestPlanRole; -import com.validation.manager.core.db.ExecutionStepHasVmUser; -import com.validation.manager.core.db.Role; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RoleJpaController implements Serializable { - - public RoleJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Role role) { - if (role.getVmUserList() == null) { - role.setVmUserList(new ArrayList()); - } - if (role.getUserRightList() == null) { - role.setUserRightList(new ArrayList()); - } - if (role.getUserTestProjectRoleList() == null) { - role.setUserTestProjectRoleList(new ArrayList()); - } - if (role.getUserTestPlanRoleList() == null) { - role.setUserTestPlanRoleList(new ArrayList()); - } - if (role.getExecutionStepHasVmUserList() == null) { - role.setExecutionStepHasVmUserList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedVmUserList = new ArrayList(); - for (VmUser vmUserListVmUserToAttach : role.getVmUserList()) { - vmUserListVmUserToAttach = em.getReference(vmUserListVmUserToAttach.getClass(), vmUserListVmUserToAttach.getId()); - attachedVmUserList.add(vmUserListVmUserToAttach); - } - role.setVmUserList(attachedVmUserList); - List attachedUserRightList = new ArrayList(); - for (UserRight userRightListUserRightToAttach : role.getUserRightList()) { - userRightListUserRightToAttach = em.getReference(userRightListUserRightToAttach.getClass(), userRightListUserRightToAttach.getId()); - attachedUserRightList.add(userRightListUserRightToAttach); - } - role.setUserRightList(attachedUserRightList); - List attachedUserTestProjectRoleList = new ArrayList(); - for (UserTestProjectRole userTestProjectRoleListUserTestProjectRoleToAttach : role.getUserTestProjectRoleList()) { - userTestProjectRoleListUserTestProjectRoleToAttach = em.getReference(userTestProjectRoleListUserTestProjectRoleToAttach.getClass(), userTestProjectRoleListUserTestProjectRoleToAttach.getUserTestProjectRolePK()); - attachedUserTestProjectRoleList.add(userTestProjectRoleListUserTestProjectRoleToAttach); - } - role.setUserTestProjectRoleList(attachedUserTestProjectRoleList); - List attachedUserTestPlanRoleList = new ArrayList(); - for (UserTestPlanRole userTestPlanRoleListUserTestPlanRoleToAttach : role.getUserTestPlanRoleList()) { - userTestPlanRoleListUserTestPlanRoleToAttach = em.getReference(userTestPlanRoleListUserTestPlanRoleToAttach.getClass(), userTestPlanRoleListUserTestPlanRoleToAttach.getUserTestPlanRolePK()); - attachedUserTestPlanRoleList.add(userTestPlanRoleListUserTestPlanRoleToAttach); - } - role.setUserTestPlanRoleList(attachedUserTestPlanRoleList); - List attachedExecutionStepHasVmUserList = new ArrayList(); - for (ExecutionStepHasVmUser executionStepHasVmUserListExecutionStepHasVmUserToAttach : role.getExecutionStepHasVmUserList()) { - executionStepHasVmUserListExecutionStepHasVmUserToAttach = em.getReference(executionStepHasVmUserListExecutionStepHasVmUserToAttach.getClass(), executionStepHasVmUserListExecutionStepHasVmUserToAttach.getExecutionStepHasVmUserPK()); - attachedExecutionStepHasVmUserList.add(executionStepHasVmUserListExecutionStepHasVmUserToAttach); - } - role.setExecutionStepHasVmUserList(attachedExecutionStepHasVmUserList); - em.persist(role); - for (VmUser vmUserListVmUser : role.getVmUserList()) { - vmUserListVmUser.getRoleList().add(role); - vmUserListVmUser = em.merge(vmUserListVmUser); - } - for (UserRight userRightListUserRight : role.getUserRightList()) { - userRightListUserRight.getRoleList().add(role); - userRightListUserRight = em.merge(userRightListUserRight); - } - for (UserTestProjectRole userTestProjectRoleListUserTestProjectRole : role.getUserTestProjectRoleList()) { - Role oldRoleOfUserTestProjectRoleListUserTestProjectRole = userTestProjectRoleListUserTestProjectRole.getRole(); - userTestProjectRoleListUserTestProjectRole.setRole(role); - userTestProjectRoleListUserTestProjectRole = em.merge(userTestProjectRoleListUserTestProjectRole); - if (oldRoleOfUserTestProjectRoleListUserTestProjectRole != null) { - oldRoleOfUserTestProjectRoleListUserTestProjectRole.getUserTestProjectRoleList().remove(userTestProjectRoleListUserTestProjectRole); - oldRoleOfUserTestProjectRoleListUserTestProjectRole = em.merge(oldRoleOfUserTestProjectRoleListUserTestProjectRole); - } - } - for (UserTestPlanRole userTestPlanRoleListUserTestPlanRole : role.getUserTestPlanRoleList()) { - Role oldRoleOfUserTestPlanRoleListUserTestPlanRole = userTestPlanRoleListUserTestPlanRole.getRole(); - userTestPlanRoleListUserTestPlanRole.setRole(role); - userTestPlanRoleListUserTestPlanRole = em.merge(userTestPlanRoleListUserTestPlanRole); - if (oldRoleOfUserTestPlanRoleListUserTestPlanRole != null) { - oldRoleOfUserTestPlanRoleListUserTestPlanRole.getUserTestPlanRoleList().remove(userTestPlanRoleListUserTestPlanRole); - oldRoleOfUserTestPlanRoleListUserTestPlanRole = em.merge(oldRoleOfUserTestPlanRoleListUserTestPlanRole); - } - } - for (ExecutionStepHasVmUser executionStepHasVmUserListExecutionStepHasVmUser : role.getExecutionStepHasVmUserList()) { - Role oldRoleOfExecutionStepHasVmUserListExecutionStepHasVmUser = executionStepHasVmUserListExecutionStepHasVmUser.getRole(); - executionStepHasVmUserListExecutionStepHasVmUser.setRole(role); - executionStepHasVmUserListExecutionStepHasVmUser = em.merge(executionStepHasVmUserListExecutionStepHasVmUser); - if (oldRoleOfExecutionStepHasVmUserListExecutionStepHasVmUser != null) { - oldRoleOfExecutionStepHasVmUserListExecutionStepHasVmUser.getExecutionStepHasVmUserList().remove(executionStepHasVmUserListExecutionStepHasVmUser); - oldRoleOfExecutionStepHasVmUserListExecutionStepHasVmUser = em.merge(oldRoleOfExecutionStepHasVmUserListExecutionStepHasVmUser); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Role role) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Role persistentRole = em.find(Role.class, role.getId()); - List vmUserListOld = persistentRole.getVmUserList(); - List vmUserListNew = role.getVmUserList(); - List userRightListOld = persistentRole.getUserRightList(); - List userRightListNew = role.getUserRightList(); - List userTestProjectRoleListOld = persistentRole.getUserTestProjectRoleList(); - List userTestProjectRoleListNew = role.getUserTestProjectRoleList(); - List userTestPlanRoleListOld = persistentRole.getUserTestPlanRoleList(); - List userTestPlanRoleListNew = role.getUserTestPlanRoleList(); - List executionStepHasVmUserListOld = persistentRole.getExecutionStepHasVmUserList(); - List executionStepHasVmUserListNew = role.getExecutionStepHasVmUserList(); - List illegalOrphanMessages = null; - for (UserTestProjectRole userTestProjectRoleListOldUserTestProjectRole : userTestProjectRoleListOld) { - if (!userTestProjectRoleListNew.contains(userTestProjectRoleListOldUserTestProjectRole)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserTestProjectRole " + userTestProjectRoleListOldUserTestProjectRole + " since its role field is not nullable."); - } - } - for (UserTestPlanRole userTestPlanRoleListOldUserTestPlanRole : userTestPlanRoleListOld) { - if (!userTestPlanRoleListNew.contains(userTestPlanRoleListOldUserTestPlanRole)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserTestPlanRole " + userTestPlanRoleListOldUserTestPlanRole + " since its role field is not nullable."); - } - } - for (ExecutionStepHasVmUser executionStepHasVmUserListOldExecutionStepHasVmUser : executionStepHasVmUserListOld) { - if (!executionStepHasVmUserListNew.contains(executionStepHasVmUserListOldExecutionStepHasVmUser)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain ExecutionStepHasVmUser " + executionStepHasVmUserListOldExecutionStepHasVmUser + " since its role field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedVmUserListNew = new ArrayList(); - for (VmUser vmUserListNewVmUserToAttach : vmUserListNew) { - vmUserListNewVmUserToAttach = em.getReference(vmUserListNewVmUserToAttach.getClass(), vmUserListNewVmUserToAttach.getId()); - attachedVmUserListNew.add(vmUserListNewVmUserToAttach); - } - vmUserListNew = attachedVmUserListNew; - role.setVmUserList(vmUserListNew); - List attachedUserRightListNew = new ArrayList(); - for (UserRight userRightListNewUserRightToAttach : userRightListNew) { - userRightListNewUserRightToAttach = em.getReference(userRightListNewUserRightToAttach.getClass(), userRightListNewUserRightToAttach.getId()); - attachedUserRightListNew.add(userRightListNewUserRightToAttach); - } - userRightListNew = attachedUserRightListNew; - role.setUserRightList(userRightListNew); - List attachedUserTestProjectRoleListNew = new ArrayList(); - for (UserTestProjectRole userTestProjectRoleListNewUserTestProjectRoleToAttach : userTestProjectRoleListNew) { - userTestProjectRoleListNewUserTestProjectRoleToAttach = em.getReference(userTestProjectRoleListNewUserTestProjectRoleToAttach.getClass(), userTestProjectRoleListNewUserTestProjectRoleToAttach.getUserTestProjectRolePK()); - attachedUserTestProjectRoleListNew.add(userTestProjectRoleListNewUserTestProjectRoleToAttach); - } - userTestProjectRoleListNew = attachedUserTestProjectRoleListNew; - role.setUserTestProjectRoleList(userTestProjectRoleListNew); - List attachedUserTestPlanRoleListNew = new ArrayList(); - for (UserTestPlanRole userTestPlanRoleListNewUserTestPlanRoleToAttach : userTestPlanRoleListNew) { - userTestPlanRoleListNewUserTestPlanRoleToAttach = em.getReference(userTestPlanRoleListNewUserTestPlanRoleToAttach.getClass(), userTestPlanRoleListNewUserTestPlanRoleToAttach.getUserTestPlanRolePK()); - attachedUserTestPlanRoleListNew.add(userTestPlanRoleListNewUserTestPlanRoleToAttach); - } - userTestPlanRoleListNew = attachedUserTestPlanRoleListNew; - role.setUserTestPlanRoleList(userTestPlanRoleListNew); - List attachedExecutionStepHasVmUserListNew = new ArrayList(); - for (ExecutionStepHasVmUser executionStepHasVmUserListNewExecutionStepHasVmUserToAttach : executionStepHasVmUserListNew) { - executionStepHasVmUserListNewExecutionStepHasVmUserToAttach = em.getReference(executionStepHasVmUserListNewExecutionStepHasVmUserToAttach.getClass(), executionStepHasVmUserListNewExecutionStepHasVmUserToAttach.getExecutionStepHasVmUserPK()); - attachedExecutionStepHasVmUserListNew.add(executionStepHasVmUserListNewExecutionStepHasVmUserToAttach); - } - executionStepHasVmUserListNew = attachedExecutionStepHasVmUserListNew; - role.setExecutionStepHasVmUserList(executionStepHasVmUserListNew); - role = em.merge(role); - for (VmUser vmUserListOldVmUser : vmUserListOld) { - if (!vmUserListNew.contains(vmUserListOldVmUser)) { - vmUserListOldVmUser.getRoleList().remove(role); - vmUserListOldVmUser = em.merge(vmUserListOldVmUser); - } - } - for (VmUser vmUserListNewVmUser : vmUserListNew) { - if (!vmUserListOld.contains(vmUserListNewVmUser)) { - vmUserListNewVmUser.getRoleList().add(role); - vmUserListNewVmUser = em.merge(vmUserListNewVmUser); - } - } - for (UserRight userRightListOldUserRight : userRightListOld) { - if (!userRightListNew.contains(userRightListOldUserRight)) { - userRightListOldUserRight.getRoleList().remove(role); - userRightListOldUserRight = em.merge(userRightListOldUserRight); - } - } - for (UserRight userRightListNewUserRight : userRightListNew) { - if (!userRightListOld.contains(userRightListNewUserRight)) { - userRightListNewUserRight.getRoleList().add(role); - userRightListNewUserRight = em.merge(userRightListNewUserRight); - } - } - for (UserTestProjectRole userTestProjectRoleListNewUserTestProjectRole : userTestProjectRoleListNew) { - if (!userTestProjectRoleListOld.contains(userTestProjectRoleListNewUserTestProjectRole)) { - Role oldRoleOfUserTestProjectRoleListNewUserTestProjectRole = userTestProjectRoleListNewUserTestProjectRole.getRole(); - userTestProjectRoleListNewUserTestProjectRole.setRole(role); - userTestProjectRoleListNewUserTestProjectRole = em.merge(userTestProjectRoleListNewUserTestProjectRole); - if (oldRoleOfUserTestProjectRoleListNewUserTestProjectRole != null && !oldRoleOfUserTestProjectRoleListNewUserTestProjectRole.equals(role)) { - oldRoleOfUserTestProjectRoleListNewUserTestProjectRole.getUserTestProjectRoleList().remove(userTestProjectRoleListNewUserTestProjectRole); - oldRoleOfUserTestProjectRoleListNewUserTestProjectRole = em.merge(oldRoleOfUserTestProjectRoleListNewUserTestProjectRole); - } - } - } - for (UserTestPlanRole userTestPlanRoleListNewUserTestPlanRole : userTestPlanRoleListNew) { - if (!userTestPlanRoleListOld.contains(userTestPlanRoleListNewUserTestPlanRole)) { - Role oldRoleOfUserTestPlanRoleListNewUserTestPlanRole = userTestPlanRoleListNewUserTestPlanRole.getRole(); - userTestPlanRoleListNewUserTestPlanRole.setRole(role); - userTestPlanRoleListNewUserTestPlanRole = em.merge(userTestPlanRoleListNewUserTestPlanRole); - if (oldRoleOfUserTestPlanRoleListNewUserTestPlanRole != null && !oldRoleOfUserTestPlanRoleListNewUserTestPlanRole.equals(role)) { - oldRoleOfUserTestPlanRoleListNewUserTestPlanRole.getUserTestPlanRoleList().remove(userTestPlanRoleListNewUserTestPlanRole); - oldRoleOfUserTestPlanRoleListNewUserTestPlanRole = em.merge(oldRoleOfUserTestPlanRoleListNewUserTestPlanRole); - } - } - } - for (ExecutionStepHasVmUser executionStepHasVmUserListNewExecutionStepHasVmUser : executionStepHasVmUserListNew) { - if (!executionStepHasVmUserListOld.contains(executionStepHasVmUserListNewExecutionStepHasVmUser)) { - Role oldRoleOfExecutionStepHasVmUserListNewExecutionStepHasVmUser = executionStepHasVmUserListNewExecutionStepHasVmUser.getRole(); - executionStepHasVmUserListNewExecutionStepHasVmUser.setRole(role); - executionStepHasVmUserListNewExecutionStepHasVmUser = em.merge(executionStepHasVmUserListNewExecutionStepHasVmUser); - if (oldRoleOfExecutionStepHasVmUserListNewExecutionStepHasVmUser != null && !oldRoleOfExecutionStepHasVmUserListNewExecutionStepHasVmUser.equals(role)) { - oldRoleOfExecutionStepHasVmUserListNewExecutionStepHasVmUser.getExecutionStepHasVmUserList().remove(executionStepHasVmUserListNewExecutionStepHasVmUser); - oldRoleOfExecutionStepHasVmUserListNewExecutionStepHasVmUser = em.merge(oldRoleOfExecutionStepHasVmUserListNewExecutionStepHasVmUser); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = role.getId(); - if (findRole(id) == null) { - throw new NonexistentEntityException("The role with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Role role; - try { - role = em.getReference(Role.class, id); - role.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The role with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List userTestProjectRoleListOrphanCheck = role.getUserTestProjectRoleList(); - for (UserTestProjectRole userTestProjectRoleListOrphanCheckUserTestProjectRole : userTestProjectRoleListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Role (" + role + ") cannot be destroyed since the UserTestProjectRole " + userTestProjectRoleListOrphanCheckUserTestProjectRole + " in its userTestProjectRoleList field has a non-nullable role field."); - } - List userTestPlanRoleListOrphanCheck = role.getUserTestPlanRoleList(); - for (UserTestPlanRole userTestPlanRoleListOrphanCheckUserTestPlanRole : userTestPlanRoleListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Role (" + role + ") cannot be destroyed since the UserTestPlanRole " + userTestPlanRoleListOrphanCheckUserTestPlanRole + " in its userTestPlanRoleList field has a non-nullable role field."); - } - List executionStepHasVmUserListOrphanCheck = role.getExecutionStepHasVmUserList(); - for (ExecutionStepHasVmUser executionStepHasVmUserListOrphanCheckExecutionStepHasVmUser : executionStepHasVmUserListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Role (" + role + ") cannot be destroyed since the ExecutionStepHasVmUser " + executionStepHasVmUserListOrphanCheckExecutionStepHasVmUser + " in its executionStepHasVmUserList field has a non-nullable role field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List vmUserList = role.getVmUserList(); - for (VmUser vmUserListVmUser : vmUserList) { - vmUserListVmUser.getRoleList().remove(role); - vmUserListVmUser = em.merge(vmUserListVmUser); - } - List userRightList = role.getUserRightList(); - for (UserRight userRightListUserRight : userRightList) { - userRightListUserRight.getRoleList().remove(role); - userRightListUserRight = em.merge(userRightListUserRight); - } - em.remove(role); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findRoleEntities() { - return findRoleEntities(true, -1, -1); - } - - public List findRoleEntities(int maxResults, int firstResult) { - return findRoleEntities(false, maxResults, firstResult); - } - - private List findRoleEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Role.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public Role findRole(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(Role.class, id); - } - finally { - em.close(); - } - } - - public int getRoleCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(Role.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.VmUser; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.UserRight; +import com.validation.manager.core.db.UserTestProjectRole; +import com.validation.manager.core.db.UserTestPlanRole; +import com.validation.manager.core.db.ExecutionStepHasVmUser; +import com.validation.manager.core.db.Role; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RoleJpaController implements Serializable { + + public RoleJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Role role) { + if (role.getVmUserList() == null) { + role.setVmUserList(new ArrayList<>()); + } + if (role.getUserRightList() == null) { + role.setUserRightList(new ArrayList<>()); + } + if (role.getUserTestProjectRoleList() == null) { + role.setUserTestProjectRoleList(new ArrayList<>()); + } + if (role.getUserTestPlanRoleList() == null) { + role.setUserTestPlanRoleList(new ArrayList<>()); + } + if (role.getExecutionStepHasVmUserList() == null) { + role.setExecutionStepHasVmUserList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedVmUserList = new ArrayList<>(); + for (VmUser vmUserListVmUserToAttach : role.getVmUserList()) { + vmUserListVmUserToAttach = em.getReference(vmUserListVmUserToAttach.getClass(), vmUserListVmUserToAttach.getId()); + attachedVmUserList.add(vmUserListVmUserToAttach); + } + role.setVmUserList(attachedVmUserList); + List attachedUserRightList = new ArrayList<>(); + for (UserRight userRightListUserRightToAttach : role.getUserRightList()) { + userRightListUserRightToAttach = em.getReference(userRightListUserRightToAttach.getClass(), userRightListUserRightToAttach.getId()); + attachedUserRightList.add(userRightListUserRightToAttach); + } + role.setUserRightList(attachedUserRightList); + List attachedUserTestProjectRoleList = new ArrayList<>(); + for (UserTestProjectRole userTestProjectRoleListUserTestProjectRoleToAttach : role.getUserTestProjectRoleList()) { + userTestProjectRoleListUserTestProjectRoleToAttach = em.getReference(userTestProjectRoleListUserTestProjectRoleToAttach.getClass(), userTestProjectRoleListUserTestProjectRoleToAttach.getUserTestProjectRolePK()); + attachedUserTestProjectRoleList.add(userTestProjectRoleListUserTestProjectRoleToAttach); + } + role.setUserTestProjectRoleList(attachedUserTestProjectRoleList); + List attachedUserTestPlanRoleList = new ArrayList<>(); + for (UserTestPlanRole userTestPlanRoleListUserTestPlanRoleToAttach : role.getUserTestPlanRoleList()) { + userTestPlanRoleListUserTestPlanRoleToAttach = em.getReference(userTestPlanRoleListUserTestPlanRoleToAttach.getClass(), userTestPlanRoleListUserTestPlanRoleToAttach.getUserTestPlanRolePK()); + attachedUserTestPlanRoleList.add(userTestPlanRoleListUserTestPlanRoleToAttach); + } + role.setUserTestPlanRoleList(attachedUserTestPlanRoleList); + List attachedExecutionStepHasVmUserList = new ArrayList<>(); + for (ExecutionStepHasVmUser executionStepHasVmUserListExecutionStepHasVmUserToAttach : role.getExecutionStepHasVmUserList()) { + executionStepHasVmUserListExecutionStepHasVmUserToAttach = em.getReference(executionStepHasVmUserListExecutionStepHasVmUserToAttach.getClass(), executionStepHasVmUserListExecutionStepHasVmUserToAttach.getExecutionStepHasVmUserPK()); + attachedExecutionStepHasVmUserList.add(executionStepHasVmUserListExecutionStepHasVmUserToAttach); + } + role.setExecutionStepHasVmUserList(attachedExecutionStepHasVmUserList); + em.persist(role); + for (VmUser vmUserListVmUser : role.getVmUserList()) { + vmUserListVmUser.getRoleList().add(role); + vmUserListVmUser = em.merge(vmUserListVmUser); + } + for (UserRight userRightListUserRight : role.getUserRightList()) { + userRightListUserRight.getRoleList().add(role); + userRightListUserRight = em.merge(userRightListUserRight); + } + for (UserTestProjectRole userTestProjectRoleListUserTestProjectRole : role.getUserTestProjectRoleList()) { + Role oldRoleOfUserTestProjectRoleListUserTestProjectRole = userTestProjectRoleListUserTestProjectRole.getRole(); + userTestProjectRoleListUserTestProjectRole.setRole(role); + userTestProjectRoleListUserTestProjectRole = em.merge(userTestProjectRoleListUserTestProjectRole); + if (oldRoleOfUserTestProjectRoleListUserTestProjectRole != null) { + oldRoleOfUserTestProjectRoleListUserTestProjectRole.getUserTestProjectRoleList().remove(userTestProjectRoleListUserTestProjectRole); + oldRoleOfUserTestProjectRoleListUserTestProjectRole = em.merge(oldRoleOfUserTestProjectRoleListUserTestProjectRole); + } + } + for (UserTestPlanRole userTestPlanRoleListUserTestPlanRole : role.getUserTestPlanRoleList()) { + Role oldRoleOfUserTestPlanRoleListUserTestPlanRole = userTestPlanRoleListUserTestPlanRole.getRole(); + userTestPlanRoleListUserTestPlanRole.setRole(role); + userTestPlanRoleListUserTestPlanRole = em.merge(userTestPlanRoleListUserTestPlanRole); + if (oldRoleOfUserTestPlanRoleListUserTestPlanRole != null) { + oldRoleOfUserTestPlanRoleListUserTestPlanRole.getUserTestPlanRoleList().remove(userTestPlanRoleListUserTestPlanRole); + oldRoleOfUserTestPlanRoleListUserTestPlanRole = em.merge(oldRoleOfUserTestPlanRoleListUserTestPlanRole); + } + } + for (ExecutionStepHasVmUser executionStepHasVmUserListExecutionStepHasVmUser : role.getExecutionStepHasVmUserList()) { + Role oldRoleOfExecutionStepHasVmUserListExecutionStepHasVmUser = executionStepHasVmUserListExecutionStepHasVmUser.getRole(); + executionStepHasVmUserListExecutionStepHasVmUser.setRole(role); + executionStepHasVmUserListExecutionStepHasVmUser = em.merge(executionStepHasVmUserListExecutionStepHasVmUser); + if (oldRoleOfExecutionStepHasVmUserListExecutionStepHasVmUser != null) { + oldRoleOfExecutionStepHasVmUserListExecutionStepHasVmUser.getExecutionStepHasVmUserList().remove(executionStepHasVmUserListExecutionStepHasVmUser); + oldRoleOfExecutionStepHasVmUserListExecutionStepHasVmUser = em.merge(oldRoleOfExecutionStepHasVmUserListExecutionStepHasVmUser); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Role role) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Role persistentRole = em.find(Role.class, role.getId()); + List vmUserListOld = persistentRole.getVmUserList(); + List vmUserListNew = role.getVmUserList(); + List userRightListOld = persistentRole.getUserRightList(); + List userRightListNew = role.getUserRightList(); + List userTestProjectRoleListOld = persistentRole.getUserTestProjectRoleList(); + List userTestProjectRoleListNew = role.getUserTestProjectRoleList(); + List userTestPlanRoleListOld = persistentRole.getUserTestPlanRoleList(); + List userTestPlanRoleListNew = role.getUserTestPlanRoleList(); + List executionStepHasVmUserListOld = persistentRole.getExecutionStepHasVmUserList(); + List executionStepHasVmUserListNew = role.getExecutionStepHasVmUserList(); + List illegalOrphanMessages = null; + for (UserTestProjectRole userTestProjectRoleListOldUserTestProjectRole : userTestProjectRoleListOld) { + if (!userTestProjectRoleListNew.contains(userTestProjectRoleListOldUserTestProjectRole)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserTestProjectRole " + userTestProjectRoleListOldUserTestProjectRole + " since its role field is not nullable."); + } + } + for (UserTestPlanRole userTestPlanRoleListOldUserTestPlanRole : userTestPlanRoleListOld) { + if (!userTestPlanRoleListNew.contains(userTestPlanRoleListOldUserTestPlanRole)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserTestPlanRole " + userTestPlanRoleListOldUserTestPlanRole + " since its role field is not nullable."); + } + } + for (ExecutionStepHasVmUser executionStepHasVmUserListOldExecutionStepHasVmUser : executionStepHasVmUserListOld) { + if (!executionStepHasVmUserListNew.contains(executionStepHasVmUserListOldExecutionStepHasVmUser)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain ExecutionStepHasVmUser " + executionStepHasVmUserListOldExecutionStepHasVmUser + " since its role field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedVmUserListNew = new ArrayList<>(); + for (VmUser vmUserListNewVmUserToAttach : vmUserListNew) { + vmUserListNewVmUserToAttach = em.getReference(vmUserListNewVmUserToAttach.getClass(), vmUserListNewVmUserToAttach.getId()); + attachedVmUserListNew.add(vmUserListNewVmUserToAttach); + } + vmUserListNew = attachedVmUserListNew; + role.setVmUserList(vmUserListNew); + List attachedUserRightListNew = new ArrayList<>(); + for (UserRight userRightListNewUserRightToAttach : userRightListNew) { + userRightListNewUserRightToAttach = em.getReference(userRightListNewUserRightToAttach.getClass(), userRightListNewUserRightToAttach.getId()); + attachedUserRightListNew.add(userRightListNewUserRightToAttach); + } + userRightListNew = attachedUserRightListNew; + role.setUserRightList(userRightListNew); + List attachedUserTestProjectRoleListNew = new ArrayList<>(); + for (UserTestProjectRole userTestProjectRoleListNewUserTestProjectRoleToAttach : userTestProjectRoleListNew) { + userTestProjectRoleListNewUserTestProjectRoleToAttach = em.getReference(userTestProjectRoleListNewUserTestProjectRoleToAttach.getClass(), userTestProjectRoleListNewUserTestProjectRoleToAttach.getUserTestProjectRolePK()); + attachedUserTestProjectRoleListNew.add(userTestProjectRoleListNewUserTestProjectRoleToAttach); + } + userTestProjectRoleListNew = attachedUserTestProjectRoleListNew; + role.setUserTestProjectRoleList(userTestProjectRoleListNew); + List attachedUserTestPlanRoleListNew = new ArrayList<>(); + for (UserTestPlanRole userTestPlanRoleListNewUserTestPlanRoleToAttach : userTestPlanRoleListNew) { + userTestPlanRoleListNewUserTestPlanRoleToAttach = em.getReference(userTestPlanRoleListNewUserTestPlanRoleToAttach.getClass(), userTestPlanRoleListNewUserTestPlanRoleToAttach.getUserTestPlanRolePK()); + attachedUserTestPlanRoleListNew.add(userTestPlanRoleListNewUserTestPlanRoleToAttach); + } + userTestPlanRoleListNew = attachedUserTestPlanRoleListNew; + role.setUserTestPlanRoleList(userTestPlanRoleListNew); + List attachedExecutionStepHasVmUserListNew = new ArrayList<>(); + for (ExecutionStepHasVmUser executionStepHasVmUserListNewExecutionStepHasVmUserToAttach : executionStepHasVmUserListNew) { + executionStepHasVmUserListNewExecutionStepHasVmUserToAttach = em.getReference(executionStepHasVmUserListNewExecutionStepHasVmUserToAttach.getClass(), executionStepHasVmUserListNewExecutionStepHasVmUserToAttach.getExecutionStepHasVmUserPK()); + attachedExecutionStepHasVmUserListNew.add(executionStepHasVmUserListNewExecutionStepHasVmUserToAttach); + } + executionStepHasVmUserListNew = attachedExecutionStepHasVmUserListNew; + role.setExecutionStepHasVmUserList(executionStepHasVmUserListNew); + role = em.merge(role); + for (VmUser vmUserListOldVmUser : vmUserListOld) { + if (!vmUserListNew.contains(vmUserListOldVmUser)) { + vmUserListOldVmUser.getRoleList().remove(role); + vmUserListOldVmUser = em.merge(vmUserListOldVmUser); + } + } + for (VmUser vmUserListNewVmUser : vmUserListNew) { + if (!vmUserListOld.contains(vmUserListNewVmUser)) { + vmUserListNewVmUser.getRoleList().add(role); + vmUserListNewVmUser = em.merge(vmUserListNewVmUser); + } + } + for (UserRight userRightListOldUserRight : userRightListOld) { + if (!userRightListNew.contains(userRightListOldUserRight)) { + userRightListOldUserRight.getRoleList().remove(role); + userRightListOldUserRight = em.merge(userRightListOldUserRight); + } + } + for (UserRight userRightListNewUserRight : userRightListNew) { + if (!userRightListOld.contains(userRightListNewUserRight)) { + userRightListNewUserRight.getRoleList().add(role); + userRightListNewUserRight = em.merge(userRightListNewUserRight); + } + } + for (UserTestProjectRole userTestProjectRoleListNewUserTestProjectRole : userTestProjectRoleListNew) { + if (!userTestProjectRoleListOld.contains(userTestProjectRoleListNewUserTestProjectRole)) { + Role oldRoleOfUserTestProjectRoleListNewUserTestProjectRole = userTestProjectRoleListNewUserTestProjectRole.getRole(); + userTestProjectRoleListNewUserTestProjectRole.setRole(role); + userTestProjectRoleListNewUserTestProjectRole = em.merge(userTestProjectRoleListNewUserTestProjectRole); + if (oldRoleOfUserTestProjectRoleListNewUserTestProjectRole != null && !oldRoleOfUserTestProjectRoleListNewUserTestProjectRole.equals(role)) { + oldRoleOfUserTestProjectRoleListNewUserTestProjectRole.getUserTestProjectRoleList().remove(userTestProjectRoleListNewUserTestProjectRole); + oldRoleOfUserTestProjectRoleListNewUserTestProjectRole = em.merge(oldRoleOfUserTestProjectRoleListNewUserTestProjectRole); + } + } + } + for (UserTestPlanRole userTestPlanRoleListNewUserTestPlanRole : userTestPlanRoleListNew) { + if (!userTestPlanRoleListOld.contains(userTestPlanRoleListNewUserTestPlanRole)) { + Role oldRoleOfUserTestPlanRoleListNewUserTestPlanRole = userTestPlanRoleListNewUserTestPlanRole.getRole(); + userTestPlanRoleListNewUserTestPlanRole.setRole(role); + userTestPlanRoleListNewUserTestPlanRole = em.merge(userTestPlanRoleListNewUserTestPlanRole); + if (oldRoleOfUserTestPlanRoleListNewUserTestPlanRole != null && !oldRoleOfUserTestPlanRoleListNewUserTestPlanRole.equals(role)) { + oldRoleOfUserTestPlanRoleListNewUserTestPlanRole.getUserTestPlanRoleList().remove(userTestPlanRoleListNewUserTestPlanRole); + oldRoleOfUserTestPlanRoleListNewUserTestPlanRole = em.merge(oldRoleOfUserTestPlanRoleListNewUserTestPlanRole); + } + } + } + for (ExecutionStepHasVmUser executionStepHasVmUserListNewExecutionStepHasVmUser : executionStepHasVmUserListNew) { + if (!executionStepHasVmUserListOld.contains(executionStepHasVmUserListNewExecutionStepHasVmUser)) { + Role oldRoleOfExecutionStepHasVmUserListNewExecutionStepHasVmUser = executionStepHasVmUserListNewExecutionStepHasVmUser.getRole(); + executionStepHasVmUserListNewExecutionStepHasVmUser.setRole(role); + executionStepHasVmUserListNewExecutionStepHasVmUser = em.merge(executionStepHasVmUserListNewExecutionStepHasVmUser); + if (oldRoleOfExecutionStepHasVmUserListNewExecutionStepHasVmUser != null && !oldRoleOfExecutionStepHasVmUserListNewExecutionStepHasVmUser.equals(role)) { + oldRoleOfExecutionStepHasVmUserListNewExecutionStepHasVmUser.getExecutionStepHasVmUserList().remove(executionStepHasVmUserListNewExecutionStepHasVmUser); + oldRoleOfExecutionStepHasVmUserListNewExecutionStepHasVmUser = em.merge(oldRoleOfExecutionStepHasVmUserListNewExecutionStepHasVmUser); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = role.getId(); + if (findRole(id) == null) { + throw new NonexistentEntityException("The role with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Role role; + try { + role = em.getReference(Role.class, id); + role.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The role with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List userTestProjectRoleListOrphanCheck = role.getUserTestProjectRoleList(); + for (UserTestProjectRole userTestProjectRoleListOrphanCheckUserTestProjectRole : userTestProjectRoleListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Role (" + role + ") cannot be destroyed since the UserTestProjectRole " + userTestProjectRoleListOrphanCheckUserTestProjectRole + " in its userTestProjectRoleList field has a non-nullable role field."); + } + List userTestPlanRoleListOrphanCheck = role.getUserTestPlanRoleList(); + for (UserTestPlanRole userTestPlanRoleListOrphanCheckUserTestPlanRole : userTestPlanRoleListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Role (" + role + ") cannot be destroyed since the UserTestPlanRole " + userTestPlanRoleListOrphanCheckUserTestPlanRole + " in its userTestPlanRoleList field has a non-nullable role field."); + } + List executionStepHasVmUserListOrphanCheck = role.getExecutionStepHasVmUserList(); + for (ExecutionStepHasVmUser executionStepHasVmUserListOrphanCheckExecutionStepHasVmUser : executionStepHasVmUserListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Role (" + role + ") cannot be destroyed since the ExecutionStepHasVmUser " + executionStepHasVmUserListOrphanCheckExecutionStepHasVmUser + " in its executionStepHasVmUserList field has a non-nullable role field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List vmUserList = role.getVmUserList(); + for (VmUser vmUserListVmUser : vmUserList) { + vmUserListVmUser.getRoleList().remove(role); + vmUserListVmUser = em.merge(vmUserListVmUser); + } + List userRightList = role.getUserRightList(); + for (UserRight userRightListUserRight : userRightList) { + userRightListUserRight.getRoleList().remove(role); + userRightListUserRight = em.merge(userRightListUserRight); + } + em.remove(role); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findRoleEntities() { + return findRoleEntities(true, -1, -1); + } + + public List findRoleEntities(int maxResults, int firstResult) { + return findRoleEntities(false, maxResults, firstResult); + } + + private List findRoleEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Role.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public Role findRole(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(Role.class, id); + } + finally { + em.close(); + } + } + + public int getRoleCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Role.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RootCauseJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RootCauseJpaController.java index 08e0e7fb..5f130858 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RootCauseJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RootCauseJpaController.java @@ -13,291 +13,291 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.RootCauseType; -import com.validation.manager.core.db.VmUser; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.ExceptionHasRootCause; -import com.validation.manager.core.db.RootCause; -import com.validation.manager.core.db.RootCausePK; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RootCauseJpaController implements Serializable { - - public RootCauseJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(RootCause rootCause) throws PreexistingEntityException, Exception { - if (rootCause.getRootCausePK() == null) { - rootCause.setRootCausePK(new RootCausePK()); - } - if (rootCause.getVmUserList() == null) { - rootCause.setVmUserList(new ArrayList()); - } - if (rootCause.getExceptionHasRootCauseList() == null) { - rootCause.setExceptionHasRootCauseList(new ArrayList()); - } - rootCause.getRootCausePK().setRootCauseTypeId(rootCause.getRootCauseType().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RootCauseType rootCauseType = rootCause.getRootCauseType(); - if (rootCauseType != null) { - rootCauseType = em.getReference(rootCauseType.getClass(), rootCauseType.getId()); - rootCause.setRootCauseType(rootCauseType); - } - List attachedVmUserList = new ArrayList(); - for (VmUser vmUserListVmUserToAttach : rootCause.getVmUserList()) { - vmUserListVmUserToAttach = em.getReference(vmUserListVmUserToAttach.getClass(), vmUserListVmUserToAttach.getId()); - attachedVmUserList.add(vmUserListVmUserToAttach); - } - rootCause.setVmUserList(attachedVmUserList); - List attachedExceptionHasRootCauseList = new ArrayList(); - for (ExceptionHasRootCause exceptionHasRootCauseListExceptionHasRootCauseToAttach : rootCause.getExceptionHasRootCauseList()) { - exceptionHasRootCauseListExceptionHasRootCauseToAttach = em.getReference(exceptionHasRootCauseListExceptionHasRootCauseToAttach.getClass(), exceptionHasRootCauseListExceptionHasRootCauseToAttach.getExceptionHasRootCausePK()); - attachedExceptionHasRootCauseList.add(exceptionHasRootCauseListExceptionHasRootCauseToAttach); - } - rootCause.setExceptionHasRootCauseList(attachedExceptionHasRootCauseList); - em.persist(rootCause); - if (rootCauseType != null) { - rootCauseType.getRootCauseList().add(rootCause); - rootCauseType = em.merge(rootCauseType); - } - for (VmUser vmUserListVmUser : rootCause.getVmUserList()) { - vmUserListVmUser.getRootCauseList().add(rootCause); - vmUserListVmUser = em.merge(vmUserListVmUser); - } - for (ExceptionHasRootCause exceptionHasRootCauseListExceptionHasRootCause : rootCause.getExceptionHasRootCauseList()) { - RootCause oldRootCauseOfExceptionHasRootCauseListExceptionHasRootCause = exceptionHasRootCauseListExceptionHasRootCause.getRootCause(); - exceptionHasRootCauseListExceptionHasRootCause.setRootCause(rootCause); - exceptionHasRootCauseListExceptionHasRootCause = em.merge(exceptionHasRootCauseListExceptionHasRootCause); - if (oldRootCauseOfExceptionHasRootCauseListExceptionHasRootCause != null) { - oldRootCauseOfExceptionHasRootCauseListExceptionHasRootCause.getExceptionHasRootCauseList().remove(exceptionHasRootCauseListExceptionHasRootCause); - oldRootCauseOfExceptionHasRootCauseListExceptionHasRootCause = em.merge(oldRootCauseOfExceptionHasRootCauseListExceptionHasRootCause); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - if (findRootCause(rootCause.getRootCausePK()) != null) { - throw new PreexistingEntityException("RootCause " + rootCause + " already exists.", ex); - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(RootCause rootCause) throws IllegalOrphanException, NonexistentEntityException, Exception { - rootCause.getRootCausePK().setRootCauseTypeId(rootCause.getRootCauseType().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RootCause persistentRootCause = em.find(RootCause.class, rootCause.getRootCausePK()); - RootCauseType rootCauseTypeOld = persistentRootCause.getRootCauseType(); - RootCauseType rootCauseTypeNew = rootCause.getRootCauseType(); - List vmUserListOld = persistentRootCause.getVmUserList(); - List vmUserListNew = rootCause.getVmUserList(); - List exceptionHasRootCauseListOld = persistentRootCause.getExceptionHasRootCauseList(); - List exceptionHasRootCauseListNew = rootCause.getExceptionHasRootCauseList(); - List illegalOrphanMessages = null; - for (ExceptionHasRootCause exceptionHasRootCauseListOldExceptionHasRootCause : exceptionHasRootCauseListOld) { - if (!exceptionHasRootCauseListNew.contains(exceptionHasRootCauseListOldExceptionHasRootCause)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain ExceptionHasRootCause " + exceptionHasRootCauseListOldExceptionHasRootCause + " since its rootCause field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (rootCauseTypeNew != null) { - rootCauseTypeNew = em.getReference(rootCauseTypeNew.getClass(), rootCauseTypeNew.getId()); - rootCause.setRootCauseType(rootCauseTypeNew); - } - List attachedVmUserListNew = new ArrayList(); - for (VmUser vmUserListNewVmUserToAttach : vmUserListNew) { - vmUserListNewVmUserToAttach = em.getReference(vmUserListNewVmUserToAttach.getClass(), vmUserListNewVmUserToAttach.getId()); - attachedVmUserListNew.add(vmUserListNewVmUserToAttach); - } - vmUserListNew = attachedVmUserListNew; - rootCause.setVmUserList(vmUserListNew); - List attachedExceptionHasRootCauseListNew = new ArrayList(); - for (ExceptionHasRootCause exceptionHasRootCauseListNewExceptionHasRootCauseToAttach : exceptionHasRootCauseListNew) { - exceptionHasRootCauseListNewExceptionHasRootCauseToAttach = em.getReference(exceptionHasRootCauseListNewExceptionHasRootCauseToAttach.getClass(), exceptionHasRootCauseListNewExceptionHasRootCauseToAttach.getExceptionHasRootCausePK()); - attachedExceptionHasRootCauseListNew.add(exceptionHasRootCauseListNewExceptionHasRootCauseToAttach); - } - exceptionHasRootCauseListNew = attachedExceptionHasRootCauseListNew; - rootCause.setExceptionHasRootCauseList(exceptionHasRootCauseListNew); - rootCause = em.merge(rootCause); - if (rootCauseTypeOld != null && !rootCauseTypeOld.equals(rootCauseTypeNew)) { - rootCauseTypeOld.getRootCauseList().remove(rootCause); - rootCauseTypeOld = em.merge(rootCauseTypeOld); - } - if (rootCauseTypeNew != null && !rootCauseTypeNew.equals(rootCauseTypeOld)) { - rootCauseTypeNew.getRootCauseList().add(rootCause); - rootCauseTypeNew = em.merge(rootCauseTypeNew); - } - for (VmUser vmUserListOldVmUser : vmUserListOld) { - if (!vmUserListNew.contains(vmUserListOldVmUser)) { - vmUserListOldVmUser.getRootCauseList().remove(rootCause); - vmUserListOldVmUser = em.merge(vmUserListOldVmUser); - } - } - for (VmUser vmUserListNewVmUser : vmUserListNew) { - if (!vmUserListOld.contains(vmUserListNewVmUser)) { - vmUserListNewVmUser.getRootCauseList().add(rootCause); - vmUserListNewVmUser = em.merge(vmUserListNewVmUser); - } - } - for (ExceptionHasRootCause exceptionHasRootCauseListNewExceptionHasRootCause : exceptionHasRootCauseListNew) { - if (!exceptionHasRootCauseListOld.contains(exceptionHasRootCauseListNewExceptionHasRootCause)) { - RootCause oldRootCauseOfExceptionHasRootCauseListNewExceptionHasRootCause = exceptionHasRootCauseListNewExceptionHasRootCause.getRootCause(); - exceptionHasRootCauseListNewExceptionHasRootCause.setRootCause(rootCause); - exceptionHasRootCauseListNewExceptionHasRootCause = em.merge(exceptionHasRootCauseListNewExceptionHasRootCause); - if (oldRootCauseOfExceptionHasRootCauseListNewExceptionHasRootCause != null && !oldRootCauseOfExceptionHasRootCauseListNewExceptionHasRootCause.equals(rootCause)) { - oldRootCauseOfExceptionHasRootCauseListNewExceptionHasRootCause.getExceptionHasRootCauseList().remove(exceptionHasRootCauseListNewExceptionHasRootCause); - oldRootCauseOfExceptionHasRootCauseListNewExceptionHasRootCause = em.merge(oldRootCauseOfExceptionHasRootCauseListNewExceptionHasRootCause); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - RootCausePK id = rootCause.getRootCausePK(); - if (findRootCause(id) == null) { - throw new NonexistentEntityException("The rootCause with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(RootCausePK id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RootCause rootCause; - try { - rootCause = em.getReference(RootCause.class, id); - rootCause.getRootCausePK(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The rootCause with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List exceptionHasRootCauseListOrphanCheck = rootCause.getExceptionHasRootCauseList(); - for (ExceptionHasRootCause exceptionHasRootCauseListOrphanCheckExceptionHasRootCause : exceptionHasRootCauseListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This RootCause (" + rootCause + ") cannot be destroyed since the ExceptionHasRootCause " + exceptionHasRootCauseListOrphanCheckExceptionHasRootCause + " in its exceptionHasRootCauseList field has a non-nullable rootCause field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - RootCauseType rootCauseType = rootCause.getRootCauseType(); - if (rootCauseType != null) { - rootCauseType.getRootCauseList().remove(rootCause); - rootCauseType = em.merge(rootCauseType); - } - List vmUserList = rootCause.getVmUserList(); - for (VmUser vmUserListVmUser : vmUserList) { - vmUserListVmUser.getRootCauseList().remove(rootCause); - vmUserListVmUser = em.merge(vmUserListVmUser); - } - em.remove(rootCause); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findRootCauseEntities() { - return findRootCauseEntities(true, -1, -1); - } - - public List findRootCauseEntities(int maxResults, int firstResult) { - return findRootCauseEntities(false, maxResults, firstResult); - } - - private List findRootCauseEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(RootCause.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public RootCause findRootCause(RootCausePK id) { - EntityManager em = getEntityManager(); - try { - return em.find(RootCause.class, id); - } - finally { - em.close(); - } - } - - public int getRootCauseCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(RootCause.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.RootCauseType; +import com.validation.manager.core.db.VmUser; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.ExceptionHasRootCause; +import com.validation.manager.core.db.RootCause; +import com.validation.manager.core.db.RootCausePK; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RootCauseJpaController implements Serializable { + + public RootCauseJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(RootCause rootCause) throws PreexistingEntityException, Exception { + if (rootCause.getRootCausePK() == null) { + rootCause.setRootCausePK(new RootCausePK()); + } + if (rootCause.getVmUserList() == null) { + rootCause.setVmUserList(new ArrayList<>()); + } + if (rootCause.getExceptionHasRootCauseList() == null) { + rootCause.setExceptionHasRootCauseList(new ArrayList<>()); + } + rootCause.getRootCausePK().setRootCauseTypeId(rootCause.getRootCauseType().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RootCauseType rootCauseType = rootCause.getRootCauseType(); + if (rootCauseType != null) { + rootCauseType = em.getReference(rootCauseType.getClass(), rootCauseType.getId()); + rootCause.setRootCauseType(rootCauseType); + } + List attachedVmUserList = new ArrayList<>(); + for (VmUser vmUserListVmUserToAttach : rootCause.getVmUserList()) { + vmUserListVmUserToAttach = em.getReference(vmUserListVmUserToAttach.getClass(), vmUserListVmUserToAttach.getId()); + attachedVmUserList.add(vmUserListVmUserToAttach); + } + rootCause.setVmUserList(attachedVmUserList); + List attachedExceptionHasRootCauseList = new ArrayList<>(); + for (ExceptionHasRootCause exceptionHasRootCauseListExceptionHasRootCauseToAttach : rootCause.getExceptionHasRootCauseList()) { + exceptionHasRootCauseListExceptionHasRootCauseToAttach = em.getReference(exceptionHasRootCauseListExceptionHasRootCauseToAttach.getClass(), exceptionHasRootCauseListExceptionHasRootCauseToAttach.getExceptionHasRootCausePK()); + attachedExceptionHasRootCauseList.add(exceptionHasRootCauseListExceptionHasRootCauseToAttach); + } + rootCause.setExceptionHasRootCauseList(attachedExceptionHasRootCauseList); + em.persist(rootCause); + if (rootCauseType != null) { + rootCauseType.getRootCauseList().add(rootCause); + rootCauseType = em.merge(rootCauseType); + } + for (VmUser vmUserListVmUser : rootCause.getVmUserList()) { + vmUserListVmUser.getRootCauseList().add(rootCause); + vmUserListVmUser = em.merge(vmUserListVmUser); + } + for (ExceptionHasRootCause exceptionHasRootCauseListExceptionHasRootCause : rootCause.getExceptionHasRootCauseList()) { + RootCause oldRootCauseOfExceptionHasRootCauseListExceptionHasRootCause = exceptionHasRootCauseListExceptionHasRootCause.getRootCause(); + exceptionHasRootCauseListExceptionHasRootCause.setRootCause(rootCause); + exceptionHasRootCauseListExceptionHasRootCause = em.merge(exceptionHasRootCauseListExceptionHasRootCause); + if (oldRootCauseOfExceptionHasRootCauseListExceptionHasRootCause != null) { + oldRootCauseOfExceptionHasRootCauseListExceptionHasRootCause.getExceptionHasRootCauseList().remove(exceptionHasRootCauseListExceptionHasRootCause); + oldRootCauseOfExceptionHasRootCauseListExceptionHasRootCause = em.merge(oldRootCauseOfExceptionHasRootCauseListExceptionHasRootCause); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + if (findRootCause(rootCause.getRootCausePK()) != null) { + throw new PreexistingEntityException("RootCause " + rootCause + " already exists.", ex); + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(RootCause rootCause) throws IllegalOrphanException, NonexistentEntityException, Exception { + rootCause.getRootCausePK().setRootCauseTypeId(rootCause.getRootCauseType().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RootCause persistentRootCause = em.find(RootCause.class, rootCause.getRootCausePK()); + RootCauseType rootCauseTypeOld = persistentRootCause.getRootCauseType(); + RootCauseType rootCauseTypeNew = rootCause.getRootCauseType(); + List vmUserListOld = persistentRootCause.getVmUserList(); + List vmUserListNew = rootCause.getVmUserList(); + List exceptionHasRootCauseListOld = persistentRootCause.getExceptionHasRootCauseList(); + List exceptionHasRootCauseListNew = rootCause.getExceptionHasRootCauseList(); + List illegalOrphanMessages = null; + for (ExceptionHasRootCause exceptionHasRootCauseListOldExceptionHasRootCause : exceptionHasRootCauseListOld) { + if (!exceptionHasRootCauseListNew.contains(exceptionHasRootCauseListOldExceptionHasRootCause)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain ExceptionHasRootCause " + exceptionHasRootCauseListOldExceptionHasRootCause + " since its rootCause field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (rootCauseTypeNew != null) { + rootCauseTypeNew = em.getReference(rootCauseTypeNew.getClass(), rootCauseTypeNew.getId()); + rootCause.setRootCauseType(rootCauseTypeNew); + } + List attachedVmUserListNew = new ArrayList<>(); + for (VmUser vmUserListNewVmUserToAttach : vmUserListNew) { + vmUserListNewVmUserToAttach = em.getReference(vmUserListNewVmUserToAttach.getClass(), vmUserListNewVmUserToAttach.getId()); + attachedVmUserListNew.add(vmUserListNewVmUserToAttach); + } + vmUserListNew = attachedVmUserListNew; + rootCause.setVmUserList(vmUserListNew); + List attachedExceptionHasRootCauseListNew = new ArrayList<>(); + for (ExceptionHasRootCause exceptionHasRootCauseListNewExceptionHasRootCauseToAttach : exceptionHasRootCauseListNew) { + exceptionHasRootCauseListNewExceptionHasRootCauseToAttach = em.getReference(exceptionHasRootCauseListNewExceptionHasRootCauseToAttach.getClass(), exceptionHasRootCauseListNewExceptionHasRootCauseToAttach.getExceptionHasRootCausePK()); + attachedExceptionHasRootCauseListNew.add(exceptionHasRootCauseListNewExceptionHasRootCauseToAttach); + } + exceptionHasRootCauseListNew = attachedExceptionHasRootCauseListNew; + rootCause.setExceptionHasRootCauseList(exceptionHasRootCauseListNew); + rootCause = em.merge(rootCause); + if (rootCauseTypeOld != null && !rootCauseTypeOld.equals(rootCauseTypeNew)) { + rootCauseTypeOld.getRootCauseList().remove(rootCause); + rootCauseTypeOld = em.merge(rootCauseTypeOld); + } + if (rootCauseTypeNew != null && !rootCauseTypeNew.equals(rootCauseTypeOld)) { + rootCauseTypeNew.getRootCauseList().add(rootCause); + rootCauseTypeNew = em.merge(rootCauseTypeNew); + } + for (VmUser vmUserListOldVmUser : vmUserListOld) { + if (!vmUserListNew.contains(vmUserListOldVmUser)) { + vmUserListOldVmUser.getRootCauseList().remove(rootCause); + vmUserListOldVmUser = em.merge(vmUserListOldVmUser); + } + } + for (VmUser vmUserListNewVmUser : vmUserListNew) { + if (!vmUserListOld.contains(vmUserListNewVmUser)) { + vmUserListNewVmUser.getRootCauseList().add(rootCause); + vmUserListNewVmUser = em.merge(vmUserListNewVmUser); + } + } + for (ExceptionHasRootCause exceptionHasRootCauseListNewExceptionHasRootCause : exceptionHasRootCauseListNew) { + if (!exceptionHasRootCauseListOld.contains(exceptionHasRootCauseListNewExceptionHasRootCause)) { + RootCause oldRootCauseOfExceptionHasRootCauseListNewExceptionHasRootCause = exceptionHasRootCauseListNewExceptionHasRootCause.getRootCause(); + exceptionHasRootCauseListNewExceptionHasRootCause.setRootCause(rootCause); + exceptionHasRootCauseListNewExceptionHasRootCause = em.merge(exceptionHasRootCauseListNewExceptionHasRootCause); + if (oldRootCauseOfExceptionHasRootCauseListNewExceptionHasRootCause != null && !oldRootCauseOfExceptionHasRootCauseListNewExceptionHasRootCause.equals(rootCause)) { + oldRootCauseOfExceptionHasRootCauseListNewExceptionHasRootCause.getExceptionHasRootCauseList().remove(exceptionHasRootCauseListNewExceptionHasRootCause); + oldRootCauseOfExceptionHasRootCauseListNewExceptionHasRootCause = em.merge(oldRootCauseOfExceptionHasRootCauseListNewExceptionHasRootCause); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + RootCausePK id = rootCause.getRootCausePK(); + if (findRootCause(id) == null) { + throw new NonexistentEntityException("The rootCause with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(RootCausePK id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RootCause rootCause; + try { + rootCause = em.getReference(RootCause.class, id); + rootCause.getRootCausePK(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The rootCause with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List exceptionHasRootCauseListOrphanCheck = rootCause.getExceptionHasRootCauseList(); + for (ExceptionHasRootCause exceptionHasRootCauseListOrphanCheckExceptionHasRootCause : exceptionHasRootCauseListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This RootCause (" + rootCause + ") cannot be destroyed since the ExceptionHasRootCause " + exceptionHasRootCauseListOrphanCheckExceptionHasRootCause + " in its exceptionHasRootCauseList field has a non-nullable rootCause field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + RootCauseType rootCauseType = rootCause.getRootCauseType(); + if (rootCauseType != null) { + rootCauseType.getRootCauseList().remove(rootCause); + rootCauseType = em.merge(rootCauseType); + } + List vmUserList = rootCause.getVmUserList(); + for (VmUser vmUserListVmUser : vmUserList) { + vmUserListVmUser.getRootCauseList().remove(rootCause); + vmUserListVmUser = em.merge(vmUserListVmUser); + } + em.remove(rootCause); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findRootCauseEntities() { + return findRootCauseEntities(true, -1, -1); + } + + public List findRootCauseEntities(int maxResults, int firstResult) { + return findRootCauseEntities(false, maxResults, firstResult); + } + + private List findRootCauseEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(RootCause.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public RootCause findRootCause(RootCausePK id) { + EntityManager em = getEntityManager(); + try { + return em.find(RootCause.class, id); + } + finally { + em.close(); + } + } + + public int getRootCauseCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(RootCause.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RootCauseTypeJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RootCauseTypeJpaController.java index 863498ef..d4b19ace 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/RootCauseTypeJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/RootCauseTypeJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.RootCause; -import com.validation.manager.core.db.RootCauseType; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RootCauseTypeJpaController implements Serializable { - - public RootCauseTypeJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(RootCauseType rootCauseType) { - if (rootCauseType.getRootCauseList() == null) { - rootCauseType.setRootCauseList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedRootCauseList = new ArrayList(); - for (RootCause rootCauseListRootCauseToAttach : rootCauseType.getRootCauseList()) { - rootCauseListRootCauseToAttach = em.getReference(rootCauseListRootCauseToAttach.getClass(), rootCauseListRootCauseToAttach.getRootCausePK()); - attachedRootCauseList.add(rootCauseListRootCauseToAttach); - } - rootCauseType.setRootCauseList(attachedRootCauseList); - em.persist(rootCauseType); - for (RootCause rootCauseListRootCause : rootCauseType.getRootCauseList()) { - RootCauseType oldRootCauseTypeOfRootCauseListRootCause = rootCauseListRootCause.getRootCauseType(); - rootCauseListRootCause.setRootCauseType(rootCauseType); - rootCauseListRootCause = em.merge(rootCauseListRootCause); - if (oldRootCauseTypeOfRootCauseListRootCause != null) { - oldRootCauseTypeOfRootCauseListRootCause.getRootCauseList().remove(rootCauseListRootCause); - oldRootCauseTypeOfRootCauseListRootCause = em.merge(oldRootCauseTypeOfRootCauseListRootCause); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(RootCauseType rootCauseType) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RootCauseType persistentRootCauseType = em.find(RootCauseType.class, rootCauseType.getId()); - List rootCauseListOld = persistentRootCauseType.getRootCauseList(); - List rootCauseListNew = rootCauseType.getRootCauseList(); - List illegalOrphanMessages = null; - for (RootCause rootCauseListOldRootCause : rootCauseListOld) { - if (!rootCauseListNew.contains(rootCauseListOldRootCause)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain RootCause " + rootCauseListOldRootCause + " since its rootCauseType field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedRootCauseListNew = new ArrayList(); - for (RootCause rootCauseListNewRootCauseToAttach : rootCauseListNew) { - rootCauseListNewRootCauseToAttach = em.getReference(rootCauseListNewRootCauseToAttach.getClass(), rootCauseListNewRootCauseToAttach.getRootCausePK()); - attachedRootCauseListNew.add(rootCauseListNewRootCauseToAttach); - } - rootCauseListNew = attachedRootCauseListNew; - rootCauseType.setRootCauseList(rootCauseListNew); - rootCauseType = em.merge(rootCauseType); - for (RootCause rootCauseListNewRootCause : rootCauseListNew) { - if (!rootCauseListOld.contains(rootCauseListNewRootCause)) { - RootCauseType oldRootCauseTypeOfRootCauseListNewRootCause = rootCauseListNewRootCause.getRootCauseType(); - rootCauseListNewRootCause.setRootCauseType(rootCauseType); - rootCauseListNewRootCause = em.merge(rootCauseListNewRootCause); - if (oldRootCauseTypeOfRootCauseListNewRootCause != null && !oldRootCauseTypeOfRootCauseListNewRootCause.equals(rootCauseType)) { - oldRootCauseTypeOfRootCauseListNewRootCause.getRootCauseList().remove(rootCauseListNewRootCause); - oldRootCauseTypeOfRootCauseListNewRootCause = em.merge(oldRootCauseTypeOfRootCauseListNewRootCause); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = rootCauseType.getId(); - if (findRootCauseType(id) == null) { - throw new NonexistentEntityException("The rootCauseType with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - RootCauseType rootCauseType; - try { - rootCauseType = em.getReference(RootCauseType.class, id); - rootCauseType.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The rootCauseType with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List rootCauseListOrphanCheck = rootCauseType.getRootCauseList(); - for (RootCause rootCauseListOrphanCheckRootCause : rootCauseListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This RootCauseType (" + rootCauseType + ") cannot be destroyed since the RootCause " + rootCauseListOrphanCheckRootCause + " in its rootCauseList field has a non-nullable rootCauseType field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(rootCauseType); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findRootCauseTypeEntities() { - return findRootCauseTypeEntities(true, -1, -1); - } - - public List findRootCauseTypeEntities(int maxResults, int firstResult) { - return findRootCauseTypeEntities(false, maxResults, firstResult); - } - - private List findRootCauseTypeEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(RootCauseType.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public RootCauseType findRootCauseType(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(RootCauseType.class, id); - } - finally { - em.close(); - } - } - - public int getRootCauseTypeCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(RootCauseType.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.RootCause; +import com.validation.manager.core.db.RootCauseType; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RootCauseTypeJpaController implements Serializable { + + public RootCauseTypeJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(RootCauseType rootCauseType) { + if (rootCauseType.getRootCauseList() == null) { + rootCauseType.setRootCauseList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedRootCauseList = new ArrayList<>(); + for (RootCause rootCauseListRootCauseToAttach : rootCauseType.getRootCauseList()) { + rootCauseListRootCauseToAttach = em.getReference(rootCauseListRootCauseToAttach.getClass(), rootCauseListRootCauseToAttach.getRootCausePK()); + attachedRootCauseList.add(rootCauseListRootCauseToAttach); + } + rootCauseType.setRootCauseList(attachedRootCauseList); + em.persist(rootCauseType); + for (RootCause rootCauseListRootCause : rootCauseType.getRootCauseList()) { + RootCauseType oldRootCauseTypeOfRootCauseListRootCause = rootCauseListRootCause.getRootCauseType(); + rootCauseListRootCause.setRootCauseType(rootCauseType); + rootCauseListRootCause = em.merge(rootCauseListRootCause); + if (oldRootCauseTypeOfRootCauseListRootCause != null) { + oldRootCauseTypeOfRootCauseListRootCause.getRootCauseList().remove(rootCauseListRootCause); + oldRootCauseTypeOfRootCauseListRootCause = em.merge(oldRootCauseTypeOfRootCauseListRootCause); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(RootCauseType rootCauseType) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RootCauseType persistentRootCauseType = em.find(RootCauseType.class, rootCauseType.getId()); + List rootCauseListOld = persistentRootCauseType.getRootCauseList(); + List rootCauseListNew = rootCauseType.getRootCauseList(); + List illegalOrphanMessages = null; + for (RootCause rootCauseListOldRootCause : rootCauseListOld) { + if (!rootCauseListNew.contains(rootCauseListOldRootCause)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain RootCause " + rootCauseListOldRootCause + " since its rootCauseType field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedRootCauseListNew = new ArrayList<>(); + for (RootCause rootCauseListNewRootCauseToAttach : rootCauseListNew) { + rootCauseListNewRootCauseToAttach = em.getReference(rootCauseListNewRootCauseToAttach.getClass(), rootCauseListNewRootCauseToAttach.getRootCausePK()); + attachedRootCauseListNew.add(rootCauseListNewRootCauseToAttach); + } + rootCauseListNew = attachedRootCauseListNew; + rootCauseType.setRootCauseList(rootCauseListNew); + rootCauseType = em.merge(rootCauseType); + for (RootCause rootCauseListNewRootCause : rootCauseListNew) { + if (!rootCauseListOld.contains(rootCauseListNewRootCause)) { + RootCauseType oldRootCauseTypeOfRootCauseListNewRootCause = rootCauseListNewRootCause.getRootCauseType(); + rootCauseListNewRootCause.setRootCauseType(rootCauseType); + rootCauseListNewRootCause = em.merge(rootCauseListNewRootCause); + if (oldRootCauseTypeOfRootCauseListNewRootCause != null && !oldRootCauseTypeOfRootCauseListNewRootCause.equals(rootCauseType)) { + oldRootCauseTypeOfRootCauseListNewRootCause.getRootCauseList().remove(rootCauseListNewRootCause); + oldRootCauseTypeOfRootCauseListNewRootCause = em.merge(oldRootCauseTypeOfRootCauseListNewRootCause); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = rootCauseType.getId(); + if (findRootCauseType(id) == null) { + throw new NonexistentEntityException("The rootCauseType with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + RootCauseType rootCauseType; + try { + rootCauseType = em.getReference(RootCauseType.class, id); + rootCauseType.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The rootCauseType with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List rootCauseListOrphanCheck = rootCauseType.getRootCauseList(); + for (RootCause rootCauseListOrphanCheckRootCause : rootCauseListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This RootCauseType (" + rootCauseType + ") cannot be destroyed since the RootCause " + rootCauseListOrphanCheckRootCause + " in its rootCauseList field has a non-nullable rootCauseType field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(rootCauseType); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findRootCauseTypeEntities() { + return findRootCauseTypeEntities(true, -1, -1); + } + + public List findRootCauseTypeEntities(int maxResults, int firstResult) { + return findRootCauseTypeEntities(false, maxResults, firstResult); + } + + private List findRootCauseTypeEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(RootCauseType.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public RootCauseType findRootCauseType(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(RootCauseType.class, id); + } + finally { + em.close(); + } + } + + public int getRootCauseTypeCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(RootCauseType.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/SpecLevelJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/SpecLevelJpaController.java index 2ba104bb..11ac0b54 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/SpecLevelJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/SpecLevelJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.RequirementSpec; -import com.validation.manager.core.db.SpecLevel; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class SpecLevelJpaController implements Serializable { - - public SpecLevelJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(SpecLevel specLevel) { - if (specLevel.getRequirementSpecList() == null) { - specLevel.setRequirementSpecList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedRequirementSpecList = new ArrayList(); - for (RequirementSpec requirementSpecListRequirementSpecToAttach : specLevel.getRequirementSpecList()) { - requirementSpecListRequirementSpecToAttach = em.getReference(requirementSpecListRequirementSpecToAttach.getClass(), requirementSpecListRequirementSpecToAttach.getRequirementSpecPK()); - attachedRequirementSpecList.add(requirementSpecListRequirementSpecToAttach); - } - specLevel.setRequirementSpecList(attachedRequirementSpecList); - em.persist(specLevel); - for (RequirementSpec requirementSpecListRequirementSpec : specLevel.getRequirementSpecList()) { - SpecLevel oldSpecLevelOfRequirementSpecListRequirementSpec = requirementSpecListRequirementSpec.getSpecLevel(); - requirementSpecListRequirementSpec.setSpecLevel(specLevel); - requirementSpecListRequirementSpec = em.merge(requirementSpecListRequirementSpec); - if (oldSpecLevelOfRequirementSpecListRequirementSpec != null) { - oldSpecLevelOfRequirementSpecListRequirementSpec.getRequirementSpecList().remove(requirementSpecListRequirementSpec); - oldSpecLevelOfRequirementSpecListRequirementSpec = em.merge(oldSpecLevelOfRequirementSpecListRequirementSpec); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(SpecLevel specLevel) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - SpecLevel persistentSpecLevel = em.find(SpecLevel.class, specLevel.getId()); - List requirementSpecListOld = persistentSpecLevel.getRequirementSpecList(); - List requirementSpecListNew = specLevel.getRequirementSpecList(); - List illegalOrphanMessages = null; - for (RequirementSpec requirementSpecListOldRequirementSpec : requirementSpecListOld) { - if (!requirementSpecListNew.contains(requirementSpecListOldRequirementSpec)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain RequirementSpec " + requirementSpecListOldRequirementSpec + " since its specLevel field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedRequirementSpecListNew = new ArrayList(); - for (RequirementSpec requirementSpecListNewRequirementSpecToAttach : requirementSpecListNew) { - requirementSpecListNewRequirementSpecToAttach = em.getReference(requirementSpecListNewRequirementSpecToAttach.getClass(), requirementSpecListNewRequirementSpecToAttach.getRequirementSpecPK()); - attachedRequirementSpecListNew.add(requirementSpecListNewRequirementSpecToAttach); - } - requirementSpecListNew = attachedRequirementSpecListNew; - specLevel.setRequirementSpecList(requirementSpecListNew); - specLevel = em.merge(specLevel); - for (RequirementSpec requirementSpecListNewRequirementSpec : requirementSpecListNew) { - if (!requirementSpecListOld.contains(requirementSpecListNewRequirementSpec)) { - SpecLevel oldSpecLevelOfRequirementSpecListNewRequirementSpec = requirementSpecListNewRequirementSpec.getSpecLevel(); - requirementSpecListNewRequirementSpec.setSpecLevel(specLevel); - requirementSpecListNewRequirementSpec = em.merge(requirementSpecListNewRequirementSpec); - if (oldSpecLevelOfRequirementSpecListNewRequirementSpec != null && !oldSpecLevelOfRequirementSpecListNewRequirementSpec.equals(specLevel)) { - oldSpecLevelOfRequirementSpecListNewRequirementSpec.getRequirementSpecList().remove(requirementSpecListNewRequirementSpec); - oldSpecLevelOfRequirementSpecListNewRequirementSpec = em.merge(oldSpecLevelOfRequirementSpecListNewRequirementSpec); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = specLevel.getId(); - if (findSpecLevel(id) == null) { - throw new NonexistentEntityException("The specLevel with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - SpecLevel specLevel; - try { - specLevel = em.getReference(SpecLevel.class, id); - specLevel.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The specLevel with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List requirementSpecListOrphanCheck = specLevel.getRequirementSpecList(); - for (RequirementSpec requirementSpecListOrphanCheckRequirementSpec : requirementSpecListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This SpecLevel (" + specLevel + ") cannot be destroyed since the RequirementSpec " + requirementSpecListOrphanCheckRequirementSpec + " in its requirementSpecList field has a non-nullable specLevel field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(specLevel); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findSpecLevelEntities() { - return findSpecLevelEntities(true, -1, -1); - } - - public List findSpecLevelEntities(int maxResults, int firstResult) { - return findSpecLevelEntities(false, maxResults, firstResult); - } - - private List findSpecLevelEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(SpecLevel.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public SpecLevel findSpecLevel(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(SpecLevel.class, id); - } - finally { - em.close(); - } - } - - public int getSpecLevelCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(SpecLevel.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.RequirementSpec; +import com.validation.manager.core.db.SpecLevel; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class SpecLevelJpaController implements Serializable { + + public SpecLevelJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(SpecLevel specLevel) { + if (specLevel.getRequirementSpecList() == null) { + specLevel.setRequirementSpecList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedRequirementSpecList = new ArrayList<>(); + for (RequirementSpec requirementSpecListRequirementSpecToAttach : specLevel.getRequirementSpecList()) { + requirementSpecListRequirementSpecToAttach = em.getReference(requirementSpecListRequirementSpecToAttach.getClass(), requirementSpecListRequirementSpecToAttach.getRequirementSpecPK()); + attachedRequirementSpecList.add(requirementSpecListRequirementSpecToAttach); + } + specLevel.setRequirementSpecList(attachedRequirementSpecList); + em.persist(specLevel); + for (RequirementSpec requirementSpecListRequirementSpec : specLevel.getRequirementSpecList()) { + SpecLevel oldSpecLevelOfRequirementSpecListRequirementSpec = requirementSpecListRequirementSpec.getSpecLevel(); + requirementSpecListRequirementSpec.setSpecLevel(specLevel); + requirementSpecListRequirementSpec = em.merge(requirementSpecListRequirementSpec); + if (oldSpecLevelOfRequirementSpecListRequirementSpec != null) { + oldSpecLevelOfRequirementSpecListRequirementSpec.getRequirementSpecList().remove(requirementSpecListRequirementSpec); + oldSpecLevelOfRequirementSpecListRequirementSpec = em.merge(oldSpecLevelOfRequirementSpecListRequirementSpec); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(SpecLevel specLevel) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + SpecLevel persistentSpecLevel = em.find(SpecLevel.class, specLevel.getId()); + List requirementSpecListOld = persistentSpecLevel.getRequirementSpecList(); + List requirementSpecListNew = specLevel.getRequirementSpecList(); + List illegalOrphanMessages = null; + for (RequirementSpec requirementSpecListOldRequirementSpec : requirementSpecListOld) { + if (!requirementSpecListNew.contains(requirementSpecListOldRequirementSpec)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain RequirementSpec " + requirementSpecListOldRequirementSpec + " since its specLevel field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedRequirementSpecListNew = new ArrayList<>(); + for (RequirementSpec requirementSpecListNewRequirementSpecToAttach : requirementSpecListNew) { + requirementSpecListNewRequirementSpecToAttach = em.getReference(requirementSpecListNewRequirementSpecToAttach.getClass(), requirementSpecListNewRequirementSpecToAttach.getRequirementSpecPK()); + attachedRequirementSpecListNew.add(requirementSpecListNewRequirementSpecToAttach); + } + requirementSpecListNew = attachedRequirementSpecListNew; + specLevel.setRequirementSpecList(requirementSpecListNew); + specLevel = em.merge(specLevel); + for (RequirementSpec requirementSpecListNewRequirementSpec : requirementSpecListNew) { + if (!requirementSpecListOld.contains(requirementSpecListNewRequirementSpec)) { + SpecLevel oldSpecLevelOfRequirementSpecListNewRequirementSpec = requirementSpecListNewRequirementSpec.getSpecLevel(); + requirementSpecListNewRequirementSpec.setSpecLevel(specLevel); + requirementSpecListNewRequirementSpec = em.merge(requirementSpecListNewRequirementSpec); + if (oldSpecLevelOfRequirementSpecListNewRequirementSpec != null && !oldSpecLevelOfRequirementSpecListNewRequirementSpec.equals(specLevel)) { + oldSpecLevelOfRequirementSpecListNewRequirementSpec.getRequirementSpecList().remove(requirementSpecListNewRequirementSpec); + oldSpecLevelOfRequirementSpecListNewRequirementSpec = em.merge(oldSpecLevelOfRequirementSpecListNewRequirementSpec); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = specLevel.getId(); + if (findSpecLevel(id) == null) { + throw new NonexistentEntityException("The specLevel with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + SpecLevel specLevel; + try { + specLevel = em.getReference(SpecLevel.class, id); + specLevel.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The specLevel with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List requirementSpecListOrphanCheck = specLevel.getRequirementSpecList(); + for (RequirementSpec requirementSpecListOrphanCheckRequirementSpec : requirementSpecListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This SpecLevel (" + specLevel + ") cannot be destroyed since the RequirementSpec " + requirementSpecListOrphanCheckRequirementSpec + " in its requirementSpecList field has a non-nullable specLevel field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(specLevel); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findSpecLevelEntities() { + return findSpecLevelEntities(true, -1, -1); + } + + public List findSpecLevelEntities(int maxResults, int firstResult) { + return findSpecLevelEntities(false, maxResults, firstResult); + } + + private List findSpecLevelEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(SpecLevel.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public SpecLevel findSpecLevel(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(SpecLevel.class, id); + } + finally { + em.close(); + } + } + + public int getSpecLevelCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(SpecLevel.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/StepJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/StepJpaController.java index 251fc57e..9dac0b91 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/StepJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/StepJpaController.java @@ -13,345 +13,345 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.TestCase; -import com.validation.manager.core.db.Requirement; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.Step; -import com.validation.manager.core.db.StepPK; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class StepJpaController implements Serializable { - - public StepJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Step step) throws PreexistingEntityException, Exception { - if (step.getStepPK() == null) { - step.setStepPK(new StepPK()); - } - if (step.getRequirementList() == null) { - step.setRequirementList(new ArrayList()); - } - if (step.getExecutionStepList() == null) { - step.setExecutionStepList(new ArrayList()); - } - if (step.getHistoryList() == null) { - step.setHistoryList(new ArrayList()); - } - step.getStepPK().setTestCaseId(step.getTestCase().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - TestCase testCase = step.getTestCase(); - if (testCase != null) { - testCase = em.getReference(testCase.getClass(), testCase.getId()); - step.setTestCase(testCase); - } - List attachedRequirementList = new ArrayList(); - for (Requirement requirementListRequirementToAttach : step.getRequirementList()) { - requirementListRequirementToAttach = em.getReference(requirementListRequirementToAttach.getClass(), requirementListRequirementToAttach.getId()); - attachedRequirementList.add(requirementListRequirementToAttach); - } - step.setRequirementList(attachedRequirementList); - List attachedExecutionStepList = new ArrayList(); - for (ExecutionStep executionStepListExecutionStepToAttach : step.getExecutionStepList()) { - executionStepListExecutionStepToAttach = em.getReference(executionStepListExecutionStepToAttach.getClass(), executionStepListExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepList.add(executionStepListExecutionStepToAttach); - } - step.setExecutionStepList(attachedExecutionStepList); - List attachedHistoryList = new ArrayList(); - for (History historyListHistoryToAttach : step.getHistoryList()) { - historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); - attachedHistoryList.add(historyListHistoryToAttach); - } - step.setHistoryList(attachedHistoryList); - em.persist(step); - if (testCase != null) { - testCase.getStepList().add(step); - testCase = em.merge(testCase); - } - for (Requirement requirementListRequirement : step.getRequirementList()) { - requirementListRequirement.getStepList().add(step); - requirementListRequirement = em.merge(requirementListRequirement); - } - for (ExecutionStep executionStepListExecutionStep : step.getExecutionStepList()) { - Step oldStepOfExecutionStepListExecutionStep = executionStepListExecutionStep.getStep(); - executionStepListExecutionStep.setStep(step); - executionStepListExecutionStep = em.merge(executionStepListExecutionStep); - if (oldStepOfExecutionStepListExecutionStep != null) { - oldStepOfExecutionStepListExecutionStep.getExecutionStepList().remove(executionStepListExecutionStep); - oldStepOfExecutionStepListExecutionStep = em.merge(oldStepOfExecutionStepListExecutionStep); - } - } - for (History historyListHistory : step.getHistoryList()) { - Step oldStepOfHistoryListHistory = historyListHistory.getStep(); - historyListHistory.setStep(step); - historyListHistory = em.merge(historyListHistory); - if (oldStepOfHistoryListHistory != null) { - oldStepOfHistoryListHistory.getHistoryList().remove(historyListHistory); - oldStepOfHistoryListHistory = em.merge(oldStepOfHistoryListHistory); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - if (findStep(step.getStepPK()) != null) { - throw new PreexistingEntityException("Step " + step + " already exists.", ex); - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Step step) throws IllegalOrphanException, NonexistentEntityException, Exception { - step.getStepPK().setTestCaseId(step.getTestCase().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Step persistentStep = em.find(Step.class, step.getStepPK()); - TestCase testCaseOld = persistentStep.getTestCase(); - TestCase testCaseNew = step.getTestCase(); - List requirementListOld = persistentStep.getRequirementList(); - List requirementListNew = step.getRequirementList(); - List executionStepListOld = persistentStep.getExecutionStepList(); - List executionStepListNew = step.getExecutionStepList(); - List historyListOld = persistentStep.getHistoryList(); - List historyListNew = step.getHistoryList(); - List illegalOrphanMessages = null; - for (ExecutionStep executionStepListOldExecutionStep : executionStepListOld) { - if (!executionStepListNew.contains(executionStepListOldExecutionStep)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain ExecutionStep " + executionStepListOldExecutionStep + " since its step field is not nullable."); - } - } - for (History historyListOldHistory : historyListOld) { - if (!historyListNew.contains(historyListOldHistory)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain History " + historyListOldHistory + " since its step field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (testCaseNew != null) { - testCaseNew = em.getReference(testCaseNew.getClass(), testCaseNew.getId()); - step.setTestCase(testCaseNew); - } - List attachedRequirementListNew = new ArrayList(); - for (Requirement requirementListNewRequirementToAttach : requirementListNew) { - requirementListNewRequirementToAttach = em.getReference(requirementListNewRequirementToAttach.getClass(), requirementListNewRequirementToAttach.getId()); - attachedRequirementListNew.add(requirementListNewRequirementToAttach); - } - requirementListNew = attachedRequirementListNew; - step.setRequirementList(requirementListNew); - List attachedExecutionStepListNew = new ArrayList(); - for (ExecutionStep executionStepListNewExecutionStepToAttach : executionStepListNew) { - executionStepListNewExecutionStepToAttach = em.getReference(executionStepListNewExecutionStepToAttach.getClass(), executionStepListNewExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepListNew.add(executionStepListNewExecutionStepToAttach); - } - executionStepListNew = attachedExecutionStepListNew; - step.setExecutionStepList(executionStepListNew); - List attachedHistoryListNew = new ArrayList(); - for (History historyListNewHistoryToAttach : historyListNew) { - historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); - attachedHistoryListNew.add(historyListNewHistoryToAttach); - } - historyListNew = attachedHistoryListNew; - step.setHistoryList(historyListNew); - step = em.merge(step); - if (testCaseOld != null && !testCaseOld.equals(testCaseNew)) { - testCaseOld.getStepList().remove(step); - testCaseOld = em.merge(testCaseOld); - } - if (testCaseNew != null && !testCaseNew.equals(testCaseOld)) { - testCaseNew.getStepList().add(step); - testCaseNew = em.merge(testCaseNew); - } - for (Requirement requirementListOldRequirement : requirementListOld) { - if (!requirementListNew.contains(requirementListOldRequirement)) { - requirementListOldRequirement.getStepList().remove(step); - requirementListOldRequirement = em.merge(requirementListOldRequirement); - } - } - for (Requirement requirementListNewRequirement : requirementListNew) { - if (!requirementListOld.contains(requirementListNewRequirement)) { - requirementListNewRequirement.getStepList().add(step); - requirementListNewRequirement = em.merge(requirementListNewRequirement); - } - } - for (ExecutionStep executionStepListNewExecutionStep : executionStepListNew) { - if (!executionStepListOld.contains(executionStepListNewExecutionStep)) { - Step oldStepOfExecutionStepListNewExecutionStep = executionStepListNewExecutionStep.getStep(); - executionStepListNewExecutionStep.setStep(step); - executionStepListNewExecutionStep = em.merge(executionStepListNewExecutionStep); - if (oldStepOfExecutionStepListNewExecutionStep != null && !oldStepOfExecutionStepListNewExecutionStep.equals(step)) { - oldStepOfExecutionStepListNewExecutionStep.getExecutionStepList().remove(executionStepListNewExecutionStep); - oldStepOfExecutionStepListNewExecutionStep = em.merge(oldStepOfExecutionStepListNewExecutionStep); - } - } - } - for (History historyListNewHistory : historyListNew) { - if (!historyListOld.contains(historyListNewHistory)) { - Step oldStepOfHistoryListNewHistory = historyListNewHistory.getStep(); - historyListNewHistory.setStep(step); - historyListNewHistory = em.merge(historyListNewHistory); - if (oldStepOfHistoryListNewHistory != null && !oldStepOfHistoryListNewHistory.equals(step)) { - oldStepOfHistoryListNewHistory.getHistoryList().remove(historyListNewHistory); - oldStepOfHistoryListNewHistory = em.merge(oldStepOfHistoryListNewHistory); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - StepPK id = step.getStepPK(); - if (findStep(id) == null) { - throw new NonexistentEntityException("The step with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(StepPK id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Step step; - try { - step = em.getReference(Step.class, id); - step.getStepPK(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The step with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List executionStepListOrphanCheck = step.getExecutionStepList(); - for (ExecutionStep executionStepListOrphanCheckExecutionStep : executionStepListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Step (" + step + ") cannot be destroyed since the ExecutionStep " + executionStepListOrphanCheckExecutionStep + " in its executionStepList field has a non-nullable step field."); - } - List historyListOrphanCheck = step.getHistoryList(); - for (History historyListOrphanCheckHistory : historyListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This Step (" + step + ") cannot be destroyed since the History " + historyListOrphanCheckHistory + " in its historyList field has a non-nullable step field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - TestCase testCase = step.getTestCase(); - if (testCase != null) { - testCase.getStepList().remove(step); - testCase = em.merge(testCase); - } - List requirementList = step.getRequirementList(); - for (Requirement requirementListRequirement : requirementList) { - requirementListRequirement.getStepList().remove(step); - requirementListRequirement = em.merge(requirementListRequirement); - } - em.remove(step); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findStepEntities() { - return findStepEntities(true, -1, -1); - } - - public List findStepEntities(int maxResults, int firstResult) { - return findStepEntities(false, maxResults, firstResult); - } - - private List findStepEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Step.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public Step findStep(StepPK id) { - EntityManager em = getEntityManager(); - try { - return em.find(Step.class, id); - } - finally { - em.close(); - } - } - - public int getStepCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(Step.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.TestCase; +import com.validation.manager.core.db.Requirement; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.Step; +import com.validation.manager.core.db.StepPK; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class StepJpaController implements Serializable { + + public StepJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(Step step) throws PreexistingEntityException, Exception { + if (step.getStepPK() == null) { + step.setStepPK(new StepPK()); + } + if (step.getRequirementList() == null) { + step.setRequirementList(new ArrayList<>()); + } + if (step.getExecutionStepList() == null) { + step.setExecutionStepList(new ArrayList<>()); + } + if (step.getHistoryList() == null) { + step.setHistoryList(new ArrayList<>()); + } + step.getStepPK().setTestCaseId(step.getTestCase().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + TestCase testCase = step.getTestCase(); + if (testCase != null) { + testCase = em.getReference(testCase.getClass(), testCase.getId()); + step.setTestCase(testCase); + } + List attachedRequirementList = new ArrayList<>(); + for (Requirement requirementListRequirementToAttach : step.getRequirementList()) { + requirementListRequirementToAttach = em.getReference(requirementListRequirementToAttach.getClass(), requirementListRequirementToAttach.getId()); + attachedRequirementList.add(requirementListRequirementToAttach); + } + step.setRequirementList(attachedRequirementList); + List attachedExecutionStepList = new ArrayList<>(); + for (ExecutionStep executionStepListExecutionStepToAttach : step.getExecutionStepList()) { + executionStepListExecutionStepToAttach = em.getReference(executionStepListExecutionStepToAttach.getClass(), executionStepListExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepList.add(executionStepListExecutionStepToAttach); + } + step.setExecutionStepList(attachedExecutionStepList); + List attachedHistoryList = new ArrayList<>(); + for (History historyListHistoryToAttach : step.getHistoryList()) { + historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); + attachedHistoryList.add(historyListHistoryToAttach); + } + step.setHistoryList(attachedHistoryList); + em.persist(step); + if (testCase != null) { + testCase.getStepList().add(step); + testCase = em.merge(testCase); + } + for (Requirement requirementListRequirement : step.getRequirementList()) { + requirementListRequirement.getStepList().add(step); + requirementListRequirement = em.merge(requirementListRequirement); + } + for (ExecutionStep executionStepListExecutionStep : step.getExecutionStepList()) { + Step oldStepOfExecutionStepListExecutionStep = executionStepListExecutionStep.getStep(); + executionStepListExecutionStep.setStep(step); + executionStepListExecutionStep = em.merge(executionStepListExecutionStep); + if (oldStepOfExecutionStepListExecutionStep != null) { + oldStepOfExecutionStepListExecutionStep.getExecutionStepList().remove(executionStepListExecutionStep); + oldStepOfExecutionStepListExecutionStep = em.merge(oldStepOfExecutionStepListExecutionStep); + } + } + for (History historyListHistory : step.getHistoryList()) { + Step oldStepOfHistoryListHistory = historyListHistory.getStep(); + historyListHistory.setStep(step); + historyListHistory = em.merge(historyListHistory); + if (oldStepOfHistoryListHistory != null) { + oldStepOfHistoryListHistory.getHistoryList().remove(historyListHistory); + oldStepOfHistoryListHistory = em.merge(oldStepOfHistoryListHistory); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + if (findStep(step.getStepPK()) != null) { + throw new PreexistingEntityException("Step " + step + " already exists.", ex); + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(Step step) throws IllegalOrphanException, NonexistentEntityException, Exception { + step.getStepPK().setTestCaseId(step.getTestCase().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Step persistentStep = em.find(Step.class, step.getStepPK()); + TestCase testCaseOld = persistentStep.getTestCase(); + TestCase testCaseNew = step.getTestCase(); + List requirementListOld = persistentStep.getRequirementList(); + List requirementListNew = step.getRequirementList(); + List executionStepListOld = persistentStep.getExecutionStepList(); + List executionStepListNew = step.getExecutionStepList(); + List historyListOld = persistentStep.getHistoryList(); + List historyListNew = step.getHistoryList(); + List illegalOrphanMessages = null; + for (ExecutionStep executionStepListOldExecutionStep : executionStepListOld) { + if (!executionStepListNew.contains(executionStepListOldExecutionStep)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain ExecutionStep " + executionStepListOldExecutionStep + " since its step field is not nullable."); + } + } + for (History historyListOldHistory : historyListOld) { + if (!historyListNew.contains(historyListOldHistory)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain History " + historyListOldHistory + " since its step field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (testCaseNew != null) { + testCaseNew = em.getReference(testCaseNew.getClass(), testCaseNew.getId()); + step.setTestCase(testCaseNew); + } + List attachedRequirementListNew = new ArrayList<>(); + for (Requirement requirementListNewRequirementToAttach : requirementListNew) { + requirementListNewRequirementToAttach = em.getReference(requirementListNewRequirementToAttach.getClass(), requirementListNewRequirementToAttach.getId()); + attachedRequirementListNew.add(requirementListNewRequirementToAttach); + } + requirementListNew = attachedRequirementListNew; + step.setRequirementList(requirementListNew); + List attachedExecutionStepListNew = new ArrayList<>(); + for (ExecutionStep executionStepListNewExecutionStepToAttach : executionStepListNew) { + executionStepListNewExecutionStepToAttach = em.getReference(executionStepListNewExecutionStepToAttach.getClass(), executionStepListNewExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepListNew.add(executionStepListNewExecutionStepToAttach); + } + executionStepListNew = attachedExecutionStepListNew; + step.setExecutionStepList(executionStepListNew); + List attachedHistoryListNew = new ArrayList<>(); + for (History historyListNewHistoryToAttach : historyListNew) { + historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); + attachedHistoryListNew.add(historyListNewHistoryToAttach); + } + historyListNew = attachedHistoryListNew; + step.setHistoryList(historyListNew); + step = em.merge(step); + if (testCaseOld != null && !testCaseOld.equals(testCaseNew)) { + testCaseOld.getStepList().remove(step); + testCaseOld = em.merge(testCaseOld); + } + if (testCaseNew != null && !testCaseNew.equals(testCaseOld)) { + testCaseNew.getStepList().add(step); + testCaseNew = em.merge(testCaseNew); + } + for (Requirement requirementListOldRequirement : requirementListOld) { + if (!requirementListNew.contains(requirementListOldRequirement)) { + requirementListOldRequirement.getStepList().remove(step); + requirementListOldRequirement = em.merge(requirementListOldRequirement); + } + } + for (Requirement requirementListNewRequirement : requirementListNew) { + if (!requirementListOld.contains(requirementListNewRequirement)) { + requirementListNewRequirement.getStepList().add(step); + requirementListNewRequirement = em.merge(requirementListNewRequirement); + } + } + for (ExecutionStep executionStepListNewExecutionStep : executionStepListNew) { + if (!executionStepListOld.contains(executionStepListNewExecutionStep)) { + Step oldStepOfExecutionStepListNewExecutionStep = executionStepListNewExecutionStep.getStep(); + executionStepListNewExecutionStep.setStep(step); + executionStepListNewExecutionStep = em.merge(executionStepListNewExecutionStep); + if (oldStepOfExecutionStepListNewExecutionStep != null && !oldStepOfExecutionStepListNewExecutionStep.equals(step)) { + oldStepOfExecutionStepListNewExecutionStep.getExecutionStepList().remove(executionStepListNewExecutionStep); + oldStepOfExecutionStepListNewExecutionStep = em.merge(oldStepOfExecutionStepListNewExecutionStep); + } + } + } + for (History historyListNewHistory : historyListNew) { + if (!historyListOld.contains(historyListNewHistory)) { + Step oldStepOfHistoryListNewHistory = historyListNewHistory.getStep(); + historyListNewHistory.setStep(step); + historyListNewHistory = em.merge(historyListNewHistory); + if (oldStepOfHistoryListNewHistory != null && !oldStepOfHistoryListNewHistory.equals(step)) { + oldStepOfHistoryListNewHistory.getHistoryList().remove(historyListNewHistory); + oldStepOfHistoryListNewHistory = em.merge(oldStepOfHistoryListNewHistory); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + StepPK id = step.getStepPK(); + if (findStep(id) == null) { + throw new NonexistentEntityException("The step with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(StepPK id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + Step step; + try { + step = em.getReference(Step.class, id); + step.getStepPK(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The step with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List executionStepListOrphanCheck = step.getExecutionStepList(); + for (ExecutionStep executionStepListOrphanCheckExecutionStep : executionStepListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Step (" + step + ") cannot be destroyed since the ExecutionStep " + executionStepListOrphanCheckExecutionStep + " in its executionStepList field has a non-nullable step field."); + } + List historyListOrphanCheck = step.getHistoryList(); + for (History historyListOrphanCheckHistory : historyListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This Step (" + step + ") cannot be destroyed since the History " + historyListOrphanCheckHistory + " in its historyList field has a non-nullable step field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + TestCase testCase = step.getTestCase(); + if (testCase != null) { + testCase.getStepList().remove(step); + testCase = em.merge(testCase); + } + List requirementList = step.getRequirementList(); + for (Requirement requirementListRequirement : requirementList) { + requirementListRequirement.getStepList().remove(step); + requirementListRequirement = em.merge(requirementListRequirement); + } + em.remove(step); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findStepEntities() { + return findStepEntities(true, -1, -1); + } + + public List findStepEntities(int maxResults, int firstResult) { + return findStepEntities(false, maxResults, firstResult); + } + + private List findStepEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(Step.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public Step findStep(StepPK id) { + EntityManager em = getEntityManager(); + try { + return em.find(Step.class, id); + } + finally { + em.close(); + } + } + + public int getStepCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(Step.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestCaseExecutionJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestCaseExecutionJpaController.java index e7156e5e..dda77abd 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestCaseExecutionJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestCaseExecutionJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.TestCaseExecution; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class TestCaseExecutionJpaController implements Serializable { - - public TestCaseExecutionJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(TestCaseExecution testCaseExecution) { - if (testCaseExecution.getExecutionStepList() == null) { - testCaseExecution.setExecutionStepList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedExecutionStepList = new ArrayList(); - for (ExecutionStep executionStepListExecutionStepToAttach : testCaseExecution.getExecutionStepList()) { - executionStepListExecutionStepToAttach = em.getReference(executionStepListExecutionStepToAttach.getClass(), executionStepListExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepList.add(executionStepListExecutionStepToAttach); - } - testCaseExecution.setExecutionStepList(attachedExecutionStepList); - em.persist(testCaseExecution); - for (ExecutionStep executionStepListExecutionStep : testCaseExecution.getExecutionStepList()) { - TestCaseExecution oldTestCaseExecutionOfExecutionStepListExecutionStep = executionStepListExecutionStep.getTestCaseExecution(); - executionStepListExecutionStep.setTestCaseExecution(testCaseExecution); - executionStepListExecutionStep = em.merge(executionStepListExecutionStep); - if (oldTestCaseExecutionOfExecutionStepListExecutionStep != null) { - oldTestCaseExecutionOfExecutionStepListExecutionStep.getExecutionStepList().remove(executionStepListExecutionStep); - oldTestCaseExecutionOfExecutionStepListExecutionStep = em.merge(oldTestCaseExecutionOfExecutionStepListExecutionStep); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(TestCaseExecution testCaseExecution) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - TestCaseExecution persistentTestCaseExecution = em.find(TestCaseExecution.class, testCaseExecution.getId()); - List executionStepListOld = persistentTestCaseExecution.getExecutionStepList(); - List executionStepListNew = testCaseExecution.getExecutionStepList(); - List illegalOrphanMessages = null; - for (ExecutionStep executionStepListOldExecutionStep : executionStepListOld) { - if (!executionStepListNew.contains(executionStepListOldExecutionStep)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain ExecutionStep " + executionStepListOldExecutionStep + " since its testCaseExecution field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedExecutionStepListNew = new ArrayList(); - for (ExecutionStep executionStepListNewExecutionStepToAttach : executionStepListNew) { - executionStepListNewExecutionStepToAttach = em.getReference(executionStepListNewExecutionStepToAttach.getClass(), executionStepListNewExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepListNew.add(executionStepListNewExecutionStepToAttach); - } - executionStepListNew = attachedExecutionStepListNew; - testCaseExecution.setExecutionStepList(executionStepListNew); - testCaseExecution = em.merge(testCaseExecution); - for (ExecutionStep executionStepListNewExecutionStep : executionStepListNew) { - if (!executionStepListOld.contains(executionStepListNewExecutionStep)) { - TestCaseExecution oldTestCaseExecutionOfExecutionStepListNewExecutionStep = executionStepListNewExecutionStep.getTestCaseExecution(); - executionStepListNewExecutionStep.setTestCaseExecution(testCaseExecution); - executionStepListNewExecutionStep = em.merge(executionStepListNewExecutionStep); - if (oldTestCaseExecutionOfExecutionStepListNewExecutionStep != null && !oldTestCaseExecutionOfExecutionStepListNewExecutionStep.equals(testCaseExecution)) { - oldTestCaseExecutionOfExecutionStepListNewExecutionStep.getExecutionStepList().remove(executionStepListNewExecutionStep); - oldTestCaseExecutionOfExecutionStepListNewExecutionStep = em.merge(oldTestCaseExecutionOfExecutionStepListNewExecutionStep); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = testCaseExecution.getId(); - if (findTestCaseExecution(id) == null) { - throw new NonexistentEntityException("The testCaseExecution with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - TestCaseExecution testCaseExecution; - try { - testCaseExecution = em.getReference(TestCaseExecution.class, id); - testCaseExecution.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The testCaseExecution with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List executionStepListOrphanCheck = testCaseExecution.getExecutionStepList(); - for (ExecutionStep executionStepListOrphanCheckExecutionStep : executionStepListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This TestCaseExecution (" + testCaseExecution + ") cannot be destroyed since the ExecutionStep " + executionStepListOrphanCheckExecutionStep + " in its executionStepList field has a non-nullable testCaseExecution field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(testCaseExecution); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findTestCaseExecutionEntities() { - return findTestCaseExecutionEntities(true, -1, -1); - } - - public List findTestCaseExecutionEntities(int maxResults, int firstResult) { - return findTestCaseExecutionEntities(false, maxResults, firstResult); - } - - private List findTestCaseExecutionEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(TestCaseExecution.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public TestCaseExecution findTestCaseExecution(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(TestCaseExecution.class, id); - } - finally { - em.close(); - } - } - - public int getTestCaseExecutionCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(TestCaseExecution.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.TestCaseExecution; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class TestCaseExecutionJpaController implements Serializable { + + public TestCaseExecutionJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(TestCaseExecution testCaseExecution) { + if (testCaseExecution.getExecutionStepList() == null) { + testCaseExecution.setExecutionStepList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedExecutionStepList = new ArrayList<>(); + for (ExecutionStep executionStepListExecutionStepToAttach : testCaseExecution.getExecutionStepList()) { + executionStepListExecutionStepToAttach = em.getReference(executionStepListExecutionStepToAttach.getClass(), executionStepListExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepList.add(executionStepListExecutionStepToAttach); + } + testCaseExecution.setExecutionStepList(attachedExecutionStepList); + em.persist(testCaseExecution); + for (ExecutionStep executionStepListExecutionStep : testCaseExecution.getExecutionStepList()) { + TestCaseExecution oldTestCaseExecutionOfExecutionStepListExecutionStep = executionStepListExecutionStep.getTestCaseExecution(); + executionStepListExecutionStep.setTestCaseExecution(testCaseExecution); + executionStepListExecutionStep = em.merge(executionStepListExecutionStep); + if (oldTestCaseExecutionOfExecutionStepListExecutionStep != null) { + oldTestCaseExecutionOfExecutionStepListExecutionStep.getExecutionStepList().remove(executionStepListExecutionStep); + oldTestCaseExecutionOfExecutionStepListExecutionStep = em.merge(oldTestCaseExecutionOfExecutionStepListExecutionStep); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(TestCaseExecution testCaseExecution) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + TestCaseExecution persistentTestCaseExecution = em.find(TestCaseExecution.class, testCaseExecution.getId()); + List executionStepListOld = persistentTestCaseExecution.getExecutionStepList(); + List executionStepListNew = testCaseExecution.getExecutionStepList(); + List illegalOrphanMessages = null; + for (ExecutionStep executionStepListOldExecutionStep : executionStepListOld) { + if (!executionStepListNew.contains(executionStepListOldExecutionStep)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain ExecutionStep " + executionStepListOldExecutionStep + " since its testCaseExecution field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedExecutionStepListNew = new ArrayList<>(); + for (ExecutionStep executionStepListNewExecutionStepToAttach : executionStepListNew) { + executionStepListNewExecutionStepToAttach = em.getReference(executionStepListNewExecutionStepToAttach.getClass(), executionStepListNewExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepListNew.add(executionStepListNewExecutionStepToAttach); + } + executionStepListNew = attachedExecutionStepListNew; + testCaseExecution.setExecutionStepList(executionStepListNew); + testCaseExecution = em.merge(testCaseExecution); + for (ExecutionStep executionStepListNewExecutionStep : executionStepListNew) { + if (!executionStepListOld.contains(executionStepListNewExecutionStep)) { + TestCaseExecution oldTestCaseExecutionOfExecutionStepListNewExecutionStep = executionStepListNewExecutionStep.getTestCaseExecution(); + executionStepListNewExecutionStep.setTestCaseExecution(testCaseExecution); + executionStepListNewExecutionStep = em.merge(executionStepListNewExecutionStep); + if (oldTestCaseExecutionOfExecutionStepListNewExecutionStep != null && !oldTestCaseExecutionOfExecutionStepListNewExecutionStep.equals(testCaseExecution)) { + oldTestCaseExecutionOfExecutionStepListNewExecutionStep.getExecutionStepList().remove(executionStepListNewExecutionStep); + oldTestCaseExecutionOfExecutionStepListNewExecutionStep = em.merge(oldTestCaseExecutionOfExecutionStepListNewExecutionStep); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = testCaseExecution.getId(); + if (findTestCaseExecution(id) == null) { + throw new NonexistentEntityException("The testCaseExecution with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + TestCaseExecution testCaseExecution; + try { + testCaseExecution = em.getReference(TestCaseExecution.class, id); + testCaseExecution.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The testCaseExecution with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List executionStepListOrphanCheck = testCaseExecution.getExecutionStepList(); + for (ExecutionStep executionStepListOrphanCheckExecutionStep : executionStepListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This TestCaseExecution (" + testCaseExecution + ") cannot be destroyed since the ExecutionStep " + executionStepListOrphanCheckExecutionStep + " in its executionStepList field has a non-nullable testCaseExecution field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(testCaseExecution); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findTestCaseExecutionEntities() { + return findTestCaseExecutionEntities(true, -1, -1); + } + + public List findTestCaseExecutionEntities(int maxResults, int firstResult) { + return findTestCaseExecutionEntities(false, maxResults, firstResult); + } + + private List findTestCaseExecutionEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(TestCaseExecution.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public TestCaseExecution findTestCaseExecution(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(TestCaseExecution.class, id); + } + finally { + em.close(); + } + } + + public int getTestCaseExecutionCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(TestCaseExecution.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestCaseJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestCaseJpaController.java index 47b67f17..aeeee3df 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestCaseJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestCaseJpaController.java @@ -13,303 +13,303 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.TestPlan; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.RiskControlHasTestCase; -import com.validation.manager.core.db.Step; -import com.validation.manager.core.db.TestCase; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class TestCaseJpaController implements Serializable { - - public TestCaseJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(TestCase testCase) { - if (testCase.getTestPlanList() == null) { - testCase.setTestPlanList(new ArrayList()); - } - if (testCase.getRiskControlHasTestCaseList() == null) { - testCase.setRiskControlHasTestCaseList(new ArrayList()); - } - if (testCase.getStepList() == null) { - testCase.setStepList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedTestPlanList = new ArrayList(); - for (TestPlan testPlanListTestPlanToAttach : testCase.getTestPlanList()) { - testPlanListTestPlanToAttach = em.getReference(testPlanListTestPlanToAttach.getClass(), testPlanListTestPlanToAttach.getTestPlanPK()); - attachedTestPlanList.add(testPlanListTestPlanToAttach); - } - testCase.setTestPlanList(attachedTestPlanList); - List attachedRiskControlHasTestCaseList = new ArrayList(); - for (RiskControlHasTestCase riskControlHasTestCaseListRiskControlHasTestCaseToAttach : testCase.getRiskControlHasTestCaseList()) { - riskControlHasTestCaseListRiskControlHasTestCaseToAttach = em.getReference(riskControlHasTestCaseListRiskControlHasTestCaseToAttach.getClass(), riskControlHasTestCaseListRiskControlHasTestCaseToAttach.getRiskControlHasTestCasePK()); - attachedRiskControlHasTestCaseList.add(riskControlHasTestCaseListRiskControlHasTestCaseToAttach); - } - testCase.setRiskControlHasTestCaseList(attachedRiskControlHasTestCaseList); - List attachedStepList = new ArrayList(); - for (Step stepListStepToAttach : testCase.getStepList()) { - stepListStepToAttach = em.getReference(stepListStepToAttach.getClass(), stepListStepToAttach.getStepPK()); - attachedStepList.add(stepListStepToAttach); - } - testCase.setStepList(attachedStepList); - em.persist(testCase); - for (TestPlan testPlanListTestPlan : testCase.getTestPlanList()) { - testPlanListTestPlan.getTestCaseList().add(testCase); - testPlanListTestPlan = em.merge(testPlanListTestPlan); - } - for (RiskControlHasTestCase riskControlHasTestCaseListRiskControlHasTestCase : testCase.getRiskControlHasTestCaseList()) { - TestCase oldTestCaseOfRiskControlHasTestCaseListRiskControlHasTestCase = riskControlHasTestCaseListRiskControlHasTestCase.getTestCase(); - riskControlHasTestCaseListRiskControlHasTestCase.setTestCase(testCase); - riskControlHasTestCaseListRiskControlHasTestCase = em.merge(riskControlHasTestCaseListRiskControlHasTestCase); - if (oldTestCaseOfRiskControlHasTestCaseListRiskControlHasTestCase != null) { - oldTestCaseOfRiskControlHasTestCaseListRiskControlHasTestCase.getRiskControlHasTestCaseList().remove(riskControlHasTestCaseListRiskControlHasTestCase); - oldTestCaseOfRiskControlHasTestCaseListRiskControlHasTestCase = em.merge(oldTestCaseOfRiskControlHasTestCaseListRiskControlHasTestCase); - } - } - for (Step stepListStep : testCase.getStepList()) { - TestCase oldTestCaseOfStepListStep = stepListStep.getTestCase(); - stepListStep.setTestCase(testCase); - stepListStep = em.merge(stepListStep); - if (oldTestCaseOfStepListStep != null) { - oldTestCaseOfStepListStep.getStepList().remove(stepListStep); - oldTestCaseOfStepListStep = em.merge(oldTestCaseOfStepListStep); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(TestCase testCase) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - TestCase persistentTestCase = em.find(TestCase.class, testCase.getId()); - List testPlanListOld = persistentTestCase.getTestPlanList(); - List testPlanListNew = testCase.getTestPlanList(); - List riskControlHasTestCaseListOld = persistentTestCase.getRiskControlHasTestCaseList(); - List riskControlHasTestCaseListNew = testCase.getRiskControlHasTestCaseList(); - List stepListOld = persistentTestCase.getStepList(); - List stepListNew = testCase.getStepList(); - List illegalOrphanMessages = null; - for (RiskControlHasTestCase riskControlHasTestCaseListOldRiskControlHasTestCase : riskControlHasTestCaseListOld) { - if (!riskControlHasTestCaseListNew.contains(riskControlHasTestCaseListOldRiskControlHasTestCase)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain RiskControlHasTestCase " + riskControlHasTestCaseListOldRiskControlHasTestCase + " since its testCase field is not nullable."); - } - } - for (Step stepListOldStep : stepListOld) { - if (!stepListNew.contains(stepListOldStep)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain Step " + stepListOldStep + " since its testCase field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedTestPlanListNew = new ArrayList(); - for (TestPlan testPlanListNewTestPlanToAttach : testPlanListNew) { - testPlanListNewTestPlanToAttach = em.getReference(testPlanListNewTestPlanToAttach.getClass(), testPlanListNewTestPlanToAttach.getTestPlanPK()); - attachedTestPlanListNew.add(testPlanListNewTestPlanToAttach); - } - testPlanListNew = attachedTestPlanListNew; - testCase.setTestPlanList(testPlanListNew); - List attachedRiskControlHasTestCaseListNew = new ArrayList(); - for (RiskControlHasTestCase riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach : riskControlHasTestCaseListNew) { - riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach = em.getReference(riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach.getClass(), riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach.getRiskControlHasTestCasePK()); - attachedRiskControlHasTestCaseListNew.add(riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach); - } - riskControlHasTestCaseListNew = attachedRiskControlHasTestCaseListNew; - testCase.setRiskControlHasTestCaseList(riskControlHasTestCaseListNew); - List attachedStepListNew = new ArrayList(); - for (Step stepListNewStepToAttach : stepListNew) { - stepListNewStepToAttach = em.getReference(stepListNewStepToAttach.getClass(), stepListNewStepToAttach.getStepPK()); - attachedStepListNew.add(stepListNewStepToAttach); - } - stepListNew = attachedStepListNew; - testCase.setStepList(stepListNew); - testCase = em.merge(testCase); - for (TestPlan testPlanListOldTestPlan : testPlanListOld) { - if (!testPlanListNew.contains(testPlanListOldTestPlan)) { - testPlanListOldTestPlan.getTestCaseList().remove(testCase); - testPlanListOldTestPlan = em.merge(testPlanListOldTestPlan); - } - } - for (TestPlan testPlanListNewTestPlan : testPlanListNew) { - if (!testPlanListOld.contains(testPlanListNewTestPlan)) { - testPlanListNewTestPlan.getTestCaseList().add(testCase); - testPlanListNewTestPlan = em.merge(testPlanListNewTestPlan); - } - } - for (RiskControlHasTestCase riskControlHasTestCaseListNewRiskControlHasTestCase : riskControlHasTestCaseListNew) { - if (!riskControlHasTestCaseListOld.contains(riskControlHasTestCaseListNewRiskControlHasTestCase)) { - TestCase oldTestCaseOfRiskControlHasTestCaseListNewRiskControlHasTestCase = riskControlHasTestCaseListNewRiskControlHasTestCase.getTestCase(); - riskControlHasTestCaseListNewRiskControlHasTestCase.setTestCase(testCase); - riskControlHasTestCaseListNewRiskControlHasTestCase = em.merge(riskControlHasTestCaseListNewRiskControlHasTestCase); - if (oldTestCaseOfRiskControlHasTestCaseListNewRiskControlHasTestCase != null && !oldTestCaseOfRiskControlHasTestCaseListNewRiskControlHasTestCase.equals(testCase)) { - oldTestCaseOfRiskControlHasTestCaseListNewRiskControlHasTestCase.getRiskControlHasTestCaseList().remove(riskControlHasTestCaseListNewRiskControlHasTestCase); - oldTestCaseOfRiskControlHasTestCaseListNewRiskControlHasTestCase = em.merge(oldTestCaseOfRiskControlHasTestCaseListNewRiskControlHasTestCase); - } - } - } - for (Step stepListNewStep : stepListNew) { - if (!stepListOld.contains(stepListNewStep)) { - TestCase oldTestCaseOfStepListNewStep = stepListNewStep.getTestCase(); - stepListNewStep.setTestCase(testCase); - stepListNewStep = em.merge(stepListNewStep); - if (oldTestCaseOfStepListNewStep != null && !oldTestCaseOfStepListNewStep.equals(testCase)) { - oldTestCaseOfStepListNewStep.getStepList().remove(stepListNewStep); - oldTestCaseOfStepListNewStep = em.merge(oldTestCaseOfStepListNewStep); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = testCase.getId(); - if (findTestCase(id) == null) { - throw new NonexistentEntityException("The testCase with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - TestCase testCase; - try { - testCase = em.getReference(TestCase.class, id); - testCase.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The testCase with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List riskControlHasTestCaseListOrphanCheck = testCase.getRiskControlHasTestCaseList(); - for (RiskControlHasTestCase riskControlHasTestCaseListOrphanCheckRiskControlHasTestCase : riskControlHasTestCaseListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This TestCase (" + testCase + ") cannot be destroyed since the RiskControlHasTestCase " + riskControlHasTestCaseListOrphanCheckRiskControlHasTestCase + " in its riskControlHasTestCaseList field has a non-nullable testCase field."); - } - List stepListOrphanCheck = testCase.getStepList(); - for (Step stepListOrphanCheckStep : stepListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This TestCase (" + testCase + ") cannot be destroyed since the Step " + stepListOrphanCheckStep + " in its stepList field has a non-nullable testCase field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List testPlanList = testCase.getTestPlanList(); - for (TestPlan testPlanListTestPlan : testPlanList) { - testPlanListTestPlan.getTestCaseList().remove(testCase); - testPlanListTestPlan = em.merge(testPlanListTestPlan); - } - em.remove(testCase); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findTestCaseEntities() { - return findTestCaseEntities(true, -1, -1); - } - - public List findTestCaseEntities(int maxResults, int firstResult) { - return findTestCaseEntities(false, maxResults, firstResult); - } - - private List findTestCaseEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(TestCase.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public TestCase findTestCase(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(TestCase.class, id); - } - finally { - em.close(); - } - } - - public int getTestCaseCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(TestCase.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.TestPlan; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.RiskControlHasTestCase; +import com.validation.manager.core.db.Step; +import com.validation.manager.core.db.TestCase; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class TestCaseJpaController implements Serializable { + + public TestCaseJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(TestCase testCase) { + if (testCase.getTestPlanList() == null) { + testCase.setTestPlanList(new ArrayList<>()); + } + if (testCase.getRiskControlHasTestCaseList() == null) { + testCase.setRiskControlHasTestCaseList(new ArrayList<>()); + } + if (testCase.getStepList() == null) { + testCase.setStepList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedTestPlanList = new ArrayList<>(); + for (TestPlan testPlanListTestPlanToAttach : testCase.getTestPlanList()) { + testPlanListTestPlanToAttach = em.getReference(testPlanListTestPlanToAttach.getClass(), testPlanListTestPlanToAttach.getTestPlanPK()); + attachedTestPlanList.add(testPlanListTestPlanToAttach); + } + testCase.setTestPlanList(attachedTestPlanList); + List attachedRiskControlHasTestCaseList = new ArrayList<>(); + for (RiskControlHasTestCase riskControlHasTestCaseListRiskControlHasTestCaseToAttach : testCase.getRiskControlHasTestCaseList()) { + riskControlHasTestCaseListRiskControlHasTestCaseToAttach = em.getReference(riskControlHasTestCaseListRiskControlHasTestCaseToAttach.getClass(), riskControlHasTestCaseListRiskControlHasTestCaseToAttach.getRiskControlHasTestCasePK()); + attachedRiskControlHasTestCaseList.add(riskControlHasTestCaseListRiskControlHasTestCaseToAttach); + } + testCase.setRiskControlHasTestCaseList(attachedRiskControlHasTestCaseList); + List attachedStepList = new ArrayList<>(); + for (Step stepListStepToAttach : testCase.getStepList()) { + stepListStepToAttach = em.getReference(stepListStepToAttach.getClass(), stepListStepToAttach.getStepPK()); + attachedStepList.add(stepListStepToAttach); + } + testCase.setStepList(attachedStepList); + em.persist(testCase); + for (TestPlan testPlanListTestPlan : testCase.getTestPlanList()) { + testPlanListTestPlan.getTestCaseList().add(testCase); + testPlanListTestPlan = em.merge(testPlanListTestPlan); + } + for (RiskControlHasTestCase riskControlHasTestCaseListRiskControlHasTestCase : testCase.getRiskControlHasTestCaseList()) { + TestCase oldTestCaseOfRiskControlHasTestCaseListRiskControlHasTestCase = riskControlHasTestCaseListRiskControlHasTestCase.getTestCase(); + riskControlHasTestCaseListRiskControlHasTestCase.setTestCase(testCase); + riskControlHasTestCaseListRiskControlHasTestCase = em.merge(riskControlHasTestCaseListRiskControlHasTestCase); + if (oldTestCaseOfRiskControlHasTestCaseListRiskControlHasTestCase != null) { + oldTestCaseOfRiskControlHasTestCaseListRiskControlHasTestCase.getRiskControlHasTestCaseList().remove(riskControlHasTestCaseListRiskControlHasTestCase); + oldTestCaseOfRiskControlHasTestCaseListRiskControlHasTestCase = em.merge(oldTestCaseOfRiskControlHasTestCaseListRiskControlHasTestCase); + } + } + for (Step stepListStep : testCase.getStepList()) { + TestCase oldTestCaseOfStepListStep = stepListStep.getTestCase(); + stepListStep.setTestCase(testCase); + stepListStep = em.merge(stepListStep); + if (oldTestCaseOfStepListStep != null) { + oldTestCaseOfStepListStep.getStepList().remove(stepListStep); + oldTestCaseOfStepListStep = em.merge(oldTestCaseOfStepListStep); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(TestCase testCase) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + TestCase persistentTestCase = em.find(TestCase.class, testCase.getId()); + List testPlanListOld = persistentTestCase.getTestPlanList(); + List testPlanListNew = testCase.getTestPlanList(); + List riskControlHasTestCaseListOld = persistentTestCase.getRiskControlHasTestCaseList(); + List riskControlHasTestCaseListNew = testCase.getRiskControlHasTestCaseList(); + List stepListOld = persistentTestCase.getStepList(); + List stepListNew = testCase.getStepList(); + List illegalOrphanMessages = null; + for (RiskControlHasTestCase riskControlHasTestCaseListOldRiskControlHasTestCase : riskControlHasTestCaseListOld) { + if (!riskControlHasTestCaseListNew.contains(riskControlHasTestCaseListOldRiskControlHasTestCase)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain RiskControlHasTestCase " + riskControlHasTestCaseListOldRiskControlHasTestCase + " since its testCase field is not nullable."); + } + } + for (Step stepListOldStep : stepListOld) { + if (!stepListNew.contains(stepListOldStep)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain Step " + stepListOldStep + " since its testCase field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedTestPlanListNew = new ArrayList<>(); + for (TestPlan testPlanListNewTestPlanToAttach : testPlanListNew) { + testPlanListNewTestPlanToAttach = em.getReference(testPlanListNewTestPlanToAttach.getClass(), testPlanListNewTestPlanToAttach.getTestPlanPK()); + attachedTestPlanListNew.add(testPlanListNewTestPlanToAttach); + } + testPlanListNew = attachedTestPlanListNew; + testCase.setTestPlanList(testPlanListNew); + List attachedRiskControlHasTestCaseListNew = new ArrayList<>(); + for (RiskControlHasTestCase riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach : riskControlHasTestCaseListNew) { + riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach = em.getReference(riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach.getClass(), riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach.getRiskControlHasTestCasePK()); + attachedRiskControlHasTestCaseListNew.add(riskControlHasTestCaseListNewRiskControlHasTestCaseToAttach); + } + riskControlHasTestCaseListNew = attachedRiskControlHasTestCaseListNew; + testCase.setRiskControlHasTestCaseList(riskControlHasTestCaseListNew); + List attachedStepListNew = new ArrayList<>(); + for (Step stepListNewStepToAttach : stepListNew) { + stepListNewStepToAttach = em.getReference(stepListNewStepToAttach.getClass(), stepListNewStepToAttach.getStepPK()); + attachedStepListNew.add(stepListNewStepToAttach); + } + stepListNew = attachedStepListNew; + testCase.setStepList(stepListNew); + testCase = em.merge(testCase); + for (TestPlan testPlanListOldTestPlan : testPlanListOld) { + if (!testPlanListNew.contains(testPlanListOldTestPlan)) { + testPlanListOldTestPlan.getTestCaseList().remove(testCase); + testPlanListOldTestPlan = em.merge(testPlanListOldTestPlan); + } + } + for (TestPlan testPlanListNewTestPlan : testPlanListNew) { + if (!testPlanListOld.contains(testPlanListNewTestPlan)) { + testPlanListNewTestPlan.getTestCaseList().add(testCase); + testPlanListNewTestPlan = em.merge(testPlanListNewTestPlan); + } + } + for (RiskControlHasTestCase riskControlHasTestCaseListNewRiskControlHasTestCase : riskControlHasTestCaseListNew) { + if (!riskControlHasTestCaseListOld.contains(riskControlHasTestCaseListNewRiskControlHasTestCase)) { + TestCase oldTestCaseOfRiskControlHasTestCaseListNewRiskControlHasTestCase = riskControlHasTestCaseListNewRiskControlHasTestCase.getTestCase(); + riskControlHasTestCaseListNewRiskControlHasTestCase.setTestCase(testCase); + riskControlHasTestCaseListNewRiskControlHasTestCase = em.merge(riskControlHasTestCaseListNewRiskControlHasTestCase); + if (oldTestCaseOfRiskControlHasTestCaseListNewRiskControlHasTestCase != null && !oldTestCaseOfRiskControlHasTestCaseListNewRiskControlHasTestCase.equals(testCase)) { + oldTestCaseOfRiskControlHasTestCaseListNewRiskControlHasTestCase.getRiskControlHasTestCaseList().remove(riskControlHasTestCaseListNewRiskControlHasTestCase); + oldTestCaseOfRiskControlHasTestCaseListNewRiskControlHasTestCase = em.merge(oldTestCaseOfRiskControlHasTestCaseListNewRiskControlHasTestCase); + } + } + } + for (Step stepListNewStep : stepListNew) { + if (!stepListOld.contains(stepListNewStep)) { + TestCase oldTestCaseOfStepListNewStep = stepListNewStep.getTestCase(); + stepListNewStep.setTestCase(testCase); + stepListNewStep = em.merge(stepListNewStep); + if (oldTestCaseOfStepListNewStep != null && !oldTestCaseOfStepListNewStep.equals(testCase)) { + oldTestCaseOfStepListNewStep.getStepList().remove(stepListNewStep); + oldTestCaseOfStepListNewStep = em.merge(oldTestCaseOfStepListNewStep); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = testCase.getId(); + if (findTestCase(id) == null) { + throw new NonexistentEntityException("The testCase with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + TestCase testCase; + try { + testCase = em.getReference(TestCase.class, id); + testCase.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The testCase with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List riskControlHasTestCaseListOrphanCheck = testCase.getRiskControlHasTestCaseList(); + for (RiskControlHasTestCase riskControlHasTestCaseListOrphanCheckRiskControlHasTestCase : riskControlHasTestCaseListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This TestCase (" + testCase + ") cannot be destroyed since the RiskControlHasTestCase " + riskControlHasTestCaseListOrphanCheckRiskControlHasTestCase + " in its riskControlHasTestCaseList field has a non-nullable testCase field."); + } + List stepListOrphanCheck = testCase.getStepList(); + for (Step stepListOrphanCheckStep : stepListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This TestCase (" + testCase + ") cannot be destroyed since the Step " + stepListOrphanCheckStep + " in its stepList field has a non-nullable testCase field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List testPlanList = testCase.getTestPlanList(); + for (TestPlan testPlanListTestPlan : testPlanList) { + testPlanListTestPlan.getTestCaseList().remove(testCase); + testPlanListTestPlan = em.merge(testPlanListTestPlan); + } + em.remove(testCase); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findTestCaseEntities() { + return findTestCaseEntities(true, -1, -1); + } + + public List findTestCaseEntities(int maxResults, int firstResult) { + return findTestCaseEntities(false, maxResults, firstResult); + } + + private List findTestCaseEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(TestCase.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public TestCase findTestCase(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(TestCase.class, id); + } + finally { + em.close(); + } + } + + public int getTestCaseCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(TestCase.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestPlanJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestPlanJpaController.java index 764716b7..ffd165a6 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestPlanJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestPlanJpaController.java @@ -13,368 +13,368 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.TestPlan; -import com.validation.manager.core.db.TestProject; -import com.validation.manager.core.db.TestCase; -import com.validation.manager.core.db.TestPlanPK; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.UserTestPlanRole; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class TestPlanJpaController implements Serializable { - - public TestPlanJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(TestPlan testPlan) throws PreexistingEntityException, Exception { - if (testPlan.getTestPlanPK() == null) { - testPlan.setTestPlanPK(new TestPlanPK()); - } - if (testPlan.getTestCaseList() == null) { - testPlan.setTestCaseList(new ArrayList()); - } - if (testPlan.getTestPlanList() == null) { - testPlan.setTestPlanList(new ArrayList()); - } - if (testPlan.getUserTestPlanRoleList() == null) { - testPlan.setUserTestPlanRoleList(new ArrayList()); - } - testPlan.getTestPlanPK().setTestProjectId(testPlan.getTestProject().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - TestPlan testPlanRel = testPlan.getTestPlan(); - if (testPlanRel != null) { - testPlanRel = em.getReference(testPlanRel.getClass(), testPlanRel.getTestPlanPK()); - testPlan.setTestPlan(testPlanRel); - } - TestProject testProject = testPlan.getTestProject(); - if (testProject != null) { - testProject = em.getReference(testProject.getClass(), testProject.getId()); - testPlan.setTestProject(testProject); - } - List attachedTestCaseList = new ArrayList(); - for (TestCase testCaseListTestCaseToAttach : testPlan.getTestCaseList()) { - testCaseListTestCaseToAttach = em.getReference(testCaseListTestCaseToAttach.getClass(), testCaseListTestCaseToAttach.getId()); - attachedTestCaseList.add(testCaseListTestCaseToAttach); - } - testPlan.setTestCaseList(attachedTestCaseList); - List attachedTestPlanList = new ArrayList(); - for (TestPlan testPlanListTestPlanToAttach : testPlan.getTestPlanList()) { - testPlanListTestPlanToAttach = em.getReference(testPlanListTestPlanToAttach.getClass(), testPlanListTestPlanToAttach.getTestPlanPK()); - attachedTestPlanList.add(testPlanListTestPlanToAttach); - } - testPlan.setTestPlanList(attachedTestPlanList); - List attachedUserTestPlanRoleList = new ArrayList(); - for (UserTestPlanRole userTestPlanRoleListUserTestPlanRoleToAttach : testPlan.getUserTestPlanRoleList()) { - userTestPlanRoleListUserTestPlanRoleToAttach = em.getReference(userTestPlanRoleListUserTestPlanRoleToAttach.getClass(), userTestPlanRoleListUserTestPlanRoleToAttach.getUserTestPlanRolePK()); - attachedUserTestPlanRoleList.add(userTestPlanRoleListUserTestPlanRoleToAttach); - } - testPlan.setUserTestPlanRoleList(attachedUserTestPlanRoleList); - em.persist(testPlan); - if (testPlanRel != null) { - testPlanRel.getTestPlanList().add(testPlan); - testPlanRel = em.merge(testPlanRel); - } - if (testProject != null) { - testProject.getTestPlanList().add(testPlan); - testProject = em.merge(testProject); - } - for (TestCase testCaseListTestCase : testPlan.getTestCaseList()) { - testCaseListTestCase.getTestPlanList().add(testPlan); - testCaseListTestCase = em.merge(testCaseListTestCase); - } - for (TestPlan testPlanListTestPlan : testPlan.getTestPlanList()) { - TestPlan oldTestPlanOfTestPlanListTestPlan = testPlanListTestPlan.getTestPlan(); - testPlanListTestPlan.setTestPlan(testPlan); - testPlanListTestPlan = em.merge(testPlanListTestPlan); - if (oldTestPlanOfTestPlanListTestPlan != null) { - oldTestPlanOfTestPlanListTestPlan.getTestPlanList().remove(testPlanListTestPlan); - oldTestPlanOfTestPlanListTestPlan = em.merge(oldTestPlanOfTestPlanListTestPlan); - } - } - for (UserTestPlanRole userTestPlanRoleListUserTestPlanRole : testPlan.getUserTestPlanRoleList()) { - TestPlan oldTestPlanOfUserTestPlanRoleListUserTestPlanRole = userTestPlanRoleListUserTestPlanRole.getTestPlan(); - userTestPlanRoleListUserTestPlanRole.setTestPlan(testPlan); - userTestPlanRoleListUserTestPlanRole = em.merge(userTestPlanRoleListUserTestPlanRole); - if (oldTestPlanOfUserTestPlanRoleListUserTestPlanRole != null) { - oldTestPlanOfUserTestPlanRoleListUserTestPlanRole.getUserTestPlanRoleList().remove(userTestPlanRoleListUserTestPlanRole); - oldTestPlanOfUserTestPlanRoleListUserTestPlanRole = em.merge(oldTestPlanOfUserTestPlanRoleListUserTestPlanRole); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - if (findTestPlan(testPlan.getTestPlanPK()) != null) { - throw new PreexistingEntityException("TestPlan " + testPlan + " already exists.", ex); - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(TestPlan testPlan) throws IllegalOrphanException, NonexistentEntityException, Exception { - testPlan.getTestPlanPK().setTestProjectId(testPlan.getTestProject().getId()); - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - TestPlan persistentTestPlan = em.find(TestPlan.class, testPlan.getTestPlanPK()); - TestPlan testPlanRelOld = persistentTestPlan.getTestPlan(); - TestPlan testPlanRelNew = testPlan.getTestPlan(); - TestProject testProjectOld = persistentTestPlan.getTestProject(); - TestProject testProjectNew = testPlan.getTestProject(); - List testCaseListOld = persistentTestPlan.getTestCaseList(); - List testCaseListNew = testPlan.getTestCaseList(); - List testPlanListOld = persistentTestPlan.getTestPlanList(); - List testPlanListNew = testPlan.getTestPlanList(); - List userTestPlanRoleListOld = persistentTestPlan.getUserTestPlanRoleList(); - List userTestPlanRoleListNew = testPlan.getUserTestPlanRoleList(); - List illegalOrphanMessages = null; - for (UserTestPlanRole userTestPlanRoleListOldUserTestPlanRole : userTestPlanRoleListOld) { - if (!userTestPlanRoleListNew.contains(userTestPlanRoleListOldUserTestPlanRole)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserTestPlanRole " + userTestPlanRoleListOldUserTestPlanRole + " since its testPlan field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (testPlanRelNew != null) { - testPlanRelNew = em.getReference(testPlanRelNew.getClass(), testPlanRelNew.getTestPlanPK()); - testPlan.setTestPlan(testPlanRelNew); - } - if (testProjectNew != null) { - testProjectNew = em.getReference(testProjectNew.getClass(), testProjectNew.getId()); - testPlan.setTestProject(testProjectNew); - } - List attachedTestCaseListNew = new ArrayList(); - for (TestCase testCaseListNewTestCaseToAttach : testCaseListNew) { - testCaseListNewTestCaseToAttach = em.getReference(testCaseListNewTestCaseToAttach.getClass(), testCaseListNewTestCaseToAttach.getId()); - attachedTestCaseListNew.add(testCaseListNewTestCaseToAttach); - } - testCaseListNew = attachedTestCaseListNew; - testPlan.setTestCaseList(testCaseListNew); - List attachedTestPlanListNew = new ArrayList(); - for (TestPlan testPlanListNewTestPlanToAttach : testPlanListNew) { - testPlanListNewTestPlanToAttach = em.getReference(testPlanListNewTestPlanToAttach.getClass(), testPlanListNewTestPlanToAttach.getTestPlanPK()); - attachedTestPlanListNew.add(testPlanListNewTestPlanToAttach); - } - testPlanListNew = attachedTestPlanListNew; - testPlan.setTestPlanList(testPlanListNew); - List attachedUserTestPlanRoleListNew = new ArrayList(); - for (UserTestPlanRole userTestPlanRoleListNewUserTestPlanRoleToAttach : userTestPlanRoleListNew) { - userTestPlanRoleListNewUserTestPlanRoleToAttach = em.getReference(userTestPlanRoleListNewUserTestPlanRoleToAttach.getClass(), userTestPlanRoleListNewUserTestPlanRoleToAttach.getUserTestPlanRolePK()); - attachedUserTestPlanRoleListNew.add(userTestPlanRoleListNewUserTestPlanRoleToAttach); - } - userTestPlanRoleListNew = attachedUserTestPlanRoleListNew; - testPlan.setUserTestPlanRoleList(userTestPlanRoleListNew); - testPlan = em.merge(testPlan); - if (testPlanRelOld != null && !testPlanRelOld.equals(testPlanRelNew)) { - testPlanRelOld.getTestPlanList().remove(testPlan); - testPlanRelOld = em.merge(testPlanRelOld); - } - if (testPlanRelNew != null && !testPlanRelNew.equals(testPlanRelOld)) { - testPlanRelNew.getTestPlanList().add(testPlan); - testPlanRelNew = em.merge(testPlanRelNew); - } - if (testProjectOld != null && !testProjectOld.equals(testProjectNew)) { - testProjectOld.getTestPlanList().remove(testPlan); - testProjectOld = em.merge(testProjectOld); - } - if (testProjectNew != null && !testProjectNew.equals(testProjectOld)) { - testProjectNew.getTestPlanList().add(testPlan); - testProjectNew = em.merge(testProjectNew); - } - for (TestCase testCaseListOldTestCase : testCaseListOld) { - if (!testCaseListNew.contains(testCaseListOldTestCase)) { - testCaseListOldTestCase.getTestPlanList().remove(testPlan); - testCaseListOldTestCase = em.merge(testCaseListOldTestCase); - } - } - for (TestCase testCaseListNewTestCase : testCaseListNew) { - if (!testCaseListOld.contains(testCaseListNewTestCase)) { - testCaseListNewTestCase.getTestPlanList().add(testPlan); - testCaseListNewTestCase = em.merge(testCaseListNewTestCase); - } - } - for (TestPlan testPlanListOldTestPlan : testPlanListOld) { - if (!testPlanListNew.contains(testPlanListOldTestPlan)) { - testPlanListOldTestPlan.setTestPlan(null); - testPlanListOldTestPlan = em.merge(testPlanListOldTestPlan); - } - } - for (TestPlan testPlanListNewTestPlan : testPlanListNew) { - if (!testPlanListOld.contains(testPlanListNewTestPlan)) { - TestPlan oldTestPlanOfTestPlanListNewTestPlan = testPlanListNewTestPlan.getTestPlan(); - testPlanListNewTestPlan.setTestPlan(testPlan); - testPlanListNewTestPlan = em.merge(testPlanListNewTestPlan); - if (oldTestPlanOfTestPlanListNewTestPlan != null && !oldTestPlanOfTestPlanListNewTestPlan.equals(testPlan)) { - oldTestPlanOfTestPlanListNewTestPlan.getTestPlanList().remove(testPlanListNewTestPlan); - oldTestPlanOfTestPlanListNewTestPlan = em.merge(oldTestPlanOfTestPlanListNewTestPlan); - } - } - } - for (UserTestPlanRole userTestPlanRoleListNewUserTestPlanRole : userTestPlanRoleListNew) { - if (!userTestPlanRoleListOld.contains(userTestPlanRoleListNewUserTestPlanRole)) { - TestPlan oldTestPlanOfUserTestPlanRoleListNewUserTestPlanRole = userTestPlanRoleListNewUserTestPlanRole.getTestPlan(); - userTestPlanRoleListNewUserTestPlanRole.setTestPlan(testPlan); - userTestPlanRoleListNewUserTestPlanRole = em.merge(userTestPlanRoleListNewUserTestPlanRole); - if (oldTestPlanOfUserTestPlanRoleListNewUserTestPlanRole != null && !oldTestPlanOfUserTestPlanRoleListNewUserTestPlanRole.equals(testPlan)) { - oldTestPlanOfUserTestPlanRoleListNewUserTestPlanRole.getUserTestPlanRoleList().remove(userTestPlanRoleListNewUserTestPlanRole); - oldTestPlanOfUserTestPlanRoleListNewUserTestPlanRole = em.merge(oldTestPlanOfUserTestPlanRoleListNewUserTestPlanRole); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - TestPlanPK id = testPlan.getTestPlanPK(); - if (findTestPlan(id) == null) { - throw new NonexistentEntityException("The testPlan with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(TestPlanPK id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - TestPlan testPlan; - try { - testPlan = em.getReference(TestPlan.class, id); - testPlan.getTestPlanPK(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The testPlan with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List userTestPlanRoleListOrphanCheck = testPlan.getUserTestPlanRoleList(); - for (UserTestPlanRole userTestPlanRoleListOrphanCheckUserTestPlanRole : userTestPlanRoleListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This TestPlan (" + testPlan + ") cannot be destroyed since the UserTestPlanRole " + userTestPlanRoleListOrphanCheckUserTestPlanRole + " in its userTestPlanRoleList field has a non-nullable testPlan field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - TestPlan testPlanRel = testPlan.getTestPlan(); - if (testPlanRel != null) { - testPlanRel.getTestPlanList().remove(testPlan); - testPlanRel = em.merge(testPlanRel); - } - TestProject testProject = testPlan.getTestProject(); - if (testProject != null) { - testProject.getTestPlanList().remove(testPlan); - testProject = em.merge(testProject); - } - List testCaseList = testPlan.getTestCaseList(); - for (TestCase testCaseListTestCase : testCaseList) { - testCaseListTestCase.getTestPlanList().remove(testPlan); - testCaseListTestCase = em.merge(testCaseListTestCase); - } - List testPlanList = testPlan.getTestPlanList(); - for (TestPlan testPlanListTestPlan : testPlanList) { - testPlanListTestPlan.setTestPlan(null); - testPlanListTestPlan = em.merge(testPlanListTestPlan); - } - em.remove(testPlan); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findTestPlanEntities() { - return findTestPlanEntities(true, -1, -1); - } - - public List findTestPlanEntities(int maxResults, int firstResult) { - return findTestPlanEntities(false, maxResults, firstResult); - } - - private List findTestPlanEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(TestPlan.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public TestPlan findTestPlan(TestPlanPK id) { - EntityManager em = getEntityManager(); - try { - return em.find(TestPlan.class, id); - } - finally { - em.close(); - } - } - - public int getTestPlanCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(TestPlan.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.TestPlan; +import com.validation.manager.core.db.TestProject; +import com.validation.manager.core.db.TestCase; +import com.validation.manager.core.db.TestPlanPK; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.UserTestPlanRole; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class TestPlanJpaController implements Serializable { + + public TestPlanJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(TestPlan testPlan) throws PreexistingEntityException, Exception { + if (testPlan.getTestPlanPK() == null) { + testPlan.setTestPlanPK(new TestPlanPK()); + } + if (testPlan.getTestCaseList() == null) { + testPlan.setTestCaseList(new ArrayList<>()); + } + if (testPlan.getTestPlanList() == null) { + testPlan.setTestPlanList(new ArrayList<>()); + } + if (testPlan.getUserTestPlanRoleList() == null) { + testPlan.setUserTestPlanRoleList(new ArrayList<>()); + } + testPlan.getTestPlanPK().setTestProjectId(testPlan.getTestProject().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + TestPlan testPlanRel = testPlan.getTestPlan(); + if (testPlanRel != null) { + testPlanRel = em.getReference(testPlanRel.getClass(), testPlanRel.getTestPlanPK()); + testPlan.setTestPlan(testPlanRel); + } + TestProject testProject = testPlan.getTestProject(); + if (testProject != null) { + testProject = em.getReference(testProject.getClass(), testProject.getId()); + testPlan.setTestProject(testProject); + } + List attachedTestCaseList = new ArrayList<>(); + for (TestCase testCaseListTestCaseToAttach : testPlan.getTestCaseList()) { + testCaseListTestCaseToAttach = em.getReference(testCaseListTestCaseToAttach.getClass(), testCaseListTestCaseToAttach.getId()); + attachedTestCaseList.add(testCaseListTestCaseToAttach); + } + testPlan.setTestCaseList(attachedTestCaseList); + List attachedTestPlanList = new ArrayList<>(); + for (TestPlan testPlanListTestPlanToAttach : testPlan.getTestPlanList()) { + testPlanListTestPlanToAttach = em.getReference(testPlanListTestPlanToAttach.getClass(), testPlanListTestPlanToAttach.getTestPlanPK()); + attachedTestPlanList.add(testPlanListTestPlanToAttach); + } + testPlan.setTestPlanList(attachedTestPlanList); + List attachedUserTestPlanRoleList = new ArrayList<>(); + for (UserTestPlanRole userTestPlanRoleListUserTestPlanRoleToAttach : testPlan.getUserTestPlanRoleList()) { + userTestPlanRoleListUserTestPlanRoleToAttach = em.getReference(userTestPlanRoleListUserTestPlanRoleToAttach.getClass(), userTestPlanRoleListUserTestPlanRoleToAttach.getUserTestPlanRolePK()); + attachedUserTestPlanRoleList.add(userTestPlanRoleListUserTestPlanRoleToAttach); + } + testPlan.setUserTestPlanRoleList(attachedUserTestPlanRoleList); + em.persist(testPlan); + if (testPlanRel != null) { + testPlanRel.getTestPlanList().add(testPlan); + testPlanRel = em.merge(testPlanRel); + } + if (testProject != null) { + testProject.getTestPlanList().add(testPlan); + testProject = em.merge(testProject); + } + for (TestCase testCaseListTestCase : testPlan.getTestCaseList()) { + testCaseListTestCase.getTestPlanList().add(testPlan); + testCaseListTestCase = em.merge(testCaseListTestCase); + } + for (TestPlan testPlanListTestPlan : testPlan.getTestPlanList()) { + TestPlan oldTestPlanOfTestPlanListTestPlan = testPlanListTestPlan.getTestPlan(); + testPlanListTestPlan.setTestPlan(testPlan); + testPlanListTestPlan = em.merge(testPlanListTestPlan); + if (oldTestPlanOfTestPlanListTestPlan != null) { + oldTestPlanOfTestPlanListTestPlan.getTestPlanList().remove(testPlanListTestPlan); + oldTestPlanOfTestPlanListTestPlan = em.merge(oldTestPlanOfTestPlanListTestPlan); + } + } + for (UserTestPlanRole userTestPlanRoleListUserTestPlanRole : testPlan.getUserTestPlanRoleList()) { + TestPlan oldTestPlanOfUserTestPlanRoleListUserTestPlanRole = userTestPlanRoleListUserTestPlanRole.getTestPlan(); + userTestPlanRoleListUserTestPlanRole.setTestPlan(testPlan); + userTestPlanRoleListUserTestPlanRole = em.merge(userTestPlanRoleListUserTestPlanRole); + if (oldTestPlanOfUserTestPlanRoleListUserTestPlanRole != null) { + oldTestPlanOfUserTestPlanRoleListUserTestPlanRole.getUserTestPlanRoleList().remove(userTestPlanRoleListUserTestPlanRole); + oldTestPlanOfUserTestPlanRoleListUserTestPlanRole = em.merge(oldTestPlanOfUserTestPlanRoleListUserTestPlanRole); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + if (findTestPlan(testPlan.getTestPlanPK()) != null) { + throw new PreexistingEntityException("TestPlan " + testPlan + " already exists.", ex); + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(TestPlan testPlan) throws IllegalOrphanException, NonexistentEntityException, Exception { + testPlan.getTestPlanPK().setTestProjectId(testPlan.getTestProject().getId()); + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + TestPlan persistentTestPlan = em.find(TestPlan.class, testPlan.getTestPlanPK()); + TestPlan testPlanRelOld = persistentTestPlan.getTestPlan(); + TestPlan testPlanRelNew = testPlan.getTestPlan(); + TestProject testProjectOld = persistentTestPlan.getTestProject(); + TestProject testProjectNew = testPlan.getTestProject(); + List testCaseListOld = persistentTestPlan.getTestCaseList(); + List testCaseListNew = testPlan.getTestCaseList(); + List testPlanListOld = persistentTestPlan.getTestPlanList(); + List testPlanListNew = testPlan.getTestPlanList(); + List userTestPlanRoleListOld = persistentTestPlan.getUserTestPlanRoleList(); + List userTestPlanRoleListNew = testPlan.getUserTestPlanRoleList(); + List illegalOrphanMessages = null; + for (UserTestPlanRole userTestPlanRoleListOldUserTestPlanRole : userTestPlanRoleListOld) { + if (!userTestPlanRoleListNew.contains(userTestPlanRoleListOldUserTestPlanRole)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserTestPlanRole " + userTestPlanRoleListOldUserTestPlanRole + " since its testPlan field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (testPlanRelNew != null) { + testPlanRelNew = em.getReference(testPlanRelNew.getClass(), testPlanRelNew.getTestPlanPK()); + testPlan.setTestPlan(testPlanRelNew); + } + if (testProjectNew != null) { + testProjectNew = em.getReference(testProjectNew.getClass(), testProjectNew.getId()); + testPlan.setTestProject(testProjectNew); + } + List attachedTestCaseListNew = new ArrayList<>(); + for (TestCase testCaseListNewTestCaseToAttach : testCaseListNew) { + testCaseListNewTestCaseToAttach = em.getReference(testCaseListNewTestCaseToAttach.getClass(), testCaseListNewTestCaseToAttach.getId()); + attachedTestCaseListNew.add(testCaseListNewTestCaseToAttach); + } + testCaseListNew = attachedTestCaseListNew; + testPlan.setTestCaseList(testCaseListNew); + List attachedTestPlanListNew = new ArrayList<>(); + for (TestPlan testPlanListNewTestPlanToAttach : testPlanListNew) { + testPlanListNewTestPlanToAttach = em.getReference(testPlanListNewTestPlanToAttach.getClass(), testPlanListNewTestPlanToAttach.getTestPlanPK()); + attachedTestPlanListNew.add(testPlanListNewTestPlanToAttach); + } + testPlanListNew = attachedTestPlanListNew; + testPlan.setTestPlanList(testPlanListNew); + List attachedUserTestPlanRoleListNew = new ArrayList<>(); + for (UserTestPlanRole userTestPlanRoleListNewUserTestPlanRoleToAttach : userTestPlanRoleListNew) { + userTestPlanRoleListNewUserTestPlanRoleToAttach = em.getReference(userTestPlanRoleListNewUserTestPlanRoleToAttach.getClass(), userTestPlanRoleListNewUserTestPlanRoleToAttach.getUserTestPlanRolePK()); + attachedUserTestPlanRoleListNew.add(userTestPlanRoleListNewUserTestPlanRoleToAttach); + } + userTestPlanRoleListNew = attachedUserTestPlanRoleListNew; + testPlan.setUserTestPlanRoleList(userTestPlanRoleListNew); + testPlan = em.merge(testPlan); + if (testPlanRelOld != null && !testPlanRelOld.equals(testPlanRelNew)) { + testPlanRelOld.getTestPlanList().remove(testPlan); + testPlanRelOld = em.merge(testPlanRelOld); + } + if (testPlanRelNew != null && !testPlanRelNew.equals(testPlanRelOld)) { + testPlanRelNew.getTestPlanList().add(testPlan); + testPlanRelNew = em.merge(testPlanRelNew); + } + if (testProjectOld != null && !testProjectOld.equals(testProjectNew)) { + testProjectOld.getTestPlanList().remove(testPlan); + testProjectOld = em.merge(testProjectOld); + } + if (testProjectNew != null && !testProjectNew.equals(testProjectOld)) { + testProjectNew.getTestPlanList().add(testPlan); + testProjectNew = em.merge(testProjectNew); + } + for (TestCase testCaseListOldTestCase : testCaseListOld) { + if (!testCaseListNew.contains(testCaseListOldTestCase)) { + testCaseListOldTestCase.getTestPlanList().remove(testPlan); + testCaseListOldTestCase = em.merge(testCaseListOldTestCase); + } + } + for (TestCase testCaseListNewTestCase : testCaseListNew) { + if (!testCaseListOld.contains(testCaseListNewTestCase)) { + testCaseListNewTestCase.getTestPlanList().add(testPlan); + testCaseListNewTestCase = em.merge(testCaseListNewTestCase); + } + } + for (TestPlan testPlanListOldTestPlan : testPlanListOld) { + if (!testPlanListNew.contains(testPlanListOldTestPlan)) { + testPlanListOldTestPlan.setTestPlan(null); + testPlanListOldTestPlan = em.merge(testPlanListOldTestPlan); + } + } + for (TestPlan testPlanListNewTestPlan : testPlanListNew) { + if (!testPlanListOld.contains(testPlanListNewTestPlan)) { + TestPlan oldTestPlanOfTestPlanListNewTestPlan = testPlanListNewTestPlan.getTestPlan(); + testPlanListNewTestPlan.setTestPlan(testPlan); + testPlanListNewTestPlan = em.merge(testPlanListNewTestPlan); + if (oldTestPlanOfTestPlanListNewTestPlan != null && !oldTestPlanOfTestPlanListNewTestPlan.equals(testPlan)) { + oldTestPlanOfTestPlanListNewTestPlan.getTestPlanList().remove(testPlanListNewTestPlan); + oldTestPlanOfTestPlanListNewTestPlan = em.merge(oldTestPlanOfTestPlanListNewTestPlan); + } + } + } + for (UserTestPlanRole userTestPlanRoleListNewUserTestPlanRole : userTestPlanRoleListNew) { + if (!userTestPlanRoleListOld.contains(userTestPlanRoleListNewUserTestPlanRole)) { + TestPlan oldTestPlanOfUserTestPlanRoleListNewUserTestPlanRole = userTestPlanRoleListNewUserTestPlanRole.getTestPlan(); + userTestPlanRoleListNewUserTestPlanRole.setTestPlan(testPlan); + userTestPlanRoleListNewUserTestPlanRole = em.merge(userTestPlanRoleListNewUserTestPlanRole); + if (oldTestPlanOfUserTestPlanRoleListNewUserTestPlanRole != null && !oldTestPlanOfUserTestPlanRoleListNewUserTestPlanRole.equals(testPlan)) { + oldTestPlanOfUserTestPlanRoleListNewUserTestPlanRole.getUserTestPlanRoleList().remove(userTestPlanRoleListNewUserTestPlanRole); + oldTestPlanOfUserTestPlanRoleListNewUserTestPlanRole = em.merge(oldTestPlanOfUserTestPlanRoleListNewUserTestPlanRole); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + TestPlanPK id = testPlan.getTestPlanPK(); + if (findTestPlan(id) == null) { + throw new NonexistentEntityException("The testPlan with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(TestPlanPK id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + TestPlan testPlan; + try { + testPlan = em.getReference(TestPlan.class, id); + testPlan.getTestPlanPK(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The testPlan with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List userTestPlanRoleListOrphanCheck = testPlan.getUserTestPlanRoleList(); + for (UserTestPlanRole userTestPlanRoleListOrphanCheckUserTestPlanRole : userTestPlanRoleListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This TestPlan (" + testPlan + ") cannot be destroyed since the UserTestPlanRole " + userTestPlanRoleListOrphanCheckUserTestPlanRole + " in its userTestPlanRoleList field has a non-nullable testPlan field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + TestPlan testPlanRel = testPlan.getTestPlan(); + if (testPlanRel != null) { + testPlanRel.getTestPlanList().remove(testPlan); + testPlanRel = em.merge(testPlanRel); + } + TestProject testProject = testPlan.getTestProject(); + if (testProject != null) { + testProject.getTestPlanList().remove(testPlan); + testProject = em.merge(testProject); + } + List testCaseList = testPlan.getTestCaseList(); + for (TestCase testCaseListTestCase : testCaseList) { + testCaseListTestCase.getTestPlanList().remove(testPlan); + testCaseListTestCase = em.merge(testCaseListTestCase); + } + List testPlanList = testPlan.getTestPlanList(); + for (TestPlan testPlanListTestPlan : testPlanList) { + testPlanListTestPlan.setTestPlan(null); + testPlanListTestPlan = em.merge(testPlanListTestPlan); + } + em.remove(testPlan); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findTestPlanEntities() { + return findTestPlanEntities(true, -1, -1); + } + + public List findTestPlanEntities(int maxResults, int firstResult) { + return findTestPlanEntities(false, maxResults, firstResult); + } + + private List findTestPlanEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(TestPlan.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public TestPlan findTestPlan(TestPlanPK id) { + EntityManager em = getEntityManager(); + try { + return em.find(TestPlan.class, id); + } + finally { + em.close(); + } + } + + public int getTestPlanCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(TestPlan.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestProjectJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestProjectJpaController.java index aeb5ddc4..ff628e31 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestProjectJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/TestProjectJpaController.java @@ -13,303 +13,303 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Project; -import java.util.ArrayList; -import java.util.List; -import com.validation.manager.core.db.UserTestProjectRole; -import com.validation.manager.core.db.TestPlan; -import com.validation.manager.core.db.TestProject; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class TestProjectJpaController implements Serializable { - - public TestProjectJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(TestProject testProject) { - if (testProject.getProjectList() == null) { - testProject.setProjectList(new ArrayList()); - } - if (testProject.getUserTestProjectRoleList() == null) { - testProject.setUserTestProjectRoleList(new ArrayList()); - } - if (testProject.getTestPlanList() == null) { - testProject.setTestPlanList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedProjectList = new ArrayList(); - for (Project projectListProjectToAttach : testProject.getProjectList()) { - projectListProjectToAttach = em.getReference(projectListProjectToAttach.getClass(), projectListProjectToAttach.getId()); - attachedProjectList.add(projectListProjectToAttach); - } - testProject.setProjectList(attachedProjectList); - List attachedUserTestProjectRoleList = new ArrayList(); - for (UserTestProjectRole userTestProjectRoleListUserTestProjectRoleToAttach : testProject.getUserTestProjectRoleList()) { - userTestProjectRoleListUserTestProjectRoleToAttach = em.getReference(userTestProjectRoleListUserTestProjectRoleToAttach.getClass(), userTestProjectRoleListUserTestProjectRoleToAttach.getUserTestProjectRolePK()); - attachedUserTestProjectRoleList.add(userTestProjectRoleListUserTestProjectRoleToAttach); - } - testProject.setUserTestProjectRoleList(attachedUserTestProjectRoleList); - List attachedTestPlanList = new ArrayList(); - for (TestPlan testPlanListTestPlanToAttach : testProject.getTestPlanList()) { - testPlanListTestPlanToAttach = em.getReference(testPlanListTestPlanToAttach.getClass(), testPlanListTestPlanToAttach.getTestPlanPK()); - attachedTestPlanList.add(testPlanListTestPlanToAttach); - } - testProject.setTestPlanList(attachedTestPlanList); - em.persist(testProject); - for (Project projectListProject : testProject.getProjectList()) { - projectListProject.getTestProjectList().add(testProject); - projectListProject = em.merge(projectListProject); - } - for (UserTestProjectRole userTestProjectRoleListUserTestProjectRole : testProject.getUserTestProjectRoleList()) { - TestProject oldTestProjectOfUserTestProjectRoleListUserTestProjectRole = userTestProjectRoleListUserTestProjectRole.getTestProject(); - userTestProjectRoleListUserTestProjectRole.setTestProject(testProject); - userTestProjectRoleListUserTestProjectRole = em.merge(userTestProjectRoleListUserTestProjectRole); - if (oldTestProjectOfUserTestProjectRoleListUserTestProjectRole != null) { - oldTestProjectOfUserTestProjectRoleListUserTestProjectRole.getUserTestProjectRoleList().remove(userTestProjectRoleListUserTestProjectRole); - oldTestProjectOfUserTestProjectRoleListUserTestProjectRole = em.merge(oldTestProjectOfUserTestProjectRoleListUserTestProjectRole); - } - } - for (TestPlan testPlanListTestPlan : testProject.getTestPlanList()) { - TestProject oldTestProjectOfTestPlanListTestPlan = testPlanListTestPlan.getTestProject(); - testPlanListTestPlan.setTestProject(testProject); - testPlanListTestPlan = em.merge(testPlanListTestPlan); - if (oldTestProjectOfTestPlanListTestPlan != null) { - oldTestProjectOfTestPlanListTestPlan.getTestPlanList().remove(testPlanListTestPlan); - oldTestProjectOfTestPlanListTestPlan = em.merge(oldTestProjectOfTestPlanListTestPlan); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(TestProject testProject) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - TestProject persistentTestProject = em.find(TestProject.class, testProject.getId()); - List projectListOld = persistentTestProject.getProjectList(); - List projectListNew = testProject.getProjectList(); - List userTestProjectRoleListOld = persistentTestProject.getUserTestProjectRoleList(); - List userTestProjectRoleListNew = testProject.getUserTestProjectRoleList(); - List testPlanListOld = persistentTestProject.getTestPlanList(); - List testPlanListNew = testProject.getTestPlanList(); - List illegalOrphanMessages = null; - for (UserTestProjectRole userTestProjectRoleListOldUserTestProjectRole : userTestProjectRoleListOld) { - if (!userTestProjectRoleListNew.contains(userTestProjectRoleListOldUserTestProjectRole)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserTestProjectRole " + userTestProjectRoleListOldUserTestProjectRole + " since its testProject field is not nullable."); - } - } - for (TestPlan testPlanListOldTestPlan : testPlanListOld) { - if (!testPlanListNew.contains(testPlanListOldTestPlan)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain TestPlan " + testPlanListOldTestPlan + " since its testProject field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedProjectListNew = new ArrayList(); - for (Project projectListNewProjectToAttach : projectListNew) { - projectListNewProjectToAttach = em.getReference(projectListNewProjectToAttach.getClass(), projectListNewProjectToAttach.getId()); - attachedProjectListNew.add(projectListNewProjectToAttach); - } - projectListNew = attachedProjectListNew; - testProject.setProjectList(projectListNew); - List attachedUserTestProjectRoleListNew = new ArrayList(); - for (UserTestProjectRole userTestProjectRoleListNewUserTestProjectRoleToAttach : userTestProjectRoleListNew) { - userTestProjectRoleListNewUserTestProjectRoleToAttach = em.getReference(userTestProjectRoleListNewUserTestProjectRoleToAttach.getClass(), userTestProjectRoleListNewUserTestProjectRoleToAttach.getUserTestProjectRolePK()); - attachedUserTestProjectRoleListNew.add(userTestProjectRoleListNewUserTestProjectRoleToAttach); - } - userTestProjectRoleListNew = attachedUserTestProjectRoleListNew; - testProject.setUserTestProjectRoleList(userTestProjectRoleListNew); - List attachedTestPlanListNew = new ArrayList(); - for (TestPlan testPlanListNewTestPlanToAttach : testPlanListNew) { - testPlanListNewTestPlanToAttach = em.getReference(testPlanListNewTestPlanToAttach.getClass(), testPlanListNewTestPlanToAttach.getTestPlanPK()); - attachedTestPlanListNew.add(testPlanListNewTestPlanToAttach); - } - testPlanListNew = attachedTestPlanListNew; - testProject.setTestPlanList(testPlanListNew); - testProject = em.merge(testProject); - for (Project projectListOldProject : projectListOld) { - if (!projectListNew.contains(projectListOldProject)) { - projectListOldProject.getTestProjectList().remove(testProject); - projectListOldProject = em.merge(projectListOldProject); - } - } - for (Project projectListNewProject : projectListNew) { - if (!projectListOld.contains(projectListNewProject)) { - projectListNewProject.getTestProjectList().add(testProject); - projectListNewProject = em.merge(projectListNewProject); - } - } - for (UserTestProjectRole userTestProjectRoleListNewUserTestProjectRole : userTestProjectRoleListNew) { - if (!userTestProjectRoleListOld.contains(userTestProjectRoleListNewUserTestProjectRole)) { - TestProject oldTestProjectOfUserTestProjectRoleListNewUserTestProjectRole = userTestProjectRoleListNewUserTestProjectRole.getTestProject(); - userTestProjectRoleListNewUserTestProjectRole.setTestProject(testProject); - userTestProjectRoleListNewUserTestProjectRole = em.merge(userTestProjectRoleListNewUserTestProjectRole); - if (oldTestProjectOfUserTestProjectRoleListNewUserTestProjectRole != null && !oldTestProjectOfUserTestProjectRoleListNewUserTestProjectRole.equals(testProject)) { - oldTestProjectOfUserTestProjectRoleListNewUserTestProjectRole.getUserTestProjectRoleList().remove(userTestProjectRoleListNewUserTestProjectRole); - oldTestProjectOfUserTestProjectRoleListNewUserTestProjectRole = em.merge(oldTestProjectOfUserTestProjectRoleListNewUserTestProjectRole); - } - } - } - for (TestPlan testPlanListNewTestPlan : testPlanListNew) { - if (!testPlanListOld.contains(testPlanListNewTestPlan)) { - TestProject oldTestProjectOfTestPlanListNewTestPlan = testPlanListNewTestPlan.getTestProject(); - testPlanListNewTestPlan.setTestProject(testProject); - testPlanListNewTestPlan = em.merge(testPlanListNewTestPlan); - if (oldTestProjectOfTestPlanListNewTestPlan != null && !oldTestProjectOfTestPlanListNewTestPlan.equals(testProject)) { - oldTestProjectOfTestPlanListNewTestPlan.getTestPlanList().remove(testPlanListNewTestPlan); - oldTestProjectOfTestPlanListNewTestPlan = em.merge(oldTestProjectOfTestPlanListNewTestPlan); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = testProject.getId(); - if (findTestProject(id) == null) { - throw new NonexistentEntityException("The testProject with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - TestProject testProject; - try { - testProject = em.getReference(TestProject.class, id); - testProject.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The testProject with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List userTestProjectRoleListOrphanCheck = testProject.getUserTestProjectRoleList(); - for (UserTestProjectRole userTestProjectRoleListOrphanCheckUserTestProjectRole : userTestProjectRoleListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This TestProject (" + testProject + ") cannot be destroyed since the UserTestProjectRole " + userTestProjectRoleListOrphanCheckUserTestProjectRole + " in its userTestProjectRoleList field has a non-nullable testProject field."); - } - List testPlanListOrphanCheck = testProject.getTestPlanList(); - for (TestPlan testPlanListOrphanCheckTestPlan : testPlanListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This TestProject (" + testProject + ") cannot be destroyed since the TestPlan " + testPlanListOrphanCheckTestPlan + " in its testPlanList field has a non-nullable testProject field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List projectList = testProject.getProjectList(); - for (Project projectListProject : projectList) { - projectListProject.getTestProjectList().remove(testProject); - projectListProject = em.merge(projectListProject); - } - em.remove(testProject); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findTestProjectEntities() { - return findTestProjectEntities(true, -1, -1); - } - - public List findTestProjectEntities(int maxResults, int firstResult) { - return findTestProjectEntities(false, maxResults, firstResult); - } - - private List findTestProjectEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(TestProject.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public TestProject findTestProject(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(TestProject.class, id); - } - finally { - em.close(); - } - } - - public int getTestProjectCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(TestProject.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Project; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.UserTestProjectRole; +import com.validation.manager.core.db.TestPlan; +import com.validation.manager.core.db.TestProject; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class TestProjectJpaController implements Serializable { + + public TestProjectJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(TestProject testProject) { + if (testProject.getProjectList() == null) { + testProject.setProjectList(new ArrayList<>()); + } + if (testProject.getUserTestProjectRoleList() == null) { + testProject.setUserTestProjectRoleList(new ArrayList<>()); + } + if (testProject.getTestPlanList() == null) { + testProject.setTestPlanList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedProjectList = new ArrayList<>(); + for (Project projectListProjectToAttach : testProject.getProjectList()) { + projectListProjectToAttach = em.getReference(projectListProjectToAttach.getClass(), projectListProjectToAttach.getId()); + attachedProjectList.add(projectListProjectToAttach); + } + testProject.setProjectList(attachedProjectList); + List attachedUserTestProjectRoleList = new ArrayList<>(); + for (UserTestProjectRole userTestProjectRoleListUserTestProjectRoleToAttach : testProject.getUserTestProjectRoleList()) { + userTestProjectRoleListUserTestProjectRoleToAttach = em.getReference(userTestProjectRoleListUserTestProjectRoleToAttach.getClass(), userTestProjectRoleListUserTestProjectRoleToAttach.getUserTestProjectRolePK()); + attachedUserTestProjectRoleList.add(userTestProjectRoleListUserTestProjectRoleToAttach); + } + testProject.setUserTestProjectRoleList(attachedUserTestProjectRoleList); + List attachedTestPlanList = new ArrayList<>(); + for (TestPlan testPlanListTestPlanToAttach : testProject.getTestPlanList()) { + testPlanListTestPlanToAttach = em.getReference(testPlanListTestPlanToAttach.getClass(), testPlanListTestPlanToAttach.getTestPlanPK()); + attachedTestPlanList.add(testPlanListTestPlanToAttach); + } + testProject.setTestPlanList(attachedTestPlanList); + em.persist(testProject); + for (Project projectListProject : testProject.getProjectList()) { + projectListProject.getTestProjectList().add(testProject); + projectListProject = em.merge(projectListProject); + } + for (UserTestProjectRole userTestProjectRoleListUserTestProjectRole : testProject.getUserTestProjectRoleList()) { + TestProject oldTestProjectOfUserTestProjectRoleListUserTestProjectRole = userTestProjectRoleListUserTestProjectRole.getTestProject(); + userTestProjectRoleListUserTestProjectRole.setTestProject(testProject); + userTestProjectRoleListUserTestProjectRole = em.merge(userTestProjectRoleListUserTestProjectRole); + if (oldTestProjectOfUserTestProjectRoleListUserTestProjectRole != null) { + oldTestProjectOfUserTestProjectRoleListUserTestProjectRole.getUserTestProjectRoleList().remove(userTestProjectRoleListUserTestProjectRole); + oldTestProjectOfUserTestProjectRoleListUserTestProjectRole = em.merge(oldTestProjectOfUserTestProjectRoleListUserTestProjectRole); + } + } + for (TestPlan testPlanListTestPlan : testProject.getTestPlanList()) { + TestProject oldTestProjectOfTestPlanListTestPlan = testPlanListTestPlan.getTestProject(); + testPlanListTestPlan.setTestProject(testProject); + testPlanListTestPlan = em.merge(testPlanListTestPlan); + if (oldTestProjectOfTestPlanListTestPlan != null) { + oldTestProjectOfTestPlanListTestPlan.getTestPlanList().remove(testPlanListTestPlan); + oldTestProjectOfTestPlanListTestPlan = em.merge(oldTestProjectOfTestPlanListTestPlan); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(TestProject testProject) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + TestProject persistentTestProject = em.find(TestProject.class, testProject.getId()); + List projectListOld = persistentTestProject.getProjectList(); + List projectListNew = testProject.getProjectList(); + List userTestProjectRoleListOld = persistentTestProject.getUserTestProjectRoleList(); + List userTestProjectRoleListNew = testProject.getUserTestProjectRoleList(); + List testPlanListOld = persistentTestProject.getTestPlanList(); + List testPlanListNew = testProject.getTestPlanList(); + List illegalOrphanMessages = null; + for (UserTestProjectRole userTestProjectRoleListOldUserTestProjectRole : userTestProjectRoleListOld) { + if (!userTestProjectRoleListNew.contains(userTestProjectRoleListOldUserTestProjectRole)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserTestProjectRole " + userTestProjectRoleListOldUserTestProjectRole + " since its testProject field is not nullable."); + } + } + for (TestPlan testPlanListOldTestPlan : testPlanListOld) { + if (!testPlanListNew.contains(testPlanListOldTestPlan)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain TestPlan " + testPlanListOldTestPlan + " since its testProject field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedProjectListNew = new ArrayList<>(); + for (Project projectListNewProjectToAttach : projectListNew) { + projectListNewProjectToAttach = em.getReference(projectListNewProjectToAttach.getClass(), projectListNewProjectToAttach.getId()); + attachedProjectListNew.add(projectListNewProjectToAttach); + } + projectListNew = attachedProjectListNew; + testProject.setProjectList(projectListNew); + List attachedUserTestProjectRoleListNew = new ArrayList<>(); + for (UserTestProjectRole userTestProjectRoleListNewUserTestProjectRoleToAttach : userTestProjectRoleListNew) { + userTestProjectRoleListNewUserTestProjectRoleToAttach = em.getReference(userTestProjectRoleListNewUserTestProjectRoleToAttach.getClass(), userTestProjectRoleListNewUserTestProjectRoleToAttach.getUserTestProjectRolePK()); + attachedUserTestProjectRoleListNew.add(userTestProjectRoleListNewUserTestProjectRoleToAttach); + } + userTestProjectRoleListNew = attachedUserTestProjectRoleListNew; + testProject.setUserTestProjectRoleList(userTestProjectRoleListNew); + List attachedTestPlanListNew = new ArrayList<>(); + for (TestPlan testPlanListNewTestPlanToAttach : testPlanListNew) { + testPlanListNewTestPlanToAttach = em.getReference(testPlanListNewTestPlanToAttach.getClass(), testPlanListNewTestPlanToAttach.getTestPlanPK()); + attachedTestPlanListNew.add(testPlanListNewTestPlanToAttach); + } + testPlanListNew = attachedTestPlanListNew; + testProject.setTestPlanList(testPlanListNew); + testProject = em.merge(testProject); + for (Project projectListOldProject : projectListOld) { + if (!projectListNew.contains(projectListOldProject)) { + projectListOldProject.getTestProjectList().remove(testProject); + projectListOldProject = em.merge(projectListOldProject); + } + } + for (Project projectListNewProject : projectListNew) { + if (!projectListOld.contains(projectListNewProject)) { + projectListNewProject.getTestProjectList().add(testProject); + projectListNewProject = em.merge(projectListNewProject); + } + } + for (UserTestProjectRole userTestProjectRoleListNewUserTestProjectRole : userTestProjectRoleListNew) { + if (!userTestProjectRoleListOld.contains(userTestProjectRoleListNewUserTestProjectRole)) { + TestProject oldTestProjectOfUserTestProjectRoleListNewUserTestProjectRole = userTestProjectRoleListNewUserTestProjectRole.getTestProject(); + userTestProjectRoleListNewUserTestProjectRole.setTestProject(testProject); + userTestProjectRoleListNewUserTestProjectRole = em.merge(userTestProjectRoleListNewUserTestProjectRole); + if (oldTestProjectOfUserTestProjectRoleListNewUserTestProjectRole != null && !oldTestProjectOfUserTestProjectRoleListNewUserTestProjectRole.equals(testProject)) { + oldTestProjectOfUserTestProjectRoleListNewUserTestProjectRole.getUserTestProjectRoleList().remove(userTestProjectRoleListNewUserTestProjectRole); + oldTestProjectOfUserTestProjectRoleListNewUserTestProjectRole = em.merge(oldTestProjectOfUserTestProjectRoleListNewUserTestProjectRole); + } + } + } + for (TestPlan testPlanListNewTestPlan : testPlanListNew) { + if (!testPlanListOld.contains(testPlanListNewTestPlan)) { + TestProject oldTestProjectOfTestPlanListNewTestPlan = testPlanListNewTestPlan.getTestProject(); + testPlanListNewTestPlan.setTestProject(testProject); + testPlanListNewTestPlan = em.merge(testPlanListNewTestPlan); + if (oldTestProjectOfTestPlanListNewTestPlan != null && !oldTestProjectOfTestPlanListNewTestPlan.equals(testProject)) { + oldTestProjectOfTestPlanListNewTestPlan.getTestPlanList().remove(testPlanListNewTestPlan); + oldTestProjectOfTestPlanListNewTestPlan = em.merge(oldTestProjectOfTestPlanListNewTestPlan); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = testProject.getId(); + if (findTestProject(id) == null) { + throw new NonexistentEntityException("The testProject with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + TestProject testProject; + try { + testProject = em.getReference(TestProject.class, id); + testProject.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The testProject with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List userTestProjectRoleListOrphanCheck = testProject.getUserTestProjectRoleList(); + for (UserTestProjectRole userTestProjectRoleListOrphanCheckUserTestProjectRole : userTestProjectRoleListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This TestProject (" + testProject + ") cannot be destroyed since the UserTestProjectRole " + userTestProjectRoleListOrphanCheckUserTestProjectRole + " in its userTestProjectRoleList field has a non-nullable testProject field."); + } + List testPlanListOrphanCheck = testProject.getTestPlanList(); + for (TestPlan testPlanListOrphanCheckTestPlan : testPlanListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This TestProject (" + testProject + ") cannot be destroyed since the TestPlan " + testPlanListOrphanCheckTestPlan + " in its testPlanList field has a non-nullable testProject field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List projectList = testProject.getProjectList(); + for (Project projectListProject : projectList) { + projectListProject.getTestProjectList().remove(testProject); + projectListProject = em.merge(projectListProject); + } + em.remove(testProject); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findTestProjectEntities() { + return findTestProjectEntities(true, -1, -1); + } + + public List findTestProjectEntities(int maxResults, int firstResult) { + return findTestProjectEntities(false, maxResults, firstResult); + } + + private List findTestProjectEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(TestProject.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public TestProject findTestProject(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(TestProject.class, id); + } + finally { + em.close(); + } + } + + public int getTestProjectCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(TestProject.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/UserRightJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/UserRightJpaController.java index 83addca5..4eec04d6 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/UserRightJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/UserRightJpaController.java @@ -13,186 +13,186 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.Role; -import com.validation.manager.core.db.UserRight; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class UserRightJpaController implements Serializable { - - public UserRightJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(UserRight userRight) { - if (userRight.getRoleList() == null) { - userRight.setRoleList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedRoleList = new ArrayList(); - for (Role roleListRoleToAttach : userRight.getRoleList()) { - roleListRoleToAttach = em.getReference(roleListRoleToAttach.getClass(), roleListRoleToAttach.getId()); - attachedRoleList.add(roleListRoleToAttach); - } - userRight.setRoleList(attachedRoleList); - em.persist(userRight); - for (Role roleListRole : userRight.getRoleList()) { - roleListRole.getUserRightList().add(userRight); - roleListRole = em.merge(roleListRole); - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(UserRight userRight) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - UserRight persistentUserRight = em.find(UserRight.class, userRight.getId()); - List roleListOld = persistentUserRight.getRoleList(); - List roleListNew = userRight.getRoleList(); - List attachedRoleListNew = new ArrayList(); - for (Role roleListNewRoleToAttach : roleListNew) { - roleListNewRoleToAttach = em.getReference(roleListNewRoleToAttach.getClass(), roleListNewRoleToAttach.getId()); - attachedRoleListNew.add(roleListNewRoleToAttach); - } - roleListNew = attachedRoleListNew; - userRight.setRoleList(roleListNew); - userRight = em.merge(userRight); - for (Role roleListOldRole : roleListOld) { - if (!roleListNew.contains(roleListOldRole)) { - roleListOldRole.getUserRightList().remove(userRight); - roleListOldRole = em.merge(roleListOldRole); - } - } - for (Role roleListNewRole : roleListNew) { - if (!roleListOld.contains(roleListNewRole)) { - roleListNewRole.getUserRightList().add(userRight); - roleListNewRole = em.merge(roleListNewRole); - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = userRight.getId(); - if (findUserRight(id) == null) { - throw new NonexistentEntityException("The userRight with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - UserRight userRight; - try { - userRight = em.getReference(UserRight.class, id); - userRight.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The userRight with id " + id + " no longer exists.", enfe); - } - List roleList = userRight.getRoleList(); - for (Role roleListRole : roleList) { - roleListRole.getUserRightList().remove(userRight); - roleListRole = em.merge(roleListRole); - } - em.remove(userRight); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findUserRightEntities() { - return findUserRightEntities(true, -1, -1); - } - - public List findUserRightEntities(int maxResults, int firstResult) { - return findUserRightEntities(false, maxResults, firstResult); - } - - private List findUserRightEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(UserRight.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public UserRight findUserRight(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(UserRight.class, id); - } - finally { - em.close(); - } - } - - public int getUserRightCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(UserRight.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.Role; +import com.validation.manager.core.db.UserRight; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class UserRightJpaController implements Serializable { + + public UserRightJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(UserRight userRight) { + if (userRight.getRoleList() == null) { + userRight.setRoleList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedRoleList = new ArrayList<>(); + for (Role roleListRoleToAttach : userRight.getRoleList()) { + roleListRoleToAttach = em.getReference(roleListRoleToAttach.getClass(), roleListRoleToAttach.getId()); + attachedRoleList.add(roleListRoleToAttach); + } + userRight.setRoleList(attachedRoleList); + em.persist(userRight); + for (Role roleListRole : userRight.getRoleList()) { + roleListRole.getUserRightList().add(userRight); + roleListRole = em.merge(roleListRole); + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(UserRight userRight) throws NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + UserRight persistentUserRight = em.find(UserRight.class, userRight.getId()); + List roleListOld = persistentUserRight.getRoleList(); + List roleListNew = userRight.getRoleList(); + List attachedRoleListNew = new ArrayList<>(); + for (Role roleListNewRoleToAttach : roleListNew) { + roleListNewRoleToAttach = em.getReference(roleListNewRoleToAttach.getClass(), roleListNewRoleToAttach.getId()); + attachedRoleListNew.add(roleListNewRoleToAttach); + } + roleListNew = attachedRoleListNew; + userRight.setRoleList(roleListNew); + userRight = em.merge(userRight); + for (Role roleListOldRole : roleListOld) { + if (!roleListNew.contains(roleListOldRole)) { + roleListOldRole.getUserRightList().remove(userRight); + roleListOldRole = em.merge(roleListOldRole); + } + } + for (Role roleListNewRole : roleListNew) { + if (!roleListOld.contains(roleListNewRole)) { + roleListNewRole.getUserRightList().add(userRight); + roleListNewRole = em.merge(roleListNewRole); + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = userRight.getId(); + if (findUserRight(id) == null) { + throw new NonexistentEntityException("The userRight with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + UserRight userRight; + try { + userRight = em.getReference(UserRight.class, id); + userRight.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The userRight with id " + id + " no longer exists.", enfe); + } + List roleList = userRight.getRoleList(); + for (Role roleListRole : roleList) { + roleListRole.getUserRightList().remove(userRight); + roleListRole = em.merge(roleListRole); + } + em.remove(userRight); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findUserRightEntities() { + return findUserRightEntities(true, -1, -1); + } + + public List findUserRightEntities(int maxResults, int firstResult) { + return findUserRightEntities(false, maxResults, firstResult); + } + + private List findUserRightEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(UserRight.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public UserRight findUserRight(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(UserRight.class, id); + } + finally { + em.close(); + } + } + + public int getUserRightCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(UserRight.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/UserStatusJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/UserStatusJpaController.java index 771b1c3a..ec8b3ce1 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/UserStatusJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/UserStatusJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.UserStatus; -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class UserStatusJpaController implements Serializable { - - public UserStatusJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(UserStatus userStatus) { - if (userStatus.getVmUserList() == null) { - userStatus.setVmUserList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedVmUserList = new ArrayList(); - for (VmUser vmUserListVmUserToAttach : userStatus.getVmUserList()) { - vmUserListVmUserToAttach = em.getReference(vmUserListVmUserToAttach.getClass(), vmUserListVmUserToAttach.getId()); - attachedVmUserList.add(vmUserListVmUserToAttach); - } - userStatus.setVmUserList(attachedVmUserList); - em.persist(userStatus); - for (VmUser vmUserListVmUser : userStatus.getVmUserList()) { - UserStatus oldUserStatusIdOfVmUserListVmUser = vmUserListVmUser.getUserStatusId(); - vmUserListVmUser.setUserStatusId(userStatus); - vmUserListVmUser = em.merge(vmUserListVmUser); - if (oldUserStatusIdOfVmUserListVmUser != null) { - oldUserStatusIdOfVmUserListVmUser.getVmUserList().remove(vmUserListVmUser); - oldUserStatusIdOfVmUserListVmUser = em.merge(oldUserStatusIdOfVmUserListVmUser); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(UserStatus userStatus) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - UserStatus persistentUserStatus = em.find(UserStatus.class, userStatus.getId()); - List vmUserListOld = persistentUserStatus.getVmUserList(); - List vmUserListNew = userStatus.getVmUserList(); - List illegalOrphanMessages = null; - for (VmUser vmUserListOldVmUser : vmUserListOld) { - if (!vmUserListNew.contains(vmUserListOldVmUser)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain VmUser " + vmUserListOldVmUser + " since its userStatusId field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedVmUserListNew = new ArrayList(); - for (VmUser vmUserListNewVmUserToAttach : vmUserListNew) { - vmUserListNewVmUserToAttach = em.getReference(vmUserListNewVmUserToAttach.getClass(), vmUserListNewVmUserToAttach.getId()); - attachedVmUserListNew.add(vmUserListNewVmUserToAttach); - } - vmUserListNew = attachedVmUserListNew; - userStatus.setVmUserList(vmUserListNew); - userStatus = em.merge(userStatus); - for (VmUser vmUserListNewVmUser : vmUserListNew) { - if (!vmUserListOld.contains(vmUserListNewVmUser)) { - UserStatus oldUserStatusIdOfVmUserListNewVmUser = vmUserListNewVmUser.getUserStatusId(); - vmUserListNewVmUser.setUserStatusId(userStatus); - vmUserListNewVmUser = em.merge(vmUserListNewVmUser); - if (oldUserStatusIdOfVmUserListNewVmUser != null && !oldUserStatusIdOfVmUserListNewVmUser.equals(userStatus)) { - oldUserStatusIdOfVmUserListNewVmUser.getVmUserList().remove(vmUserListNewVmUser); - oldUserStatusIdOfVmUserListNewVmUser = em.merge(oldUserStatusIdOfVmUserListNewVmUser); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = userStatus.getId(); - if (findUserStatus(id) == null) { - throw new NonexistentEntityException("The userStatus with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - UserStatus userStatus; - try { - userStatus = em.getReference(UserStatus.class, id); - userStatus.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The userStatus with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List vmUserListOrphanCheck = userStatus.getVmUserList(); - for (VmUser vmUserListOrphanCheckVmUser : vmUserListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This UserStatus (" + userStatus + ") cannot be destroyed since the VmUser " + vmUserListOrphanCheckVmUser + " in its vmUserList field has a non-nullable userStatusId field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(userStatus); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findUserStatusEntities() { - return findUserStatusEntities(true, -1, -1); - } - - public List findUserStatusEntities(int maxResults, int firstResult) { - return findUserStatusEntities(false, maxResults, firstResult); - } - - private List findUserStatusEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(UserStatus.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public UserStatus findUserStatus(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(UserStatus.class, id); - } - finally { - em.close(); - } - } - - public int getUserStatusCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(UserStatus.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import com.validation.manager.core.db.UserStatus; +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class UserStatusJpaController implements Serializable { + + public UserStatusJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(UserStatus userStatus) { + if (userStatus.getVmUserList() == null) { + userStatus.setVmUserList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedVmUserList = new ArrayList<>(); + for (VmUser vmUserListVmUserToAttach : userStatus.getVmUserList()) { + vmUserListVmUserToAttach = em.getReference(vmUserListVmUserToAttach.getClass(), vmUserListVmUserToAttach.getId()); + attachedVmUserList.add(vmUserListVmUserToAttach); + } + userStatus.setVmUserList(attachedVmUserList); + em.persist(userStatus); + for (VmUser vmUserListVmUser : userStatus.getVmUserList()) { + UserStatus oldUserStatusIdOfVmUserListVmUser = vmUserListVmUser.getUserStatusId(); + vmUserListVmUser.setUserStatusId(userStatus); + vmUserListVmUser = em.merge(vmUserListVmUser); + if (oldUserStatusIdOfVmUserListVmUser != null) { + oldUserStatusIdOfVmUserListVmUser.getVmUserList().remove(vmUserListVmUser); + oldUserStatusIdOfVmUserListVmUser = em.merge(oldUserStatusIdOfVmUserListVmUser); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(UserStatus userStatus) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + UserStatus persistentUserStatus = em.find(UserStatus.class, userStatus.getId()); + List vmUserListOld = persistentUserStatus.getVmUserList(); + List vmUserListNew = userStatus.getVmUserList(); + List illegalOrphanMessages = null; + for (VmUser vmUserListOldVmUser : vmUserListOld) { + if (!vmUserListNew.contains(vmUserListOldVmUser)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain VmUser " + vmUserListOldVmUser + " since its userStatusId field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedVmUserListNew = new ArrayList<>(); + for (VmUser vmUserListNewVmUserToAttach : vmUserListNew) { + vmUserListNewVmUserToAttach = em.getReference(vmUserListNewVmUserToAttach.getClass(), vmUserListNewVmUserToAttach.getId()); + attachedVmUserListNew.add(vmUserListNewVmUserToAttach); + } + vmUserListNew = attachedVmUserListNew; + userStatus.setVmUserList(vmUserListNew); + userStatus = em.merge(userStatus); + for (VmUser vmUserListNewVmUser : vmUserListNew) { + if (!vmUserListOld.contains(vmUserListNewVmUser)) { + UserStatus oldUserStatusIdOfVmUserListNewVmUser = vmUserListNewVmUser.getUserStatusId(); + vmUserListNewVmUser.setUserStatusId(userStatus); + vmUserListNewVmUser = em.merge(vmUserListNewVmUser); + if (oldUserStatusIdOfVmUserListNewVmUser != null && !oldUserStatusIdOfVmUserListNewVmUser.equals(userStatus)) { + oldUserStatusIdOfVmUserListNewVmUser.getVmUserList().remove(vmUserListNewVmUser); + oldUserStatusIdOfVmUserListNewVmUser = em.merge(oldUserStatusIdOfVmUserListNewVmUser); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = userStatus.getId(); + if (findUserStatus(id) == null) { + throw new NonexistentEntityException("The userStatus with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + UserStatus userStatus; + try { + userStatus = em.getReference(UserStatus.class, id); + userStatus.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The userStatus with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List vmUserListOrphanCheck = userStatus.getVmUserList(); + for (VmUser vmUserListOrphanCheckVmUser : vmUserListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This UserStatus (" + userStatus + ") cannot be destroyed since the VmUser " + vmUserListOrphanCheckVmUser + " in its vmUserList field has a non-nullable userStatusId field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(userStatus); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findUserStatusEntities() { + return findUserStatusEntities(true, -1, -1); + } + + public List findUserStatusEntities(int maxResults, int firstResult) { + return findUserStatusEntities(false, maxResults, firstResult); + } + + private List findUserStatusEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(UserStatus.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public UserStatus findUserStatus(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(UserStatus.class, id); + } + finally { + em.close(); + } + } + + public int getUserStatusCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(UserStatus.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/VmSettingJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/VmSettingJpaController.java index 9a1f195a..ae077189 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/VmSettingJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/VmSettingJpaController.java @@ -13,209 +13,209 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import java.io.Serializable; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.VmSetting; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class VmSettingJpaController implements Serializable { - - public VmSettingJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(VmSetting vmSetting) { - if (vmSetting.getHistoryList() == null) { - vmSetting.setHistoryList(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - List attachedHistoryList = new ArrayList(); - for (History historyListHistoryToAttach : vmSetting.getHistoryList()) { - historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); - attachedHistoryList.add(historyListHistoryToAttach); - } - vmSetting.setHistoryList(attachedHistoryList); - em.persist(vmSetting); - for (History historyListHistory : vmSetting.getHistoryList()) { - VmSetting oldVmSettingIdOfHistoryListHistory = historyListHistory.getVmSettingId(); - historyListHistory.setVmSettingId(vmSetting); - historyListHistory = em.merge(historyListHistory); - if (oldVmSettingIdOfHistoryListHistory != null) { - oldVmSettingIdOfHistoryListHistory.getHistoryList().remove(historyListHistory); - oldVmSettingIdOfHistoryListHistory = em.merge(oldVmSettingIdOfHistoryListHistory); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(VmSetting vmSetting) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - VmSetting persistentVmSetting = em.find(VmSetting.class, vmSetting.getId()); - List historyListOld = persistentVmSetting.getHistoryList(); - List historyListNew = vmSetting.getHistoryList(); - List illegalOrphanMessages = null; - for (History historyListOldHistory : historyListOld) { - if (!historyListNew.contains(historyListOldHistory)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain History " + historyListOldHistory + " since its vmSettingId field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - List attachedHistoryListNew = new ArrayList(); - for (History historyListNewHistoryToAttach : historyListNew) { - historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); - attachedHistoryListNew.add(historyListNewHistoryToAttach); - } - historyListNew = attachedHistoryListNew; - vmSetting.setHistoryList(historyListNew); - vmSetting = em.merge(vmSetting); - for (History historyListNewHistory : historyListNew) { - if (!historyListOld.contains(historyListNewHistory)) { - VmSetting oldVmSettingIdOfHistoryListNewHistory = historyListNewHistory.getVmSettingId(); - historyListNewHistory.setVmSettingId(vmSetting); - historyListNewHistory = em.merge(historyListNewHistory); - if (oldVmSettingIdOfHistoryListNewHistory != null && !oldVmSettingIdOfHistoryListNewHistory.equals(vmSetting)) { - oldVmSettingIdOfHistoryListNewHistory.getHistoryList().remove(historyListNewHistory); - oldVmSettingIdOfHistoryListNewHistory = em.merge(oldVmSettingIdOfHistoryListNewHistory); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = vmSetting.getId(); - if (findVmSetting(id) == null) { - throw new NonexistentEntityException("The vmSetting with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - VmSetting vmSetting; - try { - vmSetting = em.getReference(VmSetting.class, id); - vmSetting.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The vmSetting with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List historyListOrphanCheck = vmSetting.getHistoryList(); - for (History historyListOrphanCheckHistory : historyListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This VmSetting (" + vmSetting + ") cannot be destroyed since the History " + historyListOrphanCheckHistory + " in its historyList field has a non-nullable vmSettingId field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - em.remove(vmSetting); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findVmSettingEntities() { - return findVmSettingEntities(true, -1, -1); - } - - public List findVmSettingEntities(int maxResults, int firstResult) { - return findVmSettingEntities(false, maxResults, firstResult); - } - - private List findVmSettingEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(VmSetting.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public VmSetting findVmSetting(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(VmSetting.class, id); - } - finally { - em.close(); - } - } - - public int getVmSettingCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(VmSetting.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.VmSetting; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class VmSettingJpaController implements Serializable { + + public VmSettingJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(VmSetting vmSetting) { + if (vmSetting.getHistoryList() == null) { + vmSetting.setHistoryList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + List attachedHistoryList = new ArrayList<>(); + for (History historyListHistoryToAttach : vmSetting.getHistoryList()) { + historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); + attachedHistoryList.add(historyListHistoryToAttach); + } + vmSetting.setHistoryList(attachedHistoryList); + em.persist(vmSetting); + for (History historyListHistory : vmSetting.getHistoryList()) { + VmSetting oldVmSettingIdOfHistoryListHistory = historyListHistory.getVmSettingId(); + historyListHistory.setVmSettingId(vmSetting); + historyListHistory = em.merge(historyListHistory); + if (oldVmSettingIdOfHistoryListHistory != null) { + oldVmSettingIdOfHistoryListHistory.getHistoryList().remove(historyListHistory); + oldVmSettingIdOfHistoryListHistory = em.merge(oldVmSettingIdOfHistoryListHistory); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(VmSetting vmSetting) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + VmSetting persistentVmSetting = em.find(VmSetting.class, vmSetting.getId()); + List historyListOld = persistentVmSetting.getHistoryList(); + List historyListNew = vmSetting.getHistoryList(); + List illegalOrphanMessages = null; + for (History historyListOldHistory : historyListOld) { + if (!historyListNew.contains(historyListOldHistory)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain History " + historyListOldHistory + " since its vmSettingId field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + List attachedHistoryListNew = new ArrayList<>(); + for (History historyListNewHistoryToAttach : historyListNew) { + historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); + attachedHistoryListNew.add(historyListNewHistoryToAttach); + } + historyListNew = attachedHistoryListNew; + vmSetting.setHistoryList(historyListNew); + vmSetting = em.merge(vmSetting); + for (History historyListNewHistory : historyListNew) { + if (!historyListOld.contains(historyListNewHistory)) { + VmSetting oldVmSettingIdOfHistoryListNewHistory = historyListNewHistory.getVmSettingId(); + historyListNewHistory.setVmSettingId(vmSetting); + historyListNewHistory = em.merge(historyListNewHistory); + if (oldVmSettingIdOfHistoryListNewHistory != null && !oldVmSettingIdOfHistoryListNewHistory.equals(vmSetting)) { + oldVmSettingIdOfHistoryListNewHistory.getHistoryList().remove(historyListNewHistory); + oldVmSettingIdOfHistoryListNewHistory = em.merge(oldVmSettingIdOfHistoryListNewHistory); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = vmSetting.getId(); + if (findVmSetting(id) == null) { + throw new NonexistentEntityException("The vmSetting with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + VmSetting vmSetting; + try { + vmSetting = em.getReference(VmSetting.class, id); + vmSetting.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The vmSetting with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List historyListOrphanCheck = vmSetting.getHistoryList(); + for (History historyListOrphanCheckHistory : historyListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This VmSetting (" + vmSetting + ") cannot be destroyed since the History " + historyListOrphanCheckHistory + " in its historyList field has a non-nullable vmSettingId field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + em.remove(vmSetting); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findVmSettingEntities() { + return findVmSettingEntities(true, -1, -1); + } + + public List findVmSettingEntities(int maxResults, int firstResult) { + return findVmSettingEntities(false, maxResults, firstResult); + } + + private List findVmSettingEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(VmSetting.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public VmSetting findVmSetting(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(VmSetting.class, id); + } + finally { + em.close(); + } + } + + public int getVmSettingCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(VmSetting.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/db/controller/VmUserJpaController.java b/VM-Core/src/main/java/com/validation/manager/core/db/controller/VmUserJpaController.java index e0b7e761..ae05777e 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/db/controller/VmUserJpaController.java +++ b/VM-Core/src/main/java/com/validation/manager/core/db/controller/VmUserJpaController.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,981 +13,1034 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db.controller; - -import com.validation.manager.core.db.CorrectiveAction; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.ExecutionStepHasIssue; -import com.validation.manager.core.db.ExecutionStepHasVmUser; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.Notification; -import com.validation.manager.core.db.Role; -import com.validation.manager.core.db.RootCause; -import com.validation.manager.core.db.UserAssigment; -import com.validation.manager.core.db.UserHasInvestigation; -import com.validation.manager.core.db.UserModifiedRecord; -import com.validation.manager.core.db.UserStatus; -import com.validation.manager.core.db.UserTestPlanRole; -import com.validation.manager.core.db.UserTestProjectRole; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityNotFoundException; -import javax.persistence.Query; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class VmUserJpaController implements Serializable { - - public VmUserJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(VmUser vmUser) { - if (vmUser.getCorrectiveActionList() == null) { - vmUser.setCorrectiveActionList(new ArrayList()); - } - if (vmUser.getRoleList() == null) { - vmUser.setRoleList(new ArrayList()); - } - if (vmUser.getRootCauseList() == null) { - vmUser.setRootCauseList(new ArrayList()); - } - if (vmUser.getExecutionStepList() == null) { - vmUser.setExecutionStepList(new ArrayList()); - } - if (vmUser.getExecutionStepList1() == null) { - vmUser.setExecutionStepList1(new ArrayList()); - } - if (vmUser.getUserTestProjectRoleList() == null) { - vmUser.setUserTestProjectRoleList(new ArrayList()); - } - if (vmUser.getUserTestPlanRoleList() == null) { - vmUser.setUserTestPlanRoleList(new ArrayList()); - } - if (vmUser.getUserModifiedRecordList() == null) { - vmUser.setUserModifiedRecordList(new ArrayList()); - } - if (vmUser.getUserHasInvestigationList() == null) { - vmUser.setUserHasInvestigationList(new ArrayList()); - } - if (vmUser.getUserAssigmentList() == null) { - vmUser.setUserAssigmentList(new ArrayList()); - } - if (vmUser.getUserAssigmentList1() == null) { - vmUser.setUserAssigmentList1(new ArrayList()); - } - if (vmUser.getExecutionStepHasIssueList() == null) { - vmUser.setExecutionStepHasIssueList(new ArrayList()); - } - if (vmUser.getExecutionStepHasVmUserList() == null) { - vmUser.setExecutionStepHasVmUserList(new ArrayList()); - } - if (vmUser.getHistoryModificationList() == null) { - vmUser.setHistoryModificationList(new ArrayList()); - } - if (vmUser.getNotificationList() == null) { - vmUser.setNotificationList(new ArrayList()); - } - if (vmUser.getNotificationList1() == null) { - vmUser.setNotificationList1(new ArrayList()); - } - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - UserStatus userStatusId = vmUser.getUserStatusId(); - if (userStatusId != null) { - userStatusId = em.getReference(userStatusId.getClass(), userStatusId.getId()); - vmUser.setUserStatusId(userStatusId); - } - List attachedCorrectiveActionList = new ArrayList(); - for (CorrectiveAction correctiveActionListCorrectiveActionToAttach : vmUser.getCorrectiveActionList()) { - correctiveActionListCorrectiveActionToAttach = em.getReference(correctiveActionListCorrectiveActionToAttach.getClass(), correctiveActionListCorrectiveActionToAttach.getId()); - attachedCorrectiveActionList.add(correctiveActionListCorrectiveActionToAttach); - } - vmUser.setCorrectiveActionList(attachedCorrectiveActionList); - List attachedRoleList = new ArrayList(); - for (Role roleListRoleToAttach : vmUser.getRoleList()) { - roleListRoleToAttach = em.getReference(roleListRoleToAttach.getClass(), roleListRoleToAttach.getId()); - attachedRoleList.add(roleListRoleToAttach); - } - vmUser.setRoleList(attachedRoleList); - List attachedRootCauseList = new ArrayList(); - for (RootCause rootCauseListRootCauseToAttach : vmUser.getRootCauseList()) { - rootCauseListRootCauseToAttach = em.getReference(rootCauseListRootCauseToAttach.getClass(), rootCauseListRootCauseToAttach.getRootCausePK()); - attachedRootCauseList.add(rootCauseListRootCauseToAttach); - } - vmUser.setRootCauseList(attachedRootCauseList); - List attachedExecutionStepList = new ArrayList(); - for (ExecutionStep executionStepListExecutionStepToAttach : vmUser.getExecutionStepList()) { - executionStepListExecutionStepToAttach = em.getReference(executionStepListExecutionStepToAttach.getClass(), executionStepListExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepList.add(executionStepListExecutionStepToAttach); - } - vmUser.setExecutionStepList(attachedExecutionStepList); - List attachedExecutionStepList1 = new ArrayList(); - for (ExecutionStep executionStepList1ExecutionStepToAttach : vmUser.getExecutionStepList1()) { - executionStepList1ExecutionStepToAttach = em.getReference(executionStepList1ExecutionStepToAttach.getClass(), executionStepList1ExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepList1.add(executionStepList1ExecutionStepToAttach); - } - vmUser.setExecutionStepList1(attachedExecutionStepList1); - List attachedUserTestProjectRoleList = new ArrayList(); - for (UserTestProjectRole userTestProjectRoleListUserTestProjectRoleToAttach : vmUser.getUserTestProjectRoleList()) { - userTestProjectRoleListUserTestProjectRoleToAttach = em.getReference(userTestProjectRoleListUserTestProjectRoleToAttach.getClass(), userTestProjectRoleListUserTestProjectRoleToAttach.getUserTestProjectRolePK()); - attachedUserTestProjectRoleList.add(userTestProjectRoleListUserTestProjectRoleToAttach); - } - vmUser.setUserTestProjectRoleList(attachedUserTestProjectRoleList); - List attachedUserTestPlanRoleList = new ArrayList(); - for (UserTestPlanRole userTestPlanRoleListUserTestPlanRoleToAttach : vmUser.getUserTestPlanRoleList()) { - userTestPlanRoleListUserTestPlanRoleToAttach = em.getReference(userTestPlanRoleListUserTestPlanRoleToAttach.getClass(), userTestPlanRoleListUserTestPlanRoleToAttach.getUserTestPlanRolePK()); - attachedUserTestPlanRoleList.add(userTestPlanRoleListUserTestPlanRoleToAttach); - } - vmUser.setUserTestPlanRoleList(attachedUserTestPlanRoleList); - List attachedUserModifiedRecordList = new ArrayList(); - for (UserModifiedRecord userModifiedRecordListUserModifiedRecordToAttach : vmUser.getUserModifiedRecordList()) { - userModifiedRecordListUserModifiedRecordToAttach = em.getReference(userModifiedRecordListUserModifiedRecordToAttach.getClass(), userModifiedRecordListUserModifiedRecordToAttach.getUserModifiedRecordPK()); - attachedUserModifiedRecordList.add(userModifiedRecordListUserModifiedRecordToAttach); - } - vmUser.setUserModifiedRecordList(attachedUserModifiedRecordList); - List attachedUserHasInvestigationList = new ArrayList(); - for (UserHasInvestigation userHasInvestigationListUserHasInvestigationToAttach : vmUser.getUserHasInvestigationList()) { - userHasInvestigationListUserHasInvestigationToAttach = em.getReference(userHasInvestigationListUserHasInvestigationToAttach.getClass(), userHasInvestigationListUserHasInvestigationToAttach.getUserHasInvestigationPK()); - attachedUserHasInvestigationList.add(userHasInvestigationListUserHasInvestigationToAttach); - } - vmUser.setUserHasInvestigationList(attachedUserHasInvestigationList); - List attachedUserAssigmentList = new ArrayList(); - for (UserAssigment userAssigmentListUserAssigmentToAttach : vmUser.getUserAssigmentList()) { - userAssigmentListUserAssigmentToAttach = em.getReference(userAssigmentListUserAssigmentToAttach.getClass(), userAssigmentListUserAssigmentToAttach.getUserAssigmentPK()); - attachedUserAssigmentList.add(userAssigmentListUserAssigmentToAttach); - } - vmUser.setUserAssigmentList(attachedUserAssigmentList); - List attachedUserAssigmentList1 = new ArrayList(); - for (UserAssigment userAssigmentList1UserAssigmentToAttach : vmUser.getUserAssigmentList1()) { - userAssigmentList1UserAssigmentToAttach = em.getReference(userAssigmentList1UserAssigmentToAttach.getClass(), userAssigmentList1UserAssigmentToAttach.getUserAssigmentPK()); - attachedUserAssigmentList1.add(userAssigmentList1UserAssigmentToAttach); - } - vmUser.setUserAssigmentList1(attachedUserAssigmentList1); - List attachedExecutionStepHasIssueList = new ArrayList(); - for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssueToAttach : vmUser.getExecutionStepHasIssueList()) { - executionStepHasIssueListExecutionStepHasIssueToAttach = em.getReference(executionStepHasIssueListExecutionStepHasIssueToAttach.getClass(), executionStepHasIssueListExecutionStepHasIssueToAttach.getExecutionStepHasIssuePK()); - attachedExecutionStepHasIssueList.add(executionStepHasIssueListExecutionStepHasIssueToAttach); - } - vmUser.setExecutionStepHasIssueList(attachedExecutionStepHasIssueList); - List attachedExecutionStepHasVmUserList = new ArrayList(); - for (ExecutionStepHasVmUser executionStepHasVmUserListExecutionStepHasVmUserToAttach : vmUser.getExecutionStepHasVmUserList()) { - executionStepHasVmUserListExecutionStepHasVmUserToAttach = em.getReference(executionStepHasVmUserListExecutionStepHasVmUserToAttach.getClass(), executionStepHasVmUserListExecutionStepHasVmUserToAttach.getExecutionStepHasVmUserPK()); - attachedExecutionStepHasVmUserList.add(executionStepHasVmUserListExecutionStepHasVmUserToAttach); - } - vmUser.setExecutionStepHasVmUserList(attachedExecutionStepHasVmUserList); - List attachedHistoryModificationList = new ArrayList(); - for (History historyModificationListHistoryToAttach : vmUser.getHistoryModificationList()) { - historyModificationListHistoryToAttach = em.getReference(historyModificationListHistoryToAttach.getClass(), historyModificationListHistoryToAttach.getId()); - attachedHistoryModificationList.add(historyModificationListHistoryToAttach); - } - vmUser.setHistoryModificationList(attachedHistoryModificationList); - List attachedNotificationList = new ArrayList(); - for (Notification notificationListNotificationToAttach : vmUser.getNotificationList()) { - notificationListNotificationToAttach = em.getReference(notificationListNotificationToAttach.getClass(), notificationListNotificationToAttach.getNotificationPK()); - attachedNotificationList.add(notificationListNotificationToAttach); - } - vmUser.setNotificationList(attachedNotificationList); - List attachedNotificationList1 = new ArrayList(); - for (Notification notificationList1NotificationToAttach : vmUser.getNotificationList1()) { - notificationList1NotificationToAttach = em.getReference(notificationList1NotificationToAttach.getClass(), notificationList1NotificationToAttach.getNotificationPK()); - attachedNotificationList1.add(notificationList1NotificationToAttach); - } - vmUser.setNotificationList1(attachedNotificationList1); - em.persist(vmUser); - if (userStatusId != null) { - userStatusId.getVmUserList().add(vmUser); - userStatusId = em.merge(userStatusId); - } - for (CorrectiveAction correctiveActionListCorrectiveAction : vmUser.getCorrectiveActionList()) { - correctiveActionListCorrectiveAction.getVmUserList().add(vmUser); - correctiveActionListCorrectiveAction = em.merge(correctiveActionListCorrectiveAction); - } - for (Role roleListRole : vmUser.getRoleList()) { - roleListRole.getVmUserList().add(vmUser); - roleListRole = em.merge(roleListRole); - } - for (RootCause rootCauseListRootCause : vmUser.getRootCauseList()) { - rootCauseListRootCause.getVmUserList().add(vmUser); - rootCauseListRootCause = em.merge(rootCauseListRootCause); - } - for (ExecutionStep executionStepListExecutionStep : vmUser.getExecutionStepList()) { - VmUser oldAssigneeOfExecutionStepListExecutionStep = executionStepListExecutionStep.getAssignee(); - executionStepListExecutionStep.setAssignee(vmUser); - executionStepListExecutionStep = em.merge(executionStepListExecutionStep); - if (oldAssigneeOfExecutionStepListExecutionStep != null) { - oldAssigneeOfExecutionStepListExecutionStep.getExecutionStepList().remove(executionStepListExecutionStep); - oldAssigneeOfExecutionStepListExecutionStep = em.merge(oldAssigneeOfExecutionStepListExecutionStep); - } - } - for (ExecutionStep executionStepList1ExecutionStep : vmUser.getExecutionStepList1()) { - VmUser oldAssignerOfExecutionStepList1ExecutionStep = executionStepList1ExecutionStep.getAssigner(); - executionStepList1ExecutionStep.setAssigner(vmUser); - executionStepList1ExecutionStep = em.merge(executionStepList1ExecutionStep); - if (oldAssignerOfExecutionStepList1ExecutionStep != null) { - oldAssignerOfExecutionStepList1ExecutionStep.getExecutionStepList1().remove(executionStepList1ExecutionStep); - oldAssignerOfExecutionStepList1ExecutionStep = em.merge(oldAssignerOfExecutionStepList1ExecutionStep); - } - } - for (UserTestProjectRole userTestProjectRoleListUserTestProjectRole : vmUser.getUserTestProjectRoleList()) { - VmUser oldVmUserOfUserTestProjectRoleListUserTestProjectRole = userTestProjectRoleListUserTestProjectRole.getVmUser(); - userTestProjectRoleListUserTestProjectRole.setVmUser(vmUser); - userTestProjectRoleListUserTestProjectRole = em.merge(userTestProjectRoleListUserTestProjectRole); - if (oldVmUserOfUserTestProjectRoleListUserTestProjectRole != null) { - oldVmUserOfUserTestProjectRoleListUserTestProjectRole.getUserTestProjectRoleList().remove(userTestProjectRoleListUserTestProjectRole); - oldVmUserOfUserTestProjectRoleListUserTestProjectRole = em.merge(oldVmUserOfUserTestProjectRoleListUserTestProjectRole); - } - } - for (UserTestPlanRole userTestPlanRoleListUserTestPlanRole : vmUser.getUserTestPlanRoleList()) { - VmUser oldVmUserOfUserTestPlanRoleListUserTestPlanRole = userTestPlanRoleListUserTestPlanRole.getVmUser(); - userTestPlanRoleListUserTestPlanRole.setVmUser(vmUser); - userTestPlanRoleListUserTestPlanRole = em.merge(userTestPlanRoleListUserTestPlanRole); - if (oldVmUserOfUserTestPlanRoleListUserTestPlanRole != null) { - oldVmUserOfUserTestPlanRoleListUserTestPlanRole.getUserTestPlanRoleList().remove(userTestPlanRoleListUserTestPlanRole); - oldVmUserOfUserTestPlanRoleListUserTestPlanRole = em.merge(oldVmUserOfUserTestPlanRoleListUserTestPlanRole); - } - } - for (UserModifiedRecord userModifiedRecordListUserModifiedRecord : vmUser.getUserModifiedRecordList()) { - VmUser oldVmUserOfUserModifiedRecordListUserModifiedRecord = userModifiedRecordListUserModifiedRecord.getVmUser(); - userModifiedRecordListUserModifiedRecord.setVmUser(vmUser); - userModifiedRecordListUserModifiedRecord = em.merge(userModifiedRecordListUserModifiedRecord); - if (oldVmUserOfUserModifiedRecordListUserModifiedRecord != null) { - oldVmUserOfUserModifiedRecordListUserModifiedRecord.getUserModifiedRecordList().remove(userModifiedRecordListUserModifiedRecord); - oldVmUserOfUserModifiedRecordListUserModifiedRecord = em.merge(oldVmUserOfUserModifiedRecordListUserModifiedRecord); - } - } - for (UserHasInvestigation userHasInvestigationListUserHasInvestigation : vmUser.getUserHasInvestigationList()) { - VmUser oldVmUserOfUserHasInvestigationListUserHasInvestigation = userHasInvestigationListUserHasInvestigation.getVmUser(); - userHasInvestigationListUserHasInvestigation.setVmUser(vmUser); - userHasInvestigationListUserHasInvestigation = em.merge(userHasInvestigationListUserHasInvestigation); - if (oldVmUserOfUserHasInvestigationListUserHasInvestigation != null) { - oldVmUserOfUserHasInvestigationListUserHasInvestigation.getUserHasInvestigationList().remove(userHasInvestigationListUserHasInvestigation); - oldVmUserOfUserHasInvestigationListUserHasInvestigation = em.merge(oldVmUserOfUserHasInvestigationListUserHasInvestigation); - } - } - for (UserAssigment userAssigmentListUserAssigment : vmUser.getUserAssigmentList()) { - VmUser oldVmUserOfUserAssigmentListUserAssigment = userAssigmentListUserAssigment.getVmUser(); - userAssigmentListUserAssigment.setVmUser(vmUser); - userAssigmentListUserAssigment = em.merge(userAssigmentListUserAssigment); - if (oldVmUserOfUserAssigmentListUserAssigment != null) { - oldVmUserOfUserAssigmentListUserAssigment.getUserAssigmentList().remove(userAssigmentListUserAssigment); - oldVmUserOfUserAssigmentListUserAssigment = em.merge(oldVmUserOfUserAssigmentListUserAssigment); - } - } - for (UserAssigment userAssigmentList1UserAssigment : vmUser.getUserAssigmentList1()) { - VmUser oldAssigneeIdOfUserAssigmentList1UserAssigment = userAssigmentList1UserAssigment.getAssigneeId(); - userAssigmentList1UserAssigment.setAssigneeId(vmUser); - userAssigmentList1UserAssigment = em.merge(userAssigmentList1UserAssigment); - if (oldAssigneeIdOfUserAssigmentList1UserAssigment != null) { - oldAssigneeIdOfUserAssigmentList1UserAssigment.getUserAssigmentList1().remove(userAssigmentList1UserAssigment); - oldAssigneeIdOfUserAssigmentList1UserAssigment = em.merge(oldAssigneeIdOfUserAssigmentList1UserAssigment); - } - } - for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssue : vmUser.getExecutionStepHasIssueList()) { - executionStepHasIssueListExecutionStepHasIssue.getVmUserList().add(vmUser); - executionStepHasIssueListExecutionStepHasIssue = em.merge(executionStepHasIssueListExecutionStepHasIssue); - } - for (ExecutionStepHasVmUser executionStepHasVmUserListExecutionStepHasVmUser : vmUser.getExecutionStepHasVmUserList()) { - VmUser oldVmUserOfExecutionStepHasVmUserListExecutionStepHasVmUser = executionStepHasVmUserListExecutionStepHasVmUser.getVmUser(); - executionStepHasVmUserListExecutionStepHasVmUser.setVmUser(vmUser); - executionStepHasVmUserListExecutionStepHasVmUser = em.merge(executionStepHasVmUserListExecutionStepHasVmUser); - if (oldVmUserOfExecutionStepHasVmUserListExecutionStepHasVmUser != null) { - oldVmUserOfExecutionStepHasVmUserListExecutionStepHasVmUser.getExecutionStepHasVmUserList().remove(executionStepHasVmUserListExecutionStepHasVmUser); - oldVmUserOfExecutionStepHasVmUserListExecutionStepHasVmUser = em.merge(oldVmUserOfExecutionStepHasVmUserListExecutionStepHasVmUser); - } - } - for (History historyModificationListHistory : vmUser.getHistoryModificationList()) { - VmUser oldModifierIdOfHistoryModificationListHistory = historyModificationListHistory.getModifierId(); - historyModificationListHistory.setModifierId(vmUser); - historyModificationListHistory = em.merge(historyModificationListHistory); - if (oldModifierIdOfHistoryModificationListHistory != null) { - oldModifierIdOfHistoryModificationListHistory.getHistoryModificationList().remove(historyModificationListHistory); - oldModifierIdOfHistoryModificationListHistory = em.merge(oldModifierIdOfHistoryModificationListHistory); - } - } - for (Notification notificationListNotification : vmUser.getNotificationList()) { - VmUser oldTargetOfNotificationListNotification = notificationListNotification.getTargetUser(); - notificationListNotification.setTargetUser(vmUser); - notificationListNotification = em.merge(notificationListNotification); - if (oldTargetOfNotificationListNotification != null) { - oldTargetOfNotificationListNotification.getNotificationList().remove(notificationListNotification); - oldTargetOfNotificationListNotification = em.merge(oldTargetOfNotificationListNotification); - } - } - for (Notification notificationList1Notification : vmUser.getNotificationList1()) { - VmUser oldAuthorOfNotificationList1Notification = notificationList1Notification.getAuthor(); - notificationList1Notification.setAuthor(vmUser); - notificationList1Notification = em.merge(notificationList1Notification); - if (oldAuthorOfNotificationList1Notification != null) { - oldAuthorOfNotificationList1Notification.getNotificationList1().remove(notificationList1Notification); - oldAuthorOfNotificationList1Notification = em.merge(oldAuthorOfNotificationList1Notification); - } - } - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(VmUser vmUser) throws IllegalOrphanException, NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - VmUser persistentVmUser = em.find(VmUser.class, vmUser.getId()); - UserStatus userStatusIdOld = persistentVmUser.getUserStatusId(); - UserStatus userStatusIdNew = vmUser.getUserStatusId(); - List correctiveActionListOld = persistentVmUser.getCorrectiveActionList(); - List correctiveActionListNew = vmUser.getCorrectiveActionList(); - List roleListOld = persistentVmUser.getRoleList(); - List roleListNew = vmUser.getRoleList(); - List rootCauseListOld = persistentVmUser.getRootCauseList(); - List rootCauseListNew = vmUser.getRootCauseList(); - List executionStepListOld = persistentVmUser.getExecutionStepList(); - List executionStepListNew = vmUser.getExecutionStepList(); - List executionStepList1Old = persistentVmUser.getExecutionStepList1(); - List executionStepList1New = vmUser.getExecutionStepList1(); - List userTestProjectRoleListOld = persistentVmUser.getUserTestProjectRoleList(); - List userTestProjectRoleListNew = vmUser.getUserTestProjectRoleList(); - List userTestPlanRoleListOld = persistentVmUser.getUserTestPlanRoleList(); - List userTestPlanRoleListNew = vmUser.getUserTestPlanRoleList(); - List userModifiedRecordListOld = persistentVmUser.getUserModifiedRecordList(); - List userModifiedRecordListNew = vmUser.getUserModifiedRecordList(); - List userHasInvestigationListOld = persistentVmUser.getUserHasInvestigationList(); - List userHasInvestigationListNew = vmUser.getUserHasInvestigationList(); - List userAssigmentListOld = persistentVmUser.getUserAssigmentList(); - List userAssigmentListNew = vmUser.getUserAssigmentList(); - List userAssigmentList1Old = persistentVmUser.getUserAssigmentList1(); - List userAssigmentList1New = vmUser.getUserAssigmentList1(); - List executionStepHasIssueListOld = persistentVmUser.getExecutionStepHasIssueList(); - List executionStepHasIssueListNew = vmUser.getExecutionStepHasIssueList(); - List executionStepHasVmUserListOld = persistentVmUser.getExecutionStepHasVmUserList(); - List executionStepHasVmUserListNew = vmUser.getExecutionStepHasVmUserList(); - List historyModificationListOld = persistentVmUser.getHistoryModificationList(); - List historyModificationListNew = vmUser.getHistoryModificationList(); - List notificationListOld = persistentVmUser.getNotificationList(); - List notificationListNew = vmUser.getNotificationList(); - List notificationList1Old = persistentVmUser.getNotificationList1(); - List notificationList1New = vmUser.getNotificationList1(); - List illegalOrphanMessages = null; - for (UserTestProjectRole userTestProjectRoleListOldUserTestProjectRole : userTestProjectRoleListOld) { - if (!userTestProjectRoleListNew.contains(userTestProjectRoleListOldUserTestProjectRole)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserTestProjectRole " + userTestProjectRoleListOldUserTestProjectRole + " since its vmUser field is not nullable."); - } - } - for (UserTestPlanRole userTestPlanRoleListOldUserTestPlanRole : userTestPlanRoleListOld) { - if (!userTestPlanRoleListNew.contains(userTestPlanRoleListOldUserTestPlanRole)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserTestPlanRole " + userTestPlanRoleListOldUserTestPlanRole + " since its vmUser field is not nullable."); - } - } - for (UserModifiedRecord userModifiedRecordListOldUserModifiedRecord : userModifiedRecordListOld) { - if (!userModifiedRecordListNew.contains(userModifiedRecordListOldUserModifiedRecord)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserModifiedRecord " + userModifiedRecordListOldUserModifiedRecord + " since its vmUser field is not nullable."); - } - } - for (UserHasInvestigation userHasInvestigationListOldUserHasInvestigation : userHasInvestigationListOld) { - if (!userHasInvestigationListNew.contains(userHasInvestigationListOldUserHasInvestigation)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserHasInvestigation " + userHasInvestigationListOldUserHasInvestigation + " since its vmUser field is not nullable."); - } - } - for (UserAssigment userAssigmentListOldUserAssigment : userAssigmentListOld) { - if (!userAssigmentListNew.contains(userAssigmentListOldUserAssigment)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserAssigment " + userAssigmentListOldUserAssigment + " since its vmUser field is not nullable."); - } - } - for (UserAssigment userAssigmentList1OldUserAssigment : userAssigmentList1Old) { - if (!userAssigmentList1New.contains(userAssigmentList1OldUserAssigment)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain UserAssigment " + userAssigmentList1OldUserAssigment + " since its assigneeId field is not nullable."); - } - } - for (ExecutionStepHasVmUser executionStepHasVmUserListOldExecutionStepHasVmUser : executionStepHasVmUserListOld) { - if (!executionStepHasVmUserListNew.contains(executionStepHasVmUserListOldExecutionStepHasVmUser)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain ExecutionStepHasVmUser " + executionStepHasVmUserListOldExecutionStepHasVmUser + " since its vmUser field is not nullable."); - } - } - for (History historyModificationListOldHistory : historyModificationListOld) { - if (!historyModificationListNew.contains(historyModificationListOldHistory)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain History " + historyModificationListOldHistory + " since its modifierId field is not nullable."); - } - } - for (Notification notificationListOldNotification : notificationListOld) { - if (!notificationListNew.contains(notificationListOldNotification)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain Notification " + notificationListOldNotification + " since its target field is not nullable."); - } - } - for (Notification notificationList1OldNotification : notificationList1Old) { - if (!notificationList1New.contains(notificationList1OldNotification)) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("You must retain Notification " + notificationList1OldNotification + " since its author field is not nullable."); - } - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - if (userStatusIdNew != null) { - userStatusIdNew = em.getReference(userStatusIdNew.getClass(), userStatusIdNew.getId()); - vmUser.setUserStatusId(userStatusIdNew); - } - List attachedCorrectiveActionListNew = new ArrayList(); - for (CorrectiveAction correctiveActionListNewCorrectiveActionToAttach : correctiveActionListNew) { - correctiveActionListNewCorrectiveActionToAttach = em.getReference(correctiveActionListNewCorrectiveActionToAttach.getClass(), correctiveActionListNewCorrectiveActionToAttach.getId()); - attachedCorrectiveActionListNew.add(correctiveActionListNewCorrectiveActionToAttach); - } - correctiveActionListNew = attachedCorrectiveActionListNew; - vmUser.setCorrectiveActionList(correctiveActionListNew); - List attachedRoleListNew = new ArrayList(); - for (Role roleListNewRoleToAttach : roleListNew) { - roleListNewRoleToAttach = em.getReference(roleListNewRoleToAttach.getClass(), roleListNewRoleToAttach.getId()); - attachedRoleListNew.add(roleListNewRoleToAttach); - } - roleListNew = attachedRoleListNew; - vmUser.setRoleList(roleListNew); - List attachedRootCauseListNew = new ArrayList(); - for (RootCause rootCauseListNewRootCauseToAttach : rootCauseListNew) { - rootCauseListNewRootCauseToAttach = em.getReference(rootCauseListNewRootCauseToAttach.getClass(), rootCauseListNewRootCauseToAttach.getRootCausePK()); - attachedRootCauseListNew.add(rootCauseListNewRootCauseToAttach); - } - rootCauseListNew = attachedRootCauseListNew; - vmUser.setRootCauseList(rootCauseListNew); - List attachedExecutionStepListNew = new ArrayList(); - for (ExecutionStep executionStepListNewExecutionStepToAttach : executionStepListNew) { - executionStepListNewExecutionStepToAttach = em.getReference(executionStepListNewExecutionStepToAttach.getClass(), executionStepListNewExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepListNew.add(executionStepListNewExecutionStepToAttach); - } - executionStepListNew = attachedExecutionStepListNew; - vmUser.setExecutionStepList(executionStepListNew); - List attachedExecutionStepList1New = new ArrayList(); - for (ExecutionStep executionStepList1NewExecutionStepToAttach : executionStepList1New) { - executionStepList1NewExecutionStepToAttach = em.getReference(executionStepList1NewExecutionStepToAttach.getClass(), executionStepList1NewExecutionStepToAttach.getExecutionStepPK()); - attachedExecutionStepList1New.add(executionStepList1NewExecutionStepToAttach); - } - executionStepList1New = attachedExecutionStepList1New; - vmUser.setExecutionStepList1(executionStepList1New); - List attachedUserTestProjectRoleListNew = new ArrayList(); - for (UserTestProjectRole userTestProjectRoleListNewUserTestProjectRoleToAttach : userTestProjectRoleListNew) { - userTestProjectRoleListNewUserTestProjectRoleToAttach = em.getReference(userTestProjectRoleListNewUserTestProjectRoleToAttach.getClass(), userTestProjectRoleListNewUserTestProjectRoleToAttach.getUserTestProjectRolePK()); - attachedUserTestProjectRoleListNew.add(userTestProjectRoleListNewUserTestProjectRoleToAttach); - } - userTestProjectRoleListNew = attachedUserTestProjectRoleListNew; - vmUser.setUserTestProjectRoleList(userTestProjectRoleListNew); - List attachedUserTestPlanRoleListNew = new ArrayList(); - for (UserTestPlanRole userTestPlanRoleListNewUserTestPlanRoleToAttach : userTestPlanRoleListNew) { - userTestPlanRoleListNewUserTestPlanRoleToAttach = em.getReference(userTestPlanRoleListNewUserTestPlanRoleToAttach.getClass(), userTestPlanRoleListNewUserTestPlanRoleToAttach.getUserTestPlanRolePK()); - attachedUserTestPlanRoleListNew.add(userTestPlanRoleListNewUserTestPlanRoleToAttach); - } - userTestPlanRoleListNew = attachedUserTestPlanRoleListNew; - vmUser.setUserTestPlanRoleList(userTestPlanRoleListNew); - List attachedUserModifiedRecordListNew = new ArrayList(); - for (UserModifiedRecord userModifiedRecordListNewUserModifiedRecordToAttach : userModifiedRecordListNew) { - userModifiedRecordListNewUserModifiedRecordToAttach = em.getReference(userModifiedRecordListNewUserModifiedRecordToAttach.getClass(), userModifiedRecordListNewUserModifiedRecordToAttach.getUserModifiedRecordPK()); - attachedUserModifiedRecordListNew.add(userModifiedRecordListNewUserModifiedRecordToAttach); - } - userModifiedRecordListNew = attachedUserModifiedRecordListNew; - vmUser.setUserModifiedRecordList(userModifiedRecordListNew); - List attachedUserHasInvestigationListNew = new ArrayList(); - for (UserHasInvestigation userHasInvestigationListNewUserHasInvestigationToAttach : userHasInvestigationListNew) { - userHasInvestigationListNewUserHasInvestigationToAttach = em.getReference(userHasInvestigationListNewUserHasInvestigationToAttach.getClass(), userHasInvestigationListNewUserHasInvestigationToAttach.getUserHasInvestigationPK()); - attachedUserHasInvestigationListNew.add(userHasInvestigationListNewUserHasInvestigationToAttach); - } - userHasInvestigationListNew = attachedUserHasInvestigationListNew; - vmUser.setUserHasInvestigationList(userHasInvestigationListNew); - List attachedUserAssigmentListNew = new ArrayList(); - for (UserAssigment userAssigmentListNewUserAssigmentToAttach : userAssigmentListNew) { - userAssigmentListNewUserAssigmentToAttach = em.getReference(userAssigmentListNewUserAssigmentToAttach.getClass(), userAssigmentListNewUserAssigmentToAttach.getUserAssigmentPK()); - attachedUserAssigmentListNew.add(userAssigmentListNewUserAssigmentToAttach); - } - userAssigmentListNew = attachedUserAssigmentListNew; - vmUser.setUserAssigmentList(userAssigmentListNew); - List attachedUserAssigmentList1New = new ArrayList(); - for (UserAssigment userAssigmentList1NewUserAssigmentToAttach : userAssigmentList1New) { - userAssigmentList1NewUserAssigmentToAttach = em.getReference(userAssigmentList1NewUserAssigmentToAttach.getClass(), userAssigmentList1NewUserAssigmentToAttach.getUserAssigmentPK()); - attachedUserAssigmentList1New.add(userAssigmentList1NewUserAssigmentToAttach); - } - userAssigmentList1New = attachedUserAssigmentList1New; - vmUser.setUserAssigmentList1(userAssigmentList1New); - List attachedExecutionStepHasIssueListNew = new ArrayList(); - for (ExecutionStepHasIssue executionStepHasIssueListNewExecutionStepHasIssueToAttach : executionStepHasIssueListNew) { - executionStepHasIssueListNewExecutionStepHasIssueToAttach = em.getReference(executionStepHasIssueListNewExecutionStepHasIssueToAttach.getClass(), executionStepHasIssueListNewExecutionStepHasIssueToAttach.getExecutionStepHasIssuePK()); - attachedExecutionStepHasIssueListNew.add(executionStepHasIssueListNewExecutionStepHasIssueToAttach); - } - executionStepHasIssueListNew = attachedExecutionStepHasIssueListNew; - vmUser.setExecutionStepHasIssueList(executionStepHasIssueListNew); - List attachedExecutionStepHasVmUserListNew = new ArrayList(); - for (ExecutionStepHasVmUser executionStepHasVmUserListNewExecutionStepHasVmUserToAttach : executionStepHasVmUserListNew) { - executionStepHasVmUserListNewExecutionStepHasVmUserToAttach = em.getReference(executionStepHasVmUserListNewExecutionStepHasVmUserToAttach.getClass(), executionStepHasVmUserListNewExecutionStepHasVmUserToAttach.getExecutionStepHasVmUserPK()); - attachedExecutionStepHasVmUserListNew.add(executionStepHasVmUserListNewExecutionStepHasVmUserToAttach); - } - executionStepHasVmUserListNew = attachedExecutionStepHasVmUserListNew; - vmUser.setExecutionStepHasVmUserList(executionStepHasVmUserListNew); - List attachedHistoryModificationListNew = new ArrayList(); - for (History historyModificationListNewHistoryToAttach : historyModificationListNew) { - historyModificationListNewHistoryToAttach = em.getReference(historyModificationListNewHistoryToAttach.getClass(), historyModificationListNewHistoryToAttach.getId()); - attachedHistoryModificationListNew.add(historyModificationListNewHistoryToAttach); - } - historyModificationListNew = attachedHistoryModificationListNew; - vmUser.setHistoryModificationList(historyModificationListNew); - List attachedNotificationListNew = new ArrayList(); - for (Notification notificationListNewNotificationToAttach : notificationListNew) { - notificationListNewNotificationToAttach = em.getReference(notificationListNewNotificationToAttach.getClass(), notificationListNewNotificationToAttach.getNotificationPK()); - attachedNotificationListNew.add(notificationListNewNotificationToAttach); - } - notificationListNew = attachedNotificationListNew; - vmUser.setNotificationList(notificationListNew); - List attachedNotificationList1New = new ArrayList(); - for (Notification notificationList1NewNotificationToAttach : notificationList1New) { - notificationList1NewNotificationToAttach = em.getReference(notificationList1NewNotificationToAttach.getClass(), notificationList1NewNotificationToAttach.getNotificationPK()); - attachedNotificationList1New.add(notificationList1NewNotificationToAttach); - } - notificationList1New = attachedNotificationList1New; - vmUser.setNotificationList1(notificationList1New); - vmUser = em.merge(vmUser); - if (userStatusIdOld != null && !userStatusIdOld.equals(userStatusIdNew)) { - userStatusIdOld.getVmUserList().remove(vmUser); - userStatusIdOld = em.merge(userStatusIdOld); - } - if (userStatusIdNew != null && !userStatusIdNew.equals(userStatusIdOld)) { - userStatusIdNew.getVmUserList().add(vmUser); - userStatusIdNew = em.merge(userStatusIdNew); - } - for (CorrectiveAction correctiveActionListOldCorrectiveAction : correctiveActionListOld) { - if (!correctiveActionListNew.contains(correctiveActionListOldCorrectiveAction)) { - correctiveActionListOldCorrectiveAction.getVmUserList().remove(vmUser); - correctiveActionListOldCorrectiveAction = em.merge(correctiveActionListOldCorrectiveAction); - } - } - for (CorrectiveAction correctiveActionListNewCorrectiveAction : correctiveActionListNew) { - if (!correctiveActionListOld.contains(correctiveActionListNewCorrectiveAction)) { - correctiveActionListNewCorrectiveAction.getVmUserList().add(vmUser); - correctiveActionListNewCorrectiveAction = em.merge(correctiveActionListNewCorrectiveAction); - } - } - for (Role roleListOldRole : roleListOld) { - if (!roleListNew.contains(roleListOldRole)) { - roleListOldRole.getVmUserList().remove(vmUser); - roleListOldRole = em.merge(roleListOldRole); - } - } - for (Role roleListNewRole : roleListNew) { - if (!roleListOld.contains(roleListNewRole)) { - roleListNewRole.getVmUserList().add(vmUser); - roleListNewRole = em.merge(roleListNewRole); - } - } - for (RootCause rootCauseListOldRootCause : rootCauseListOld) { - if (!rootCauseListNew.contains(rootCauseListOldRootCause)) { - rootCauseListOldRootCause.getVmUserList().remove(vmUser); - rootCauseListOldRootCause = em.merge(rootCauseListOldRootCause); - } - } - for (RootCause rootCauseListNewRootCause : rootCauseListNew) { - if (!rootCauseListOld.contains(rootCauseListNewRootCause)) { - rootCauseListNewRootCause.getVmUserList().add(vmUser); - rootCauseListNewRootCause = em.merge(rootCauseListNewRootCause); - } - } - for (ExecutionStep executionStepListOldExecutionStep : executionStepListOld) { - if (!executionStepListNew.contains(executionStepListOldExecutionStep)) { - executionStepListOldExecutionStep.setAssignee(null); - executionStepListOldExecutionStep = em.merge(executionStepListOldExecutionStep); - } - } - for (ExecutionStep executionStepListNewExecutionStep : executionStepListNew) { - if (!executionStepListOld.contains(executionStepListNewExecutionStep)) { - VmUser oldAssigneeOfExecutionStepListNewExecutionStep = executionStepListNewExecutionStep.getAssignee(); - executionStepListNewExecutionStep.setAssignee(vmUser); - executionStepListNewExecutionStep = em.merge(executionStepListNewExecutionStep); - if (oldAssigneeOfExecutionStepListNewExecutionStep != null && !oldAssigneeOfExecutionStepListNewExecutionStep.equals(vmUser)) { - oldAssigneeOfExecutionStepListNewExecutionStep.getExecutionStepList().remove(executionStepListNewExecutionStep); - oldAssigneeOfExecutionStepListNewExecutionStep = em.merge(oldAssigneeOfExecutionStepListNewExecutionStep); - } - } - } - for (ExecutionStep executionStepList1OldExecutionStep : executionStepList1Old) { - if (!executionStepList1New.contains(executionStepList1OldExecutionStep)) { - executionStepList1OldExecutionStep.setAssigner(null); - executionStepList1OldExecutionStep = em.merge(executionStepList1OldExecutionStep); - } - } - for (ExecutionStep executionStepList1NewExecutionStep : executionStepList1New) { - if (!executionStepList1Old.contains(executionStepList1NewExecutionStep)) { - VmUser oldAssignerOfExecutionStepList1NewExecutionStep = executionStepList1NewExecutionStep.getAssigner(); - executionStepList1NewExecutionStep.setAssigner(vmUser); - executionStepList1NewExecutionStep = em.merge(executionStepList1NewExecutionStep); - if (oldAssignerOfExecutionStepList1NewExecutionStep != null && !oldAssignerOfExecutionStepList1NewExecutionStep.equals(vmUser)) { - oldAssignerOfExecutionStepList1NewExecutionStep.getExecutionStepList1().remove(executionStepList1NewExecutionStep); - oldAssignerOfExecutionStepList1NewExecutionStep = em.merge(oldAssignerOfExecutionStepList1NewExecutionStep); - } - } - } - for (UserTestProjectRole userTestProjectRoleListNewUserTestProjectRole : userTestProjectRoleListNew) { - if (!userTestProjectRoleListOld.contains(userTestProjectRoleListNewUserTestProjectRole)) { - VmUser oldVmUserOfUserTestProjectRoleListNewUserTestProjectRole = userTestProjectRoleListNewUserTestProjectRole.getVmUser(); - userTestProjectRoleListNewUserTestProjectRole.setVmUser(vmUser); - userTestProjectRoleListNewUserTestProjectRole = em.merge(userTestProjectRoleListNewUserTestProjectRole); - if (oldVmUserOfUserTestProjectRoleListNewUserTestProjectRole != null && !oldVmUserOfUserTestProjectRoleListNewUserTestProjectRole.equals(vmUser)) { - oldVmUserOfUserTestProjectRoleListNewUserTestProjectRole.getUserTestProjectRoleList().remove(userTestProjectRoleListNewUserTestProjectRole); - oldVmUserOfUserTestProjectRoleListNewUserTestProjectRole = em.merge(oldVmUserOfUserTestProjectRoleListNewUserTestProjectRole); - } - } - } - for (UserTestPlanRole userTestPlanRoleListNewUserTestPlanRole : userTestPlanRoleListNew) { - if (!userTestPlanRoleListOld.contains(userTestPlanRoleListNewUserTestPlanRole)) { - VmUser oldVmUserOfUserTestPlanRoleListNewUserTestPlanRole = userTestPlanRoleListNewUserTestPlanRole.getVmUser(); - userTestPlanRoleListNewUserTestPlanRole.setVmUser(vmUser); - userTestPlanRoleListNewUserTestPlanRole = em.merge(userTestPlanRoleListNewUserTestPlanRole); - if (oldVmUserOfUserTestPlanRoleListNewUserTestPlanRole != null && !oldVmUserOfUserTestPlanRoleListNewUserTestPlanRole.equals(vmUser)) { - oldVmUserOfUserTestPlanRoleListNewUserTestPlanRole.getUserTestPlanRoleList().remove(userTestPlanRoleListNewUserTestPlanRole); - oldVmUserOfUserTestPlanRoleListNewUserTestPlanRole = em.merge(oldVmUserOfUserTestPlanRoleListNewUserTestPlanRole); - } - } - } - for (UserModifiedRecord userModifiedRecordListNewUserModifiedRecord : userModifiedRecordListNew) { - if (!userModifiedRecordListOld.contains(userModifiedRecordListNewUserModifiedRecord)) { - VmUser oldVmUserOfUserModifiedRecordListNewUserModifiedRecord = userModifiedRecordListNewUserModifiedRecord.getVmUser(); - userModifiedRecordListNewUserModifiedRecord.setVmUser(vmUser); - userModifiedRecordListNewUserModifiedRecord = em.merge(userModifiedRecordListNewUserModifiedRecord); - if (oldVmUserOfUserModifiedRecordListNewUserModifiedRecord != null && !oldVmUserOfUserModifiedRecordListNewUserModifiedRecord.equals(vmUser)) { - oldVmUserOfUserModifiedRecordListNewUserModifiedRecord.getUserModifiedRecordList().remove(userModifiedRecordListNewUserModifiedRecord); - oldVmUserOfUserModifiedRecordListNewUserModifiedRecord = em.merge(oldVmUserOfUserModifiedRecordListNewUserModifiedRecord); - } - } - } - for (UserHasInvestigation userHasInvestigationListNewUserHasInvestigation : userHasInvestigationListNew) { - if (!userHasInvestigationListOld.contains(userHasInvestigationListNewUserHasInvestigation)) { - VmUser oldVmUserOfUserHasInvestigationListNewUserHasInvestigation = userHasInvestigationListNewUserHasInvestigation.getVmUser(); - userHasInvestigationListNewUserHasInvestigation.setVmUser(vmUser); - userHasInvestigationListNewUserHasInvestigation = em.merge(userHasInvestigationListNewUserHasInvestigation); - if (oldVmUserOfUserHasInvestigationListNewUserHasInvestigation != null && !oldVmUserOfUserHasInvestigationListNewUserHasInvestigation.equals(vmUser)) { - oldVmUserOfUserHasInvestigationListNewUserHasInvestigation.getUserHasInvestigationList().remove(userHasInvestigationListNewUserHasInvestigation); - oldVmUserOfUserHasInvestigationListNewUserHasInvestigation = em.merge(oldVmUserOfUserHasInvestigationListNewUserHasInvestigation); - } - } - } - for (UserAssigment userAssigmentListNewUserAssigment : userAssigmentListNew) { - if (!userAssigmentListOld.contains(userAssigmentListNewUserAssigment)) { - VmUser oldVmUserOfUserAssigmentListNewUserAssigment = userAssigmentListNewUserAssigment.getVmUser(); - userAssigmentListNewUserAssigment.setVmUser(vmUser); - userAssigmentListNewUserAssigment = em.merge(userAssigmentListNewUserAssigment); - if (oldVmUserOfUserAssigmentListNewUserAssigment != null && !oldVmUserOfUserAssigmentListNewUserAssigment.equals(vmUser)) { - oldVmUserOfUserAssigmentListNewUserAssigment.getUserAssigmentList().remove(userAssigmentListNewUserAssigment); - oldVmUserOfUserAssigmentListNewUserAssigment = em.merge(oldVmUserOfUserAssigmentListNewUserAssigment); - } - } - } - for (UserAssigment userAssigmentList1NewUserAssigment : userAssigmentList1New) { - if (!userAssigmentList1Old.contains(userAssigmentList1NewUserAssigment)) { - VmUser oldAssigneeIdOfUserAssigmentList1NewUserAssigment = userAssigmentList1NewUserAssigment.getAssigneeId(); - userAssigmentList1NewUserAssigment.setAssigneeId(vmUser); - userAssigmentList1NewUserAssigment = em.merge(userAssigmentList1NewUserAssigment); - if (oldAssigneeIdOfUserAssigmentList1NewUserAssigment != null && !oldAssigneeIdOfUserAssigmentList1NewUserAssigment.equals(vmUser)) { - oldAssigneeIdOfUserAssigmentList1NewUserAssigment.getUserAssigmentList1().remove(userAssigmentList1NewUserAssigment); - oldAssigneeIdOfUserAssigmentList1NewUserAssigment = em.merge(oldAssigneeIdOfUserAssigmentList1NewUserAssigment); - } - } - } - for (ExecutionStepHasIssue executionStepHasIssueListOldExecutionStepHasIssue : executionStepHasIssueListOld) { - if (!executionStepHasIssueListNew.contains(executionStepHasIssueListOldExecutionStepHasIssue)) { - executionStepHasIssueListOldExecutionStepHasIssue.getVmUserList().remove(vmUser); - executionStepHasIssueListOldExecutionStepHasIssue = em.merge(executionStepHasIssueListOldExecutionStepHasIssue); - } - } - for (ExecutionStepHasIssue executionStepHasIssueListNewExecutionStepHasIssue : executionStepHasIssueListNew) { - if (!executionStepHasIssueListOld.contains(executionStepHasIssueListNewExecutionStepHasIssue)) { - executionStepHasIssueListNewExecutionStepHasIssue.getVmUserList().add(vmUser); - executionStepHasIssueListNewExecutionStepHasIssue = em.merge(executionStepHasIssueListNewExecutionStepHasIssue); - } - } - for (ExecutionStepHasVmUser executionStepHasVmUserListNewExecutionStepHasVmUser : executionStepHasVmUserListNew) { - if (!executionStepHasVmUserListOld.contains(executionStepHasVmUserListNewExecutionStepHasVmUser)) { - VmUser oldVmUserOfExecutionStepHasVmUserListNewExecutionStepHasVmUser = executionStepHasVmUserListNewExecutionStepHasVmUser.getVmUser(); - executionStepHasVmUserListNewExecutionStepHasVmUser.setVmUser(vmUser); - executionStepHasVmUserListNewExecutionStepHasVmUser = em.merge(executionStepHasVmUserListNewExecutionStepHasVmUser); - if (oldVmUserOfExecutionStepHasVmUserListNewExecutionStepHasVmUser != null && !oldVmUserOfExecutionStepHasVmUserListNewExecutionStepHasVmUser.equals(vmUser)) { - oldVmUserOfExecutionStepHasVmUserListNewExecutionStepHasVmUser.getExecutionStepHasVmUserList().remove(executionStepHasVmUserListNewExecutionStepHasVmUser); - oldVmUserOfExecutionStepHasVmUserListNewExecutionStepHasVmUser = em.merge(oldVmUserOfExecutionStepHasVmUserListNewExecutionStepHasVmUser); - } - } - } - for (History historyModificationListNewHistory : historyModificationListNew) { - if (!historyModificationListOld.contains(historyModificationListNewHistory)) { - VmUser oldModifierIdOfHistoryModificationListNewHistory = historyModificationListNewHistory.getModifierId(); - historyModificationListNewHistory.setModifierId(vmUser); - historyModificationListNewHistory = em.merge(historyModificationListNewHistory); - if (oldModifierIdOfHistoryModificationListNewHistory != null && !oldModifierIdOfHistoryModificationListNewHistory.equals(vmUser)) { - oldModifierIdOfHistoryModificationListNewHistory.getHistoryModificationList().remove(historyModificationListNewHistory); - oldModifierIdOfHistoryModificationListNewHistory = em.merge(oldModifierIdOfHistoryModificationListNewHistory); - } - } - } - for (Notification notificationListNewNotification : notificationListNew) { - if (!notificationListOld.contains(notificationListNewNotification)) { - VmUser oldTargetOfNotificationListNewNotification = notificationListNewNotification.getTargetUser(); - notificationListNewNotification.setTargetUser(vmUser); - notificationListNewNotification = em.merge(notificationListNewNotification); - if (oldTargetOfNotificationListNewNotification != null && !oldTargetOfNotificationListNewNotification.equals(vmUser)) { - oldTargetOfNotificationListNewNotification.getNotificationList().remove(notificationListNewNotification); - oldTargetOfNotificationListNewNotification = em.merge(oldTargetOfNotificationListNewNotification); - } - } - } - for (Notification notificationList1NewNotification : notificationList1New) { - if (!notificationList1Old.contains(notificationList1NewNotification)) { - VmUser oldAuthorOfNotificationList1NewNotification = notificationList1NewNotification.getAuthor(); - notificationList1NewNotification.setAuthor(vmUser); - notificationList1NewNotification = em.merge(notificationList1NewNotification); - if (oldAuthorOfNotificationList1NewNotification != null && !oldAuthorOfNotificationList1NewNotification.equals(vmUser)) { - oldAuthorOfNotificationList1NewNotification.getNotificationList1().remove(notificationList1NewNotification); - oldAuthorOfNotificationList1NewNotification = em.merge(oldAuthorOfNotificationList1NewNotification); - } - } - } - em.getTransaction().commit(); - } - catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - Integer id = vmUser.getId(); - if (findVmUser(id) == null) { - throw new NonexistentEntityException("The vmUser with id " + id + " no longer exists."); - } - } - throw ex; - } - finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - VmUser vmUser; - try { - vmUser = em.getReference(VmUser.class, id); - vmUser.getId(); - } - catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The vmUser with id " + id + " no longer exists.", enfe); - } - List illegalOrphanMessages = null; - List userTestProjectRoleListOrphanCheck = vmUser.getUserTestProjectRoleList(); - for (UserTestProjectRole userTestProjectRoleListOrphanCheckUserTestProjectRole : userTestProjectRoleListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the UserTestProjectRole " + userTestProjectRoleListOrphanCheckUserTestProjectRole + " in its userTestProjectRoleList field has a non-nullable vmUser field."); - } - List userTestPlanRoleListOrphanCheck = vmUser.getUserTestPlanRoleList(); - for (UserTestPlanRole userTestPlanRoleListOrphanCheckUserTestPlanRole : userTestPlanRoleListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the UserTestPlanRole " + userTestPlanRoleListOrphanCheckUserTestPlanRole + " in its userTestPlanRoleList field has a non-nullable vmUser field."); - } - List userModifiedRecordListOrphanCheck = vmUser.getUserModifiedRecordList(); - for (UserModifiedRecord userModifiedRecordListOrphanCheckUserModifiedRecord : userModifiedRecordListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the UserModifiedRecord " + userModifiedRecordListOrphanCheckUserModifiedRecord + " in its userModifiedRecordList field has a non-nullable vmUser field."); - } - List userHasInvestigationListOrphanCheck = vmUser.getUserHasInvestigationList(); - for (UserHasInvestigation userHasInvestigationListOrphanCheckUserHasInvestigation : userHasInvestigationListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the UserHasInvestigation " + userHasInvestigationListOrphanCheckUserHasInvestigation + " in its userHasInvestigationList field has a non-nullable vmUser field."); - } - List userAssigmentListOrphanCheck = vmUser.getUserAssigmentList(); - for (UserAssigment userAssigmentListOrphanCheckUserAssigment : userAssigmentListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the UserAssigment " + userAssigmentListOrphanCheckUserAssigment + " in its userAssigmentList field has a non-nullable vmUser field."); - } - List userAssigmentList1OrphanCheck = vmUser.getUserAssigmentList1(); - for (UserAssigment userAssigmentList1OrphanCheckUserAssigment : userAssigmentList1OrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the UserAssigment " + userAssigmentList1OrphanCheckUserAssigment + " in its userAssigmentList1 field has a non-nullable assigneeId field."); - } - List executionStepHasVmUserListOrphanCheck = vmUser.getExecutionStepHasVmUserList(); - for (ExecutionStepHasVmUser executionStepHasVmUserListOrphanCheckExecutionStepHasVmUser : executionStepHasVmUserListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the ExecutionStepHasVmUser " + executionStepHasVmUserListOrphanCheckExecutionStepHasVmUser + " in its executionStepHasVmUserList field has a non-nullable vmUser field."); - } - List historyModificationListOrphanCheck = vmUser.getHistoryModificationList(); - for (History historyModificationListOrphanCheckHistory : historyModificationListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the History " + historyModificationListOrphanCheckHistory + " in its historyModificationList field has a non-nullable modifierId field."); - } - List notificationListOrphanCheck = vmUser.getNotificationList(); - for (Notification notificationListOrphanCheckNotification : notificationListOrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the Notification " + notificationListOrphanCheckNotification + " in its notificationList field has a non-nullable target field."); - } - List notificationList1OrphanCheck = vmUser.getNotificationList1(); - for (Notification notificationList1OrphanCheckNotification : notificationList1OrphanCheck) { - if (illegalOrphanMessages == null) { - illegalOrphanMessages = new ArrayList(); - } - illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the Notification " + notificationList1OrphanCheckNotification + " in its notificationList1 field has a non-nullable author field."); - } - if (illegalOrphanMessages != null) { - throw new IllegalOrphanException(illegalOrphanMessages); - } - UserStatus userStatusId = vmUser.getUserStatusId(); - if (userStatusId != null) { - userStatusId.getVmUserList().remove(vmUser); - userStatusId = em.merge(userStatusId); - } - List correctiveActionList = vmUser.getCorrectiveActionList(); - for (CorrectiveAction correctiveActionListCorrectiveAction : correctiveActionList) { - correctiveActionListCorrectiveAction.getVmUserList().remove(vmUser); - correctiveActionListCorrectiveAction = em.merge(correctiveActionListCorrectiveAction); - } - List roleList = vmUser.getRoleList(); - for (Role roleListRole : roleList) { - roleListRole.getVmUserList().remove(vmUser); - roleListRole = em.merge(roleListRole); - } - List rootCauseList = vmUser.getRootCauseList(); - for (RootCause rootCauseListRootCause : rootCauseList) { - rootCauseListRootCause.getVmUserList().remove(vmUser); - rootCauseListRootCause = em.merge(rootCauseListRootCause); - } - List executionStepList = vmUser.getExecutionStepList(); - for (ExecutionStep executionStepListExecutionStep : executionStepList) { - executionStepListExecutionStep.setAssignee(null); - executionStepListExecutionStep = em.merge(executionStepListExecutionStep); - } - List executionStepList1 = vmUser.getExecutionStepList1(); - for (ExecutionStep executionStepList1ExecutionStep : executionStepList1) { - executionStepList1ExecutionStep.setAssigner(null); - executionStepList1ExecutionStep = em.merge(executionStepList1ExecutionStep); - } - List executionStepHasIssueList = vmUser.getExecutionStepHasIssueList(); - for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssue : executionStepHasIssueList) { - executionStepHasIssueListExecutionStepHasIssue.getVmUserList().remove(vmUser); - executionStepHasIssueListExecutionStepHasIssue = em.merge(executionStepHasIssueListExecutionStepHasIssue); - } - em.remove(vmUser); - em.getTransaction().commit(); - } - finally { - if (em != null) { - em.close(); - } - } - } - - public List findVmUserEntities() { - return findVmUserEntities(true, -1, -1); - } - - public List findVmUserEntities(int maxResults, int firstResult) { - return findVmUserEntities(false, maxResults, firstResult); - } - - private List findVmUserEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(VmUser.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } - finally { - em.close(); - } - } - - public VmUser findVmUser(Integer id) { - EntityManager em = getEntityManager(); - try { - return em.find(VmUser.class, id); - } - finally { - em.close(); - } - } - - public int getVmUserCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root rt = cq.from(VmUser.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - finally { - em.close(); - } - } - -} +package com.validation.manager.core.db.controller; + +import java.io.Serializable; +import javax.persistence.Query; +import javax.persistence.EntityNotFoundException; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import com.validation.manager.core.db.UserStatus; +import com.validation.manager.core.db.CorrectiveAction; +import java.util.ArrayList; +import java.util.List; +import com.validation.manager.core.db.Role; +import com.validation.manager.core.db.RootCause; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.UserTestProjectRole; +import com.validation.manager.core.db.UserTestPlanRole; +import com.validation.manager.core.db.UserModifiedRecord; +import com.validation.manager.core.db.UserHasInvestigation; +import com.validation.manager.core.db.UserAssigment; +import com.validation.manager.core.db.ExecutionStepHasIssue; +import com.validation.manager.core.db.ExecutionStepHasVmUser; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.Notification; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class VmUserJpaController implements Serializable { + + public VmUserJpaController(EntityManagerFactory emf) { + this.emf = emf; + } + private EntityManagerFactory emf = null; + + public EntityManager getEntityManager() { + return emf.createEntityManager(); + } + + public void create(VmUser vmUser) { + if (vmUser.getCorrectiveActionList() == null) { + vmUser.setCorrectiveActionList(new ArrayList<>()); + } + if (vmUser.getRoleList() == null) { + vmUser.setRoleList(new ArrayList<>()); + } + if (vmUser.getRootCauseList() == null) { + vmUser.setRootCauseList(new ArrayList<>()); + } + if (vmUser.getExecutionStepList() == null) { + vmUser.setExecutionStepList(new ArrayList<>()); + } + if (vmUser.getExecutionStepList1() == null) { + vmUser.setExecutionStepList1(new ArrayList<>()); + } + if (vmUser.getUserTestProjectRoleList() == null) { + vmUser.setUserTestProjectRoleList(new ArrayList<>()); + } + if (vmUser.getUserTestPlanRoleList() == null) { + vmUser.setUserTestPlanRoleList(new ArrayList<>()); + } + if (vmUser.getUserModifiedRecordList() == null) { + vmUser.setUserModifiedRecordList(new ArrayList<>()); + } + if (vmUser.getUserHasInvestigationList() == null) { + vmUser.setUserHasInvestigationList(new ArrayList<>()); + } + if (vmUser.getUserAssigmentList() == null) { + vmUser.setUserAssigmentList(new ArrayList<>()); + } + if (vmUser.getUserAssigmentList1() == null) { + vmUser.setUserAssigmentList1(new ArrayList<>()); + } + if (vmUser.getExecutionStepHasIssueList() == null) { + vmUser.setExecutionStepHasIssueList(new ArrayList<>()); + } + if (vmUser.getExecutionStepHasVmUserList() == null) { + vmUser.setExecutionStepHasVmUserList(new ArrayList<>()); + } + if (vmUser.getHistoryModificationList() == null) { + vmUser.setHistoryModificationList(new ArrayList<>()); + } + if (vmUser.getNotificationList() == null) { + vmUser.setNotificationList(new ArrayList<>()); + } + if (vmUser.getNotificationList1() == null) { + vmUser.setNotificationList1(new ArrayList<>()); + } + if (vmUser.getHistoryList() == null) { + vmUser.setHistoryList(new ArrayList<>()); + } + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + UserStatus userStatusId = vmUser.getUserStatusId(); + if (userStatusId != null) { + userStatusId = em.getReference(userStatusId.getClass(), userStatusId.getId()); + vmUser.setUserStatusId(userStatusId); + } + List attachedCorrectiveActionList = new ArrayList<>(); + for (CorrectiveAction correctiveActionListCorrectiveActionToAttach : vmUser.getCorrectiveActionList()) { + correctiveActionListCorrectiveActionToAttach = em.getReference(correctiveActionListCorrectiveActionToAttach.getClass(), correctiveActionListCorrectiveActionToAttach.getId()); + attachedCorrectiveActionList.add(correctiveActionListCorrectiveActionToAttach); + } + vmUser.setCorrectiveActionList(attachedCorrectiveActionList); + List attachedRoleList = new ArrayList<>(); + for (Role roleListRoleToAttach : vmUser.getRoleList()) { + roleListRoleToAttach = em.getReference(roleListRoleToAttach.getClass(), roleListRoleToAttach.getId()); + attachedRoleList.add(roleListRoleToAttach); + } + vmUser.setRoleList(attachedRoleList); + List attachedRootCauseList = new ArrayList<>(); + for (RootCause rootCauseListRootCauseToAttach : vmUser.getRootCauseList()) { + rootCauseListRootCauseToAttach = em.getReference(rootCauseListRootCauseToAttach.getClass(), rootCauseListRootCauseToAttach.getRootCausePK()); + attachedRootCauseList.add(rootCauseListRootCauseToAttach); + } + vmUser.setRootCauseList(attachedRootCauseList); + List attachedExecutionStepList = new ArrayList<>(); + for (ExecutionStep executionStepListExecutionStepToAttach : vmUser.getExecutionStepList()) { + executionStepListExecutionStepToAttach = em.getReference(executionStepListExecutionStepToAttach.getClass(), executionStepListExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepList.add(executionStepListExecutionStepToAttach); + } + vmUser.setExecutionStepList(attachedExecutionStepList); + List attachedExecutionStepList1 = new ArrayList<>(); + for (ExecutionStep executionStepList1ExecutionStepToAttach : vmUser.getExecutionStepList1()) { + executionStepList1ExecutionStepToAttach = em.getReference(executionStepList1ExecutionStepToAttach.getClass(), executionStepList1ExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepList1.add(executionStepList1ExecutionStepToAttach); + } + vmUser.setExecutionStepList1(attachedExecutionStepList1); + List attachedUserTestProjectRoleList = new ArrayList<>(); + for (UserTestProjectRole userTestProjectRoleListUserTestProjectRoleToAttach : vmUser.getUserTestProjectRoleList()) { + userTestProjectRoleListUserTestProjectRoleToAttach = em.getReference(userTestProjectRoleListUserTestProjectRoleToAttach.getClass(), userTestProjectRoleListUserTestProjectRoleToAttach.getUserTestProjectRolePK()); + attachedUserTestProjectRoleList.add(userTestProjectRoleListUserTestProjectRoleToAttach); + } + vmUser.setUserTestProjectRoleList(attachedUserTestProjectRoleList); + List attachedUserTestPlanRoleList = new ArrayList<>(); + for (UserTestPlanRole userTestPlanRoleListUserTestPlanRoleToAttach : vmUser.getUserTestPlanRoleList()) { + userTestPlanRoleListUserTestPlanRoleToAttach = em.getReference(userTestPlanRoleListUserTestPlanRoleToAttach.getClass(), userTestPlanRoleListUserTestPlanRoleToAttach.getUserTestPlanRolePK()); + attachedUserTestPlanRoleList.add(userTestPlanRoleListUserTestPlanRoleToAttach); + } + vmUser.setUserTestPlanRoleList(attachedUserTestPlanRoleList); + List attachedUserModifiedRecordList = new ArrayList<>(); + for (UserModifiedRecord userModifiedRecordListUserModifiedRecordToAttach : vmUser.getUserModifiedRecordList()) { + userModifiedRecordListUserModifiedRecordToAttach = em.getReference(userModifiedRecordListUserModifiedRecordToAttach.getClass(), userModifiedRecordListUserModifiedRecordToAttach.getUserModifiedRecordPK()); + attachedUserModifiedRecordList.add(userModifiedRecordListUserModifiedRecordToAttach); + } + vmUser.setUserModifiedRecordList(attachedUserModifiedRecordList); + List attachedUserHasInvestigationList = new ArrayList<>(); + for (UserHasInvestigation userHasInvestigationListUserHasInvestigationToAttach : vmUser.getUserHasInvestigationList()) { + userHasInvestigationListUserHasInvestigationToAttach = em.getReference(userHasInvestigationListUserHasInvestigationToAttach.getClass(), userHasInvestigationListUserHasInvestigationToAttach.getUserHasInvestigationPK()); + attachedUserHasInvestigationList.add(userHasInvestigationListUserHasInvestigationToAttach); + } + vmUser.setUserHasInvestigationList(attachedUserHasInvestigationList); + List attachedUserAssigmentList = new ArrayList<>(); + for (UserAssigment userAssigmentListUserAssigmentToAttach : vmUser.getUserAssigmentList()) { + userAssigmentListUserAssigmentToAttach = em.getReference(userAssigmentListUserAssigmentToAttach.getClass(), userAssigmentListUserAssigmentToAttach.getUserAssigmentPK()); + attachedUserAssigmentList.add(userAssigmentListUserAssigmentToAttach); + } + vmUser.setUserAssigmentList(attachedUserAssigmentList); + List attachedUserAssigmentList1 = new ArrayList<>(); + for (UserAssigment userAssigmentList1UserAssigmentToAttach : vmUser.getUserAssigmentList1()) { + userAssigmentList1UserAssigmentToAttach = em.getReference(userAssigmentList1UserAssigmentToAttach.getClass(), userAssigmentList1UserAssigmentToAttach.getUserAssigmentPK()); + attachedUserAssigmentList1.add(userAssigmentList1UserAssigmentToAttach); + } + vmUser.setUserAssigmentList1(attachedUserAssigmentList1); + List attachedExecutionStepHasIssueList = new ArrayList<>(); + for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssueToAttach : vmUser.getExecutionStepHasIssueList()) { + executionStepHasIssueListExecutionStepHasIssueToAttach = em.getReference(executionStepHasIssueListExecutionStepHasIssueToAttach.getClass(), executionStepHasIssueListExecutionStepHasIssueToAttach.getExecutionStepHasIssuePK()); + attachedExecutionStepHasIssueList.add(executionStepHasIssueListExecutionStepHasIssueToAttach); + } + vmUser.setExecutionStepHasIssueList(attachedExecutionStepHasIssueList); + List attachedExecutionStepHasVmUserList = new ArrayList<>(); + for (ExecutionStepHasVmUser executionStepHasVmUserListExecutionStepHasVmUserToAttach : vmUser.getExecutionStepHasVmUserList()) { + executionStepHasVmUserListExecutionStepHasVmUserToAttach = em.getReference(executionStepHasVmUserListExecutionStepHasVmUserToAttach.getClass(), executionStepHasVmUserListExecutionStepHasVmUserToAttach.getExecutionStepHasVmUserPK()); + attachedExecutionStepHasVmUserList.add(executionStepHasVmUserListExecutionStepHasVmUserToAttach); + } + vmUser.setExecutionStepHasVmUserList(attachedExecutionStepHasVmUserList); + List attachedHistoryModificationList = new ArrayList<>(); + for (History historyModificationListHistoryToAttach : vmUser.getHistoryModificationList()) { + historyModificationListHistoryToAttach = em.getReference(historyModificationListHistoryToAttach.getClass(), historyModificationListHistoryToAttach.getId()); + attachedHistoryModificationList.add(historyModificationListHistoryToAttach); + } + vmUser.setHistoryModificationList(attachedHistoryModificationList); + List attachedNotificationList = new ArrayList<>(); + for (Notification notificationListNotificationToAttach : vmUser.getNotificationList()) { + notificationListNotificationToAttach = em.getReference(notificationListNotificationToAttach.getClass(), notificationListNotificationToAttach.getNotificationPK()); + attachedNotificationList.add(notificationListNotificationToAttach); + } + vmUser.setNotificationList(attachedNotificationList); + List attachedNotificationList1 = new ArrayList<>(); + for (Notification notificationList1NotificationToAttach : vmUser.getNotificationList1()) { + notificationList1NotificationToAttach = em.getReference(notificationList1NotificationToAttach.getClass(), notificationList1NotificationToAttach.getNotificationPK()); + attachedNotificationList1.add(notificationList1NotificationToAttach); + } + vmUser.setNotificationList1(attachedNotificationList1); + List attachedHistoryList = new ArrayList<>(); + for (History historyListHistoryToAttach : vmUser.getHistoryList()) { + historyListHistoryToAttach = em.getReference(historyListHistoryToAttach.getClass(), historyListHistoryToAttach.getId()); + attachedHistoryList.add(historyListHistoryToAttach); + } + vmUser.setHistoryList(attachedHistoryList); + em.persist(vmUser); + if (userStatusId != null) { + userStatusId.getVmUserList().add(vmUser); + userStatusId = em.merge(userStatusId); + } + for (CorrectiveAction correctiveActionListCorrectiveAction : vmUser.getCorrectiveActionList()) { + correctiveActionListCorrectiveAction.getVmUserList().add(vmUser); + correctiveActionListCorrectiveAction = em.merge(correctiveActionListCorrectiveAction); + } + for (Role roleListRole : vmUser.getRoleList()) { + roleListRole.getVmUserList().add(vmUser); + roleListRole = em.merge(roleListRole); + } + for (RootCause rootCauseListRootCause : vmUser.getRootCauseList()) { + rootCauseListRootCause.getVmUserList().add(vmUser); + rootCauseListRootCause = em.merge(rootCauseListRootCause); + } + for (ExecutionStep executionStepListExecutionStep : vmUser.getExecutionStepList()) { + VmUser oldAssigneeOfExecutionStepListExecutionStep = executionStepListExecutionStep.getAssignee(); + executionStepListExecutionStep.setAssignee(vmUser); + executionStepListExecutionStep = em.merge(executionStepListExecutionStep); + if (oldAssigneeOfExecutionStepListExecutionStep != null) { + oldAssigneeOfExecutionStepListExecutionStep.getExecutionStepList().remove(executionStepListExecutionStep); + oldAssigneeOfExecutionStepListExecutionStep = em.merge(oldAssigneeOfExecutionStepListExecutionStep); + } + } + for (ExecutionStep executionStepList1ExecutionStep : vmUser.getExecutionStepList1()) { + VmUser oldAssignerOfExecutionStepList1ExecutionStep = executionStepList1ExecutionStep.getAssigner(); + executionStepList1ExecutionStep.setAssigner(vmUser); + executionStepList1ExecutionStep = em.merge(executionStepList1ExecutionStep); + if (oldAssignerOfExecutionStepList1ExecutionStep != null) { + oldAssignerOfExecutionStepList1ExecutionStep.getExecutionStepList1().remove(executionStepList1ExecutionStep); + oldAssignerOfExecutionStepList1ExecutionStep = em.merge(oldAssignerOfExecutionStepList1ExecutionStep); + } + } + for (UserTestProjectRole userTestProjectRoleListUserTestProjectRole : vmUser.getUserTestProjectRoleList()) { + VmUser oldVmUserOfUserTestProjectRoleListUserTestProjectRole = userTestProjectRoleListUserTestProjectRole.getVmUser(); + userTestProjectRoleListUserTestProjectRole.setVmUser(vmUser); + userTestProjectRoleListUserTestProjectRole = em.merge(userTestProjectRoleListUserTestProjectRole); + if (oldVmUserOfUserTestProjectRoleListUserTestProjectRole != null) { + oldVmUserOfUserTestProjectRoleListUserTestProjectRole.getUserTestProjectRoleList().remove(userTestProjectRoleListUserTestProjectRole); + oldVmUserOfUserTestProjectRoleListUserTestProjectRole = em.merge(oldVmUserOfUserTestProjectRoleListUserTestProjectRole); + } + } + for (UserTestPlanRole userTestPlanRoleListUserTestPlanRole : vmUser.getUserTestPlanRoleList()) { + VmUser oldVmUserOfUserTestPlanRoleListUserTestPlanRole = userTestPlanRoleListUserTestPlanRole.getVmUser(); + userTestPlanRoleListUserTestPlanRole.setVmUser(vmUser); + userTestPlanRoleListUserTestPlanRole = em.merge(userTestPlanRoleListUserTestPlanRole); + if (oldVmUserOfUserTestPlanRoleListUserTestPlanRole != null) { + oldVmUserOfUserTestPlanRoleListUserTestPlanRole.getUserTestPlanRoleList().remove(userTestPlanRoleListUserTestPlanRole); + oldVmUserOfUserTestPlanRoleListUserTestPlanRole = em.merge(oldVmUserOfUserTestPlanRoleListUserTestPlanRole); + } + } + for (UserModifiedRecord userModifiedRecordListUserModifiedRecord : vmUser.getUserModifiedRecordList()) { + VmUser oldVmUserOfUserModifiedRecordListUserModifiedRecord = userModifiedRecordListUserModifiedRecord.getVmUser(); + userModifiedRecordListUserModifiedRecord.setVmUser(vmUser); + userModifiedRecordListUserModifiedRecord = em.merge(userModifiedRecordListUserModifiedRecord); + if (oldVmUserOfUserModifiedRecordListUserModifiedRecord != null) { + oldVmUserOfUserModifiedRecordListUserModifiedRecord.getUserModifiedRecordList().remove(userModifiedRecordListUserModifiedRecord); + oldVmUserOfUserModifiedRecordListUserModifiedRecord = em.merge(oldVmUserOfUserModifiedRecordListUserModifiedRecord); + } + } + for (UserHasInvestigation userHasInvestigationListUserHasInvestigation : vmUser.getUserHasInvestigationList()) { + VmUser oldVmUserOfUserHasInvestigationListUserHasInvestigation = userHasInvestigationListUserHasInvestigation.getVmUser(); + userHasInvestigationListUserHasInvestigation.setVmUser(vmUser); + userHasInvestigationListUserHasInvestigation = em.merge(userHasInvestigationListUserHasInvestigation); + if (oldVmUserOfUserHasInvestigationListUserHasInvestigation != null) { + oldVmUserOfUserHasInvestigationListUserHasInvestigation.getUserHasInvestigationList().remove(userHasInvestigationListUserHasInvestigation); + oldVmUserOfUserHasInvestigationListUserHasInvestigation = em.merge(oldVmUserOfUserHasInvestigationListUserHasInvestigation); + } + } + for (UserAssigment userAssigmentListUserAssigment : vmUser.getUserAssigmentList()) { + VmUser oldVmUserOfUserAssigmentListUserAssigment = userAssigmentListUserAssigment.getVmUser(); + userAssigmentListUserAssigment.setVmUser(vmUser); + userAssigmentListUserAssigment = em.merge(userAssigmentListUserAssigment); + if (oldVmUserOfUserAssigmentListUserAssigment != null) { + oldVmUserOfUserAssigmentListUserAssigment.getUserAssigmentList().remove(userAssigmentListUserAssigment); + oldVmUserOfUserAssigmentListUserAssigment = em.merge(oldVmUserOfUserAssigmentListUserAssigment); + } + } + for (UserAssigment userAssigmentList1UserAssigment : vmUser.getUserAssigmentList1()) { + VmUser oldAssigneeIdOfUserAssigmentList1UserAssigment = userAssigmentList1UserAssigment.getAssigneeId(); + userAssigmentList1UserAssigment.setAssigneeId(vmUser); + userAssigmentList1UserAssigment = em.merge(userAssigmentList1UserAssigment); + if (oldAssigneeIdOfUserAssigmentList1UserAssigment != null) { + oldAssigneeIdOfUserAssigmentList1UserAssigment.getUserAssigmentList1().remove(userAssigmentList1UserAssigment); + oldAssigneeIdOfUserAssigmentList1UserAssigment = em.merge(oldAssigneeIdOfUserAssigmentList1UserAssigment); + } + } + for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssue : vmUser.getExecutionStepHasIssueList()) { + executionStepHasIssueListExecutionStepHasIssue.getVmUserList().add(vmUser); + executionStepHasIssueListExecutionStepHasIssue = em.merge(executionStepHasIssueListExecutionStepHasIssue); + } + for (ExecutionStepHasVmUser executionStepHasVmUserListExecutionStepHasVmUser : vmUser.getExecutionStepHasVmUserList()) { + VmUser oldVmUserOfExecutionStepHasVmUserListExecutionStepHasVmUser = executionStepHasVmUserListExecutionStepHasVmUser.getVmUser(); + executionStepHasVmUserListExecutionStepHasVmUser.setVmUser(vmUser); + executionStepHasVmUserListExecutionStepHasVmUser = em.merge(executionStepHasVmUserListExecutionStepHasVmUser); + if (oldVmUserOfExecutionStepHasVmUserListExecutionStepHasVmUser != null) { + oldVmUserOfExecutionStepHasVmUserListExecutionStepHasVmUser.getExecutionStepHasVmUserList().remove(executionStepHasVmUserListExecutionStepHasVmUser); + oldVmUserOfExecutionStepHasVmUserListExecutionStepHasVmUser = em.merge(oldVmUserOfExecutionStepHasVmUserListExecutionStepHasVmUser); + } + } + for (History historyModificationListHistory : vmUser.getHistoryModificationList()) { + VmUser oldModifierIdOfHistoryModificationListHistory = historyModificationListHistory.getModifierId(); + historyModificationListHistory.setModifierId(vmUser); + historyModificationListHistory = em.merge(historyModificationListHistory); + if (oldModifierIdOfHistoryModificationListHistory != null) { + oldModifierIdOfHistoryModificationListHistory.getHistoryModificationList().remove(historyModificationListHistory); + oldModifierIdOfHistoryModificationListHistory = em.merge(oldModifierIdOfHistoryModificationListHistory); + } + } + for (Notification notificationListNotification : vmUser.getNotificationList()) { + VmUser oldTargetUserOfNotificationListNotification = notificationListNotification.getTargetUser(); + notificationListNotification.setTargetUser(vmUser); + notificationListNotification = em.merge(notificationListNotification); + if (oldTargetUserOfNotificationListNotification != null) { + oldTargetUserOfNotificationListNotification.getNotificationList().remove(notificationListNotification); + oldTargetUserOfNotificationListNotification = em.merge(oldTargetUserOfNotificationListNotification); + } + } + for (Notification notificationList1Notification : vmUser.getNotificationList1()) { + VmUser oldAuthorOfNotificationList1Notification = notificationList1Notification.getAuthor(); + notificationList1Notification.setAuthor(vmUser); + notificationList1Notification = em.merge(notificationList1Notification); + if (oldAuthorOfNotificationList1Notification != null) { + oldAuthorOfNotificationList1Notification.getNotificationList1().remove(notificationList1Notification); + oldAuthorOfNotificationList1Notification = em.merge(oldAuthorOfNotificationList1Notification); + } + } + for (History historyListHistory : vmUser.getHistoryList()) { + VmUser oldVmUserIdOfHistoryListHistory = historyListHistory.getVmUserId(); + historyListHistory.setVmUserId(vmUser); + historyListHistory = em.merge(historyListHistory); + if (oldVmUserIdOfHistoryListHistory != null) { + oldVmUserIdOfHistoryListHistory.getHistoryList().remove(historyListHistory); + oldVmUserIdOfHistoryListHistory = em.merge(oldVmUserIdOfHistoryListHistory); + } + } + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void edit(VmUser vmUser) throws IllegalOrphanException, NonexistentEntityException, Exception { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + VmUser persistentVmUser = em.find(VmUser.class, vmUser.getId()); + UserStatus userStatusIdOld = persistentVmUser.getUserStatusId(); + UserStatus userStatusIdNew = vmUser.getUserStatusId(); + List correctiveActionListOld = persistentVmUser.getCorrectiveActionList(); + List correctiveActionListNew = vmUser.getCorrectiveActionList(); + List roleListOld = persistentVmUser.getRoleList(); + List roleListNew = vmUser.getRoleList(); + List rootCauseListOld = persistentVmUser.getRootCauseList(); + List rootCauseListNew = vmUser.getRootCauseList(); + List executionStepListOld = persistentVmUser.getExecutionStepList(); + List executionStepListNew = vmUser.getExecutionStepList(); + List executionStepList1Old = persistentVmUser.getExecutionStepList1(); + List executionStepList1New = vmUser.getExecutionStepList1(); + List userTestProjectRoleListOld = persistentVmUser.getUserTestProjectRoleList(); + List userTestProjectRoleListNew = vmUser.getUserTestProjectRoleList(); + List userTestPlanRoleListOld = persistentVmUser.getUserTestPlanRoleList(); + List userTestPlanRoleListNew = vmUser.getUserTestPlanRoleList(); + List userModifiedRecordListOld = persistentVmUser.getUserModifiedRecordList(); + List userModifiedRecordListNew = vmUser.getUserModifiedRecordList(); + List userHasInvestigationListOld = persistentVmUser.getUserHasInvestigationList(); + List userHasInvestigationListNew = vmUser.getUserHasInvestigationList(); + List userAssigmentListOld = persistentVmUser.getUserAssigmentList(); + List userAssigmentListNew = vmUser.getUserAssigmentList(); + List userAssigmentList1Old = persistentVmUser.getUserAssigmentList1(); + List userAssigmentList1New = vmUser.getUserAssigmentList1(); + List executionStepHasIssueListOld = persistentVmUser.getExecutionStepHasIssueList(); + List executionStepHasIssueListNew = vmUser.getExecutionStepHasIssueList(); + List executionStepHasVmUserListOld = persistentVmUser.getExecutionStepHasVmUserList(); + List executionStepHasVmUserListNew = vmUser.getExecutionStepHasVmUserList(); + List historyModificationListOld = persistentVmUser.getHistoryModificationList(); + List historyModificationListNew = vmUser.getHistoryModificationList(); + List notificationListOld = persistentVmUser.getNotificationList(); + List notificationListNew = vmUser.getNotificationList(); + List notificationList1Old = persistentVmUser.getNotificationList1(); + List notificationList1New = vmUser.getNotificationList1(); + List historyListOld = persistentVmUser.getHistoryList(); + List historyListNew = vmUser.getHistoryList(); + List illegalOrphanMessages = null; + for (UserTestProjectRole userTestProjectRoleListOldUserTestProjectRole : userTestProjectRoleListOld) { + if (!userTestProjectRoleListNew.contains(userTestProjectRoleListOldUserTestProjectRole)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserTestProjectRole " + userTestProjectRoleListOldUserTestProjectRole + " since its vmUser field is not nullable."); + } + } + for (UserTestPlanRole userTestPlanRoleListOldUserTestPlanRole : userTestPlanRoleListOld) { + if (!userTestPlanRoleListNew.contains(userTestPlanRoleListOldUserTestPlanRole)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserTestPlanRole " + userTestPlanRoleListOldUserTestPlanRole + " since its vmUser field is not nullable."); + } + } + for (UserModifiedRecord userModifiedRecordListOldUserModifiedRecord : userModifiedRecordListOld) { + if (!userModifiedRecordListNew.contains(userModifiedRecordListOldUserModifiedRecord)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserModifiedRecord " + userModifiedRecordListOldUserModifiedRecord + " since its vmUser field is not nullable."); + } + } + for (UserHasInvestigation userHasInvestigationListOldUserHasInvestigation : userHasInvestigationListOld) { + if (!userHasInvestigationListNew.contains(userHasInvestigationListOldUserHasInvestigation)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserHasInvestigation " + userHasInvestigationListOldUserHasInvestigation + " since its vmUser field is not nullable."); + } + } + for (UserAssigment userAssigmentListOldUserAssigment : userAssigmentListOld) { + if (!userAssigmentListNew.contains(userAssigmentListOldUserAssigment)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserAssigment " + userAssigmentListOldUserAssigment + " since its vmUser field is not nullable."); + } + } + for (UserAssigment userAssigmentList1OldUserAssigment : userAssigmentList1Old) { + if (!userAssigmentList1New.contains(userAssigmentList1OldUserAssigment)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain UserAssigment " + userAssigmentList1OldUserAssigment + " since its assigneeId field is not nullable."); + } + } + for (ExecutionStepHasVmUser executionStepHasVmUserListOldExecutionStepHasVmUser : executionStepHasVmUserListOld) { + if (!executionStepHasVmUserListNew.contains(executionStepHasVmUserListOldExecutionStepHasVmUser)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain ExecutionStepHasVmUser " + executionStepHasVmUserListOldExecutionStepHasVmUser + " since its vmUser field is not nullable."); + } + } + for (History historyModificationListOldHistory : historyModificationListOld) { + if (!historyModificationListNew.contains(historyModificationListOldHistory)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain History " + historyModificationListOldHistory + " since its modifierId field is not nullable."); + } + } + for (Notification notificationListOldNotification : notificationListOld) { + if (!notificationListNew.contains(notificationListOldNotification)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain Notification " + notificationListOldNotification + " since its targetUser field is not nullable."); + } + } + for (Notification notificationList1OldNotification : notificationList1Old) { + if (!notificationList1New.contains(notificationList1OldNotification)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain Notification " + notificationList1OldNotification + " since its author field is not nullable."); + } + } + for (History historyListOldHistory : historyListOld) { + if (!historyListNew.contains(historyListOldHistory)) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("You must retain History " + historyListOldHistory + " since its vmUserId field is not nullable."); + } + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + if (userStatusIdNew != null) { + userStatusIdNew = em.getReference(userStatusIdNew.getClass(), userStatusIdNew.getId()); + vmUser.setUserStatusId(userStatusIdNew); + } + List attachedCorrectiveActionListNew = new ArrayList<>(); + for (CorrectiveAction correctiveActionListNewCorrectiveActionToAttach : correctiveActionListNew) { + correctiveActionListNewCorrectiveActionToAttach = em.getReference(correctiveActionListNewCorrectiveActionToAttach.getClass(), correctiveActionListNewCorrectiveActionToAttach.getId()); + attachedCorrectiveActionListNew.add(correctiveActionListNewCorrectiveActionToAttach); + } + correctiveActionListNew = attachedCorrectiveActionListNew; + vmUser.setCorrectiveActionList(correctiveActionListNew); + List attachedRoleListNew = new ArrayList<>(); + for (Role roleListNewRoleToAttach : roleListNew) { + roleListNewRoleToAttach = em.getReference(roleListNewRoleToAttach.getClass(), roleListNewRoleToAttach.getId()); + attachedRoleListNew.add(roleListNewRoleToAttach); + } + roleListNew = attachedRoleListNew; + vmUser.setRoleList(roleListNew); + List attachedRootCauseListNew = new ArrayList<>(); + for (RootCause rootCauseListNewRootCauseToAttach : rootCauseListNew) { + rootCauseListNewRootCauseToAttach = em.getReference(rootCauseListNewRootCauseToAttach.getClass(), rootCauseListNewRootCauseToAttach.getRootCausePK()); + attachedRootCauseListNew.add(rootCauseListNewRootCauseToAttach); + } + rootCauseListNew = attachedRootCauseListNew; + vmUser.setRootCauseList(rootCauseListNew); + List attachedExecutionStepListNew = new ArrayList<>(); + for (ExecutionStep executionStepListNewExecutionStepToAttach : executionStepListNew) { + executionStepListNewExecutionStepToAttach = em.getReference(executionStepListNewExecutionStepToAttach.getClass(), executionStepListNewExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepListNew.add(executionStepListNewExecutionStepToAttach); + } + executionStepListNew = attachedExecutionStepListNew; + vmUser.setExecutionStepList(executionStepListNew); + List attachedExecutionStepList1New = new ArrayList<>(); + for (ExecutionStep executionStepList1NewExecutionStepToAttach : executionStepList1New) { + executionStepList1NewExecutionStepToAttach = em.getReference(executionStepList1NewExecutionStepToAttach.getClass(), executionStepList1NewExecutionStepToAttach.getExecutionStepPK()); + attachedExecutionStepList1New.add(executionStepList1NewExecutionStepToAttach); + } + executionStepList1New = attachedExecutionStepList1New; + vmUser.setExecutionStepList1(executionStepList1New); + List attachedUserTestProjectRoleListNew = new ArrayList<>(); + for (UserTestProjectRole userTestProjectRoleListNewUserTestProjectRoleToAttach : userTestProjectRoleListNew) { + userTestProjectRoleListNewUserTestProjectRoleToAttach = em.getReference(userTestProjectRoleListNewUserTestProjectRoleToAttach.getClass(), userTestProjectRoleListNewUserTestProjectRoleToAttach.getUserTestProjectRolePK()); + attachedUserTestProjectRoleListNew.add(userTestProjectRoleListNewUserTestProjectRoleToAttach); + } + userTestProjectRoleListNew = attachedUserTestProjectRoleListNew; + vmUser.setUserTestProjectRoleList(userTestProjectRoleListNew); + List attachedUserTestPlanRoleListNew = new ArrayList<>(); + for (UserTestPlanRole userTestPlanRoleListNewUserTestPlanRoleToAttach : userTestPlanRoleListNew) { + userTestPlanRoleListNewUserTestPlanRoleToAttach = em.getReference(userTestPlanRoleListNewUserTestPlanRoleToAttach.getClass(), userTestPlanRoleListNewUserTestPlanRoleToAttach.getUserTestPlanRolePK()); + attachedUserTestPlanRoleListNew.add(userTestPlanRoleListNewUserTestPlanRoleToAttach); + } + userTestPlanRoleListNew = attachedUserTestPlanRoleListNew; + vmUser.setUserTestPlanRoleList(userTestPlanRoleListNew); + List attachedUserModifiedRecordListNew = new ArrayList<>(); + for (UserModifiedRecord userModifiedRecordListNewUserModifiedRecordToAttach : userModifiedRecordListNew) { + userModifiedRecordListNewUserModifiedRecordToAttach = em.getReference(userModifiedRecordListNewUserModifiedRecordToAttach.getClass(), userModifiedRecordListNewUserModifiedRecordToAttach.getUserModifiedRecordPK()); + attachedUserModifiedRecordListNew.add(userModifiedRecordListNewUserModifiedRecordToAttach); + } + userModifiedRecordListNew = attachedUserModifiedRecordListNew; + vmUser.setUserModifiedRecordList(userModifiedRecordListNew); + List attachedUserHasInvestigationListNew = new ArrayList<>(); + for (UserHasInvestigation userHasInvestigationListNewUserHasInvestigationToAttach : userHasInvestigationListNew) { + userHasInvestigationListNewUserHasInvestigationToAttach = em.getReference(userHasInvestigationListNewUserHasInvestigationToAttach.getClass(), userHasInvestigationListNewUserHasInvestigationToAttach.getUserHasInvestigationPK()); + attachedUserHasInvestigationListNew.add(userHasInvestigationListNewUserHasInvestigationToAttach); + } + userHasInvestigationListNew = attachedUserHasInvestigationListNew; + vmUser.setUserHasInvestigationList(userHasInvestigationListNew); + List attachedUserAssigmentListNew = new ArrayList<>(); + for (UserAssigment userAssigmentListNewUserAssigmentToAttach : userAssigmentListNew) { + userAssigmentListNewUserAssigmentToAttach = em.getReference(userAssigmentListNewUserAssigmentToAttach.getClass(), userAssigmentListNewUserAssigmentToAttach.getUserAssigmentPK()); + attachedUserAssigmentListNew.add(userAssigmentListNewUserAssigmentToAttach); + } + userAssigmentListNew = attachedUserAssigmentListNew; + vmUser.setUserAssigmentList(userAssigmentListNew); + List attachedUserAssigmentList1New = new ArrayList<>(); + for (UserAssigment userAssigmentList1NewUserAssigmentToAttach : userAssigmentList1New) { + userAssigmentList1NewUserAssigmentToAttach = em.getReference(userAssigmentList1NewUserAssigmentToAttach.getClass(), userAssigmentList1NewUserAssigmentToAttach.getUserAssigmentPK()); + attachedUserAssigmentList1New.add(userAssigmentList1NewUserAssigmentToAttach); + } + userAssigmentList1New = attachedUserAssigmentList1New; + vmUser.setUserAssigmentList1(userAssigmentList1New); + List attachedExecutionStepHasIssueListNew = new ArrayList<>(); + for (ExecutionStepHasIssue executionStepHasIssueListNewExecutionStepHasIssueToAttach : executionStepHasIssueListNew) { + executionStepHasIssueListNewExecutionStepHasIssueToAttach = em.getReference(executionStepHasIssueListNewExecutionStepHasIssueToAttach.getClass(), executionStepHasIssueListNewExecutionStepHasIssueToAttach.getExecutionStepHasIssuePK()); + attachedExecutionStepHasIssueListNew.add(executionStepHasIssueListNewExecutionStepHasIssueToAttach); + } + executionStepHasIssueListNew = attachedExecutionStepHasIssueListNew; + vmUser.setExecutionStepHasIssueList(executionStepHasIssueListNew); + List attachedExecutionStepHasVmUserListNew = new ArrayList<>(); + for (ExecutionStepHasVmUser executionStepHasVmUserListNewExecutionStepHasVmUserToAttach : executionStepHasVmUserListNew) { + executionStepHasVmUserListNewExecutionStepHasVmUserToAttach = em.getReference(executionStepHasVmUserListNewExecutionStepHasVmUserToAttach.getClass(), executionStepHasVmUserListNewExecutionStepHasVmUserToAttach.getExecutionStepHasVmUserPK()); + attachedExecutionStepHasVmUserListNew.add(executionStepHasVmUserListNewExecutionStepHasVmUserToAttach); + } + executionStepHasVmUserListNew = attachedExecutionStepHasVmUserListNew; + vmUser.setExecutionStepHasVmUserList(executionStepHasVmUserListNew); + List attachedHistoryModificationListNew = new ArrayList<>(); + for (History historyModificationListNewHistoryToAttach : historyModificationListNew) { + historyModificationListNewHistoryToAttach = em.getReference(historyModificationListNewHistoryToAttach.getClass(), historyModificationListNewHistoryToAttach.getId()); + attachedHistoryModificationListNew.add(historyModificationListNewHistoryToAttach); + } + historyModificationListNew = attachedHistoryModificationListNew; + vmUser.setHistoryModificationList(historyModificationListNew); + List attachedNotificationListNew = new ArrayList<>(); + for (Notification notificationListNewNotificationToAttach : notificationListNew) { + notificationListNewNotificationToAttach = em.getReference(notificationListNewNotificationToAttach.getClass(), notificationListNewNotificationToAttach.getNotificationPK()); + attachedNotificationListNew.add(notificationListNewNotificationToAttach); + } + notificationListNew = attachedNotificationListNew; + vmUser.setNotificationList(notificationListNew); + List attachedNotificationList1New = new ArrayList<>(); + for (Notification notificationList1NewNotificationToAttach : notificationList1New) { + notificationList1NewNotificationToAttach = em.getReference(notificationList1NewNotificationToAttach.getClass(), notificationList1NewNotificationToAttach.getNotificationPK()); + attachedNotificationList1New.add(notificationList1NewNotificationToAttach); + } + notificationList1New = attachedNotificationList1New; + vmUser.setNotificationList1(notificationList1New); + List attachedHistoryListNew = new ArrayList<>(); + for (History historyListNewHistoryToAttach : historyListNew) { + historyListNewHistoryToAttach = em.getReference(historyListNewHistoryToAttach.getClass(), historyListNewHistoryToAttach.getId()); + attachedHistoryListNew.add(historyListNewHistoryToAttach); + } + historyListNew = attachedHistoryListNew; + vmUser.setHistoryList(historyListNew); + vmUser = em.merge(vmUser); + if (userStatusIdOld != null && !userStatusIdOld.equals(userStatusIdNew)) { + userStatusIdOld.getVmUserList().remove(vmUser); + userStatusIdOld = em.merge(userStatusIdOld); + } + if (userStatusIdNew != null && !userStatusIdNew.equals(userStatusIdOld)) { + userStatusIdNew.getVmUserList().add(vmUser); + userStatusIdNew = em.merge(userStatusIdNew); + } + for (CorrectiveAction correctiveActionListOldCorrectiveAction : correctiveActionListOld) { + if (!correctiveActionListNew.contains(correctiveActionListOldCorrectiveAction)) { + correctiveActionListOldCorrectiveAction.getVmUserList().remove(vmUser); + correctiveActionListOldCorrectiveAction = em.merge(correctiveActionListOldCorrectiveAction); + } + } + for (CorrectiveAction correctiveActionListNewCorrectiveAction : correctiveActionListNew) { + if (!correctiveActionListOld.contains(correctiveActionListNewCorrectiveAction)) { + correctiveActionListNewCorrectiveAction.getVmUserList().add(vmUser); + correctiveActionListNewCorrectiveAction = em.merge(correctiveActionListNewCorrectiveAction); + } + } + for (Role roleListOldRole : roleListOld) { + if (!roleListNew.contains(roleListOldRole)) { + roleListOldRole.getVmUserList().remove(vmUser); + roleListOldRole = em.merge(roleListOldRole); + } + } + for (Role roleListNewRole : roleListNew) { + if (!roleListOld.contains(roleListNewRole)) { + roleListNewRole.getVmUserList().add(vmUser); + roleListNewRole = em.merge(roleListNewRole); + } + } + for (RootCause rootCauseListOldRootCause : rootCauseListOld) { + if (!rootCauseListNew.contains(rootCauseListOldRootCause)) { + rootCauseListOldRootCause.getVmUserList().remove(vmUser); + rootCauseListOldRootCause = em.merge(rootCauseListOldRootCause); + } + } + for (RootCause rootCauseListNewRootCause : rootCauseListNew) { + if (!rootCauseListOld.contains(rootCauseListNewRootCause)) { + rootCauseListNewRootCause.getVmUserList().add(vmUser); + rootCauseListNewRootCause = em.merge(rootCauseListNewRootCause); + } + } + for (ExecutionStep executionStepListOldExecutionStep : executionStepListOld) { + if (!executionStepListNew.contains(executionStepListOldExecutionStep)) { + executionStepListOldExecutionStep.setAssignee(null); + executionStepListOldExecutionStep = em.merge(executionStepListOldExecutionStep); + } + } + for (ExecutionStep executionStepListNewExecutionStep : executionStepListNew) { + if (!executionStepListOld.contains(executionStepListNewExecutionStep)) { + VmUser oldAssigneeOfExecutionStepListNewExecutionStep = executionStepListNewExecutionStep.getAssignee(); + executionStepListNewExecutionStep.setAssignee(vmUser); + executionStepListNewExecutionStep = em.merge(executionStepListNewExecutionStep); + if (oldAssigneeOfExecutionStepListNewExecutionStep != null && !oldAssigneeOfExecutionStepListNewExecutionStep.equals(vmUser)) { + oldAssigneeOfExecutionStepListNewExecutionStep.getExecutionStepList().remove(executionStepListNewExecutionStep); + oldAssigneeOfExecutionStepListNewExecutionStep = em.merge(oldAssigneeOfExecutionStepListNewExecutionStep); + } + } + } + for (ExecutionStep executionStepList1OldExecutionStep : executionStepList1Old) { + if (!executionStepList1New.contains(executionStepList1OldExecutionStep)) { + executionStepList1OldExecutionStep.setAssigner(null); + executionStepList1OldExecutionStep = em.merge(executionStepList1OldExecutionStep); + } + } + for (ExecutionStep executionStepList1NewExecutionStep : executionStepList1New) { + if (!executionStepList1Old.contains(executionStepList1NewExecutionStep)) { + VmUser oldAssignerOfExecutionStepList1NewExecutionStep = executionStepList1NewExecutionStep.getAssigner(); + executionStepList1NewExecutionStep.setAssigner(vmUser); + executionStepList1NewExecutionStep = em.merge(executionStepList1NewExecutionStep); + if (oldAssignerOfExecutionStepList1NewExecutionStep != null && !oldAssignerOfExecutionStepList1NewExecutionStep.equals(vmUser)) { + oldAssignerOfExecutionStepList1NewExecutionStep.getExecutionStepList1().remove(executionStepList1NewExecutionStep); + oldAssignerOfExecutionStepList1NewExecutionStep = em.merge(oldAssignerOfExecutionStepList1NewExecutionStep); + } + } + } + for (UserTestProjectRole userTestProjectRoleListNewUserTestProjectRole : userTestProjectRoleListNew) { + if (!userTestProjectRoleListOld.contains(userTestProjectRoleListNewUserTestProjectRole)) { + VmUser oldVmUserOfUserTestProjectRoleListNewUserTestProjectRole = userTestProjectRoleListNewUserTestProjectRole.getVmUser(); + userTestProjectRoleListNewUserTestProjectRole.setVmUser(vmUser); + userTestProjectRoleListNewUserTestProjectRole = em.merge(userTestProjectRoleListNewUserTestProjectRole); + if (oldVmUserOfUserTestProjectRoleListNewUserTestProjectRole != null && !oldVmUserOfUserTestProjectRoleListNewUserTestProjectRole.equals(vmUser)) { + oldVmUserOfUserTestProjectRoleListNewUserTestProjectRole.getUserTestProjectRoleList().remove(userTestProjectRoleListNewUserTestProjectRole); + oldVmUserOfUserTestProjectRoleListNewUserTestProjectRole = em.merge(oldVmUserOfUserTestProjectRoleListNewUserTestProjectRole); + } + } + } + for (UserTestPlanRole userTestPlanRoleListNewUserTestPlanRole : userTestPlanRoleListNew) { + if (!userTestPlanRoleListOld.contains(userTestPlanRoleListNewUserTestPlanRole)) { + VmUser oldVmUserOfUserTestPlanRoleListNewUserTestPlanRole = userTestPlanRoleListNewUserTestPlanRole.getVmUser(); + userTestPlanRoleListNewUserTestPlanRole.setVmUser(vmUser); + userTestPlanRoleListNewUserTestPlanRole = em.merge(userTestPlanRoleListNewUserTestPlanRole); + if (oldVmUserOfUserTestPlanRoleListNewUserTestPlanRole != null && !oldVmUserOfUserTestPlanRoleListNewUserTestPlanRole.equals(vmUser)) { + oldVmUserOfUserTestPlanRoleListNewUserTestPlanRole.getUserTestPlanRoleList().remove(userTestPlanRoleListNewUserTestPlanRole); + oldVmUserOfUserTestPlanRoleListNewUserTestPlanRole = em.merge(oldVmUserOfUserTestPlanRoleListNewUserTestPlanRole); + } + } + } + for (UserModifiedRecord userModifiedRecordListNewUserModifiedRecord : userModifiedRecordListNew) { + if (!userModifiedRecordListOld.contains(userModifiedRecordListNewUserModifiedRecord)) { + VmUser oldVmUserOfUserModifiedRecordListNewUserModifiedRecord = userModifiedRecordListNewUserModifiedRecord.getVmUser(); + userModifiedRecordListNewUserModifiedRecord.setVmUser(vmUser); + userModifiedRecordListNewUserModifiedRecord = em.merge(userModifiedRecordListNewUserModifiedRecord); + if (oldVmUserOfUserModifiedRecordListNewUserModifiedRecord != null && !oldVmUserOfUserModifiedRecordListNewUserModifiedRecord.equals(vmUser)) { + oldVmUserOfUserModifiedRecordListNewUserModifiedRecord.getUserModifiedRecordList().remove(userModifiedRecordListNewUserModifiedRecord); + oldVmUserOfUserModifiedRecordListNewUserModifiedRecord = em.merge(oldVmUserOfUserModifiedRecordListNewUserModifiedRecord); + } + } + } + for (UserHasInvestigation userHasInvestigationListNewUserHasInvestigation : userHasInvestigationListNew) { + if (!userHasInvestigationListOld.contains(userHasInvestigationListNewUserHasInvestigation)) { + VmUser oldVmUserOfUserHasInvestigationListNewUserHasInvestigation = userHasInvestigationListNewUserHasInvestigation.getVmUser(); + userHasInvestigationListNewUserHasInvestigation.setVmUser(vmUser); + userHasInvestigationListNewUserHasInvestigation = em.merge(userHasInvestigationListNewUserHasInvestigation); + if (oldVmUserOfUserHasInvestigationListNewUserHasInvestigation != null && !oldVmUserOfUserHasInvestigationListNewUserHasInvestigation.equals(vmUser)) { + oldVmUserOfUserHasInvestigationListNewUserHasInvestigation.getUserHasInvestigationList().remove(userHasInvestigationListNewUserHasInvestigation); + oldVmUserOfUserHasInvestigationListNewUserHasInvestigation = em.merge(oldVmUserOfUserHasInvestigationListNewUserHasInvestigation); + } + } + } + for (UserAssigment userAssigmentListNewUserAssigment : userAssigmentListNew) { + if (!userAssigmentListOld.contains(userAssigmentListNewUserAssigment)) { + VmUser oldVmUserOfUserAssigmentListNewUserAssigment = userAssigmentListNewUserAssigment.getVmUser(); + userAssigmentListNewUserAssigment.setVmUser(vmUser); + userAssigmentListNewUserAssigment = em.merge(userAssigmentListNewUserAssigment); + if (oldVmUserOfUserAssigmentListNewUserAssigment != null && !oldVmUserOfUserAssigmentListNewUserAssigment.equals(vmUser)) { + oldVmUserOfUserAssigmentListNewUserAssigment.getUserAssigmentList().remove(userAssigmentListNewUserAssigment); + oldVmUserOfUserAssigmentListNewUserAssigment = em.merge(oldVmUserOfUserAssigmentListNewUserAssigment); + } + } + } + for (UserAssigment userAssigmentList1NewUserAssigment : userAssigmentList1New) { + if (!userAssigmentList1Old.contains(userAssigmentList1NewUserAssigment)) { + VmUser oldAssigneeIdOfUserAssigmentList1NewUserAssigment = userAssigmentList1NewUserAssigment.getAssigneeId(); + userAssigmentList1NewUserAssigment.setAssigneeId(vmUser); + userAssigmentList1NewUserAssigment = em.merge(userAssigmentList1NewUserAssigment); + if (oldAssigneeIdOfUserAssigmentList1NewUserAssigment != null && !oldAssigneeIdOfUserAssigmentList1NewUserAssigment.equals(vmUser)) { + oldAssigneeIdOfUserAssigmentList1NewUserAssigment.getUserAssigmentList1().remove(userAssigmentList1NewUserAssigment); + oldAssigneeIdOfUserAssigmentList1NewUserAssigment = em.merge(oldAssigneeIdOfUserAssigmentList1NewUserAssigment); + } + } + } + for (ExecutionStepHasIssue executionStepHasIssueListOldExecutionStepHasIssue : executionStepHasIssueListOld) { + if (!executionStepHasIssueListNew.contains(executionStepHasIssueListOldExecutionStepHasIssue)) { + executionStepHasIssueListOldExecutionStepHasIssue.getVmUserList().remove(vmUser); + executionStepHasIssueListOldExecutionStepHasIssue = em.merge(executionStepHasIssueListOldExecutionStepHasIssue); + } + } + for (ExecutionStepHasIssue executionStepHasIssueListNewExecutionStepHasIssue : executionStepHasIssueListNew) { + if (!executionStepHasIssueListOld.contains(executionStepHasIssueListNewExecutionStepHasIssue)) { + executionStepHasIssueListNewExecutionStepHasIssue.getVmUserList().add(vmUser); + executionStepHasIssueListNewExecutionStepHasIssue = em.merge(executionStepHasIssueListNewExecutionStepHasIssue); + } + } + for (ExecutionStepHasVmUser executionStepHasVmUserListNewExecutionStepHasVmUser : executionStepHasVmUserListNew) { + if (!executionStepHasVmUserListOld.contains(executionStepHasVmUserListNewExecutionStepHasVmUser)) { + VmUser oldVmUserOfExecutionStepHasVmUserListNewExecutionStepHasVmUser = executionStepHasVmUserListNewExecutionStepHasVmUser.getVmUser(); + executionStepHasVmUserListNewExecutionStepHasVmUser.setVmUser(vmUser); + executionStepHasVmUserListNewExecutionStepHasVmUser = em.merge(executionStepHasVmUserListNewExecutionStepHasVmUser); + if (oldVmUserOfExecutionStepHasVmUserListNewExecutionStepHasVmUser != null && !oldVmUserOfExecutionStepHasVmUserListNewExecutionStepHasVmUser.equals(vmUser)) { + oldVmUserOfExecutionStepHasVmUserListNewExecutionStepHasVmUser.getExecutionStepHasVmUserList().remove(executionStepHasVmUserListNewExecutionStepHasVmUser); + oldVmUserOfExecutionStepHasVmUserListNewExecutionStepHasVmUser = em.merge(oldVmUserOfExecutionStepHasVmUserListNewExecutionStepHasVmUser); + } + } + } + for (History historyModificationListNewHistory : historyModificationListNew) { + if (!historyModificationListOld.contains(historyModificationListNewHistory)) { + VmUser oldModifierIdOfHistoryModificationListNewHistory = historyModificationListNewHistory.getModifierId(); + historyModificationListNewHistory.setModifierId(vmUser); + historyModificationListNewHistory = em.merge(historyModificationListNewHistory); + if (oldModifierIdOfHistoryModificationListNewHistory != null && !oldModifierIdOfHistoryModificationListNewHistory.equals(vmUser)) { + oldModifierIdOfHistoryModificationListNewHistory.getHistoryModificationList().remove(historyModificationListNewHistory); + oldModifierIdOfHistoryModificationListNewHistory = em.merge(oldModifierIdOfHistoryModificationListNewHistory); + } + } + } + for (Notification notificationListNewNotification : notificationListNew) { + if (!notificationListOld.contains(notificationListNewNotification)) { + VmUser oldTargetUserOfNotificationListNewNotification = notificationListNewNotification.getTargetUser(); + notificationListNewNotification.setTargetUser(vmUser); + notificationListNewNotification = em.merge(notificationListNewNotification); + if (oldTargetUserOfNotificationListNewNotification != null && !oldTargetUserOfNotificationListNewNotification.equals(vmUser)) { + oldTargetUserOfNotificationListNewNotification.getNotificationList().remove(notificationListNewNotification); + oldTargetUserOfNotificationListNewNotification = em.merge(oldTargetUserOfNotificationListNewNotification); + } + } + } + for (Notification notificationList1NewNotification : notificationList1New) { + if (!notificationList1Old.contains(notificationList1NewNotification)) { + VmUser oldAuthorOfNotificationList1NewNotification = notificationList1NewNotification.getAuthor(); + notificationList1NewNotification.setAuthor(vmUser); + notificationList1NewNotification = em.merge(notificationList1NewNotification); + if (oldAuthorOfNotificationList1NewNotification != null && !oldAuthorOfNotificationList1NewNotification.equals(vmUser)) { + oldAuthorOfNotificationList1NewNotification.getNotificationList1().remove(notificationList1NewNotification); + oldAuthorOfNotificationList1NewNotification = em.merge(oldAuthorOfNotificationList1NewNotification); + } + } + } + for (History historyListNewHistory : historyListNew) { + if (!historyListOld.contains(historyListNewHistory)) { + VmUser oldVmUserIdOfHistoryListNewHistory = historyListNewHistory.getVmUserId(); + historyListNewHistory.setVmUserId(vmUser); + historyListNewHistory = em.merge(historyListNewHistory); + if (oldVmUserIdOfHistoryListNewHistory != null && !oldVmUserIdOfHistoryListNewHistory.equals(vmUser)) { + oldVmUserIdOfHistoryListNewHistory.getHistoryList().remove(historyListNewHistory); + oldVmUserIdOfHistoryListNewHistory = em.merge(oldVmUserIdOfHistoryListNewHistory); + } + } + } + em.getTransaction().commit(); + } + catch (Exception ex) { + String msg = ex.getLocalizedMessage(); + if (msg == null || msg.length() == 0) { + Integer id = vmUser.getId(); + if (findVmUser(id) == null) { + throw new NonexistentEntityException("The vmUser with id " + id + " no longer exists."); + } + } + throw ex; + } + finally { + if (em != null) { + em.close(); + } + } + } + + public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException { + EntityManager em = null; + try { + em = getEntityManager(); + em.getTransaction().begin(); + VmUser vmUser; + try { + vmUser = em.getReference(VmUser.class, id); + vmUser.getId(); + } + catch (EntityNotFoundException enfe) { + throw new NonexistentEntityException("The vmUser with id " + id + " no longer exists.", enfe); + } + List illegalOrphanMessages = null; + List userTestProjectRoleListOrphanCheck = vmUser.getUserTestProjectRoleList(); + for (UserTestProjectRole userTestProjectRoleListOrphanCheckUserTestProjectRole : userTestProjectRoleListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the UserTestProjectRole " + userTestProjectRoleListOrphanCheckUserTestProjectRole + " in its userTestProjectRoleList field has a non-nullable vmUser field."); + } + List userTestPlanRoleListOrphanCheck = vmUser.getUserTestPlanRoleList(); + for (UserTestPlanRole userTestPlanRoleListOrphanCheckUserTestPlanRole : userTestPlanRoleListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the UserTestPlanRole " + userTestPlanRoleListOrphanCheckUserTestPlanRole + " in its userTestPlanRoleList field has a non-nullable vmUser field."); + } + List userModifiedRecordListOrphanCheck = vmUser.getUserModifiedRecordList(); + for (UserModifiedRecord userModifiedRecordListOrphanCheckUserModifiedRecord : userModifiedRecordListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the UserModifiedRecord " + userModifiedRecordListOrphanCheckUserModifiedRecord + " in its userModifiedRecordList field has a non-nullable vmUser field."); + } + List userHasInvestigationListOrphanCheck = vmUser.getUserHasInvestigationList(); + for (UserHasInvestigation userHasInvestigationListOrphanCheckUserHasInvestigation : userHasInvestigationListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the UserHasInvestigation " + userHasInvestigationListOrphanCheckUserHasInvestigation + " in its userHasInvestigationList field has a non-nullable vmUser field."); + } + List userAssigmentListOrphanCheck = vmUser.getUserAssigmentList(); + for (UserAssigment userAssigmentListOrphanCheckUserAssigment : userAssigmentListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the UserAssigment " + userAssigmentListOrphanCheckUserAssigment + " in its userAssigmentList field has a non-nullable vmUser field."); + } + List userAssigmentList1OrphanCheck = vmUser.getUserAssigmentList1(); + for (UserAssigment userAssigmentList1OrphanCheckUserAssigment : userAssigmentList1OrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the UserAssigment " + userAssigmentList1OrphanCheckUserAssigment + " in its userAssigmentList1 field has a non-nullable assigneeId field."); + } + List executionStepHasVmUserListOrphanCheck = vmUser.getExecutionStepHasVmUserList(); + for (ExecutionStepHasVmUser executionStepHasVmUserListOrphanCheckExecutionStepHasVmUser : executionStepHasVmUserListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the ExecutionStepHasVmUser " + executionStepHasVmUserListOrphanCheckExecutionStepHasVmUser + " in its executionStepHasVmUserList field has a non-nullable vmUser field."); + } + List historyModificationListOrphanCheck = vmUser.getHistoryModificationList(); + for (History historyModificationListOrphanCheckHistory : historyModificationListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the History " + historyModificationListOrphanCheckHistory + " in its historyModificationList field has a non-nullable modifierId field."); + } + List notificationListOrphanCheck = vmUser.getNotificationList(); + for (Notification notificationListOrphanCheckNotification : notificationListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the Notification " + notificationListOrphanCheckNotification + " in its notificationList field has a non-nullable targetUser field."); + } + List notificationList1OrphanCheck = vmUser.getNotificationList1(); + for (Notification notificationList1OrphanCheckNotification : notificationList1OrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the Notification " + notificationList1OrphanCheckNotification + " in its notificationList1 field has a non-nullable author field."); + } + List historyListOrphanCheck = vmUser.getHistoryList(); + for (History historyListOrphanCheckHistory : historyListOrphanCheck) { + if (illegalOrphanMessages == null) { + illegalOrphanMessages = new ArrayList<>(); + } + illegalOrphanMessages.add("This VmUser (" + vmUser + ") cannot be destroyed since the History " + historyListOrphanCheckHistory + " in its historyList field has a non-nullable vmUserId field."); + } + if (illegalOrphanMessages != null) { + throw new IllegalOrphanException(illegalOrphanMessages); + } + UserStatus userStatusId = vmUser.getUserStatusId(); + if (userStatusId != null) { + userStatusId.getVmUserList().remove(vmUser); + userStatusId = em.merge(userStatusId); + } + List correctiveActionList = vmUser.getCorrectiveActionList(); + for (CorrectiveAction correctiveActionListCorrectiveAction : correctiveActionList) { + correctiveActionListCorrectiveAction.getVmUserList().remove(vmUser); + correctiveActionListCorrectiveAction = em.merge(correctiveActionListCorrectiveAction); + } + List roleList = vmUser.getRoleList(); + for (Role roleListRole : roleList) { + roleListRole.getVmUserList().remove(vmUser); + roleListRole = em.merge(roleListRole); + } + List rootCauseList = vmUser.getRootCauseList(); + for (RootCause rootCauseListRootCause : rootCauseList) { + rootCauseListRootCause.getVmUserList().remove(vmUser); + rootCauseListRootCause = em.merge(rootCauseListRootCause); + } + List executionStepList = vmUser.getExecutionStepList(); + for (ExecutionStep executionStepListExecutionStep : executionStepList) { + executionStepListExecutionStep.setAssignee(null); + executionStepListExecutionStep = em.merge(executionStepListExecutionStep); + } + List executionStepList1 = vmUser.getExecutionStepList1(); + for (ExecutionStep executionStepList1ExecutionStep : executionStepList1) { + executionStepList1ExecutionStep.setAssigner(null); + executionStepList1ExecutionStep = em.merge(executionStepList1ExecutionStep); + } + List executionStepHasIssueList = vmUser.getExecutionStepHasIssueList(); + for (ExecutionStepHasIssue executionStepHasIssueListExecutionStepHasIssue : executionStepHasIssueList) { + executionStepHasIssueListExecutionStepHasIssue.getVmUserList().remove(vmUser); + executionStepHasIssueListExecutionStepHasIssue = em.merge(executionStepHasIssueListExecutionStepHasIssue); + } + em.remove(vmUser); + em.getTransaction().commit(); + } + finally { + if (em != null) { + em.close(); + } + } + } + + public List findVmUserEntities() { + return findVmUserEntities(true, -1, -1); + } + + public List findVmUserEntities(int maxResults, int firstResult) { + return findVmUserEntities(false, maxResults, firstResult); + } + + private List findVmUserEntities(boolean all, int maxResults, int firstResult) { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + cq.select(cq.from(VmUser.class)); + Query q = em.createQuery(cq); + if (!all) { + q.setMaxResults(maxResults); + q.setFirstResult(firstResult); + } + return q.getResultList(); + } + finally { + em.close(); + } + } + + public VmUser findVmUser(Integer id) { + EntityManager em = getEntityManager(); + try { + return em.find(VmUser.class, id); + } + finally { + em.close(); + } + } + + public int getVmUserCount() { + EntityManager em = getEntityManager(); + try { + CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); + Root rt = cq.from(VmUser.class); + cq.select(em.getCriteriaBuilder().count(rt)); + Query q = em.createQuery(cq); + return ((Long) q.getSingleResult()).intValue(); + } + finally { + em.close(); + } + } + +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/history/Login.java b/VM-Core/src/main/java/com/validation/manager/core/history/Login.java deleted file mode 100644 index 864747e9..00000000 --- a/VM-Core/src/main/java/com/validation/manager/core/history/Login.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.validation.manager.core.history; - -import java.io.Serializable; -import java.util.Date; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotNull; - -@MappedSuperclass -public abstract class Login implements Serializable { - - @Column(name = "attempts") - @Basic(optional = false) - @NotNull - @Min(value = 0) - private int attempts; - - @Column(name = "last_login") - @Basic(optional = false) - @Temporal(TemporalType.TIMESTAMP) - private Date lastModified; - - public int getAttempts() { - return this.attempts; - } - - public void setAttempts(int attempts) { - this.attempts = attempts; - } - - public Date getLastModified() { - return this.lastModified; - } - - public void setLastModified(Date lastModified) { - this.lastModified = lastModified; - } -} diff --git a/VM-Core/src/main/java/com/validation/manager/core/history/Versionable.java b/VM-Core/src/main/java/com/validation/manager/core/history/Versionable.java index 102189cc..20880cc5 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/history/Versionable.java +++ b/VM-Core/src/main/java/com/validation/manager/core/history/Versionable.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,374 +13,418 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.history; - -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.FieldType; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.HistoryField; -import com.validation.manager.core.server.core.FieldTypeServer; -import com.validation.manager.core.server.core.HistoryFieldServer; -import com.validation.manager.core.server.core.HistoryServer; -import com.validation.manager.core.server.core.VMUserServer; -import java.io.Serializable; -import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.DiscriminatorColumn; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; -import javax.persistence.MappedSuperclass; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.openide.util.Exceptions; - -@MappedSuperclass -@Inheritance(strategy = InheritanceType.JOINED) -@DiscriminatorColumn(name = "VERSIONABLE_TYPE") -public abstract class Versionable implements Comparable, - Serializable { - - private static final Logger LOG - = Logger.getLogger(Versionable.class.getSimpleName()); - - @Column(name = "majorVersion", insertable = false, updatable = false) - private Integer majorVersion = 0; - @Column(name = "midVersion", insertable = false, updatable = false) - private Integer midVersion = 0; - @Column(name = "minorVersion", insertable = false, updatable = false) - private Integer minorVersion = 1; - @Column(name = "reason", insertable = false, updatable = false) - private String reason; - @Column(name = "modifierId", insertable = false, updatable = false) - private int modifierId = -1; - @Column(name = "modificationTime", insertable = false, updatable = false) - @Temporal(TemporalType.TIMESTAMP) - private Date modificationTime; - @Column(name = "dirty") - @Basic(optional = false) - private boolean dirty = false; - - public int getModifierId() { - return modifierId; - } - - public void setModifierId(int modifierId) { - this.modifierId = modifierId; - } - - public Integer getMajorVersion() { - return this.majorVersion; - } - - public void setMajorVersion(Integer majorVersion) { - this.majorVersion = majorVersion; - } - - public Integer getMidVersion() { - return this.midVersion; - } - - public void setMidVersion(Integer midVersion) { - this.midVersion = midVersion; - } - - public Integer getMinorVersion() { - return this.minorVersion; - } - - public void setMinorVersion(Integer minorVersion) { - this.minorVersion = minorVersion; - } - - public String getReason() { - return this.reason; - } - - public void setReason(String reason) { - this.reason = reason; - } - - public Date getModificationTime() { - return this.modificationTime; - } - - public void setModificationTime(Date modificationTime) { - this.modificationTime = modificationTime; - } - - public boolean getDirty() { - return this.dirty; - } - - /** - * @param dirty the dirty to set - */ - public void setDirty(boolean dirty) { - this.dirty = dirty; - } - - /** - * Increase major version. - */ - public void increaseMajorVersion() { - setMajorVersion(getMajorVersion() + 1); - setMidVersion(0); - setMinorVersion(0); - try { - if (this instanceof EntityServer) { - EntityServer vs = (EntityServer) this; - //Copy the version changes - Versionable ao = (Versionable) vs.getEntity(); - ao.update(ao, this); - updateHistory(ao); - vs.write2DB(); - } else { - updateHistory(this); - } - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - } - - /** - * Increase major version. - */ - public void increaseMidVersion() { - setMidVersion(getMidVersion() + 1); - setMinorVersion(0); - try { - if (this instanceof EntityServer) { - EntityServer vs = (EntityServer) this; - //Copy the version changes - Versionable v = (Versionable) vs.getEntity(); - v.update(v, this); - updateHistory(v); - vs.write2DB(); - } else { - updateHistory(this); - } - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - } - - /** - * Increase minor is done by default when updating a record. - * - * @param target Target of the update. - * @param source Source of the update - */ - public void update(Versionable target, Versionable source) { - target.setDirty(source.getDirty()); - target.setMajorVersion(source.getMajorVersion()); - target.setMidVersion(source.getMidVersion()); - target.setMinorVersion(source.getMinorVersion()); - target.setModifierId(source.getModifierId()); - target.setReason(source.getReason()); - target.setModificationTime(source.getModificationTime()); - target.setHistoryList(source.getHistoryList()); - try { - target.updateHistory(); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, ex.getLocalizedMessage(), ex); - } - } - - @Override - public String toString() { - return "Version: " + getMajorVersion() + "." + getMidVersion() + "." - + getMinorVersion(); - } - - public enum CHANGE_LEVEL { - MINOR, - MODERATE, - MAJOR - } - - /** - * Get history for this entity. - * - * @return history - */ - public abstract List getHistoryList(); - - /** - * Set history for this entity - * - * @param historyList History list to set. - */ - public abstract void setHistoryList(List historyList); - - @Override - public int compareTo(Versionable o) { - if (!Objects.equals(getMajorVersion(), - o.getMajorVersion())) { - return getMajorVersion() - o.getMajorVersion(); - }//Same major version - else if (!Objects.equals(getMidVersion(), - o.getMidVersion())) { - return getMidVersion() - o.getMidVersion(); - } //Same mid version - else if (!Objects.equals(getMinorVersion(), - o.getMinorVersion())) { - return getMinorVersion() - o.getMinorVersion(); - } - //Everything the same - return 0; - } - - /** - * Add history to this entity. - * - * @param history History to add. - */ - public void addHistory(History history) { - if (getHistoryList() == null) { - setHistoryList(new ArrayList<>()); - } - getHistoryList().add(history); - } - - public static synchronized boolean auditable(Versionable v) { - History current; - boolean result = false; - if (v.getHistoryList() != null && !v.getHistoryList().isEmpty()) { - current = v.getHistoryList().get(v.getHistoryList().size() - 1); - for (HistoryField hf : current.getHistoryFieldList()) { - try { - //Compare audit field vs. the record in history. - Object o = FieldUtils.readField(FieldUtils.getField(v.getClass(), - hf.getFieldName(), true), v); - if ((o == null && !hf.getFieldValue().equals("null")) - || (!(o instanceof byte[]) && o != null - && !o.equals(hf.getFieldValue())) - || ((o instanceof byte[]) - && !new String((byte[]) o, - StandardCharsets.UTF_8) - .equals(hf.getFieldValue()))) { - result = true; - } - } - catch (SecurityException | IllegalArgumentException | IllegalAccessException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - //As last check the version fields for changes (i.e. baselineing, etc.) - if (!result) { - result = current.getMajorVersion() < v.getMajorVersion() - || current.getMidVersion() < v.getMidVersion() - || current.getMinorVersion() < v.getMinorVersion(); - } - return result; - } - //No history so it is auditable if it has marked fields for audit. - return !FieldUtils.getFieldsListWithAnnotation(v.getClass(), - Auditable.class).isEmpty(); - } - - public void updateHistory() throws Exception { - updateHistory(this); - } - - protected void updateHistory(Versionable v) throws Exception { - //Only if an auditable field has been modified - if (auditable(v)) { - //Add history of creation - HistoryServer hs = new HistoryServer(); - if (v.getModifierId() < 0) { - try { - //By default blame system - hs.setModifierId(new VMUserServer(1).getEntity()); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - } else { - hs.setModifierId(new VMUserServer(v.getModifierId()).getEntity()); - } - - if (v.getHistoryList() != null && !v.getHistoryList().isEmpty()) { - if (v.getReason() == null - || v.getReason().equals("audit.general.creation")) { - v.setReason("audit.general.modified"); - } - History last = v.getHistoryList().get(v.getHistoryList().size() - 1); - if ((v.getMajorVersion() == 0 && v.getMidVersion() == 0) // It has default values - || last.getMajorVersion() == v.getMajorVersion() // Or it has a higher mid/major version assigned. - && last.getMidVersion() == v.getMidVersion()) { - //Make it one more than latest - hs.setMajorVersion(v.getMajorVersion()); - hs.setMidVersion(v.getMidVersion()); - hs.setMinorVersion(last.getMinorVersion() + 1); - } else { - //Copy values from object as it was forced changed. - hs.setMajorVersion(v.getMajorVersion()); - hs.setMidVersion(v.getMidVersion()); - hs.setMinorVersion(v.getMinorVersion()); - } - } else { - if (v.getReason() == null) { - v.setReason("audit.general.creation"); - } - } - hs.setReason(v.getReason()); - hs.setModificationTime(v.getModificationTime() == null - ? new Date() : v.getModificationTime()); - hs.write2DB(); - //Check the fields to be placed in history - updateFields(hs, v); - } - if (v.getHistoryList() != null && v.getHistoryList().size() > 0) { - History current = v.getHistoryList().get(v.getHistoryList().size() - 1); - //Update the version the object holds - v.setMajorVersion(current.getMajorVersion()); - v.setMidVersion(current.getMidVersion()); - v.setMinorVersion(current.getMinorVersion()); - } - } - - private synchronized void updateFields(HistoryServer hs, Versionable v) - throws IllegalArgumentException, IllegalAccessException, Exception { - for (Field field : FieldUtils.getFieldsListWithAnnotation(v.getClass(), - Auditable.class)) { - Class type = field.getType(); - String name = field.getName(); - FieldType ft = FieldTypeServer.findType(type.getSimpleName()); - if (ft == null) { - FieldTypeServer fts = new FieldTypeServer(); - fts.setTypeName(type.getSimpleName()); - fts.write2DB(); - ft = fts.getEntity(); - } - HistoryFieldServer hf - = new HistoryFieldServer(ft.getId(), hs.getId()); - hf.setFieldName(name); - hf.setFieldType(ft); - hf.setHistory(hs.getEntity()); - field.setAccessible(true); - Object value = field.get(v); - if (value instanceof byte[]) { - byte[] bytes = (byte[]) value; - value = new String(bytes, StandardCharsets.UTF_8); - } - hf.setFieldValue(value == null ? "null" : value.toString()); - hf.write2DB(); - hs.getHistoryFieldList().add(hf.getEntity()); - } - hs.write2DB(); - v.addHistory(hs.getEntity()); - } -} +package com.validation.manager.core.history; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.db.FieldType; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.HistoryField; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.VmUserJpaController; +import com.validation.manager.core.server.core.FieldTypeServer; +import com.validation.manager.core.server.core.HistoryFieldServer; +import com.validation.manager.core.server.core.HistoryServer; +import java.io.Serializable; +import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.MappedSuperclass; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.openide.util.Exceptions; + +@MappedSuperclass +@Inheritance(strategy = InheritanceType.JOINED) +@DiscriminatorColumn(name = "VERSIONABLE_TYPE") +public abstract class Versionable implements Comparable, + Serializable { + + private static final Logger LOG + = Logger.getLogger(Versionable.class.getSimpleName()); + + @Column(name = "majorVersion", insertable = false, updatable = false) + private Integer majorVersion = 0; + @Column(name = "midVersion", insertable = false, updatable = false) + private Integer midVersion = 0; + @Column(name = "minorVersion", insertable = false, updatable = false) + private Integer minorVersion = 1; + @Column(name = "reason", insertable = false, updatable = false) + private String reason; + @Column(name = "modifierId", insertable = false, updatable = false) + private int modifierId = -1; + @Column(name = "modificationTime", insertable = false, updatable = false) + @Temporal(TemporalType.TIMESTAMP) + private Date modificationTime; + @Column(name = "dirty") + @Basic(optional = false) + private boolean dirty = false; + + public int getModifierId() { + return modifierId; + } + + public void setModifierId(int modifierId) { + this.modifierId = modifierId; + } + + public Integer getMajorVersion() { + return this.majorVersion; + } + + public void setMajorVersion(Integer majorVersion) { + this.majorVersion = majorVersion; + } + + public Integer getMidVersion() { + return this.midVersion; + } + + public void setMidVersion(Integer midVersion) { + this.midVersion = midVersion; + } + + public Integer getMinorVersion() { + return this.minorVersion; + } + + public void setMinorVersion(Integer minorVersion) { + this.minorVersion = minorVersion; + } + + public String getReason() { + return this.reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public Date getModificationTime() { + return this.modificationTime; + } + + public void setModificationTime(Date modificationTime) { + this.modificationTime = modificationTime; + } + + public boolean getDirty() { + return this.dirty; + } + + /** + * @param dirty the dirty to set + */ + public void setDirty(boolean dirty) { + this.dirty = dirty; + } + + private void updateInternalHistory() throws Exception { + if (this instanceof EntityServer) { + EntityServer vs = (EntityServer) this; + //Copy the version changes + Versionable ao = (Versionable) vs.getEntity(); + ao.update(ao, this); + updateHistory(ao); + vs.write2DB(); + } else { + updateHistory(); + try { + DataBaseManager.getEntityManagerFactory().getMetamodel() + .entity(this.getClass()); + Object key = DataBaseManager.getEntityManagerFactory() + .getPersistenceUnitUtil().getIdentifier(this); + if (key != null + && DataBaseManager.getEntityManager() + .find(this.getClass(), key) != null) { + DataBaseManager.getEntityManager().merge(this); + } + } + catch (IllegalArgumentException ex) { + LOG.log(Level.SEVERE, "Ignore if this is an Unit test!", ex); + } + } + } + + /** + * Increase major version. + */ + public void increaseMajorVersion() { + try { + updateInternalHistory(); + setMajorVersion(getMajorVersion() + 1); + setMidVersion(0); + setMinorVersion(0); + updateInternalHistory(); + } + catch (Exception ex) { + Exceptions.printStackTrace(ex); + } + } + + /** + * Increase major version. + */ + public void increaseMidVersion() { + try { + updateInternalHistory(); + setMidVersion(getMidVersion() + 1); + setMinorVersion(0); + updateInternalHistory(); + } + catch (Exception ex) { + Exceptions.printStackTrace(ex); + } + } + + /** + * Increase minor is done by default when updating a record. + * + * @param target Target of the update. + * @param source Source of the update + */ + public void update(Versionable target, Versionable source) { + target.setDirty(source.getDirty()); + target.setMajorVersion(source.getMajorVersion()); + target.setMidVersion(source.getMidVersion()); + target.setMinorVersion(source.getMinorVersion()); + target.setModifierId(source.getModifierId()); + target.setReason(source.getReason()); + target.setModificationTime(source.getModificationTime()); + target.setHistoryList(source.getHistoryList()); + try { + target.updateHistory(); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, ex.getLocalizedMessage(), ex); + } + } + + @Override + public String toString() { + return "Version: " + getMajorVersion() + "." + getMidVersion() + "." + + getMinorVersion(); + } + + public enum CHANGE_LEVEL { + MINOR, + MODERATE, + MAJOR + } + + /** + * Get history for this entity. + * + * @return history + */ + public abstract List getHistoryList(); + + /** + * Set history for this entity + * + * @param historyList History list to set. + */ + public abstract void setHistoryList(List historyList); + + @Override + public int compareTo(Versionable o) { + if (!Objects.equals(getMajorVersion(), + o.getMajorVersion())) { + return getMajorVersion() - o.getMajorVersion(); + }//Same major version + else if (!Objects.equals(getMidVersion(), + o.getMidVersion())) { + return getMidVersion() - o.getMidVersion(); + } //Same mid version + else if (!Objects.equals(getMinorVersion(), + o.getMinorVersion())) { + return getMinorVersion() - o.getMinorVersion(); + } + //Everything the same + return 0; + } + + /** + * Add history to this entity. + * + * @param history History to add. + */ + public void addHistory(History history) { + if (getHistoryList() == null) { + setHistoryList(new ArrayList<>()); + } + getHistoryList().add(history); + } + + public static boolean fieldMatchHistory(HistoryField hf, Object value) { + return !(value == null && !hf.getFieldValue().equals("null")) + || (!(value instanceof byte[]) && value != null + && !value.toString().equals(hf.getFieldValue())) + || ((value instanceof byte[]) + && !new String((byte[]) value, + StandardCharsets.UTF_8) + .equals(hf.getFieldValue())); + } + + public static synchronized boolean auditable(Versionable v) { + History current; + boolean result = false; + if (v.getHistoryList() != null && !v.getHistoryList().isEmpty()) { + current = v.getHistoryList().get(v.getHistoryList().size() - 1); + for (HistoryField hf : current.getHistoryFieldList()) { + try { + //Compare audit field vs. the record in history. + Object o = FieldUtils.readField(FieldUtils.getField(v.getClass(), + hf.getFieldName(), true), v); + if ((o == null && !hf.getFieldValue().equals("null")) + || (!(o instanceof byte[]) && o != null + && !o.toString().equals(hf.getFieldValue())) + || ((o instanceof byte[]) + && !new String((byte[]) o, + StandardCharsets.UTF_8) + .equals(hf.getFieldValue()))) { + result = true; + break; + } + } + catch (SecurityException | IllegalArgumentException | IllegalAccessException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + //As last check the version fields for changes (i.e. baselineing, etc.) + if (!result) { + result = current.getMajorVersion() < v.getMajorVersion() + || current.getMidVersion() < v.getMidVersion() + || current.getMinorVersion() < v.getMinorVersion(); + } + return result; + } + //No history so it is auditable if it has marked fields for audit. + return !FieldUtils.getFieldsListWithAnnotation(v.getClass(), + Auditable.class).isEmpty(); + } + + public void updateHistory() throws Exception { + updateHistory(this); + } + + protected void updateHistory(Versionable v) throws Exception { + //Only if an auditable field has been modified + if (auditable(v)) { + //Add history of creation + HistoryServer hs = new HistoryServer(); + VmUserJpaController c + = new VmUserJpaController(DataBaseManager.getEntityManagerFactory()); + if (v.getModifierId() <= 0) { + try { + //By default blame system + hs.setModifierId(c.findVmUser(1)); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + } + } else { + hs.setModifierId(c.findVmUser(v.getModifierId())); + } + + if (v.getHistoryList() != null && !v.getHistoryList().isEmpty()) { + if (v.getReason() == null + || v.getReason().equals("audit.general.creation")) { + v.setReason("audit.general.modified"); + } + History last = v.getHistoryList().get(v.getHistoryList().size() - 1); + if ((v.getMajorVersion() == 0 && v.getMidVersion() == 0) // It has default values + || last.getMajorVersion() == v.getMajorVersion() // Or it has a higher mid/major version assigned. + && last.getMidVersion() == v.getMidVersion()) { + //Make it one more than latest + hs.setMajorVersion(v.getMajorVersion()); + hs.setMidVersion(v.getMidVersion()); + hs.setMinorVersion(last.getMinorVersion() + 1); + } else { + //Copy values from object as it was forced changed. + hs.setMajorVersion(v.getMajorVersion()); + hs.setMidVersion(v.getMidVersion()); + hs.setMinorVersion(v.getMinorVersion()); + } + } else { + if (v.getReason() == null) { + v.setReason("audit.general.creation"); + } + } + hs.setReason(v.getReason()); + hs.setModificationTime(v.getModificationTime() == null + ? new Date() : v.getModificationTime()); + hs.write2DB(); + if (v instanceof VmUser) { + VmUser temp = (VmUser) v; + if (Objects.equals(temp.getId(), hs.getModifierId().getId())) { + if (temp.getHistoryModificationList() == null) { + temp.setHistoryModificationList(new ArrayList<>()); + } + temp.getHistoryModificationList().add(hs.getEntity()); + } + } else { + if (hs.getModifierId() != null) { + VmUser temp = hs.getModifierId(); + if (temp.getHistoryModificationList() == null) { + temp.setHistoryModificationList(new ArrayList<>()); + } + temp.getHistoryModificationList().add(hs.getEntity()); + c.edit(temp); + } + } + //Check the fields to be placed in history + updateFields(hs, v); + } + if (v.getHistoryList() != null && v.getHistoryList().size() > 0) { + History current = v.getHistoryList().get(v.getHistoryList().size() - 1); + //Update the version the object holds + v.setMajorVersion(current.getMajorVersion()); + v.setMidVersion(current.getMidVersion()); + v.setMinorVersion(current.getMinorVersion()); + } + } + + private synchronized void updateFields(HistoryServer hs, Versionable v) + throws IllegalArgumentException, IllegalAccessException, Exception { + for (Field field : FieldUtils.getFieldsListWithAnnotation(v.getClass(), + Auditable.class)) { + Class type = field.getType(); + String name = field.getName(); + FieldType ft = FieldTypeServer.findType(type.getSimpleName()); + if (ft == null) { + FieldTypeServer fts = new FieldTypeServer(); + fts.setTypeName(type.getSimpleName()); + fts.write2DB(); + ft = fts.getEntity(); + } + HistoryFieldServer hf + = new HistoryFieldServer(ft.getId(), hs.getId()); + hf.setFieldName(name); + hf.setFieldType(ft); + hf.setHistory(hs.getEntity()); + field.setAccessible(true); + Object value = field.get(v); + if (value instanceof byte[]) { + byte[] bytes = (byte[]) value; + value = new String(bytes, StandardCharsets.UTF_8); + } + hf.setFieldValue(value == null ? "null" : value.toString()); + hf.write2DB(); + hs.getHistoryFieldList().add(hf.getEntity()); + } + hs.write2DB(); + v.addHistory(hs.getEntity()); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/AttachmentServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/AttachmentServer.java index 44196078..ff19c599 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/AttachmentServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/AttachmentServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,122 +13,128 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.Attachment; -import com.validation.manager.core.db.AttachmentPK; -import com.validation.manager.core.db.controller.AttachmentJpaController; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.io.File; -import java.io.IOException; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.openide.util.Exceptions; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class AttachmentServer extends Attachment - implements EntityServer { - - public AttachmentServer(AttachmentPK attachmentPK) { - super(attachmentPK); - update(); - } - - public AttachmentServer() { - super(); - } - - @Override - public int write2DB() throws Exception { - AttachmentJpaController c - = new AttachmentJpaController(DataBaseManager.getEntityManagerFactory()); - if (getAttachmentPK() == null) { - Attachment a = new Attachment(); - update(a, this); - c.create(a); - setAttachmentPK(a.getAttachmentPK()); - update(); - } else { - Attachment a = new Attachment(); - update(a, this); - c.edit(a); - setAttachmentPK(a.getAttachmentPK()); - update(); - } - return getAttachmentPK().getId(); - } - - @Override - public Attachment getEntity() { - AttachmentJpaController c - = new AttachmentJpaController(DataBaseManager.getEntityManagerFactory()); - return c.findAttachment(getAttachmentPK()); - } - - @Override - public void update(Attachment target, Attachment source) { - target.setAttachmentPK(source.getAttachmentPK()); - target.setAttachmentType(source.getAttachmentType()); - target.setFileName(source.getFileName()); - target.setFile(source.getFile()); - target.setStringValue(source.getStringValue()); - target.setTextValue(source.getTextValue()); - target.setExecutionStepHasAttachmentList(source - .getExecutionStepHasAttachmentList()); - } - - @Override - public void update() { - update(this, getEntity()); - } - - public void addFile(File f, String fileName) { - try { - if (f != null && f.isFile() && f.exists()) { - byte[] array = FileUtils.readFileToByteArray(f); - setFile(array); - setFileName(fileName); - String ext = FilenameUtils.getExtension(getFileName()); - if (ext != null) { - //Set attachment type - setAttachmentType(AttachmentTypeServer.getTypeForExtension(ext)); - } - if (getAttachmentType() == null) { - //Set as undefined - setAttachmentType(AttachmentTypeServer.getTypeForExtension("")); - } - } - } - catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - } - - public File getAttachedFile() { - File result; - try { - result = File.createTempFile("temp", "vm"); - result.deleteOnExit(); - FileUtils.writeByteArrayToFile(result, getFile()); - } - catch (IOException ex) { - Exceptions.printStackTrace(ex); - result = null; - } - return result; - } - - public static void delete(Attachment entity) - throws IllegalOrphanException, NonexistentEntityException, - Exception { - AttachmentJpaController c - = new AttachmentJpaController(DataBaseManager.getEntityManagerFactory()); - c.destroy(entity.getAttachmentPK()); - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.Attachment; +import com.validation.manager.core.db.AttachmentPK; +import com.validation.manager.core.db.controller.AttachmentJpaController; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.io.File; +import java.io.IOException; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; +import org.openide.util.Exceptions; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class AttachmentServer extends Attachment + implements EntityServer { + + public AttachmentServer(AttachmentPK attachmentPK) { + super(attachmentPK); + update(); + } + + public AttachmentServer() { + super(); + } + + @Override + public int write2DB() throws VMException { + try { + AttachmentJpaController c + = new AttachmentJpaController(DataBaseManager.getEntityManagerFactory()); + if (getAttachmentPK() == null) { + Attachment a = new Attachment(); + update(a, this); + c.create(a); + setAttachmentPK(a.getAttachmentPK()); + update(); + } else { + Attachment a = new Attachment(); + update(a, this); + c.edit(a); + setAttachmentPK(a.getAttachmentPK()); + update(); + } + } + catch (Exception ex) { + throw new VMException(ex); + } + return getAttachmentPK().getId(); + } + + @Override + public Attachment getEntity() { + AttachmentJpaController c + = new AttachmentJpaController(DataBaseManager.getEntityManagerFactory()); + return c.findAttachment(getAttachmentPK()); + } + + @Override + public void update(Attachment target, Attachment source) { + target.setAttachmentPK(source.getAttachmentPK()); + target.setAttachmentType(source.getAttachmentType()); + target.setFileName(source.getFileName()); + target.setFile(source.getFile()); + target.setStringValue(source.getStringValue()); + target.setTextValue(source.getTextValue()); + target.setExecutionStepHasAttachmentList(source + .getExecutionStepHasAttachmentList()); + } + + @Override + public void update() { + update(this, getEntity()); + } + + public void addFile(File f, String fileName) { + try { + if (f != null && f.isFile() && f.exists()) { + byte[] array = FileUtils.readFileToByteArray(f); + setFile(array); + setFileName(fileName); + String ext = FilenameUtils.getExtension(getFileName()); + if (ext != null) { + //Set attachment type + setAttachmentType(AttachmentTypeServer.getTypeForExtension(ext)); + } + if (getAttachmentType() == null) { + //Set as undefined + setAttachmentType(AttachmentTypeServer.getTypeForExtension("")); + } + } + } + catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + + public File getAttachedFile() { + File result; + try { + result = File.createTempFile("temp", "vm"); + result.deleteOnExit(); + FileUtils.writeByteArrayToFile(result, getFile()); + } + catch (IOException ex) { + Exceptions.printStackTrace(ex); + result = null; + } + return result; + } + + public static void delete(Attachment entity) + throws IllegalOrphanException, NonexistentEntityException, + Exception { + AttachmentJpaController c + = new AttachmentJpaController(DataBaseManager.getEntityManagerFactory()); + c.destroy(entity.getAttachmentPK()); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/AttachmentTypeServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/AttachmentTypeServer.java index 855df8dc..807f0c22 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/AttachmentTypeServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/AttachmentTypeServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,69 +13,78 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.AttachmentType; -import com.validation.manager.core.db.controller.AttachmentTypeJpaController; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class AttachmentTypeServer extends AttachmentType - implements EntityServer { - - private final AttachmentTypeJpaController c - = new AttachmentTypeJpaController(DataBaseManager - .getEntityManagerFactory()); - - @Override - public int write2DB() throws Exception { - if (getId() == null) { - AttachmentType at = new AttachmentType(); - update(at, this); - c.create(at); - update(this, at); - } else { - AttachmentType at = getEntity(); - update(at, this); - c.edit(at); - update(this, at); - } - return getId(); - } - - @Override - public AttachmentType getEntity() { - return c.findAttachmentType(getId()); - } - - @Override - public void update(AttachmentType target, AttachmentType source) { - target.setAttachmentList(source.getAttachmentList()); - target.setDescription(source.getDescription()); - target.setType(source.getType()); - } - - @Override - public void update() { - update(this, getEntity()); - } - - public static AttachmentType getTypeForExtension(String ext) { - AttachmentType at = null; - //Set attachment type - for (AttachmentType type - : new AttachmentTypeJpaController(DataBaseManager - .getEntityManagerFactory()) - .findAttachmentTypeEntities()) { - if (type.getType().equals(ext)) { - at = type; - break; - } - } - return at; - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.db.AttachmentType; +import com.validation.manager.core.db.controller.AttachmentTypeJpaController; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class AttachmentTypeServer extends AttachmentType + implements EntityServer { + + private final AttachmentTypeJpaController c + = new AttachmentTypeJpaController(DataBaseManager + .getEntityManagerFactory()); + + public AttachmentTypeServer(String type) { + super(type); + } + + public AttachmentTypeServer(int id) { + setId(id); + update(); + } + + @Override + public int write2DB() throws Exception { + if (getId() == null) { + AttachmentType at = new AttachmentType(); + update(at, this); + c.create(at); + update(this, at); + } else { + AttachmentType at = getEntity(); + update(at, this); + c.edit(at); + update(this, at); + } + return getId(); + } + + @Override + public AttachmentType getEntity() { + return c.findAttachmentType(getId()); + } + + @Override + public void update(AttachmentType target, AttachmentType source) { + target.setAttachmentList(source.getAttachmentList()); + target.setDescription(source.getDescription()); + target.setType(source.getType()); + } + + @Override + public void update() { + update(this, getEntity()); + } + + public static AttachmentType getTypeForExtension(String ext) { + AttachmentType at = null; + //Set attachment type + for (AttachmentType type + : new AttachmentTypeJpaController(DataBaseManager + .getEntityManagerFactory()) + .findAttachmentTypeEntities()) { + if (type.getType().equals(ext)) { + at = type; + break; + } + } + return at; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/ExecutionResultServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/ExecutionResultServer.java index 3b69b1fa..d08bdbed 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/ExecutionResultServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/ExecutionResultServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,74 +13,83 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.ExecutionResult; -import com.validation.manager.core.db.controller.ExecutionResultJpaController; -import java.util.List; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class ExecutionResultServer extends ExecutionResult - implements EntityServer { - - @Override - public int write2DB() throws Exception { - ExecutionResultJpaController c - = new ExecutionResultJpaController(DataBaseManager - .getEntityManagerFactory()); - if (getId() == null) { - ExecutionResult r = new ExecutionResult(); - update(r, this); - c.create(r); - setId(r.getId()); - update(); - } else { - ExecutionResult r = getEntity(); - update(r, this); - c.create(r); - setId(r.getId()); - update(); - } - return getId(); - } - - @Override - public ExecutionResult getEntity() { - return new ExecutionResultJpaController(DataBaseManager - .getEntityManagerFactory()).findExecutionResult(getId()); - } - - @Override - public void update(ExecutionResult target, ExecutionResult source) { - target.setExecutionStepList(source.getExecutionStepList()); - target.setId(source.getId()); - target.setResultName(source.getResultName()); - } - - @Override - public void update() { - update(this, getEntity()); - } - - public static ExecutionResult getResult(String result) { - PARAMETERS.clear(); - PARAMETERS.put("resultName", result); - List r = DataBaseManager.namedQuery("ExecutionResult.findByResultName", - PARAMETERS); - if (r.isEmpty()) { - return null; - } else { - return (ExecutionResult) r.get(0); - } - } - - public static List getResults() { - return new ExecutionResultJpaController(DataBaseManager - .getEntityManagerFactory()).findExecutionResultEntities(); - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.db.ExecutionResult; +import com.validation.manager.core.db.controller.ExecutionResultJpaController; +import java.util.List; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ExecutionResultServer extends ExecutionResult + implements EntityServer { + + public ExecutionResultServer(String resultName) { + super(resultName); + } + + public ExecutionResultServer(int id) { + setId(id); + update(); + } + + @Override + public int write2DB() throws Exception { + ExecutionResultJpaController c + = new ExecutionResultJpaController(DataBaseManager + .getEntityManagerFactory()); + if (getId() == null) { + ExecutionResult r = new ExecutionResult(); + update(r, this); + c.create(r); + setId(r.getId()); + update(); + } else { + ExecutionResult r = getEntity(); + update(r, this); + c.edit(r); + setId(r.getId()); + update(); + } + return getId(); + } + + @Override + public ExecutionResult getEntity() { + return new ExecutionResultJpaController(DataBaseManager + .getEntityManagerFactory()).findExecutionResult(getId()); + } + + @Override + public void update(ExecutionResult target, ExecutionResult source) { + target.setExecutionStepList(source.getExecutionStepList()); + target.setId(source.getId()); + target.setResultName(source.getResultName()); + } + + @Override + public void update() { + update(this, getEntity()); + } + + public static ExecutionResult getResult(String result) { + PARAMETERS.clear(); + PARAMETERS.put("resultName", result); + List r = DataBaseManager.namedQuery("ExecutionResult.findByResultName", + PARAMETERS); + if (r.isEmpty()) { + return null; + } else { + return (ExecutionResult) r.get(0); + } + } + + public static List getResults() { + return new ExecutionResultJpaController(DataBaseManager + .getEntityManagerFactory()).findExecutionResultEntities(); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/ExecutionStepServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/ExecutionStepServer.java index 1d121528..7ee885de 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/ExecutionStepServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/ExecutionStepServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,170 +13,176 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.Attachment; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.ExecutionStepHasAttachment; -import com.validation.manager.core.db.ExecutionStepHasIssue; -import com.validation.manager.core.db.ExecutionStepPK; -import com.validation.manager.core.db.Issue; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.controller.ExecutionStepHasAttachmentJpaController; -import com.validation.manager.core.db.controller.ExecutionStepHasIssueJpaController; -import com.validation.manager.core.db.controller.ExecutionStepJpaController; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.Date; -import org.openide.util.Exceptions; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class ExecutionStepServer extends ExecutionStep - implements EntityServer { - - private final ExecutionStepJpaController c - = new ExecutionStepJpaController(DataBaseManager - .getEntityManagerFactory()); - - public ExecutionStepServer(ExecutionStep es) { - super(es.getExecutionStepPK()); - update(); - } - - public ExecutionStepServer(ExecutionStepPK pk) { - super(pk); - update(); - } - - @Override - public int write2DB() throws Exception { - if (getExecutionStepPK() == null) { - ExecutionStep es = new ExecutionStep(); - update(es, this); - c.create(es); - setExecutionStepPK(es.getExecutionStepPK()); - update(); - } else { - ExecutionStep es = getEntity(); - update(es, this); - c.edit(es); - update(); - } - return getExecutionStepPK().getTestCaseExecutionId(); - } - - @Override - public ExecutionStep getEntity() { - return c.findExecutionStep(getExecutionStepPK()); - } - - @Override - public void update(ExecutionStep target, ExecutionStep source) { - if (target.getExecutionStepHasAttachmentList() == null) { - target.setExecutionStepHasAttachmentList(new ArrayList<>()); - } - target.setAssignedTime(source.getAssignedTime()); - target.setComment(source.getComment()); - target.setExecutionEnd(source.getExecutionEnd()); - target.setExecutionStart(source.getExecutionStart()); - target.setExecutionStepHasAttachmentList(source - .getExecutionStepHasAttachmentList()); - target.setExecutionTime(source.getExecutionTime()); - target.setResultId(source.getResultId()); - target.setStep(source.getStep()); - target.setTestCaseExecution(source.getTestCaseExecution()); - target.setAssignee(source.getAssignee()); - target.setAssigner(source.getAssigner()); - target.setLocked(source.getLocked()); - target.setExecutionStepHasIssueList(source.getExecutionStepHasIssueList()); - target.setReviewed(source.getReviewed()); - target.setReviewDate(source.getReviewDate()); - target.setHistoryList(source.getHistoryList()); - target.setStepHistory(source.getStepHistory()); - } - - @Override - public void update() { - update(this, getEntity()); - } - - public void assignUser(VmUser assignee, VmUser assigner) { - try { - setAssignee(assignee); - setAssigner(assigner); - setAssignedTime(new Date()); - write2DB(); - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - } - - public void addAttachment(AttachmentServer attachment) throws Exception { - ExecutionStepHasAttachment esha = new ExecutionStepHasAttachment(); - ExecutionStepHasAttachmentJpaController controller - = new ExecutionStepHasAttachmentJpaController(DataBaseManager - .getEntityManagerFactory()); - esha.setAttachment(attachment.getEntity()); - esha.setExecutionStep(getEntity()); - esha.setCreationTime(new Date()); - controller.create(esha); - getExecutionStepHasAttachmentList().add(esha); - write2DB(); - update(); - } - - public void addIssue(IssueServer issue, VMUserServer user) throws Exception { - ExecutionStepHasIssue eshi = new ExecutionStepHasIssue(); - ExecutionStepHasIssueJpaController controller - = new ExecutionStepHasIssueJpaController(DataBaseManager - .getEntityManagerFactory()); - eshi.setIssue(issue.getEntity()); - eshi.setExecutionStep(getEntity()); - eshi.setVmUserList(new ArrayList<>()); - eshi.getVmUserList().add(user.getEntity()); - controller.create(eshi); - getExecutionStepHasIssueList().add(eshi); - write2DB(); - update(); - } - - public void removeAttachment(Attachment attachment) throws Exception { - ExecutionStepHasAttachment toRemove = null; - for (ExecutionStepHasAttachment esha : getExecutionStepHasAttachmentList()) { - if (esha.getAttachment().getAttachmentPK().getId() - == attachment.getAttachmentPK().getId()) { - toRemove = esha; - break; - } - } - if (toRemove != null) { - new ExecutionStepHasAttachmentJpaController(DataBaseManager - .getEntityManagerFactory()).destroy(toRemove - .getExecutionStepHasAttachmentPK()); - update(); - } - } - - public void removeIssue(Issue issue) throws NonexistentEntityException { - ExecutionStepHasIssue toRemove = null; - for (ExecutionStepHasIssue eshi : getExecutionStepHasIssueList()) { - if (eshi.getIssue().getIssuePK().getId() - == issue.getIssuePK().getId()) { - toRemove = eshi; - break; - } - } - if (toRemove != null) { - new ExecutionStepHasIssueJpaController(DataBaseManager - .getEntityManagerFactory()).destroy(toRemove - .getExecutionStepHasIssuePK()); - update(); - } - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.Attachment; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.ExecutionStepHasAttachment; +import com.validation.manager.core.db.ExecutionStepHasIssue; +import com.validation.manager.core.db.ExecutionStepPK; +import com.validation.manager.core.db.Issue; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.ExecutionStepHasAttachmentJpaController; +import com.validation.manager.core.db.controller.ExecutionStepHasIssueJpaController; +import com.validation.manager.core.db.controller.ExecutionStepJpaController; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.Date; +import org.openide.util.Exceptions; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class ExecutionStepServer extends ExecutionStep + implements EntityServer { + + private final ExecutionStepJpaController c + = new ExecutionStepJpaController(DataBaseManager + .getEntityManagerFactory()); + + public ExecutionStepServer(ExecutionStep es) { + super(es.getExecutionStepPK()); + update(); + } + + public ExecutionStepServer(ExecutionStepPK pk) { + super(pk); + update(); + } + + @Override + public int write2DB() throws VMException { + try { + if (getExecutionStepPK() == null) { + ExecutionStep es = new ExecutionStep(); + update(es, this); + c.create(es); + setExecutionStepPK(es.getExecutionStepPK()); + update(); + } else { + ExecutionStep es = getEntity(); + update(es, this); + c.edit(es); + update(); + } + } + catch (Exception ex) { + throw new VMException(ex); + } + return getExecutionStepPK().getTestCaseExecutionId(); + } + + @Override + public ExecutionStep getEntity() { + return c.findExecutionStep(getExecutionStepPK()); + } + + @Override + public void update(ExecutionStep target, ExecutionStep source) { + if (target.getExecutionStepHasAttachmentList() == null) { + target.setExecutionStepHasAttachmentList(new ArrayList<>()); + } + target.setAssignedTime(source.getAssignedTime()); + target.setComment(source.getComment()); + target.setExecutionEnd(source.getExecutionEnd()); + target.setExecutionStart(source.getExecutionStart()); + target.setExecutionStepHasAttachmentList(source + .getExecutionStepHasAttachmentList()); + target.setExecutionTime(source.getExecutionTime()); + target.setResultId(source.getResultId()); + target.setStep(source.getStep()); + target.setTestCaseExecution(source.getTestCaseExecution()); + target.setAssignee(source.getAssignee()); + target.setAssigner(source.getAssigner()); + target.setLocked(source.getLocked()); + target.setExecutionStepHasIssueList(source.getExecutionStepHasIssueList()); + target.setReviewed(source.getReviewed()); + target.setReviewDate(source.getReviewDate()); + target.setHistoryList(source.getHistoryList()); + target.setStepHistory(source.getStepHistory()); + } + + @Override + public void update() { + update(this, getEntity()); + } + + public void assignUser(VmUser assignee, VmUser assigner) { + try { + setAssignee(assignee); + setAssigner(assigner); + setAssignedTime(new Date()); + write2DB(); + } + catch (VMException ex) { + Exceptions.printStackTrace(ex); + } + } + + public void addAttachment(AttachmentServer attachment) throws Exception { + ExecutionStepHasAttachment esha = new ExecutionStepHasAttachment(); + ExecutionStepHasAttachmentJpaController controller + = new ExecutionStepHasAttachmentJpaController(DataBaseManager + .getEntityManagerFactory()); + esha.setAttachment(attachment.getEntity()); + esha.setExecutionStep(getEntity()); + esha.setCreationTime(new Date()); + controller.create(esha); + getExecutionStepHasAttachmentList().add(esha); + write2DB(); + update(); + } + + public void addIssue(IssueServer issue, VMUserServer user) throws Exception { + ExecutionStepHasIssue eshi = new ExecutionStepHasIssue(); + ExecutionStepHasIssueJpaController controller + = new ExecutionStepHasIssueJpaController(DataBaseManager + .getEntityManagerFactory()); + eshi.setIssue(issue.getEntity()); + eshi.setExecutionStep(getEntity()); + eshi.setVmUserList(new ArrayList<>()); + eshi.getVmUserList().add(user.getEntity()); + controller.create(eshi); + getExecutionStepHasIssueList().add(eshi); + write2DB(); + update(); + } + + public void removeAttachment(Attachment attachment) throws Exception { + ExecutionStepHasAttachment toRemove = null; + for (ExecutionStepHasAttachment esha : getExecutionStepHasAttachmentList()) { + if (esha.getAttachment().getAttachmentPK().getId() + == attachment.getAttachmentPK().getId()) { + toRemove = esha; + break; + } + } + if (toRemove != null) { + new ExecutionStepHasAttachmentJpaController(DataBaseManager + .getEntityManagerFactory()).destroy(toRemove + .getExecutionStepHasAttachmentPK()); + update(); + } + } + + public void removeIssue(Issue issue) throws NonexistentEntityException { + ExecutionStepHasIssue toRemove = null; + for (ExecutionStepHasIssue eshi : getExecutionStepHasIssueList()) { + if (eshi.getIssue().getIssuePK().getId() + == issue.getIssuePK().getId()) { + toRemove = eshi; + break; + } + } + if (toRemove != null) { + new ExecutionStepHasIssueJpaController(DataBaseManager + .getEntityManagerFactory()).destroy(toRemove + .getExecutionStepHasIssuePK()); + update(); + } + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/FieldTypeServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/FieldTypeServer.java index 32b65c7a..1beb9600 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/FieldTypeServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/FieldTypeServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,61 +13,67 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.FieldType; -import com.validation.manager.core.db.controller.FieldTypeJpaController; -import java.util.List; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class FieldTypeServer extends FieldType - implements EntityServer { - - public static FieldType findType(String simpleName) { - PARAMETERS.clear(); - PARAMETERS.put("typeName", simpleName); - List r = DataBaseManager.namedQuery("FieldType.findByTypeName", PARAMETERS); - return r.isEmpty() ? null : (FieldType) r.get(0); - } - - @Override - public int write2DB() throws Exception { - FieldTypeJpaController c = new FieldTypeJpaController(DataBaseManager - .getEntityManagerFactory()); - if (getId() == null) { - FieldType ft = new FieldType(); - update(ft, this); - c.create(ft); - update(this, ft); - } else { - FieldType ft = getEntity(); - update(ft, this); - c.edit(ft); - update(this, ft); - } - return getId(); - } - - @Override - public FieldType getEntity() { - return new FieldTypeJpaController(DataBaseManager - .getEntityManagerFactory()).findFieldType(getId()); - } - - @Override - public void update(FieldType target, FieldType source) { - target.setHistoryFieldList(source.getHistoryFieldList()); - target.setId(source.getId()); - target.setTypeName(source.getTypeName()); - } - - @Override - public void update() { - update(this, getEntity()); - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.FieldType; +import com.validation.manager.core.db.controller.FieldTypeJpaController; +import java.util.List; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class FieldTypeServer extends FieldType + implements EntityServer { + + public static FieldType findType(String simpleName) { + PARAMETERS.clear(); + PARAMETERS.put("typeName", simpleName); + List r = DataBaseManager.namedQuery("FieldType.findByTypeName", PARAMETERS); + return r.isEmpty() ? null : (FieldType) r.get(0); + } + + @Override + public int write2DB() throws VMException { + try { + FieldTypeJpaController c = new FieldTypeJpaController(DataBaseManager + .getEntityManagerFactory()); + if (getId() == null) { + FieldType ft = new FieldType(); + update(ft, this); + c.create(ft); + update(this, ft); + } else { + FieldType ft = getEntity(); + update(ft, this); + c.edit(ft); + update(this, ft); + } + } + catch (Exception ex) { + throw new VMException(ex); + } + return getId(); + } + + @Override + public FieldType getEntity() { + return new FieldTypeJpaController(DataBaseManager + .getEntityManagerFactory()).findFieldType(getId()); + } + + @Override + public void update(FieldType target, FieldType source) { + target.setHistoryFieldList(source.getHistoryFieldList()); + target.setId(source.getId()); + target.setTypeName(source.getTypeName()); + } + + @Override + public void update() { + update(this, getEntity()); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/HistoryServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/HistoryServer.java index 96a12472..75924c1b 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/HistoryServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/HistoryServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,97 +13,104 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.controller.HistoryJpaController; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class HistoryServer extends History - implements EntityServer { - - public HistoryServer() { - super(); - } - - public HistoryServer(History history) { - super(history.getId()); - update(); - } - - @Override - public int write2DB() throws Exception { - HistoryJpaController c = new HistoryJpaController(DataBaseManager - .getEntityManagerFactory()); - if (getId() == null) { - History h = new History(); - update(h, this); - c.create(h); - update(this, h); - } else { - History h = getEntity(); - update(h, this); - c.edit(h); - update(this, h); - } - return getId(); - } - - @Override - public History getEntity() { - return new HistoryJpaController(DataBaseManager - .getEntityManagerFactory()).findHistory(getId()); - } - - @Override - public void update(History target, History source) { - target.setBaselineList(source.getBaselineList()); - target.setExecutionStepList(source.getExecutionStepList()); - target.setHistoryFieldList(source.getHistoryFieldList()); - target.setId(source.getId()); - target.setMajorVersion(source.getMajorVersion()); - target.setMidVersion(source.getMidVersion()); - target.setMinorVersion(source.getMinorVersion()); - target.setModificationTime(source.getModificationTime()); - target.setModifierId(source.getModifierId()); - target.setReason(source.getReason()); - target.setProjectId(source.getProjectId()); - target.setStep(source.getStep()); - target.setRequirementId(source.getRequirementId()); - target.setVmSettingId(source.getVmSettingId()); - } - - @Override - public void update() { - update(this, getEntity()); - } - - /** - * Do a major version of the item - */ - public void increaseMajor() { - setMajorVersion(getMajorVersion() + 1); - setMidVersion(0); - setMinorVersion(0); - } - - /** - * Do a medium version of the item - */ - public void increaseMid() { - setMidVersion(getMidVersion() + 1); - setMinorVersion(0); - } - - /** - * Do a minor version of the item - */ - public void increaseMinor() { - setMinorVersion(getMinorVersion() + 1); - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.controller.HistoryJpaController; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class HistoryServer extends History + implements EntityServer { + + public HistoryServer() { + super(); + } + + public HistoryServer(History history) { + super(history.getId()); + update(); + } + + @Override + public int write2DB() throws VMException { + try { + HistoryJpaController c = new HistoryJpaController(DataBaseManager + .getEntityManagerFactory()); + if (getId() == null) { + History h = new History(); + update(h, this); + c.create(h); + update(this, h); + } else { + History h = getEntity(); + update(h, this); + c.edit(h); + update(this, h); + } + } + catch (Exception ex) { + throw new VMException(ex); + } + return getId(); + } + + @Override + public History getEntity() { + return new HistoryJpaController(DataBaseManager + .getEntityManagerFactory()).findHistory(getId()); + } + + @Override + public void update(History target, History source) { + target.setBaselineList(source.getBaselineList()); + target.setExecutionStepList(source.getExecutionStepList()); + target.setHistoryFieldList(source.getHistoryFieldList()); + target.setId(source.getId()); + target.setMajorVersion(source.getMajorVersion()); + target.setMidVersion(source.getMidVersion()); + target.setMinorVersion(source.getMinorVersion()); + target.setModificationTime(source.getModificationTime()); + target.setModifierId(source.getModifierId()); + target.setReason(source.getReason()); + target.setProjectId(source.getProjectId()); + target.setStep(source.getStep()); + target.setRequirementId(source.getRequirementId()); + target.setVmSettingId(source.getVmSettingId()); + target.setVmUserId(source.getVmUserId()); + } + + @Override + public void update() { + update(this, getEntity()); + } + + /** + * Do a major version of the item + */ + public void increaseMajor() { + setMajorVersion(getMajorVersion() + 1); + setMidVersion(0); + setMinorVersion(0); + } + + /** + * Do a medium version of the item + */ + public void increaseMid() { + setMidVersion(getMidVersion() + 1); + setMinorVersion(0); + } + + /** + * Do a minor version of the item + */ + public void increaseMinor() { + setMinorVersion(getMinorVersion() + 1); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/IssueTypeServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/IssueTypeServer.java index 0fba4f70..e19a7a4d 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/IssueTypeServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/IssueTypeServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,71 +13,80 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.IssueType; -import com.validation.manager.core.db.controller.IssueTypeJpaController; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class IssueTypeServer extends IssueType - implements EntityServer { - - @Override - public int write2DB() throws Exception { - if (getId() == null) { - IssueType i = new IssueType(); - update(i, this); - new IssueTypeJpaController(DataBaseManager - .getEntityManagerFactory()).create(i); - update(this, i); - } else { - IssueType i = getEntity(); - update(i, this); - new IssueTypeJpaController(DataBaseManager - .getEntityManagerFactory()).edit(i); - update(this, i); - } - return getId(); - } - - @Override - public IssueType getEntity() { - return new IssueTypeJpaController(DataBaseManager - .getEntityManagerFactory()).findIssueType(getId()); - } - - @Override - public void update(IssueType target, IssueType source) { - target.setDescription(source.getDescription()); - target.setIssueList(source.getIssueList()); - target.setTypeName(source.getTypeName()); - } - - @Override - public void update() { - update(this, getEntity()); - } - - /** - * Get an Issue Type by name. - * - * @param typename name to search for - * @return Issue Type for the specified name or null if not found. - */ - public static IssueType getType(String typename) { - IssueType result = null; - for (IssueType type : new IssueTypeJpaController(DataBaseManager - .getEntityManagerFactory()).findIssueTypeEntities()) { - if (type.getTypeName().equals(typename)) { - result = type; - break; - } - } - return result; - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.db.IssueType; +import com.validation.manager.core.db.controller.IssueTypeJpaController; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class IssueTypeServer extends IssueType + implements EntityServer { + + public IssueTypeServer(int id) { + setId(id); + update(); + } + + public IssueTypeServer(String typeName) { + super(typeName); + } + + @Override + public int write2DB() throws Exception { + if (getId() == null) { + IssueType i = new IssueType(); + update(i, this); + new IssueTypeJpaController(DataBaseManager + .getEntityManagerFactory()).create(i); + update(this, i); + } else { + IssueType i = getEntity(); + update(i, this); + new IssueTypeJpaController(DataBaseManager + .getEntityManagerFactory()).edit(i); + update(this, i); + } + return getId(); + } + + @Override + public IssueType getEntity() { + return new IssueTypeJpaController(DataBaseManager + .getEntityManagerFactory()).findIssueType(getId()); + } + + @Override + public void update(IssueType target, IssueType source) { + target.setDescription(source.getDescription()); + target.setIssueList(source.getIssueList()); + target.setTypeName(source.getTypeName()); + } + + @Override + public void update() { + update(this, getEntity()); + } + + /** + * Get an Issue Type by name. + * + * @param typename name to search for + * @return Issue Type for the specified name or null if not found. + */ + public static IssueType getType(String typename) { + IssueType result = null; + for (IssueType type : new IssueTypeJpaController(DataBaseManager + .getEntityManagerFactory()).findIssueTypeEntities()) { + if (type.getTypeName().equals(typename)) { + result = type; + break; + } + } + return result; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/NotificationServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/NotificationServer.java index a05f1928..cd5a24a5 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/NotificationServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/NotificationServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,78 +13,84 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.Notification; -import com.validation.manager.core.db.NotificationPK; -import com.validation.manager.core.db.controller.NotificationJpaController; -import java.util.Date; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class NotificationServer extends Notification - implements EntityServer { - - public NotificationServer() { - super(); - } - - public NotificationServer(Notification n) { - setNotificationPK(n.getNotificationPK()); - update(); - } - - public NotificationServer(NotificationPK pk) { - setNotificationPK(pk); - update(); - } - - @Override - public int write2DB() throws Exception { - if (getNotificationPK() == null) { - Notification n = new Notification(); - if (getCreationDate() == null) { - setCreationDate(new Date()); - } - update(n, this); - new NotificationJpaController(DataBaseManager - .getEntityManagerFactory()).create(n); - setNotificationPK(n.getNotificationPK()); - } else { - Notification n = getEntity(); - update(n, this); - new NotificationJpaController(DataBaseManager - .getEntityManagerFactory()).edit(n); - } - update(); - return getNotificationPK().getId(); - } - - @Override - public Notification getEntity() { - return new NotificationJpaController(DataBaseManager - .getEntityManagerFactory()) - .findNotification(getNotificationPK()); - } - - @Override - public void update(Notification target, Notification source) { - target.setAcknowledgeDate(source.getAcknowledgeDate()); - target.setAuthor(source.getAuthor()); - target.setContent(source.getContent()); - target.setCreationDate(source.getCreationDate()); - target.setNotificationPK(source.getNotificationPK()); - target.setNotificationType(source.getNotificationType()); - target.setTargetUser(source.getTargetUser()); - target.setArchieved(source.getArchieved()); - } - - @Override - public void update() { - update(this, getEntity()); - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.Notification; +import com.validation.manager.core.db.NotificationPK; +import com.validation.manager.core.db.controller.NotificationJpaController; +import java.util.Date; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class NotificationServer extends Notification + implements EntityServer { + + public NotificationServer() { + super(); + } + + public NotificationServer(Notification n) { + setNotificationPK(n.getNotificationPK()); + update(); + } + + public NotificationServer(NotificationPK pk) { + setNotificationPK(pk); + update(); + } + + @Override + public int write2DB() throws VMException { + try { + if (getNotificationPK() == null) { + Notification n = new Notification(); + if (getCreationDate() == null) { + setCreationDate(new Date()); + } + update(n, this); + new NotificationJpaController(DataBaseManager + .getEntityManagerFactory()).create(n); + setNotificationPK(n.getNotificationPK()); + } else { + Notification n = getEntity(); + update(n, this); + new NotificationJpaController(DataBaseManager + .getEntityManagerFactory()).edit(n); + } + update(); + } + catch (Exception ex) { + throw new VMException(ex); + } + return getNotificationPK().getId(); + } + + @Override + public Notification getEntity() { + return new NotificationJpaController(DataBaseManager + .getEntityManagerFactory()) + .findNotification(getNotificationPK()); + } + + @Override + public void update(Notification target, Notification source) { + target.setAcknowledgeDate(source.getAcknowledgeDate()); + target.setAuthor(source.getAuthor()); + target.setContent(source.getContent()); + target.setCreationDate(source.getCreationDate()); + target.setNotificationPK(source.getNotificationPK()); + target.setNotificationType(source.getNotificationType()); + target.setTargetUser(source.getTargetUser()); + target.setArchieved(source.getArchieved()); + } + + @Override + public void update() { + update(this, getEntity()); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/ProjectServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/ProjectServer.java index 963b9765..520d2d4e 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/ProjectServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/ProjectServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,153 +13,135 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.VMException; -import com.validation.manager.core.db.Project; -import com.validation.manager.core.db.TestProject; -import com.validation.manager.core.db.controller.ProjectJpaController; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import static java.util.logging.Logger.getLogger; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class ProjectServer extends Project - implements EntityServer, VersionableServer { - - private static final long serialVersionUID = 3434510483033583117L; - - public ProjectServer(String name, String notes) { - super(name); - setNotes(notes); - setProjectList(new ArrayList<>()); - setRequirementSpecList(new ArrayList<>()); - setTestProjectList(new ArrayList<>()); - } - - public ProjectServer(int id) { - Project product = new ProjectJpaController( - getEntityManagerFactory()).findProject(id); - update((ProjectServer) this, product); - } - - public ProjectServer(Project p) { - Project product = new ProjectJpaController( - getEntityManagerFactory()).findProject(p.getId()); - update((ProjectServer) this, product); - } - - @Override - public int write2DB() throws IllegalOrphanException, - NonexistentEntityException, Exception { - Project p; - if (getId() == null) { - p = new Project(getName()); - update(p, this); - new ProjectJpaController(getEntityManagerFactory()).create(p); - setId(p.getId()); - } else { - p = getEntity(); - update(p, this); - new ProjectJpaController(getEntityManagerFactory()).edit(p); - } - return getId(); - } - - public static void deleteProject(Project p) throws VMException { - if (p.getProjectList().isEmpty()) { - try { - if (p.getRequirementSpecList().isEmpty()) { - new ProjectJpaController(getEntityManagerFactory()) - .destroy(p.getId()); - } else { - throw new VMException("Unable to delete project with Requirement Specifications!"); - } - } - catch (IllegalOrphanException | NonexistentEntityException ex) { - getLogger(ProjectServer.class.getName()).log(Level.SEVERE, null, ex); - } - } else { - throw new VMException("Unable to delete project with children!"); - } - } - - @Override - public Project getEntity() { - return new ProjectJpaController(getEntityManagerFactory()) - .findProject(getId()); - } - - @Override - public void update(Project target, Project source) { - target.setNotes(source.getNotes()); - target.setName(source.getName()); - target.setParentProjectId(source.getParentProjectId()); - target.setProjectList(source.getProjectList()); - target.setRequirementSpecList(source.getRequirementSpecList()); - target.setTestProjectList(source.getTestProjectList()); - target.setId(source.getId()); - super.update(target, source); - } - - public static List getProjects() { - return new ProjectJpaController(getEntityManagerFactory()) - .findProjectEntities(); - } - - public List getChildren() { - ArrayList children = new ArrayList<>(); - getProjects().stream().filter((p) - -> (p.getParentProjectId() != null)).filter((p) - -> (p.getParentProjectId().getId().equals(getId()))) - .forEachOrdered((p) -> { - children.add(p); - }); - return children; - } - - @Override - public void update() { - update(this, getEntity()); - } - - public void copy(Project newProject) { - update(this, newProject); - } - - /** - * Get the Test Projects for this project. - * - * @return Test projects for this project. - */ - public List getTestProjects() { - return getTestProjects(false); - } - - /** - * Get the Test Projects for this project. - * - * @param includeSubProjects true to include the sub projects as well. - * - * @return Test projects for this project. - */ - public List getTestProjects(boolean includeSubProjects) { - List tps = new ArrayList<>(); - tps.addAll(getTestProjectList()); - if (includeSubProjects) { - for (Project p : getProjectList()) { - tps.addAll(new ProjectServer(p) - .getTestProjects(includeSubProjects)); - } - } - return tps; - } -} +package com.validation.manager.core.server.core; + +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.Project; +import com.validation.manager.core.db.TestProject; +import com.validation.manager.core.db.controller.ProjectJpaController; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class ProjectServer extends Project + implements EntityServer, VersionableServer { + + private static final long serialVersionUID = 3_434_510_483_033_583_117L; + + public ProjectServer(String name, String notes) { + super(name); + setNotes(notes); + setProjectList(new ArrayList<>()); + setRequirementSpecList(new ArrayList<>()); + setTestProjectList(new ArrayList<>()); + } + + public ProjectServer(int id) { + Project product = new ProjectJpaController( + getEntityManagerFactory()).findProject(id); + update((ProjectServer) this, product); + } + + public ProjectServer(Project p) { + Project product = new ProjectJpaController( + getEntityManagerFactory()).findProject(p.getId()); + update((ProjectServer) this, product); + } + + @Override + public int write2DB() throws VMException { + try { + Project p; + if (getId() == null) { + p = new Project(getName()); + update(p, this); + new ProjectJpaController(getEntityManagerFactory()).create(p); + setId(p.getId()); + } else { + p = getEntity(); + update(p, this); + new ProjectJpaController(getEntityManagerFactory()).edit(p); + } + } + catch (Exception ex) { + throw new VMException(ex); + } + return getId(); + } + + @Override + public Project getEntity() { + return new ProjectJpaController(getEntityManagerFactory()) + .findProject(getId()); + } + + @Override + public void update(Project target, Project source) { + target.setNotes(source.getNotes()); + target.setName(source.getName()); + target.setParentProjectId(source.getParentProjectId()); + target.setProjectList(source.getProjectList()); + target.setRequirementSpecList(source.getRequirementSpecList()); + target.setTestProjectList(source.getTestProjectList()); + target.setId(source.getId()); + super.update(target, source); + } + + public static List getProjects() { + return new ProjectJpaController(getEntityManagerFactory()) + .findProjectEntities(); + } + + public List getChildren() { + ArrayList children = new ArrayList<>(); + getProjects().stream().filter((p) + -> (p.getParentProjectId() != null)).filter((p) + -> (p.getParentProjectId().getId().equals(getId()))) + .forEachOrdered((p) -> { + children.add(p); + }); + return children; + } + + @Override + public void update() { + update(this, getEntity()); + } + + public void copy(Project newProject) { + update(this, newProject); + } + + /** + * Get the Test Projects for this project. + * + * @return Test projects for this project. + */ + public List getTestProjects() { + return getTestProjects(false); + } + + /** + * Get the Test Projects for this project. + * + * @param includeSubProjects true to include the sub projects as well. + * + * @return Test projects for this project. + */ + public List getTestProjects(boolean includeSubProjects) { + List tps = new ArrayList<>(); + tps.addAll(getTestProjectList()); + if (includeSubProjects) { + for (Project p : getProjectList()) { + tps.addAll(new ProjectServer(p) + .getTestProjects(includeSubProjects)); + } + } + return tps; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/RequirementStatusServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/RequirementStatusServer.java index 81313879..963bc3fd 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/RequirementStatusServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/RequirementStatusServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,65 +13,69 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.RequirementStatus; -import com.validation.manager.core.db.controller.RequirementStatusJpaController; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class RequirementStatusServer extends RequirementStatus - implements EntityServer { - - public RequirementStatusServer(Integer id) { - RequirementStatusJpaController controller - = new RequirementStatusJpaController( - getEntityManagerFactory()); - RequirementStatus rs = controller.findRequirementStatus(id); - if (rs != null) { - update(RequirementStatusServer.this, rs); - } - } - - @Override - public int write2DB() throws Exception { - RequirementStatus p; - RequirementStatusJpaController controller - = new RequirementStatusJpaController( - getEntityManagerFactory()); - if (getId() > 0) { - p = controller.findRequirementStatus(getId()); - update(p, this); - controller.edit(p); - } else { - p = new RequirementStatus(getStatus()); - update(p, this); - controller.create(p); - setId(p.getId()); - } - return getId(); - } - - @Override - public RequirementStatus getEntity() { - return new RequirementStatusJpaController( - getEntityManagerFactory()) - .findRequirementStatus(getId()); - } - - @Override - public void update(RequirementStatus target, RequirementStatus source) { - target.setId(source.getId()); - target.setStatus(source.getStatus()); - target.setRequirementList(source.getRequirementList()); - } - - @Override - public void update() { - update(this, getEntity()); - } -} +package com.validation.manager.core.server.core; + +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.db.RequirementStatus; +import com.validation.manager.core.db.controller.RequirementStatusJpaController; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class RequirementStatusServer extends RequirementStatus + implements EntityServer { + + public RequirementStatusServer(Integer id) { + RequirementStatusJpaController controller + = new RequirementStatusJpaController( + getEntityManagerFactory()); + RequirementStatus rs = controller.findRequirementStatus(id); + if (rs != null) { + update(RequirementStatusServer.this, rs); + } + } + + public RequirementStatusServer(String status) { + super(status); + } + + @Override + public int write2DB() throws Exception { + RequirementStatus p; + RequirementStatusJpaController controller + = new RequirementStatusJpaController( + getEntityManagerFactory()); + if (getId() == null) { + p = new RequirementStatus(getStatus()); + update(p, this); + controller.create(p); + setId(p.getId()); + } else { + p = controller.findRequirementStatus(getId()); + update(p, this); + controller.edit(p); + } + return getId(); + } + + @Override + public RequirementStatus getEntity() { + return new RequirementStatusJpaController( + getEntityManagerFactory()) + .findRequirementStatus(getId()); + } + + @Override + public void update(RequirementStatus target, RequirementStatus source) { + target.setId(source.getId()); + target.setStatus(source.getStatus()); + target.setRequirementList(source.getRequirementList()); + } + + @Override + public void update() { + update(this, getEntity()); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/RequirementTypeServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/RequirementTypeServer.java index 24f80b0c..2cce6640 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/RequirementTypeServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/RequirementTypeServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,75 +13,77 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.RequirementType; -import com.validation.manager.core.db.controller.RequirementTypeJpaController; -import java.util.ArrayList; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class RequirementTypeServer extends RequirementType - implements EntityServer { - - public RequirementTypeServer(RequirementType rt) { - RequirementType temp - = new RequirementTypeJpaController( - getEntityManagerFactory()) - .findRequirementType(rt.getId()); - update((RequirementType) this, temp); - } - - public RequirementTypeServer(String name) { - super(name); - setId(0); - setRequirementList(new ArrayList<>()); - } - - @Override - public int write2DB() throws Exception { - RequirementType rt; - if (getId() > 0) { - rt = new RequirementTypeJpaController(getEntityManagerFactory()).findRequirementType(getId()); - update(rt, this); - new RequirementTypeJpaController(getEntityManagerFactory()).edit(rt); - } else { - rt = new RequirementType(getName()); - update(rt, this); - new RequirementTypeJpaController(getEntityManagerFactory()).create(rt); - setId(rt.getId()); - } - return getId(); - } - - @Override - public RequirementType getEntity() { - return new RequirementTypeJpaController( - getEntityManagerFactory()) - .findRequirementType(getId()); - } - - @Override - public void update(RequirementType target, RequirementType source) { - target.setDescription(source.getDescription()); - target.setName(source.getName()); - target.setId(source.getId()); - target.setRequirementList(source.getRequirementList()); - target.setLevel(source.getLevel()); - } - - @Override - public void update() { - update(this, getEntity()); - } - - public static Iterable getRequirementTypes() { - return new RequirementTypeJpaController( - getEntityManagerFactory()) - .findRequirementTypeEntities(); - } -} +package com.validation.manager.core.server.core; + +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.db.RequirementType; +import com.validation.manager.core.db.controller.RequirementTypeJpaController; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class RequirementTypeServer extends RequirementType + implements EntityServer { + + public RequirementTypeServer(RequirementType rt) { + RequirementType temp + = new RequirementTypeJpaController( + getEntityManagerFactory()) + .findRequirementType(rt.getId()); + update((RequirementType) this, temp); + } + + public RequirementTypeServer(String name) { + super(name); + setId(0); + setRequirementList(new ArrayList<>()); + } + + @Override + public int write2DB() throws Exception { + RequirementType rt; + if (getId() > 0) { + rt = new RequirementTypeJpaController(getEntityManagerFactory()).findRequirementType(getId()); + update(rt, this); + new RequirementTypeJpaController(getEntityManagerFactory()).edit(rt); + } else { + rt = new RequirementType(getName()); + update(rt, this); + new RequirementTypeJpaController(getEntityManagerFactory()).create(rt); + setId(rt.getId()); + } + update(); + return getId(); + } + + @Override + public RequirementType getEntity() { + return new RequirementTypeJpaController( + getEntityManagerFactory()) + .findRequirementType(getId()); + } + + @Override + public void update(RequirementType target, RequirementType source) { + target.setDescription(source.getDescription()); + target.setName(source.getName()); + target.setId(source.getId()); + target.setRequirementList(source.getRequirementList()); + target.setLevel(source.getLevel()); + } + + @Override + public void update() { + update(this, getEntity()); + } + + public static List getRequirementTypes() { + return new RequirementTypeJpaController( + getEntityManagerFactory()) + .findRequirementTypeEntities(); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/ReviewResultServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/ReviewResultServer.java index e7ad759e..e391f98c 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/ReviewResultServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/ReviewResultServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,69 +13,78 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.ReviewResult; -import com.validation.manager.core.db.controller.ReviewResultJpaController; -import java.util.List; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class ReviewResultServer extends ReviewResult - implements EntityServer { - - public static ReviewResult getReview(String review) { - PARAMETERS.clear(); - PARAMETERS.put("reviewName", review); - List r = DataBaseManager.namedQuery("ReviewResult.findByReviewName", - PARAMETERS); - if (r.isEmpty()) { - return null; - } else { - return (ReviewResult) r.get(0); - } - } - - @Override - public int write2DB() throws Exception { - ReviewResultJpaController c - = new ReviewResultJpaController(DataBaseManager - .getEntityManagerFactory()); - if (getId() == null) { - ReviewResult rr = new ReviewResult(); - update(rr, this); - c.create(rr); - update(this, rr); - } else { - ReviewResult rr = getEntity(); - update(rr, this); - c.edit(rr); - update(this, rr); - } - return getId(); - } - - @Override - public ReviewResult getEntity() { - ReviewResultJpaController c - = new ReviewResultJpaController(DataBaseManager - .getEntityManagerFactory()); - return c.findReviewResult(getId()); - } - - @Override - public void update(ReviewResult target, ReviewResult source) { - target.setExecutionStepList(source.getExecutionStepList()); - target.setId(source.getId()); - target.setReviewName(source.getReviewName()); - } - - @Override - public void update() { - update(this, getEntity()); - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.db.ReviewResult; +import com.validation.manager.core.db.controller.ReviewResultJpaController; +import java.util.List; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ReviewResultServer extends ReviewResult + implements EntityServer { + + public ReviewResultServer(int id) { + setId(id); + update(); + } + + public ReviewResultServer(String reviewName) { + super(reviewName); + } + + public static ReviewResult getReview(String review) { + PARAMETERS.clear(); + PARAMETERS.put("reviewName", review); + List r = DataBaseManager.namedQuery("ReviewResult.findByReviewName", + PARAMETERS); + if (r.isEmpty()) { + return null; + } else { + return (ReviewResult) r.get(0); + } + } + + @Override + public int write2DB() throws Exception { + ReviewResultJpaController c + = new ReviewResultJpaController(DataBaseManager + .getEntityManagerFactory()); + if (getId() == null) { + ReviewResult rr = new ReviewResult(); + update(rr, this); + c.create(rr); + update(this, rr); + } else { + ReviewResult rr = getEntity(); + update(rr, this); + c.edit(rr); + update(this, rr); + } + return getId(); + } + + @Override + public ReviewResult getEntity() { + ReviewResultJpaController c + = new ReviewResultJpaController(DataBaseManager + .getEntityManagerFactory()); + return c.findReviewResult(getId()); + } + + @Override + public void update(ReviewResult target, ReviewResult source) { + target.setExecutionStepList(source.getExecutionStepList()); + target.setId(source.getId()); + target.setReviewName(source.getReviewName()); + } + + @Override + public void update() { + update(this, getEntity()); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/RiskControlServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/RiskControlServer.java index 70a4e191..8d4d8a3a 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/RiskControlServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/RiskControlServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,97 +13,98 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.RiskControl; -import com.validation.manager.core.db.RiskControlPK; -import com.validation.manager.core.db.controller.RiskControlJpaController; -import com.validation.manager.core.db.controller.RiskControlTypeJpaController; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.logging.Level; -import static java.util.logging.Logger.getLogger; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class RiskControlServer extends RiskControl - implements EntityServer { - - public RiskControlServer(RiskControlPK riskControlPK) { - super(riskControlPK); - setRiskControlType(new RiskControlTypeJpaController( - getEntityManagerFactory()).findRiskControlType( - riskControlPK.getRiskControlTypeId())); - } - - public RiskControlServer(RiskControl riskControl) { - super(riskControl.getRiskControlPK()); - setRiskControlType(new RiskControlTypeJpaController( - getEntityManagerFactory()).findRiskControlType( - riskControlPK.getRiskControlTypeId())); - } - - public RiskControlServer(int riskControlTypeId) { - super(new RiskControlPK(riskControlTypeId)); - setRiskControlType(new RiskControlTypeJpaController( - getEntityManagerFactory()).findRiskControlType(riskControlTypeId)); - } - - @Override - public int write2DB() throws NonexistentEntityException, Exception { - RiskControlJpaController controller - = new RiskControlJpaController(getEntityManagerFactory()); - if (getRiskControlPK().getId() > 0) { - RiskControl target = controller.findRiskControl(getRiskControlPK()); - update(target, this); - controller.edit(target); - } else { - RiskControl target = new RiskControl(getRiskControlPK()); - update(target, this); - controller.create(target); - setRiskControlPK(target.getRiskControlPK()); - } - return getRiskControlPK().getId(); - } - - public static boolean deleteRiskControl(RiskControl rc) { - try { - new RiskControlJpaController( - getEntityManagerFactory()) - .destroy(rc.getRiskControlPK()); - return true; - } - catch (NonexistentEntityException | IllegalOrphanException ex) { - getLogger(RiskControlServer.class.getName()).log( - Level.SEVERE, null, ex); - } - return false; - } - - @Override - public RiskControl getEntity() { - return new RiskControlJpaController( - getEntityManagerFactory()) - .findRiskControl(getRiskControlPK()); - } - - @Override - public void update(RiskControl target, RiskControl source) { - target.setRiskControlHasRequirementList(source - .getRiskControlHasRequirementList()); - target.setRiskControlHasTestCaseList(source - .getRiskControlHasTestCaseList()); - target.setRiskItemList(source.getRiskItemList()); - target.setRiskItemList1(source.getRiskItemList1()); - target.setRiskControlType(source.getRiskControlType()); - } - - @Override - public void update() { - update(this, getEntity()); - } -} +package com.validation.manager.core.server.core; + +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.db.RiskControl; +import com.validation.manager.core.db.RiskControlPK; +import com.validation.manager.core.db.controller.RiskControlJpaController; +import com.validation.manager.core.db.controller.RiskControlTypeJpaController; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.logging.Level; +import static java.util.logging.Logger.getLogger; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class RiskControlServer extends RiskControl + implements EntityServer { + + public RiskControlServer(RiskControlPK riskControlPK) { + super(riskControlPK); + setRiskControlType(new RiskControlTypeJpaController( + getEntityManagerFactory()).findRiskControlType( + riskControlPK.getRiskControlTypeId())); + update(); + } + + public RiskControlServer(RiskControl riskControl) { + super(riskControl.getRiskControlPK()); + setRiskControlType(new RiskControlTypeJpaController( + getEntityManagerFactory()).findRiskControlType( + riskControlPK.getRiskControlTypeId())); + } + + public RiskControlServer(int riskControlTypeId) { + super(new RiskControlPK(riskControlTypeId)); + setRiskControlType(new RiskControlTypeJpaController( + getEntityManagerFactory()).findRiskControlType(riskControlTypeId)); + } + + @Override + public int write2DB() throws NonexistentEntityException, Exception { + RiskControlJpaController controller + = new RiskControlJpaController(getEntityManagerFactory()); + if (getRiskControlPK().getId() > 0) { + RiskControl target = controller.findRiskControl(getRiskControlPK()); + update(target, this); + controller.edit(target); + } else { + RiskControl target = new RiskControl(getRiskControlPK()); + update(target, this); + controller.create(target); + setRiskControlPK(target.getRiskControlPK()); + } + return getRiskControlPK().getId(); + } + + public static boolean deleteRiskControl(RiskControl rc) { + try { + new RiskControlJpaController( + getEntityManagerFactory()) + .destroy(rc.getRiskControlPK()); + return true; + } + catch (NonexistentEntityException | IllegalOrphanException ex) { + getLogger(RiskControlServer.class.getName()).log( + Level.SEVERE, null, ex); + } + return false; + } + + @Override + public RiskControl getEntity() { + return new RiskControlJpaController( + getEntityManagerFactory()) + .findRiskControl(getRiskControlPK()); + } + + @Override + public void update(RiskControl target, RiskControl source) { + target.setRiskControlHasRequirementList(source + .getRiskControlHasRequirementList()); + target.setRiskControlHasTestCaseList(source + .getRiskControlHasTestCaseList()); + target.setRiskItemList(source.getRiskItemList()); + target.setRiskItemList1(source.getRiskItemList1()); + target.setRiskControlType(source.getRiskControlType()); + } + + @Override + public void update() { + update(this, getEntity()); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/RoleServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/RoleServer.java index 1d55e1e2..c3609ea5 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/RoleServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/RoleServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,76 +13,84 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.Role; -import com.validation.manager.core.db.controller.RoleJpaController; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class RoleServer extends Role implements EntityServer { - - private static final Map PARAMETERS = new HashMap<>(); - private final RoleJpaController c - = new RoleJpaController(DataBaseManager.getEntityManagerFactory()); - - public RoleServer(String description) { - super(description); - update(RoleServer.this, getRole(description)); - } - - public static Role getRole(String role) { - Role r = null; - PARAMETERS.clear(); - PARAMETERS.put("name", role); - List result = DataBaseManager.namedQuery("Role.findByName", - PARAMETERS); - if (!result.isEmpty()) { - r = (Role) result.get(0); - } - return r; - } - - @Override - public int write2DB() throws Exception { - if (getId() == null) { - Role r = new Role(); - update(r, this); - c.create(r); - update(this, r); - } else { - Role r = getEntity(); - update(r, this); - c.edit(r); - update(this, r); - } - return getId(); - } - - @Override - public void update() { - update(RoleServer.this, getEntity()); - } - - @Override - public Role getEntity() { - return getId() == null ? null : c.findRole(getId()); - } - - @Override - public void update(Role target, Role source) { - target.setDescription(source.getDescription()); - target.setId(source.getId()); - target.setRoleName(source.getRoleName()); - target.setUserRightList(source.getUserRightList()); - target.setUserTestPlanRoleList(source.getUserTestPlanRoleList()); - target.setVmUserList(source.getVmUserList()); - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.Role; +import com.validation.manager.core.db.controller.RoleJpaController; +import java.util.List; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class RoleServer extends Role implements EntityServer { + + private final RoleJpaController c + = new RoleJpaController(DataBaseManager.getEntityManagerFactory()); + + public RoleServer(int id) { + setId(id); + update(); + } + + public RoleServer(String description) { + super(description); + update(RoleServer.this, getRole(description)); + } + + public static Role getRole(String role) { + Role r = null; + PARAMETERS.clear(); + PARAMETERS.put("name", role); + List result = DataBaseManager.namedQuery("Role.findByName", + PARAMETERS); + if (!result.isEmpty()) { + r = (Role) result.get(0); + } + return r; + } + + @Override + public int write2DB() throws VMException { + try { + if (getId() == null) { + Role r = new Role(); + update(r, this); + c.create(r); + update(this, r); + } else { + Role r = getEntity(); + update(r, this); + c.edit(r); + update(this, r); + } + } + catch (Exception ex) { + throw new VMException(ex); + } + return getId(); + } + + @Override + public void update() { + update(RoleServer.this, getEntity()); + } + + @Override + public Role getEntity() { + return getId() == null ? null : c.findRole(getId()); + } + + @Override + public void update(Role target, Role source) { + target.setDescription(source.getDescription()); + target.setId(source.getId()); + target.setRoleName(source.getRoleName()); + target.setUserRightList(source.getUserRightList()); + target.setUserTestPlanRoleList(source.getUserTestPlanRoleList()); + target.setVmUserList(source.getVmUserList()); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/TestCaseExecutionServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/TestCaseExecutionServer.java index 504832a6..ce704eab 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/TestCaseExecutionServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/TestCaseExecutionServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,214 +13,214 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.Project; -import com.validation.manager.core.db.TestCase; -import com.validation.manager.core.db.TestCaseExecution; -import com.validation.manager.core.db.TestPlan; -import com.validation.manager.core.db.TestProject; -import com.validation.manager.core.db.controller.ExecutionStepJpaController; -import com.validation.manager.core.db.controller.TestCaseExecutionJpaController; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import org.openide.util.Exceptions; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class TestCaseExecutionServer extends TestCaseExecution - implements EntityServer { - - public TestCaseExecutionServer(String name, String scope) { - super(name, scope); - } - - public TestCaseExecutionServer(int id) { - super.setId(id); - update(); - } - - public TestCaseExecutionServer(TestCaseExecution tce) { - super.setId(tce.getId()); - update(); - } - - public TestCaseExecutionServer() { - } - - /** - * Add a Test Case to this execution. - * - * @param tc Test Case to add - */ - public void addTestCase(TestCase tc) { - try { - ExecutionStepJpaController econtroller - = new ExecutionStepJpaController(DataBaseManager - .getEntityManagerFactory()); - tc.getStepList().forEach((s) -> { - ExecutionStep es = new ExecutionStep(getId(), - s.getStepPK().getId(), s.getStepPK().getTestCaseId()); - es.setStep(s); - es.setStepHistory(s.getHistoryList() - .get(s.getHistoryList().size() - 1)); - es.setTestCaseExecution(getEntity()); - try { - econtroller.create(es); - getExecutionStepList().add(es); - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - }); - write2DB(); - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - } - - @Override - public int write2DB() throws Exception { - TestCaseExecutionJpaController controller - = new TestCaseExecutionJpaController(DataBaseManager - .getEntityManagerFactory()); - TestCaseExecution tce; - if (getId() == null) { - //New one - tce = new TestCaseExecution(); - update(tce, this); - controller.create(tce); - setId(tce.getId()); - } else { - tce = controller.findTestCaseExecution(getId()); - update(tce, this); - controller.edit(tce); - } - update(); - return getId(); - } - - @Override - public TestCaseExecution getEntity() { - return new TestCaseExecutionJpaController(DataBaseManager - .getEntityManagerFactory()).findTestCaseExecution(getId()); - } - - @Override - public void update(TestCaseExecution target, TestCaseExecution source) { - target.setConclusion(source.getConclusion()); - target.setId(source.getId()); - target.setScope(source.getScope()); - target.setName(source.getName()); - if (target.getExecutionStepList() == null) { - target.setExecutionStepList(new ArrayList<>()); - } else { - target.getExecutionStepList().clear(); - } - if (source.getExecutionStepList() != null) { - source.getExecutionStepList().forEach((es) -> { - target.getExecutionStepList().add(es); - }); - } - } - - @Override - public void update() { - update(this, getEntity()); - } - - /** - * Add a complete Test Project to the execution. - * - * @param tp Test Project to add - */ - public void addTestProject(TestProject tp) { - tp.getTestPlanList().forEach((plan) -> { - addTestPlan(plan); - }); - } - - /** - * Add a complete Test Plan to the execution. - * - * @param plan Test Plan to add - */ - private void addTestPlan(TestPlan plan) { - plan.getTestCaseList().forEach((tc) -> { - addTestCase(tc); - }); - } - - /** - * List of Executions for the provided project. - * - * @param p project to look into. - * @return List of Executions for the provided project. - */ - public static List getExecutions(Project p) { - List results = new ArrayList<>(); - p.getTestProjectList().forEach(tp -> { - tp.getTestPlanList().forEach(plan -> { - plan.getTestCaseList().forEach(tc -> { - tc.getStepList().forEach(s -> { - s.getExecutionStepList().forEach(es -> { - results.add(es.getTestCaseExecution()); - }); - }); - }); - }); - }); - return results; - } - - public void removeTestCase(TestCase tc) throws Exception { - List toDelete = new ArrayList<>(); - getExecutionStepList().forEach(es -> { - if (Objects.equals(es.getStep().getTestCase() - .getId(), tc.getId())) { - //Same test case - toDelete.add(es); - } - }); - getExecutionStepList().removeAll(toDelete); - ExecutionStepJpaController c - = new ExecutionStepJpaController(DataBaseManager - .getEntityManagerFactory()); - toDelete.forEach(es -> { - try { - ExecutionStepServer ess = new ExecutionStepServer(es); - ess.getExecutionStepHasAttachmentList().forEach(att -> { - try { - ess.removeAttachment(att.getAttachment()); - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - }); - ess.getExecutionStepHasIssueList().forEach(issue -> { - try { - ess.removeIssue(issue.getIssue()); - } - catch (NonexistentEntityException ex) { - Exceptions.printStackTrace(ex); - } - }); - ess.getEntity(); - c.destroy(ess.getExecutionStepPK()); - } - catch (IllegalOrphanException | NonexistentEntityException ex) { - Exceptions.printStackTrace(ex); - } - }); - write2DB(); - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.Project; +import com.validation.manager.core.db.TestCase; +import com.validation.manager.core.db.TestCaseExecution; +import com.validation.manager.core.db.TestPlan; +import com.validation.manager.core.db.TestProject; +import com.validation.manager.core.db.controller.ExecutionStepJpaController; +import com.validation.manager.core.db.controller.TestCaseExecutionJpaController; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import org.openide.util.Exceptions; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class TestCaseExecutionServer extends TestCaseExecution + implements EntityServer { + + public TestCaseExecutionServer(String name, String scope) { + super(name, scope); + } + + public TestCaseExecutionServer(int id) { + super.setId(id); + update(); + } + + public TestCaseExecutionServer(TestCaseExecution tce) { + super.setId(tce.getId()); + update(); + } + + public TestCaseExecutionServer() { + } + + /** + * Add a Test Case to this execution. + * + * @param tc Test Case to add + */ + public void addTestCase(TestCase tc) { + try { + ExecutionStepJpaController econtroller + = new ExecutionStepJpaController(DataBaseManager + .getEntityManagerFactory()); + tc.getStepList().forEach((s) -> { + ExecutionStep es = new ExecutionStep(getId(), + s.getStepPK().getId(), s.getStepPK().getTestCaseId()); + es.setStep(s); + es.setStepHistory(s.getHistoryList() + .get(s.getHistoryList().size() - 1)); + es.setTestCaseExecution(getEntity()); + try { + econtroller.create(es); + getExecutionStepList().add(es); + } + catch (Exception ex) { + Exceptions.printStackTrace(ex); + } + }); + write2DB(); + } + catch (Exception ex) { + Exceptions.printStackTrace(ex); + } + } + + @Override + public int write2DB() throws Exception { + TestCaseExecutionJpaController controller + = new TestCaseExecutionJpaController(DataBaseManager + .getEntityManagerFactory()); + TestCaseExecution tce; + if (getId() == null) { + //New one + tce = new TestCaseExecution(); + update(tce, this); + controller.create(tce); + setId(tce.getId()); + } else { + tce = controller.findTestCaseExecution(getId()); + update(tce, this); + controller.edit(tce); + } + update(); + return getId(); + } + + @Override + public TestCaseExecution getEntity() { + return new TestCaseExecutionJpaController(DataBaseManager + .getEntityManagerFactory()).findTestCaseExecution(getId()); + } + + @Override + public void update(TestCaseExecution target, TestCaseExecution source) { + target.setConclusion(source.getConclusion()); + target.setId(source.getId()); + target.setScope(source.getScope()); + target.setName(source.getName()); + if (target.getExecutionStepList() == null) { + target.setExecutionStepList(new ArrayList<>()); + } else { + target.getExecutionStepList().clear(); + } + if (source.getExecutionStepList() != null) { + source.getExecutionStepList().forEach((es) -> { + target.getExecutionStepList().add(es); + }); + } + } + + @Override + public void update() { + update(this, getEntity()); + } + + /** + * Add a complete Test Project to the execution. + * + * @param tp Test Project to add + */ + public void addTestProject(TestProject tp) { + tp.getTestPlanList().forEach((plan) -> { + addTestPlan(plan); + }); + } + + /** + * Add a complete Test Plan to the execution. + * + * @param plan Test Plan to add + */ + private void addTestPlan(TestPlan plan) { + plan.getTestCaseList().forEach((tc) -> { + addTestCase(tc); + }); + } + + /** + * List of Executions for the provided project. + * + * @param p project to look into. + * @return List of Executions for the provided project. + */ + public static List getExecutions(Project p) { + List results = new ArrayList<>(); + p.getTestProjectList().forEach(tp -> { + tp.getTestPlanList().forEach(plan -> { + plan.getTestCaseList().forEach(tc -> { + tc.getStepList().forEach(s -> { + s.getExecutionStepList().forEach(es -> { + results.add(es.getTestCaseExecution()); + }); + }); + }); + }); + }); + return results; + } + + public void removeTestCase(TestCase tc) throws Exception { + List toDelete = new ArrayList<>(); + getExecutionStepList().forEach(es -> { + if (Objects.equals(es.getStep().getTestCase() + .getId(), tc.getId())) { + //Same test case + toDelete.add(es); + } + }); + getExecutionStepList().removeAll(toDelete); + ExecutionStepJpaController c + = new ExecutionStepJpaController(DataBaseManager + .getEntityManagerFactory()); + toDelete.forEach(es -> { + try { + ExecutionStepServer ess = new ExecutionStepServer(es); + ess.getExecutionStepHasAttachmentList().forEach(att -> { + try { + ess.removeAttachment(att.getAttachment()); + } + catch (Exception ex) { + Exceptions.printStackTrace(ex); + } + }); + ess.getExecutionStepHasIssueList().forEach(issue -> { + try { + ess.removeIssue(issue.getIssue()); + } + catch (NonexistentEntityException ex) { + Exceptions.printStackTrace(ex); + } + }); + ess.getEntity(); + c.destroy(ess.getExecutionStepPK()); + } + catch (IllegalOrphanException | NonexistentEntityException ex) { + Exceptions.printStackTrace(ex); + } + }); + write2DB(); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/TestCaseServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/TestCaseServer.java index ca1b5a1f..4f034766 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/TestCaseServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/TestCaseServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,107 +13,107 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.Requirement; -import com.validation.manager.core.db.Step; -import com.validation.manager.core.db.TestCase; -import com.validation.manager.core.db.controller.TestCaseJpaController; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class TestCaseServer extends TestCase - implements EntityServer { - - public TestCaseServer(int id) { - super(id); - update(); - } - - public TestCaseServer(TestCase tc) { - super.setId(tc.getId()); - update(); - } - - public TestCaseServer(String name, Date creationDate) { - super(name, creationDate); - } - - @Override - public int write2DB() throws IllegalOrphanException, - NonexistentEntityException, Exception { - TestCaseJpaController controller - = new TestCaseJpaController(getEntityManagerFactory()); - if (getId() != null && getId() > 0) { - TestCase temp = controller.findTestCase(getId()); - update(temp, this); - controller.edit(temp); - } else { - TestCase temp = new TestCase(getName(), getCreationDate()); - temp.setCreationDate(new Date()); - controller.create(temp); - setId(temp.getId()); - } - update(); - return getId(); - } - - @Override - public TestCase getEntity() { - return new TestCaseJpaController(getEntityManagerFactory()) - .findTestCase(getId()); - } - - @Override - public void update(TestCase target, TestCase source) { - target.setActive(source.getActive()); - target.setCreationDate(source.getCreationDate()); - target.setRiskControlHasTestCaseList(source - .getRiskControlHasTestCaseList()); - target.setStepList(source.getStepList() == null - ? new ArrayList<>() : source.getStepList()); - target.setIsOpen(source.getIsOpen()); - target.setSummary(source.getSummary()); - target.setTestPlanList(new ArrayList<>()); - target.setId(source.getId()); - target.setName(source.getName()); - target.setIsOpen(source.getIsOpen()); - } - - @Override - public void update() { - update(this, getEntity()); - } - - public Step addStep(int sequence, String text, String note, String criteria, - List requirements) - throws PreexistingEntityException, Exception { - StepServer ss = new StepServer(getEntity(), sequence, text); - int amount = getStepList().size(); - ss.setNotes(note); - ss.setExpectedResult(criteria.getBytes("UTF-8")); - if (ss.getRequirementList() == null) { - ss.setRequirementList(new ArrayList<>()); - } - ss.write2DB(); - if (requirements != null) { - requirements.forEach((req) -> { - ss.getRequirementList().add(req); - }); - } - ss.write2DB(); - update(); - assert getStepList().size() > amount; - return ss.getEntity(); - } -} +package com.validation.manager.core.server.core; + +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.db.Requirement; +import com.validation.manager.core.db.Step; +import com.validation.manager.core.db.TestCase; +import com.validation.manager.core.db.controller.TestCaseJpaController; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class TestCaseServer extends TestCase + implements EntityServer { + + public TestCaseServer(int id) { + super(id); + update(); + } + + public TestCaseServer(TestCase tc) { + super.setId(tc.getId()); + update(); + } + + public TestCaseServer(String name, Date creationDate) { + super(name, creationDate); + } + + @Override + public int write2DB() throws IllegalOrphanException, + NonexistentEntityException, Exception { + TestCaseJpaController controller + = new TestCaseJpaController(getEntityManagerFactory()); + if (getId() != null && getId() > 0) { + TestCase temp = controller.findTestCase(getId()); + update(temp, this); + controller.edit(temp); + } else { + TestCase temp = new TestCase(getName(), getCreationDate()); + temp.setCreationDate(new Date()); + controller.create(temp); + setId(temp.getId()); + } + update(); + return getId(); + } + + @Override + public TestCase getEntity() { + return new TestCaseJpaController(getEntityManagerFactory()) + .findTestCase(getId()); + } + + @Override + public void update(TestCase target, TestCase source) { + target.setActive(source.getActive()); + target.setCreationDate(source.getCreationDate()); + target.setRiskControlHasTestCaseList(source + .getRiskControlHasTestCaseList()); + target.setStepList(source.getStepList() == null + ? new ArrayList<>() : source.getStepList()); + target.setIsOpen(source.getIsOpen()); + target.setSummary(source.getSummary()); + target.setTestPlanList(new ArrayList<>()); + target.setId(source.getId()); + target.setName(source.getName()); + target.setIsOpen(source.getIsOpen()); + } + + @Override + public void update() { + update(this, getEntity()); + } + + public Step addStep(int sequence, String text, String note, String criteria, + List requirements) + throws PreexistingEntityException, Exception { + StepServer ss = new StepServer(getEntity(), sequence, text); + int amount = getStepList().size(); + ss.setNotes(note); + ss.setExpectedResult(criteria.getBytes("UTF-8")); + if (ss.getRequirementList() == null) { + ss.setRequirementList(new ArrayList<>()); + } + ss.write2DB(); + if (requirements != null) { + requirements.forEach((req) -> { + ss.getRequirementList().add(req); + }); + } + ss.write2DB(); + update(); + assert getStepList().size() > amount; + return ss.getEntity(); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/TestPlanServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/TestPlanServer.java index bc5410ca..d5901e00 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/TestPlanServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/TestPlanServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,134 +13,135 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.Role; -import com.validation.manager.core.db.TestCase; -import com.validation.manager.core.db.TestPlan; -import com.validation.manager.core.db.TestProject; -import com.validation.manager.core.db.UserTestPlanRole; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.controller.TestPlanJpaController; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import java.util.ArrayList; -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class TestPlanServer extends TestPlan - implements EntityServer { - - private final static Logger LOG - = Logger.getLogger(TestPlanServer.class.getName()); - - public TestPlanServer(TestPlan plan) { - super.setTestPlanPK(plan.getTestPlanPK()); - update(); - } - - public TestPlanServer(TestProject testProject, boolean active, - boolean isOpen) { - super(testProject, active, isOpen); - setTestProject(testProject); - setTestPlanList(new ArrayList<>()); - setUserTestPlanRoleList(new ArrayList<>()); - setTestCaseList(new ArrayList<>()); - } - - @Override - public int write2DB() throws IllegalOrphanException, - NonexistentEntityException, Exception { - TestPlanJpaController controller - = new TestPlanJpaController(getEntityManagerFactory()); - if (getTestPlanPK().getId() > 0) { - TestPlan temp = controller.findTestPlan(getTestPlanPK()); - update(temp, this); - controller.edit(temp); - } else { - TestPlan temp = new TestPlan(getTestProject(), getActive(), - getIsOpen()); - update(temp, this); - controller.create(temp); - setTestPlanPK(temp.getTestPlanPK()); - } - return getTestPlanPK().getId(); - } - - public static boolean deleteTestPlan(TestPlan tp) { - try { - new TestPlanJpaController(getEntityManagerFactory()) - .destroy(tp.getTestPlanPK()); - } - catch (IllegalOrphanException | NonexistentEntityException ex) { - LOG.log(Level.SEVERE, null, ex); - return false; - } - return true; - } - - public boolean addTestCase(TestCase test) { - try { - getTestCaseList().add(test); - write2DB(); - return true; - } - catch (PreexistingEntityException ex) { - LOG.log(Level.SEVERE, null, ex); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - return false; - } - - @Override - public TestPlan getEntity() { - return new TestPlanJpaController(getEntityManagerFactory()) - .findTestPlan(getTestPlanPK()); - } - - @Override - public void update(TestPlan target, TestPlan source) { - target.setActive(source.getActive()); - target.setIsOpen(source.getIsOpen()); - target.setNotes(source.getNotes()); - target.setTestCaseList(source.getTestCaseList()); - target.setTestPlanList(source.getTestPlanList()); - target.setUserTestPlanRoleList(source.getUserTestPlanRoleList()); - target.setTestPlanPK(source.getTestPlanPK()); - target.setTestPlan(source.getTestPlan()); - target.setName(source.getName()); - } - - @Override - public void update() { - update(this, getEntity()); - } - - public void addUserTestPlanRole(VmUser user, Role role) throws Exception { - for (UserTestPlanRole utpr : getUserTestPlanRoleList()) { - if (utpr.getTestPlan().getTestPlanPK().equals(getTestPlanPK()) - && Objects.equals(utpr.getVmUser().getId(), user.getId()) - && Objects.equals(utpr.getRole().getId(), role.getId())) { - //We have already this role. - return; - } - } - UserTestPlanRoleServer temp = new UserTestPlanRoleServer(getEntity(), - user, role); - if (temp.getEntity() == null) { - temp.write2DB(); - } - getUserTestPlanRoleList().add(temp.getEntity()); - write2DB(); - } -} +package com.validation.manager.core.server.core; + +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.Role; +import com.validation.manager.core.db.TestCase; +import com.validation.manager.core.db.TestPlan; +import com.validation.manager.core.db.TestProject; +import com.validation.manager.core.db.UserTestPlanRole; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.TestPlanJpaController; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.ArrayList; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class TestPlanServer extends TestPlan + implements EntityServer { + + private final static Logger LOG + = Logger.getLogger(TestPlanServer.class.getName()); + + public TestPlanServer(TestPlan plan) { + super.setTestPlanPK(plan.getTestPlanPK()); + update(); + } + + public TestPlanServer(TestProject testProject, boolean active, + boolean isOpen) { + super(testProject, active, isOpen); + setTestProject(testProject); + setTestPlanList(new ArrayList<>()); + setUserTestPlanRoleList(new ArrayList<>()); + setTestCaseList(new ArrayList<>()); + } + + @Override + public int write2DB() throws VMException { + try { + TestPlanJpaController controller + = new TestPlanJpaController(getEntityManagerFactory()); + if (getTestPlanPK().getId() > 0) { + TestPlan temp = controller.findTestPlan(getTestPlanPK()); + update(temp, this); + controller.edit(temp); + } else { + TestPlan temp = new TestPlan(getTestProject(), getActive(), + getIsOpen()); + update(temp, this); + controller.create(temp); + setTestPlanPK(temp.getTestPlanPK()); + } + } + catch (Exception ex) { + throw new VMException(ex); + } + return getTestPlanPK().getId(); + } + + public static boolean deleteTestPlan(TestPlan tp) { + try { + new TestPlanJpaController(getEntityManagerFactory()) + .destroy(tp.getTestPlanPK()); + } + catch (IllegalOrphanException | NonexistentEntityException ex) { + LOG.log(Level.SEVERE, null, ex); + return false; + } + return true; + } + + public boolean addTestCase(TestCase test) { + try { + getTestCaseList().add(test); + write2DB(); + return true; + } + catch (VMException ex) { + LOG.log(Level.SEVERE, null, ex); + } + return false; + } + + @Override + public TestPlan getEntity() { + return new TestPlanJpaController(getEntityManagerFactory()) + .findTestPlan(getTestPlanPK()); + } + + @Override + public void update(TestPlan target, TestPlan source) { + target.setActive(source.getActive()); + target.setIsOpen(source.getIsOpen()); + target.setNotes(source.getNotes()); + target.setTestCaseList(source.getTestCaseList()); + target.setTestPlanList(source.getTestPlanList()); + target.setUserTestPlanRoleList(source.getUserTestPlanRoleList()); + target.setTestPlanPK(source.getTestPlanPK()); + target.setTestPlan(source.getTestPlan()); + target.setName(source.getName()); + } + + @Override + public void update() { + update(this, getEntity()); + } + + public void addUserTestPlanRole(VmUser user, Role role) throws Exception { + for (UserTestPlanRole utpr : getUserTestPlanRoleList()) { + if (utpr.getTestPlan().getTestPlanPK().equals(getTestPlanPK()) + && Objects.equals(utpr.getVmUser().getId(), user.getId()) + && Objects.equals(utpr.getRole().getId(), role.getId())) { + //We have already this role. + return; + } + } + UserTestPlanRoleServer temp = new UserTestPlanRoleServer(getEntity(), + user, role); + if (temp.getEntity() == null) { + temp.write2DB(); + } + getUserTestPlanRoleList().add(temp.getEntity()); + write2DB(); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/TestProjectServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/TestProjectServer.java index 5ad3ca63..6e320d78 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/TestProjectServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/TestProjectServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,92 +13,100 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.Role; -import com.validation.manager.core.db.TestProject; -import com.validation.manager.core.db.UserTestProjectRole; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.controller.TestProjectJpaController; -import com.validation.manager.core.db.controller.UserTestProjectRoleJpaController; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class TestProjectServer extends TestProject - implements EntityServer { - - public TestProjectServer(String name, boolean active) { - super(name, active); - } - - public TestProjectServer(TestProject tp) { - super.setId(tp.getId()); - update(); - } - - @Override - public int write2DB() throws IllegalOrphanException, - NonexistentEntityException, Exception { - TestProject tp; - if (getId() == null) { - tp = new TestProject(); - update(tp, this); - new TestProjectJpaController(getEntityManagerFactory()).create(tp); - setId(tp.getId()); - } else { - tp = getEntity(); - update(tp, this); - new TestProjectJpaController(getEntityManagerFactory()).edit(tp); - } - update(); - return getId(); - } - - @Override - public TestProject getEntity() { - return new TestProjectJpaController( - getEntityManagerFactory()) - .findTestProject(getId()); - } - - @Override - public void update(TestProject target, TestProject source) { - target.setActive(source.getActive()); - target.setName(source.getName()); - target.setNotes(source.getNotes()); - target.setId(source.getId()); - target.setProjectList(source.getProjectList()); - target.setTestPlanList(source.getTestPlanList()); - target.setUserTestProjectRoleList(source.getUserTestProjectRoleList()); - } - - @Override - public void update() { - update(this, getEntity()); - } - - public UserTestProjectRole addUserTestProjectRole(TestProject tp, VmUser user, Role role) - throws Exception { - UserTestProjectRole temp = new UserTestProjectRole(tp.getId(), - user.getId(), role.getId()); - temp.setVmUser(user); - temp.setRole(role); - temp.setTestProject(tp); - UserTestProjectRoleJpaController controller - = new UserTestProjectRoleJpaController(DataBaseManager - .getEntityManagerFactory()); - if (controller.findUserTestProjectRole(temp - .getUserTestProjectRolePK()) == null) { - controller.create(temp); - update(); - } - return temp; - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.Role; +import com.validation.manager.core.db.TestProject; +import com.validation.manager.core.db.UserTestProjectRole; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.TestProjectJpaController; +import com.validation.manager.core.db.controller.UserTestProjectRoleJpaController; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class TestProjectServer extends TestProject + implements EntityServer { + + public TestProjectServer(String name, boolean active) { + super(name, active); + } + + public TestProjectServer(int id) { + super.setId(id); + update(); + } + + public TestProjectServer(TestProject tp) { + super.setId(tp.getId()); + update(); + } + + @Override + public int write2DB() throws VMException { + try { + TestProject tp; + if (getId() == null) { + tp = new TestProject(); + update(tp, this); + new TestProjectJpaController(getEntityManagerFactory()).create(tp); + setId(tp.getId()); + } else { + tp = getEntity(); + update(tp, this); + new TestProjectJpaController(getEntityManagerFactory()).edit(tp); + } + update(); + } + catch (Exception ex) { + throw new VMException(ex); + } + return getId(); + } + + @Override + public TestProject getEntity() { + return new TestProjectJpaController( + getEntityManagerFactory()) + .findTestProject(getId()); + } + + @Override + public void update(TestProject target, TestProject source) { + target.setActive(source.getActive()); + target.setName(source.getName()); + target.setNotes(source.getNotes()); + target.setId(source.getId()); + target.setProjectList(source.getProjectList()); + target.setTestPlanList(source.getTestPlanList()); + target.setUserTestProjectRoleList(source.getUserTestProjectRoleList()); + } + + @Override + public void update() { + update(this, getEntity()); + } + + public UserTestProjectRole addUserTestProjectRole(TestProject tp, VmUser user, Role role) + throws Exception { + UserTestProjectRole temp = new UserTestProjectRole(tp.getId(), + user.getId(), role.getId()); + temp.setVmUser(user); + temp.setRole(role); + temp.setTestProject(tp); + UserTestProjectRoleJpaController controller + = new UserTestProjectRoleJpaController(DataBaseManager + .getEntityManagerFactory()); + if (controller.findUserTestProjectRole(temp + .getUserTestProjectRolePK()) == null) { + controller.create(temp); + update(); + } + return temp; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/UserTestPlanRoleServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/UserTestPlanRoleServer.java index a26daace..2bcfa4a3 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/UserTestPlanRoleServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/UserTestPlanRoleServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,81 +13,87 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.Role; -import com.validation.manager.core.db.TestPlan; -import com.validation.manager.core.db.UserTestPlanRole; -import com.validation.manager.core.db.UserTestPlanRolePK; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.controller.UserTestPlanRoleJpaController; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import java.util.logging.Level; -import static java.util.logging.Logger.getLogger; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class UserTestPlanRoleServer extends UserTestPlanRole - implements EntityServer { - - public UserTestPlanRoleServer(TestPlan tpl, VmUser user, Role role) { - super(tpl, user, role); - } - - public UserTestPlanRoleServer(UserTestPlanRolePK pk) { - super.setUserTestPlanRolePK(pk); - update(); - } - - @Override - public int write2DB() throws NonexistentEntityException, Exception { - UserTestPlanRoleJpaController controller - = new UserTestPlanRoleJpaController(getEntityManagerFactory()); - if (controller.findUserTestPlanRole(getUserTestPlanRolePK()) == null) { - UserTestPlanRole temp = new UserTestPlanRole(getTestPlan(), getVmUser(), - getRole()); - update(temp, this); - controller.create(temp); - update(this, temp); - } - return getUserTestPlanRolePK().getTestPlanTestProjectId(); - } - - public static boolean deleteUserTestPlanRole(UserTestPlanRole utpr) { - try { - new UserTestPlanRoleJpaController( - getEntityManagerFactory()).destroy( - utpr.getUserTestPlanRolePK()); - } - catch (NonexistentEntityException ex) { - getLogger(UserTestPlanRoleServer.class.getName()) - .log(Level.SEVERE, null, ex); - return false; - } - return true; - } - - @Override - public UserTestPlanRole getEntity() { - return new UserTestPlanRoleJpaController( - getEntityManagerFactory()) - .findUserTestPlanRole(getUserTestPlanRolePK()); - } - - @Override - public void update(UserTestPlanRole target, UserTestPlanRole source) { - target.setRole(source.getRole()); - target.setTestPlan(source.getTestPlan()); - target.setVmUser(source.getVmUser()); - target.setUserTestPlanRolePK(source.getUserTestPlanRolePK()); - } - - @Override - public void update() { - update(this, getEntity()); - } -} +package com.validation.manager.core.server.core; + +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.Role; +import com.validation.manager.core.db.TestPlan; +import com.validation.manager.core.db.UserTestPlanRole; +import com.validation.manager.core.db.UserTestPlanRolePK; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.UserTestPlanRoleJpaController; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.logging.Level; +import static java.util.logging.Logger.getLogger; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class UserTestPlanRoleServer extends UserTestPlanRole + implements EntityServer { + + public UserTestPlanRoleServer(TestPlan tpl, VmUser user, Role role) { + super(tpl, user, role); + } + + public UserTestPlanRoleServer(UserTestPlanRolePK pk) { + super.setUserTestPlanRolePK(pk); + update(); + } + + @Override + public int write2DB() throws VMException { + try { + UserTestPlanRoleJpaController controller + = new UserTestPlanRoleJpaController(getEntityManagerFactory()); + if (controller.findUserTestPlanRole(getUserTestPlanRolePK()) == null) { + UserTestPlanRole temp = new UserTestPlanRole(getTestPlan(), getVmUser(), + getRole()); + update(temp, this); + controller.create(temp); + update(this, temp); + } + } + catch (Exception ex) { + throw new VMException(ex); + } + return getUserTestPlanRolePK().getTestPlanTestProjectId(); + } + + public static boolean deleteUserTestPlanRole(UserTestPlanRole utpr) { + try { + new UserTestPlanRoleJpaController( + getEntityManagerFactory()).destroy( + utpr.getUserTestPlanRolePK()); + } + catch (NonexistentEntityException ex) { + getLogger(UserTestPlanRoleServer.class.getName()) + .log(Level.SEVERE, null, ex); + return false; + } + return true; + } + + @Override + public UserTestPlanRole getEntity() { + return new UserTestPlanRoleJpaController( + getEntityManagerFactory()) + .findUserTestPlanRole(getUserTestPlanRolePK()); + } + + @Override + public void update(UserTestPlanRole target, UserTestPlanRole source) { + target.setRole(source.getRole()); + target.setTestPlan(source.getTestPlan()); + target.setVmUser(source.getVmUser()); + target.setUserTestPlanRolePK(source.getUserTestPlanRolePK()); + } + + @Override + public void update() { + update(this, getEntity()); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/UserTestProjectRoleServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/UserTestProjectRoleServer.java index 0f8ba306..2152c907 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/UserTestProjectRoleServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/UserTestProjectRoleServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,99 +13,100 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.UserTestProjectRole; -import com.validation.manager.core.db.controller.UserTestProjectRoleJpaController; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import java.util.logging.Level; -import static java.util.logging.Logger.getLogger; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class UserTestProjectRoleServer extends UserTestProjectRole - implements EntityServer { - - public UserTestProjectRoleServer(int testProjectId, int userId, int roleId) { - super(testProjectId, userId, roleId); - update(); - } - - /** - * Persist to database - * - * @throws PreexistingEntityException If entity already exists and tried to - * be re-created. - * @throws Exception If something goes wrong writing to the database. - */ - @Override - public int write2DB() throws PreexistingEntityException, Exception { - UserTestProjectRoleJpaController controller - = new UserTestProjectRoleJpaController(getEntityManagerFactory()); - if (getUserTestProjectRolePK().getRoleId() > 0 - && getUserTestProjectRolePK().getTestProjectId() > 0 - && getUserTestProjectRolePK().getUserId() > 0) { - UserTestProjectRole temp - = controller.findUserTestProjectRole(getUserTestProjectRolePK()); - temp.setRole(getRole()); - temp.setTestProject(getTestProject()); - temp.setVmUser(getVmUser()); - controller.edit(temp); - } else { - UserTestProjectRole temp = new UserTestProjectRole( - getUserTestProjectRolePK().getTestProjectId(), - getUserTestProjectRolePK().getUserId(), - getUserTestProjectRolePK().getRoleId()); - temp.setRole(getRole()); - temp.setTestProject(getTestProject()); - temp.setVmUser(getVmUser()); - controller.create(temp); - setUserTestProjectRolePK(temp.getUserTestProjectRolePK()); - } - return getUserTestProjectRolePK().getRoleId(); - } - - /** - * Delete UserTestProjectRole - * - * @param role UserTestProjectRole to delete - * @return true if successful - */ - public static boolean deleteUserTestProjectRole(UserTestProjectRole role) { - try { - new UserTestProjectRoleJpaController( - getEntityManagerFactory()).destroy( - role.getUserTestProjectRolePK()); - } - catch (NonexistentEntityException ex) { - getLogger(UserTestProjectRoleServer.class.getName()) - .log(Level.SEVERE, null, ex); - return false; - } - return true; - } - - @Override - public UserTestProjectRole getEntity() { - return new UserTestProjectRoleJpaController( - getEntityManagerFactory()) - .findUserTestProjectRole(getUserTestProjectRolePK()); - } - - @Override - public void update(UserTestProjectRole target, UserTestProjectRole source) { - target.setRole(source.getRole()); - target.setTestProject(source.getTestProject()); - target.setVmUser(source.getVmUser()); - } - - @Override - public void update() { - update(this, getEntity()); - } -} +package com.validation.manager.core.server.core; + +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.UserTestProjectRole; +import com.validation.manager.core.db.controller.UserTestProjectRoleJpaController; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import java.util.logging.Level; +import static java.util.logging.Logger.getLogger; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class UserTestProjectRoleServer extends UserTestProjectRole + implements EntityServer { + + public UserTestProjectRoleServer(int testProjectId, int userId, + int roleId) throws Exception { + super(testProjectId, userId, roleId); + setTestProject(new TestProjectServer(testProjectId).getEntity()); + setRole(new RoleServer(roleId).getEntity()); + setVmUser(new VMUserServer(userId).getEntity()); + } + + /** + * Persist to database + * + * @throws VMException If something goes wrong writing to the database. + */ + @Override + public int write2DB() throws VMException { + try { + UserTestProjectRoleJpaController controller + = new UserTestProjectRoleJpaController(getEntityManagerFactory()); + UserTestProjectRole temp + = controller.findUserTestProjectRole(getUserTestProjectRolePK()); + if (temp == null) { + temp = new UserTestProjectRole(); + update(temp, this); + controller.create(temp); + setUserTestProjectRolePK(temp.getUserTestProjectRolePK()); + } else { + temp.setRole(getRole()); + temp.setTestProject(getTestProject()); + temp.setVmUser(getVmUser()); + controller.edit(temp); + } + update(); + } + catch (Exception ex) { + throw new VMException(ex); + } + return getUserTestProjectRolePK().getRoleId(); + } + + /** + * Delete UserTestProjectRole + * + * @param role UserTestProjectRole to delete + * @return true if successful + */ + public static boolean deleteUserTestProjectRole(UserTestProjectRole role) { + try { + new UserTestProjectRoleJpaController( + getEntityManagerFactory()).destroy( + role.getUserTestProjectRolePK()); + } + catch (NonexistentEntityException ex) { + getLogger(UserTestProjectRoleServer.class.getName()) + .log(Level.SEVERE, null, ex); + return false; + } + return true; + } + + @Override + public UserTestProjectRole getEntity() { + return new UserTestProjectRoleJpaController( + getEntityManagerFactory()) + .findUserTestProjectRole(getUserTestProjectRolePK()); + } + + @Override + public void update(UserTestProjectRole target, UserTestProjectRole source) { + target.setRole(source.getRole()); + target.setTestProject(source.getTestProject()); + target.setVmUser(source.getVmUser()); + target.setUserTestProjectRolePK(source.getUserTestProjectRolePK()); + } + + @Override + public void update() { + update(this, getEntity()); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/core/VMUserServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/core/VMUserServer.java index dcf1a370..0068e0e2 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/core/VMUserServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/core/VMUserServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,545 +13,461 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import static com.validation.manager.core.DataBaseManager.createdQuery; -import static com.validation.manager.core.DataBaseManager.getEntityManager; -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import static com.validation.manager.core.DataBaseManager.namedQuery; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.VMException; -import com.validation.manager.core.db.CorrectiveAction; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.Notification; -import com.validation.manager.core.db.Role; -import com.validation.manager.core.db.TestCase; -import com.validation.manager.core.db.TestCaseExecution; -import com.validation.manager.core.db.UserAssigment; -import com.validation.manager.core.db.UserHasInvestigation; -import com.validation.manager.core.db.UserModifiedRecord; -import com.validation.manager.core.db.UserTestPlanRole; -import com.validation.manager.core.db.UserTestProjectRole; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.controller.CorrectiveActionJpaController; -import com.validation.manager.core.db.controller.ExecutionStepJpaController; -import com.validation.manager.core.db.controller.RoleJpaController; -import com.validation.manager.core.db.controller.UserAssigmentJpaController; -import com.validation.manager.core.db.controller.UserHasInvestigationJpaController; -import com.validation.manager.core.db.controller.UserModifiedRecordJpaController; -import com.validation.manager.core.db.controller.UserStatusJpaController; -import com.validation.manager.core.db.controller.UserTestPlanRoleJpaController; -import com.validation.manager.core.db.controller.UserTestProjectRoleJpaController; -import com.validation.manager.core.db.controller.VmUserJpaController; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import static com.validation.manager.core.server.core.VMSettingServer.getSetting; -import static com.validation.manager.core.tool.MD5.encrypt; -import static java.lang.System.currentTimeMillis; -import java.util.ArrayList; -import java.util.Calendar; -import static java.util.Calendar.getInstance; -import java.util.Date; -import java.util.List; -import static java.util.Locale.getDefault; -import java.util.logging.Level; -import static java.util.logging.Logger.getLogger; -import javax.persistence.EntityTransaction; -import org.openide.util.Exceptions; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class VMUserServer extends VmUser implements EntityServer { - - private static final long serialVersionUID = 1L; - private boolean hashPassword = true; - private boolean increaseAttempts = false; - private boolean change; - - public VMUserServer(VmUser vmu) { - super.setId(vmu.getId()); - update(); - //previously hashing the already hashed password - setHashPassword(false); - } - - //create user object and login - public VMUserServer(String attrUN, String attrUPW) throws Exception { - super(); - try { - List result = createdQuery( - "SELECT u FROM VmUser uu WHERE u.username='" // NOI18N - + attrUN + "' AND u.password='" + encrypt(attrUPW) - + "' AND u.userStatusId.id <> 2"); - //throw exception if no result found - if (result.isEmpty()) { - PARAMETERS.clear(); - PARAMETERS.put("username", attrUN); - result - = namedQuery("VmUser.findByUsername", - PARAMETERS); - //The username is valid but wrong password. Increase the login attempts. - if (result.size() > 0) { - increaseAttempts = true; - VmUser xcu = (VmUser) result.get(0); - setAttempts(xcu.getAttempts()); - write2DB(); - } - throw new Exception(); - } else { - VmUser vmu = (VmUser) result.get(0); - update(VMUserServer.this, vmu); - //previously hashing the already hashed password - setHashPassword(false); - int status = vmu.getUserStatusId().getId(); - if (status != 2) { - Calendar cal2 = getInstance(), - now = getInstance(); - cal2.setTime(vmu.getLastModified()); - long diffMillis = now.getTimeInMillis() - - cal2.getTimeInMillis(); - long diffDays = diffMillis / (24 * 60 * 60 * 1000); - long age = getSetting("password.aging") - .getIntVal(); - if (diffDays >= age) { - status = 4; - } else { - status = 1; - } - setAttempts(0); - } else { - setAttempts(vmu.getAttempts()); - } - setUserStatusId(new UserStatusJpaController( - getEntityManagerFactory()) - .findUserStatus(status)); - } - } - catch (Exception e) { - EntityTransaction transaction - = getEntityManager().getTransaction(); - if (transaction.isActive()) { - transaction.rollback(); - } - List result = createdQuery("SELECT u FROM VmUser u WHERE u.username='" - + attrUN + "' AND u.userStatusId.id <> 2"); - //increase number of attempts - if (!result.isEmpty()) { - VmUser vmu = (VmUser) result.get(0); - update(VMUserServer.this, vmu); - //Don't rehash the pasword! - setHashPassword(false); //Increase attempts after a unsuccessfull login. - setIncreaseAttempts(true); - setLastModified(vmu.getLastModified()); - setChange(false); - write2DB(); - } - } - } - -//create user object for data structures - public VMUserServer(int id) throws Exception { - super.setId(id); - update(); - //previously hashing the already hashed password - setHashPassword(false); - } - - public VMUserServer(String name, String password, String firstName, - String lastName, String email) throws Exception { - setId(0); - setUsername(name); - setPassword(password); - setFirstName(firstName); - setLastName(lastName); - setEmail(email); - setLocale(getDefault().toString()); - setUserStatusId(new UserStatusJpaController( - getEntityManagerFactory()).findUserStatus(1)); - setAttempts(0); - setLastModified(new java.sql.Timestamp(currentTimeMillis())); - setHashPassword(true); - } - -//create user object - public VMUserServer(String name, String password, String firstName, - String lastName, String email, int userStatusId, int attempts, - java.sql.Timestamp lastModified) throws Exception { - setUsername(name); - setPassword(password); - setFirstName(firstName); - setLastName(lastName); - setEmail(email); - setUserStatusId(new UserStatusJpaController( - getEntityManagerFactory()) - .findUserStatus(userStatusId)); - setAttempts(attempts); - setLastModified(lastModified); - setHashPassword(true); - } - - //write to db - @Override - public int write2DB() throws Exception { - Date date; - if (getUserStatusId().getId() == 4) { - //Changed from aged out to password changed. Clear status - setUserStatusId(new UserStatusJpaController( - getEntityManagerFactory()) - .findUserStatus(1)); - setAttempts(0); -// setReason("audit.user.account.aged"); - setChange(true); - } - //Increase login attempts - if (increaseAttempts) { - setAttempts(getAttempts() + 1); - increaseAttempts = false; - } - //Lock account if needed. Can't lock main admin. - if (getAttempts() - > getSetting("password.attempts").getIntVal() - && getId() > 1) { - setUserStatusId( - new UserStatusJpaController( - getEntityManagerFactory()).findUserStatus(2)); - } - VmUserJpaController controller - = new VmUserJpaController(getEntityManagerFactory()); - if (getId() > 0) { - if (isChange()) { -// setModifierId(getEntity()); - date = new Date(); - setLastModified(date); - setChange(false); - } else { - date = getLastModified(); - } - setLastModified(date); - //Sometimes password got re-hashed - String password; - if (isHashPassword()) { - password = encrypt(getPassword().replaceAll("'", "\\\\'")); - } else { - password = getPassword().replaceAll("'", "\\\\'"); - } - VmUser vmu = controller.findVmUser(getId()); - update(vmu, this); - vmu.setPassword(password); -// vmu.setReason(getReason() == null -// ? "audit.general.modified" : getReason()); -// vmu.setModificationTime(new Date()); - controller.edit(vmu); - } else { - VmUser vmu = new VmUser( - getUsername().replaceAll("'", "\\\\'"), getPassword(), - getEmail().replaceAll("'", "\\\\'"), - getFirstName().replaceAll("'", "\\\\'"), - getLastName().replaceAll("'", "\\\\'"), getLocale(), - getLastModified(), new UserStatusJpaController( - getEntityManagerFactory()) - .findUserStatus(1), getAttempts()); - update(vmu, this); - controller.create(vmu); - setId(vmu.getId()); - } - setChange(false); -// setReason(""); - return getId(); - } - -//create complete list of users - public static ArrayList getVMUsers() { - ArrayList coreUsers = new ArrayList<>(); - try { - List result = createdQuery( - "Select x from VMUser x order by x.username"); - result.forEach((o) -> { - coreUsers.add(new VMUserServer((VmUser) o)); - }); - } - catch (Exception e) { - coreUsers.clear(); - } - return coreUsers; - } - - public boolean isHashPassword() { - return hashPassword; - } - - public void setHashPassword(boolean hashPassword) { - this.hashPassword = hashPassword; - } - - public boolean isIncreaseAttempts() { - return increaseAttempts; - } - - public void setIncreaseAttempts(boolean increaseAttempts) { - this.increaseAttempts = increaseAttempts; - } - - public boolean isPasswordUsable(String newPass, boolean hash) { - boolean passwordIsUsable = true; - try { - //Now check if password is not the same as the current password - List result = createdQuery( - "Select x from VmUser x where x.id=" + getId() - + " and x.password='" - + (hash ? encrypt(newPass) : newPass) + "'"); - if (result.size() > 0) { - passwordIsUsable = false; - } else { - //Here we'll catch if the password have been used in the - //unusable period (use id in case the username was modified) - VMUserServer user = new VMUserServer(getId()); - for (History u : user.getHistoryModificationList()) { - //Now check the aging - long diff = currentTimeMillis() - - u.getModificationTime().getTime(); - if (diff / (1000 * 60 * 60 * 24) - > getSetting("password.unusable_period") - .getIntVal()) { - passwordIsUsable = false; - } - } - } - //--------------------------- - } - catch (Exception ex) { - passwordIsUsable = false; - } - return passwordIsUsable; - } - - public boolean isPasswordUsable(String newPass) { - return isPasswordUsable(newPass, true); - } - - private void setChange(boolean c) { - change = c; - } - - private boolean isChange() { - return change; - } - - public static void deleteUser(VmUser user) { - if (user != null) { - PARAMETERS.clear(); - PARAMETERS.put("id", user.getId()); - VmUser temp = (VmUser) namedQuery("VmUser.findById", - PARAMETERS).get(0); - try { - for (CorrectiveAction ca : temp.getCorrectiveActionList()) { - new CorrectiveActionJpaController( - getEntityManagerFactory()).destroy(ca.getId()); - } - for (Role r : temp.getRoleList()) { - new RoleJpaController( - getEntityManagerFactory()).destroy(r.getId()); - } - for (UserAssigment ua : temp.getUserAssigmentList()) { - new UserAssigmentJpaController( - getEntityManagerFactory()).destroy(ua.getUserAssigmentPK()); - } - for (UserAssigment ua : temp.getUserAssigmentList1()) { - new UserAssigmentJpaController( - getEntityManagerFactory()).destroy(ua.getUserAssigmentPK()); - } - for (UserHasInvestigation i : temp.getUserHasInvestigationList()) { - new UserHasInvestigationJpaController( - getEntityManagerFactory()).destroy(i.getUserHasInvestigationPK()); - } - for (UserModifiedRecord rc : temp.getUserModifiedRecordList()) { - new UserModifiedRecordJpaController( - getEntityManagerFactory()).destroy(rc.getUserModifiedRecordPK()); - } - for (UserTestPlanRole rc : temp.getUserTestPlanRoleList()) { - new UserTestPlanRoleJpaController( - getEntityManagerFactory()).destroy(rc.getUserTestPlanRolePK()); - } - for (UserTestProjectRole rc : temp.getUserTestProjectRoleList()) { - new UserTestProjectRoleJpaController( - getEntityManagerFactory()).destroy(rc.getUserTestProjectRolePK()); - } - PARAMETERS.clear(); - PARAMETERS.put("id", temp.getId()); - temp = (VmUser) namedQuery("VmUser.findById", - PARAMETERS).get(0); - new VmUserJpaController( - getEntityManagerFactory()).destroy(temp.getId()); - } - catch (NonexistentEntityException | IllegalOrphanException ex) { - getLogger(VMUserServer.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - - /** - * Check user credentials. - * - * the password is already encrypted. Usually queries from within the server - * itself - * - * @param username User name - * @param password Password - * @param encrypt Password needs encrypting? - * @return true if valid - */ - public static boolean validCredentials(String username, - String password, boolean encrypt) { - try { - PARAMETERS.clear(); - PARAMETERS.put("username", username); - PARAMETERS.put("password", encrypt - ? encrypt(password.replaceAll("'", "\\\\'")) : password); - return !createdQuery("SELECT x FROM VmUser x " - + "WHERE x.username = :username and x.password = :password", - PARAMETERS).isEmpty(); - } - catch (VMException e) { - getLogger(VMUserServer.class.getName()).log(Level.SEVERE, null, e); - return false; - } - catch (Exception ex) { - getLogger(VMUserServer.class.getName()).log(Level.SEVERE, null, ex); - return false; - } - } - - public static VmUser getUser(String username, - String password, boolean encrypt) { - try { - PARAMETERS.clear(); - PARAMETERS.put("username", username); - PARAMETERS.put("password", encrypt - ? encrypt(password.replaceAll("'", "\\\\'")) : password); - if (validCredentials(username, password, encrypt)) { - return (VmUser) createdQuery("SELECT x FROM VmUser x " - + "WHERE x.username = :username and x.password = :password", - PARAMETERS).get(0); - } else { - return null; - } - } - catch (Exception ex) { - getLogger(VMUserServer.class.getName()).log(Level.SEVERE, null, ex); - return null; - - } - } - - @Override - public VmUser getEntity() { - return new VmUserJpaController( - getEntityManagerFactory()) - .findVmUser(getId()); - } - - @Override - public void update(VmUser target, VmUser source) { - target.setPassword(source.getPassword()); - target.setFirstName(source.getFirstName()); - target.setLastName(source.getLastName()); - target.setLocale(source.getLocale()); - target.setEmail(source.getEmail()); - target.setAttempts(source.getAttempts()); - target.setLastModified(source.getLastModified()); - target.setUserStatusId(source.getUserStatusId()); - target.setRoleList(source.getRoleList()); - target.setCorrectiveActionList(source.getCorrectiveActionList()); - target.setUserAssigmentList(source.getUserAssigmentList()); - target.setUserAssigmentList1(source.getUserAssigmentList1()); - target.setUserHasInvestigationList(source.getUserHasInvestigationList()); - target.setUsername(source.getUsername()); - target.setRootCauseList(source.getRootCauseList()); - target.setUserTestPlanRoleList(source.getUserTestPlanRoleList()); - target.setUserTestProjectRoleList(source.getUserTestProjectRoleList()); - target.setId(source.getId()); - if (target.getExecutionStepList() == null) { - target.setExecutionStepList(new ArrayList<>()); - } - if (source.getExecutionStepList() != null) { - target.setExecutionStepList(source.getExecutionStepList()); - } - if (target.getExecutionStepList1() == null) { - target.setExecutionStepList1(new ArrayList<>()); - } - if (source.getExecutionStepList1() != null) { - target.setExecutionStepList1(source.getExecutionStepList1()); - } - if (target.getExecutionStepHasIssueList() == null) { - target.setExecutionStepHasIssueList(new ArrayList<>()); - } - target.setExecutionStepList(source.getExecutionStepList()); - target.setExecutionStepList1(source.getExecutionStepList1()); - target.setExecutionStepHasIssueList(source.getExecutionStepHasIssueList()); - target.setNotificationList(source.getNotificationList()); - target.setNotificationList1(source.getNotificationList1()); -// super.update(target, source); - } - - @Override - public void update() { - update(this, getEntity()); - } - - public void assignTestCase(TestCaseExecution tce, TestCase tc, - VmUser assigner) { - try { - VMUserServer a = new VMUserServer(assigner); - ExecutionStepJpaController c - = new ExecutionStepJpaController(DataBaseManager - .getEntityManagerFactory()); - tc.getStepList().forEach((s) -> { - tce.getExecutionStepList().stream().filter((es) - -> (es.getStep().getStepPK().equals(s.getStepPK()))) - .forEachOrdered((es) -> { - try { - es.setAssignedTime(new Date()); - c.edit(es); - getExecutionStepList().add(es); - a.getExecutionStepList1().add(es); - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - }); - }); - a.write2DB(); - write2DB(); - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - } - - public void setAsAssigner(ExecutionStep es) throws Exception { - ExecutionStepServer ess = new ExecutionStepServer(es); - ess.setAssigner(getEntity()); - ess.write2DB(); - update(); - } - - @Override - public String toString() { - return getFirstName() + " " + getLastName(); - } - - public List getPendingNotifications() { - update(); - List pending = new ArrayList<>(); - getNotificationList().forEach(n -> { - if (n.getAcknowledgeDate() == null) { - pending.add(n); - } - }); - return pending; - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import static com.validation.manager.core.DataBaseManager.createdQuery; +import static com.validation.manager.core.DataBaseManager.getEntityManager; +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.Notification; +import com.validation.manager.core.db.TestCase; +import com.validation.manager.core.db.TestCaseExecution; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.ExecutionStepJpaController; +import com.validation.manager.core.db.controller.UserStatusJpaController; +import com.validation.manager.core.db.controller.VmUserJpaController; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import static com.validation.manager.core.server.core.VMSettingServer.getSetting; +import static com.validation.manager.core.tool.MD5.encrypt; +import static java.lang.System.currentTimeMillis; +import java.util.ArrayList; +import java.util.Calendar; +import static java.util.Calendar.getInstance; +import java.util.Date; +import java.util.List; +import static java.util.Locale.getDefault; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.persistence.EntityTransaction; +import org.openide.util.Exceptions; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class VMUserServer extends VmUser implements EntityServer { + + private static final long serialVersionUID = 1L; + private boolean hashPassword = true; + private boolean increaseAttempts = false; + private static final Logger LOG + = Logger.getLogger(VMUserServer.class.getName()); + private static final String USERNAME = "username"; + private static final String PWD = "password"; + + public VMUserServer(VmUser vmu) { + super.setId(vmu.getId()); + if (getId() != null) { + update(); + } + //previously hashing the already hashed password + setHashPassword(false); + } + + //create user object and login + public VMUserServer(String attrUN, String attrUPW) throws VMException { + super(); + try { + PARAMETERS.clear(); + PARAMETERS.put(USERNAME, attrUN); + PARAMETERS.put(PWD, encrypt(attrUPW)); + List result = createdQuery( + "SELECT u FROM VmUser u WHERE u.username= :username"// NOI18N + + " AND u.password= :password AND u.userStatusId.id <> 2", + PARAMETERS); + //throw exception if no result found + if (result.isEmpty()) { + //The username is valid but wrong password. Increase the login attempts. + throw new VMException("general.login.invalid.message"); + } else { + VmUser vmu = (VmUser) result.get(0); + update(VMUserServer.this, vmu); + //previously hashing the already hashed password + setHashPassword(false); + int status = vmu.getUserStatusId().getId(); + if (status != 2) { + Calendar cal2 = getInstance(), + now = getInstance(); + History last = getHistoryList().get(getHistoryList().size() - 1); + cal2.setTime(last.getModificationTime()); + long diffMillis = now.getTimeInMillis() + - cal2.getTimeInMillis(); + long diffDays = diffMillis / (24 * 60 * 60 * 1_000); + long age = getSetting("password.aging") + .getIntVal(); + if (diffDays >= age) { + status = 4; + } else { + status = 1; + } + setAttempts(0); + } else { + setAttempts(vmu.getAttempts()); + } + setUserStatusId(new UserStatusJpaController( + getEntityManagerFactory()) + .findUserStatus(status)); + } + } + catch (VMException e) { + EntityTransaction transaction + = getEntityManager().getTransaction(); + if (transaction.isActive()) { + transaction.rollback(); + } + List result = createdQuery("SELECT u FROM VmUser u WHERE u.username='" + + attrUN + "' AND u.userStatusId.id <> 2"); + //increase number of attempts + if (!result.isEmpty()) { + VMUserServer vmu = new VMUserServer((VmUser) result.get(0)); + //Don't rehash the pasword! + vmu.setHashPassword(false); + vmu.setIncreaseAttempts(true);//Increase attempts after a unsuccessfull login. + vmu.write2DB(); + } + } + } + +//create user object for data structures + public VMUserServer(int id) throws Exception { + super.setId(id); + update(); + //previously hashing the already hashed password + setHashPassword(false); + } + + public VMUserServer(String name, String password, String firstName, + String lastName, String email) throws Exception { + setId(0); + setUsername(name); + setPassword(password); + setFirstName(firstName); + setLastName(lastName); + setEmail(email); + setLocale(getDefault().toString()); + setUserStatusId(new UserStatusJpaController( + getEntityManagerFactory()).findUserStatus(1)); + setAttempts(0); + setHashPassword(true); + } + + private void prepareToPersist() { + if (getUserStatusId() == null) { + setUserStatusId(new UserStatusJpaController( + getEntityManagerFactory()) + .findUserStatus(1)); + } + if (getUserStatusId().getId() == 4) { + //Changed from aged out to password changed. Clear status + setUserStatusId(new UserStatusJpaController( + getEntityManagerFactory()) + .findUserStatus(1)); + setAttempts(0); + setReason("audit.user.account.aged"); + } + //Increase login attempts + if (increaseAttempts) { + setAttempts(getAttempts() + 1); + increaseAttempts = false; + } + //Lock account if needed. Can't lock main admin. + if (getAttempts() + > getSetting("password.attempts").getIntVal() + && getId() > 1) { + setUserStatusId( + new UserStatusJpaController( + getEntityManagerFactory()).findUserStatus(4)); + } + } + + //write to db + @Override + public int write2DB() throws VMException { + VmUserJpaController controller + = new VmUserJpaController(getEntityManagerFactory()); + if (getId() != null && getId() > 0) { + prepareToPersist(); + try { + if (getModifierId() == 0) { + setModifierId(getEntity().getId()); + } + //Sometimes password got re-hashed + String password; + if (isHashPassword()) { + password = encrypt(getPassword().replaceAll("'", "\\\\'")); + setHashPassword(false); + } else { + password = getPassword().replaceAll("'", "\\\\'"); + } + VmUser vmu = getEntity(); + update(vmu, this); + vmu.setPassword(password); + vmu.setReason(getReason() == null + ? "audit.general.modified" : getReason()); + vmu.setModificationTime(new Date()); + vmu.updateHistory(); + controller.edit(vmu); + update(); + } + catch (NonexistentEntityException ex) { + throw new VMException(ex); + } + catch (Exception ex) { + throw new VMException(ex); + } + } else { + try { + prepareToPersist(); + String password; + if (isHashPassword()) { + password = encrypt(getPassword().replaceAll("'", "\\\\'")); + setHashPassword(false); + } else { + password = getPassword().replaceAll("'", "\\\\'"); + } + VmUser vmu = new VmUser( + getUsername().replaceAll("'", "\\\\'"), password, + getEmail().replaceAll("'", "\\\\'"), + getFirstName().replaceAll("'", "\\\\'"), + getLastName().replaceAll("'", "\\\\'"), getLocale(), + new UserStatusJpaController( + getEntityManagerFactory()) + .findUserStatus(1), getAttempts()); + vmu.updateHistory(); + controller.create(vmu); + setId(vmu.getId()); + } + catch (Exception ex) { + throw new VMException(ex); + } + } + setReason(""); + update(); + return getId(); + } + + //Create complete list of users + public static ArrayList getVMUsers() { + ArrayList coreUsers = new ArrayList<>(); + try { + List result = createdQuery( + "Select x from VmUser x order by x.username"); + result.forEach((o) -> { + coreUsers.add(new VMUserServer((VmUser) o)); + }); + } + catch (Exception e) { + coreUsers.clear(); + } + return coreUsers; + } + + public boolean isHashPassword() { + return hashPassword; + } + + public void setHashPassword(boolean hashPassword) { + this.hashPassword = hashPassword; + } + + public boolean isIncreaseAttempts() { + return increaseAttempts; + } + + public void setIncreaseAttempts(boolean increaseAttempts) { + this.increaseAttempts = increaseAttempts; + } + + public boolean isPasswordUsable(String newPass, boolean hash) { + boolean passwordIsUsable = true; + try { + //Now check if password is not the same as the current password + PARAMETERS.clear(); + PARAMETERS.put(USERNAME, getUsername()); + PARAMETERS.put(PWD, hash + ? encrypt(newPass.replaceAll("'", "\\\\'")) : newPass); + List result = createdQuery("SELECT x FROM VmUser x " + + "WHERE x.username = :username and x.password = :password", + PARAMETERS); + if (result.size() > 0) { + //Can't change to same password. + passwordIsUsable = false; + } else { + //Here we'll catch if the password have been used in the + //unusable period (use id in case the username was modified) + VMUserServer user = new VMUserServer(getId()); + for (History u : user.getHistoryList()) { + //Now check the aging + long diff = currentTimeMillis() + - u.getModificationTime().getTime(); + if (diff / (1_000 * 60 * 60 * 24) + > getSetting("password.unusable_period") + .getIntVal()) { + passwordIsUsable = false; + } + } + } + //--------------------------- + } + catch (Exception ex) { + passwordIsUsable = false; + } + return passwordIsUsable; + } + + public boolean isPasswordUsable(String newPass) { + return isPasswordUsable(newPass, true); + } + + /** + * Check user credentials. + * + * The password is already encrypted. Usually queries from within the server + * itself + * + * @param username User name + * @param password Password + * @param encrypt Password needs encrypting? + * @return true if valid + */ + protected static boolean validCredentials(String username, + String password, boolean encrypt) { + try { + PARAMETERS.clear(); + PARAMETERS.put(USERNAME, username); + PARAMETERS.put(PWD, encrypt + ? encrypt(password.replaceAll("'", "\\\\'")) : password); + return !createdQuery("SELECT x FROM VmUser x " + + "WHERE x.username = :username and x.password = :password", + PARAMETERS).isEmpty(); + } + catch (VMException e) { + LOG.log(Level.SEVERE, null, e); + return false; + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + return false; + } + } + + public static VmUser getUser(String username, + String password, boolean encrypt) { + try { + PARAMETERS.clear(); + PARAMETERS.put(USERNAME, username); + PARAMETERS.put(PWD, encrypt + ? encrypt(password.replaceAll("'", "\\\\'")) : password); + if (validCredentials(username, password, encrypt)) { + return (VmUser) createdQuery("SELECT x FROM VmUser x " + + "WHERE x.username = :username and x.password = :password", + PARAMETERS).get(0); + } else { + return null; + } + } + catch (VMException ex) { + LOG.log(Level.SEVERE, null, ex); + return null; + + } + } + + @Override + public VmUser getEntity() { + return new VmUserJpaController(getEntityManagerFactory()) + .findVmUser(getId()); + } + + @Override + public void update(VmUser target, VmUser source) { + target.setPassword(source.getPassword()); + target.setFirstName(source.getFirstName()); + target.setLastName(source.getLastName()); + target.setLocale(source.getLocale()); + target.setEmail(source.getEmail()); + target.setAttempts(source.getAttempts()); + target.setUserStatusId(source.getUserStatusId()); + target.setRoleList(source.getRoleList()); + target.setCorrectiveActionList(source.getCorrectiveActionList()); + target.setUserAssigmentList(source.getUserAssigmentList()); + target.setUserAssigmentList1(source.getUserAssigmentList1()); + target.setUserHasInvestigationList(source.getUserHasInvestigationList()); + target.setUsername(source.getUsername()); + target.setRootCauseList(source.getRootCauseList()); + target.setUserTestPlanRoleList(source.getUserTestPlanRoleList()); + target.setUserTestProjectRoleList(source.getUserTestProjectRoleList()); + target.setId(source.getId()); + target.setExecutionStepList(source.getExecutionStepList()); + target.setExecutionStepList1(source.getExecutionStepList1()); + target.setExecutionStepList(source.getExecutionStepList()); + target.setExecutionStepList1(source.getExecutionStepList1()); + target.setExecutionStepHasIssueList(source.getExecutionStepHasIssueList()); + target.setNotificationList(source.getNotificationList()); + target.setNotificationList1(source.getNotificationList1()); + target.setHistoryModificationList(source.getHistoryModificationList()); + super.update(target, source); + } + + @Override + public void update() { + update(this, getEntity()); + } + + public void assignTestCase(TestCaseExecution tce, TestCase tc, + VmUser assigner) { + try { + VMUserServer a = new VMUserServer(assigner); + ExecutionStepJpaController c + = new ExecutionStepJpaController(DataBaseManager + .getEntityManagerFactory()); + tc.getStepList().forEach((s) -> { + tce.getExecutionStepList().stream().filter((es) + -> (es.getStep().getStepPK().equals(s.getStepPK()))) + .forEachOrdered((es) -> { + try { + es.setAssignedTime(new Date()); + c.edit(es); + getExecutionStepList().add(es); + a.getExecutionStepList1().add(es); + } + catch (Exception ex) { + Exceptions.printStackTrace(ex); + } + }); + }); + a.write2DB(); + write2DB(); + } + catch (VMException ex) { + Exceptions.printStackTrace(ex); + } + } + + public void setAsAssigner(ExecutionStep es) throws Exception { + ExecutionStepServer ess = new ExecutionStepServer(es); + ess.setAssigner(getEntity()); + ess.write2DB(); + update(); + } + + @Override + public String toString() { + return getFirstName() + " " + getLastName(); + } + + public List getPendingNotifications() { + update(); + List pending = new ArrayList<>(); + getNotificationList().forEach(n -> { + if (n.getAcknowledgeDate() == null) { + pending.add(n); + } + }); + return pending; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/server/fmea/CauseServer.java b/VM-Core/src/main/java/com/validation/manager/core/server/fmea/CauseServer.java index 3c0beb7b..0e97a3ed 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/server/fmea/CauseServer.java +++ b/VM-Core/src/main/java/com/validation/manager/core/server/fmea/CauseServer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,67 +13,73 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.fmea; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.EntityServer; -import com.validation.manager.core.db.Cause; -import com.validation.manager.core.db.controller.CauseJpaController; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class CauseServer extends Cause implements EntityServer { - - public CauseServer(String name, String description) { - super(name, description); - setId(0); - } - - @Override - public int write2DB() throws NonexistentEntityException, Exception { - if (getId() > 0) { - Cause c = new CauseJpaController( - getEntityManagerFactory()) - .findCause(getId()); - update(c, this); - new CauseJpaController( - getEntityManagerFactory()).edit(c); - } else { - Cause c = new Cause(); - update(c, this); - new CauseJpaController( - getEntityManagerFactory()).create(c); - setId(c.getId()); - } - return getId(); - } - - public static boolean deleteCause(Cause c) throws NonexistentEntityException { - new CauseJpaController( - getEntityManagerFactory()).destroy(c.getId()); - return true; - } - - @Override - public Cause getEntity() { - return new CauseJpaController( - getEntityManagerFactory()).findCause(getId()); - } - - @Override - public void update(Cause target, Cause source) { - target.setDescription(source.getDescription()); - target.setName(source.getName()); - if (source.getRiskItemList() != null) { - target.setRiskItemList(source.getRiskItemList()); - } - } - - @Override - public void update() { - update(this, getEntity()); - } -} +package com.validation.manager.core.server.fmea; + +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.EntityServer; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.Cause; +import com.validation.manager.core.db.controller.CauseJpaController; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class CauseServer extends Cause implements EntityServer { + + public CauseServer(String name, String description) { + super(name, description); + setId(0); + } + + @Override + public int write2DB() throws VMException { + try { + if (getId() > 0) { + Cause c = new CauseJpaController( + getEntityManagerFactory()) + .findCause(getId()); + update(c, this); + new CauseJpaController( + getEntityManagerFactory()).edit(c); + } else { + Cause c = new Cause(); + update(c, this); + new CauseJpaController( + getEntityManagerFactory()).create(c); + setId(c.getId()); + } + } + catch (Exception ex) { + throw new VMException(ex); + } + return getId(); + } + + public static boolean deleteCause(Cause c) throws NonexistentEntityException { + new CauseJpaController( + getEntityManagerFactory()).destroy(c.getId()); + return true; + } + + @Override + public Cause getEntity() { + return new CauseJpaController( + getEntityManagerFactory()).findCause(getId()); + } + + @Override + public void update(Cause target, Cause source) { + target.setDescription(source.getDescription()); + target.setName(source.getName()); + if (source.getRiskItemList() != null) { + target.setRiskItemList(source.getRiskItemList()); + } + } + + @Override + public void update() { + update(this, getEntity()); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/spi/email/EmailManager.java b/VM-Core/src/main/java/com/validation/manager/core/spi/email/EmailManager.java new file mode 100644 index 00000000..929b6c93 --- /dev/null +++ b/VM-Core/src/main/java/com/validation/manager/core/spi/email/EmailManager.java @@ -0,0 +1,94 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.spi.email; + +import com.validation.manager.core.api.email.IEmailManager; +import com.validation.manager.core.server.core.VMSettingServer; +import java.util.Date; +import java.util.Properties; +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.PasswordAuthentication; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@ServiceProvider(service = IEmailManager.class) +public class EmailManager implements IEmailManager { + + @Override + public void sendEmail(String to, String cc, String from, + String subject, String bodyText) throws MessagingException { + Properties props = new Properties(); + props.put("mail.smtp.host", + VMSettingServer.getSetting("mail.smtp.host").getStringVal()); + props.put("mail.smtp.auth", VMSettingServer.getSetting("mail.smtp.auth") + .getBoolVal().toString()); + props.put("mail.debug", "true"); + props.put("mail.smtp.starttls.enable", + VMSettingServer.getSetting("mail.smtp.starttls.enable") + .getBoolVal().toString()); + props.put("mail.smtp.port", "" + + VMSettingServer.getSetting("mail.smtp.port").getIntVal()); + props.put("mail.smtp.socketFactory.port", "" + + VMSettingServer.getSetting("mail.smtp.socketFactory.port").getIntVal()); + props.put("mail.smtp.socketFactory.class", + VMSettingServer.getSetting("mail.smtp.socketFactory.class") + .getStringVal()); + props.put("mail.smtp.socketFactory.fallback", + VMSettingServer.getSetting("mail.smtp.socketFactory.fallback") + .getBoolVal().toString()); + Session mailSession; + String username = VMSettingServer.getSetting("mail.auth.username") + .getStringVal(); + String password = VMSettingServer.getSetting("mail.auth.password") + .getStringVal(); + if (username != null) { + mailSession = Session.getInstance(props, new javax.mail.Authenticator() { + + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } else { + mailSession = Session.getInstance(props); + } + mailSession.setDebug(true); // Enable the debug mode + + Message email = new MimeMessage(mailSession); + //--[ Set the FROM, TO, DATE and SUBJECT fields + email.setFrom(new InternetAddress(from)); + email.setRecipients(Message.RecipientType.TO, + InternetAddress.parse(to)); + email.setSentDate(new Date()); + email.setSubject(subject); + if (cc != null && !cc.isEmpty()) { + email.setRecipients(Message.RecipientType.CC, + InternetAddress.parse(cc)); + } + //--[ Create the body of the mail + email.setText(bodyText); + //--[ Ask the Transport class to send our mail message + Transport.send(email); + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/spi/internationalization/DefaultInternationalizationProvider.java b/VM-Core/src/main/java/com/validation/manager/core/spi/internationalization/DefaultInternationalizationProvider.java index 33e3d212..c534969f 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/spi/internationalization/DefaultInternationalizationProvider.java +++ b/VM-Core/src/main/java/com/validation/manager/core/spi/internationalization/DefaultInternationalizationProvider.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,63 +13,66 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.spi.internationalization; - -import com.validation.manager.core.api.internationalization.InternationalizationProvider; -import com.validation.manager.core.api.internationalization.LocaleListener; -import java.io.UnsupportedEncodingException; -import java.util.Locale; -import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.openide.util.Lookup; -import org.openide.util.lookup.ServiceProvider; -import org.openide.util.lookup.ServiceProviders; - -@ServiceProviders({ - @ServiceProvider(service = InternationalizationProvider.class, position = 1) - ,@ServiceProvider(service = LocaleListener.class)}) -public class DefaultInternationalizationProvider - implements InternationalizationProvider { - - private ResourceBundle RB = ResourceBundle.getBundle( - "com.validation.manager.resources.VMMessages", Locale.getDefault()); - private static final Logger LOG - = Logger.getLogger(DefaultInternationalizationProvider.class - .getSimpleName()); - - @Override - public String translate(String mess) { - try { - if (RB.containsKey(mess)) { - return RB.containsKey(mess) ? new String(RB.getString(mess) - .getBytes("ISO-8859-1"), "UTF-8") : mess; - } else { - //Try to search on any other provider - for (InternationalizationProvider i - : Lookup.getDefault() - .lookupAll(InternationalizationProvider.class)) { - if (!(i instanceof DefaultInternationalizationProvider) - && i.getResourceBundle().containsKey(mess)) { - return i.translate(mess); - } - } - } - } - catch (UnsupportedEncodingException ex) { - LOG.log(Level.SEVERE, null, ex); - } - return mess; - } - - @Override - public void setlocale(Locale locale) { - RB = ResourceBundle.getBundle( - "com.validation.manager.resources.VMMessages", locale); - } - - @Override - public ResourceBundle getResourceBundle() { - return RB; - } -} +package com.validation.manager.core.spi.internationalization; + +import com.vaadin.ui.UI; +import com.validation.manager.core.VMUI; +import com.validation.manager.core.api.internationalization.InternationalizationProvider; +import com.validation.manager.core.server.core.VMUserServer; +import java.io.UnsupportedEncodingException; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.openide.util.Lookup; +import org.openide.util.lookup.ServiceProvider; + +@ServiceProvider(service = InternationalizationProvider.class, position = 1) +public class DefaultInternationalizationProvider + implements InternationalizationProvider { + + private static final Logger LOG + = Logger.getLogger(DefaultInternationalizationProvider.class + .getSimpleName()); + + @Override + public String translate(String mess) { + VMUI ui = (VMUI) UI.getCurrent(); + VMUserServer user = ui == null ? null : ui.getUser(); + return translate(mess, user == null ? Locale.getDefault() + : new Locale(user.getLocale())); + } + + @Override + public ResourceBundle getResourceBundle() { + return ResourceBundle.getBundle( + "com.validation.manager.resources.VMMessages"); + } + + @Override + public String translate(String mess, Locale locale) { + try { + ResourceBundle bundle = ResourceBundle.getBundle( + "com.validation.manager.resources.VMMessages", locale); + if (bundle.containsKey(mess)) { + return bundle.containsKey(mess) + ? new String(bundle.getString(mess) + .getBytes("ISO-8859-1"), "UTF-8") : mess; + } else { + //Try to search on any other provider + for (InternationalizationProvider i + : Lookup.getDefault() + .lookupAll(InternationalizationProvider.class)) { + if (!(i instanceof DefaultInternationalizationProvider) + && i.getResourceBundle().containsKey(mess)) { + return i.translate(mess); + } + } + } + } + catch (UnsupportedEncodingException ex) { + LOG.log(Level.SEVERE, null, ex); + } + return mess; + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/tool/MD5.java b/VM-Core/src/main/java/com/validation/manager/core/tool/MD5.java index 9f9b26cb..90f70f0d 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/tool/MD5.java +++ b/VM-Core/src/main/java/com/validation/manager/core/tool/MD5.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,45 +13,47 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.tool; - -import static java.lang.Integer.toHexString; -import java.security.MessageDigest; -import static java.security.MessageDigest.getInstance; -import java.security.NoSuchAlgorithmException; - -/** - * - * @author Javier A. Ortiz - */ -public class MD5 { - - private static String md5val = ""; - private static MessageDigest algorithm = null; - - private MD5() { - } - - public static String encrypt(String text) throws Exception { - try { - algorithm = getInstance("MD5"); - } catch (NoSuchAlgorithmException nsae) { - throw new Exception("Cannot find digest algorithm"); - } - byte[] defaultBytes = text.getBytes(); - algorithm.reset(); - algorithm.update(defaultBytes); - byte messageDigest[] = algorithm.digest(); - StringBuilder hexString = new StringBuilder(); - - for (int i = 0; i < messageDigest.length; i++) { - String hex = toHexString(0xFF & messageDigest[i]); - if (hex.length() == 1) { - hexString.append('0'); - } - hexString.append(hex); - } - md5val = hexString.toString(); - return md5val; - } -} +package com.validation.manager.core.tool; + +import com.validation.manager.core.VMException; +import static java.lang.Integer.toHexString; +import java.security.MessageDigest; +import static java.security.MessageDigest.getInstance; +import java.security.NoSuchAlgorithmException; + +/** + * + * @author Javier A. Ortiz + */ +public class MD5 { + + private static String md5val = ""; + private static MessageDigest algorithm = null; + + private MD5() { + } + + public static String encrypt(String text) throws VMException { + try { + algorithm = getInstance("MD5"); + } + catch (NoSuchAlgorithmException nsae) { + throw new VMException("Cannot find digest algorithm"); + } + byte[] defaultBytes = text.getBytes(); + algorithm.reset(); + algorithm.update(defaultBytes); + byte messageDigest[] = algorithm.digest(); + StringBuilder hexString = new StringBuilder(); + + for (int i = 0; i < messageDigest.length; i++) { + String hex = toHexString(0xFF & messageDigest[i]); + if (hex.length() == 1) { + hexString.append('0'); + } + hexString.append(hex); + } + md5val = hexString.toString(); + return md5val; + } +} diff --git a/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages.properties b/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages.properties index c2536ccf..b30c2289 100755 --- a/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages.properties +++ b/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages.properties @@ -1,12 +1,19 @@ add.attachment=Add Attachment -add.comment=Add comment +add.comment=Add Comment add.details=Add Details +add.user=Add User admin.desc=Administrator admin.tab.name=Administrator assign.test.case=Assign Test Case(s) assign.test.case.execution=Assign Test Case Execution attach.file=Attach File attachment.present=There are attachment present in the execution. +available.roles=Available Roles +current.roles=Current Roles +guest.desc=Guest +none.desc=None +reserved.desc=Reserved +requirement.manager.desc=Requirement Manager #Audit audit.coregroup.change=Core group changed\! audit.corenode.change=Core node changed\! @@ -54,7 +61,6 @@ date.format=Date Format #Delete delete.error=Unable to delete\! -delete.error\!=Unable to delete\! delete.execution=Delete Execution delete.with.issues.message=There are attachment(s), issue(s) and/or comment(s) present in the execution. delete.with.issues.title=Want to delete even with identified issues? @@ -103,15 +109,26 @@ general.assignment.date=Assignment Date general.attachment=Attachments general.audit.menu=Audit Trail Menu general.cancel=Cancel -general.comclusion=Conclusion +general.conclusion=Conclusion +general.configuration=Configuration general.comment=Comment general.comments=Comments general.conclusion=Conclusion general.create=Create general.creation.date=Created on +general.delete=Delete general.description=Description general.edit=Edit general.email=Email +general.email.enable=Email Enabled +general.email.from=From +general.email.to=To +general.email.send=Send +general.email.subject=Subject +general.email.message=Message +general.email.settings=Email Settings +general.email.settings.test=Test Email Settings +general.email.settings.test.success=Success! general.error.record.creation=Error creating record\! general.error.record.update=Error updating record\! general.execute=Execute @@ -141,6 +158,7 @@ general.notification=Notification general.notifications=Notifications general.obsolete=Obsolete general.open=Open +general.output=Output general.parent=Parent general.password=Password general.project=Project @@ -192,6 +210,7 @@ issue.invalid=Invalid issue.not.reproduceable=Not Reproducible issue.present=There are issues present in the execution. issue.type=Issue Type +issue.resolution=Issue Resolution leader.desc=Lead Tester linked.requirement=Linked Requirements lock.test.case.message=Locked test cases are committed and can no longer be modified.\\nIt would be equivalent to documenting in paper. @@ -245,7 +264,7 @@ message.requirement.import.missing.column=Not enough columns in data source (%c) message.requirement.import.success=Requirement import completed\! message.requirement.import.verify=Please review the requirements to be imported. message.requirement.status=Status -message.requirement.type=Requirement Type +requirement.type=Requirement Type message.section.dnd.invalid=Invalid to move section to this location\! message.spec.level=Specification Level message.step.create=Create Step @@ -277,6 +296,7 @@ notification.type=Notification Type notification.author=Author notification.mark.unread=Mark as Unread notification.archive=Archive Notification +notification.new=You received a new notification! modification.date=Modification Date observation.desc=Observation to be evaluated diff --git a/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages_es.properties b/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages_es.properties index 93b02cfc..f0feab70 100755 --- a/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages_es.properties +++ b/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages_es.properties @@ -68,7 +68,6 @@ message.requirement.import.invalid.product = Producto inválido provisto. message.requirement.import.file.null = Archivo para importar es nulo message.requirement.import.file.invalid = Archivo para importar no existe message.requirement.import.verify = Por favor revise los requicitos a importar. -message.requirement.type = Tipo de Requicito message.requirement.import.success = Importe de requicitos completado\! message.requirement.dnd.invalid = Mover requicitos a este lugar es inválido\! message.requirement.status = Estado @@ -183,6 +182,7 @@ issue.invalid = Inválido # Baseline baseline.creation = Creación de Línea de Base add.attachment = Añadir Archivo +# Fuzzy add.comment = Añadir comentario add.details = Añadir Detalles assign.test.case = Asignar Prueba(s) @@ -212,7 +212,6 @@ create.test.suite = Crear Grupo de Pruebas creation.time = Fecha de Creación # Delete delete.error = Fue imposible de eliminar\! -delete.error\! = \nFue imposible de eliminar\! delete.execution = Eliminar Ejecución delete.with.issues.message = Hay archivo(s), reporte(s) de problema y/o comentario(s) presentes en la ejecución. delete.with.issues.title = Quiere eliminar aún con los problemas identificados? @@ -246,7 +245,6 @@ general.active = Activo general.amount = Cantidad general.assignee = Usuario Asignado general.attachment = Archivos -general.comclusion = Conclusión general.comment = Comentario general.comments = Comentarios general.conclusion = Conclusión @@ -371,4 +369,26 @@ notification.mark.unread = Marcar como no leído notification.archive = Archivar Notificación general.archived = Archivado general.no = No -general.yes = Si \ No newline at end of file +general.yes = Si +general.email.enable = Correo Electrónico Activado +general.email.from = De +general.email.to = Hacia +general.email.send = Enviar +general.email.subject = Título +general.email.message = Mensaje +general.email.settings = Configuración de Correo Electrónico +general.email.settings.test = Probar Configuraciones de Correo Electrónico +general.email.settings.test.success = Exito +general.output = Salida +notification.new = Has recibido una nueva notificación\! +add.user = Añadir usuario +available.roles = Roles Disponibles +current.roles = Roles Actuales +guest.desc = Invitado +none.desc = Ninguno +reserved.desc = Reservado +requirement.manager.desc = Manejador de Requicitos +general.configuration = Configuración +general.delete = Eliminar +issue.resolution = Resolución del Problema +requirement.type = Tipo de Requicito \ No newline at end of file diff --git a/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages_fr_FR.properties b/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages_fr_FR.properties index ba21db36..c5e7e80c 100755 --- a/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages_fr_FR.properties +++ b/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages_fr_FR.properties @@ -52,7 +52,6 @@ creation.time=Creation Time #Delete delete.error=Unable to delete\! -delete.error\!=Unable to delete\! delete.execution=Delete Execution delete.with.issues.message=There are attachment(s), issue(s) and/or comment(s) present in the execution. delete.with.issues.title=Want to delete even with identified issues? @@ -100,7 +99,7 @@ general.assignment.date=Assignment Date general.attachment=Attachments general.audit.menu=Audit Trail Menu general.cancel=Cancel -general.comclusion=Conclusion +general.conclusion=Conclusion general.comment=Comment general.comments=Comments general.conclusion=Conclusion @@ -233,7 +232,7 @@ message.requirement.import.missing.column=Not enough columns in data source (%c) message.requirement.import.success=Requirement import completed\! message.requirement.import.verify=Please review the requirements to be imported. message.requirement.status=Status -message.requirement.type=Requirement Type +requirement.type=Requirement Type message.section.dnd.invalid=Invalid to move section to this location\! message.spec.level=Specification Level message.step.create=Create Step diff --git a/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages_zh_CN.properties b/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages_zh_CN.properties index ba21db36..c5e7e80c 100755 --- a/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages_zh_CN.properties +++ b/VM-Core/src/main/resources/com/validation/manager/resources/VMMessages_zh_CN.properties @@ -52,7 +52,6 @@ creation.time=Creation Time #Delete delete.error=Unable to delete\! -delete.error\!=Unable to delete\! delete.execution=Delete Execution delete.with.issues.message=There are attachment(s), issue(s) and/or comment(s) present in the execution. delete.with.issues.title=Want to delete even with identified issues? @@ -100,7 +99,7 @@ general.assignment.date=Assignment Date general.attachment=Attachments general.audit.menu=Audit Trail Menu general.cancel=Cancel -general.comclusion=Conclusion +general.conclusion=Conclusion general.comment=Comment general.comments=Comments general.conclusion=Conclusion @@ -233,7 +232,7 @@ message.requirement.import.missing.column=Not enough columns in data source (%c) message.requirement.import.success=Requirement import completed\! message.requirement.import.verify=Please review the requirements to be imported. message.requirement.status=Status -message.requirement.type=Requirement Type +requirement.type=Requirement Type message.section.dnd.invalid=Invalid to move section to this location\! message.spec.level=Specification Level message.step.create=Create Step diff --git a/VM-Core/src/main/resources/db/migration/V1_4__New_Setings.sql b/VM-Core/src/main/resources/db/migration/V1_4__New_Setings.sql new file mode 100644 index 00000000..1765c2fb --- /dev/null +++ b/VM-Core/src/main/resources/db/migration/V1_4__New_Setings.sql @@ -0,0 +1,14 @@ +/*Add settings*/ +INSERT INTO `vm_setting` (`id`, `setting`, `bool_val`, `int_val`, `long_val`, `string_val`) VALUES (13, 'mail.smtp.host', 0, 0, '0', 'smtp.gmail.com'); +INSERT INTO `vm_setting` (`id`, `setting`, `bool_val`, `int_val`, `long_val`, `string_val`) VALUES (14, 'mail.smtp.socketFactory.class', 0, 0, '0', 'javax.net.ssl.SSLSocketFactory'); +INSERT INTO `vm_setting` (`id`, `setting`, `bool_val`, `int_val`, `long_val`, `string_val`) VALUES (15, 'mail.smtp.socketFactory.fallback', 0, 0, '0', NULL);/*False*/ +INSERT INTO `vm_setting` (`id`, `setting`, `bool_val`, `int_val`, `long_val`, `string_val`) VALUES (16, 'mail.smtp.port', 0, 465, '0', NULL);/*Gmail as default*/ +INSERT INTO `vm_setting` (`id`, `setting`, `bool_val`, `int_val`, `long_val`, `string_val`) VALUES (17, 'mail.smtp.socketFactory.port', 0, 465, '0', NULL); +INSERT INTO `vm_setting` (`id`, `setting`, `bool_val`, `int_val`, `long_val`, `string_val`) VALUES (18, 'mail.smtp.auth', 1, 0, '0', NULL); +INSERT INTO `vm_setting` (`id`, `setting`, `bool_val`, `int_val`, `long_val`, `string_val`) VALUES (19, 'mail.smtp.quitwait', 0, 0, '0', NULL);/*False*/ +INSERT INTO `vm_setting` (`id`, `setting`, `bool_val`, `int_val`, `long_val`, `string_val`) VALUES (20, 'mail.smtp.starttls.enable', 1, 0, '0', NULL); +INSERT INTO `vm_setting` (`id`, `setting`, `bool_val`, `int_val`, `long_val`, `string_val`) VALUES (21, 'mail.auth.username', 1, 0, '0', NULL); +INSERT INTO `vm_setting` (`id`, `setting`, `bool_val`, `int_val`, `long_val`, `string_val`) VALUES (22, 'mail.auth.password', 1, 0, '0', NULL); +INSERT INTO `vm_setting` (`id`, `setting`, `bool_val`, `int_val`, `long_val`, `string_val`) VALUES (23, 'mail.enable', 0, 0, '0', NULL); +/*Fix typos*/ +UPDATE `role` set description = 'reserved.desc' where id in (1,2); \ No newline at end of file diff --git a/VM-Core/src/test/java/com/validation/manager/core/api/email/IEmailManagerTest.java b/VM-Core/src/test/java/com/validation/manager/core/api/email/IEmailManagerTest.java new file mode 100644 index 00000000..3a47fd54 --- /dev/null +++ b/VM-Core/src/test/java/com/validation/manager/core/api/email/IEmailManagerTest.java @@ -0,0 +1,79 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.api.email; + +import com.validation.manager.test.AbstractVMTestCase; +import de.saly.javamail.mock2.MockMailbox; +import java.util.Arrays; +import javax.mail.Message; +import org.junit.Test; +import org.openide.util.Lookup; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class IEmailManagerTest extends AbstractVMTestCase { + + /** + * Test of sendEmail method, of class IEmailManager. + * + * @throws java.lang.Exception + */ + @Test + public void testSendEmail() throws Exception { + System.out.println("sendEmail"); + String to = "target@test.com"; + String cc = "cc@test.com"; + String from = "from@test.com"; + String subject = "Sample Email"; + String bodyText = "Hello World!"; + //Setup mock email server + MockMailbox toMailbox = MockMailbox.get(to); + MockMailbox ccMailbox = MockMailbox.get(cc); + MockMailbox fromMailbox = MockMailbox.get(from); + assertEquals(0, toMailbox.getInbox().getMessageCount()); + assertEquals(0, ccMailbox.getInbox().getMessageCount()); + assertEquals(0, fromMailbox.getInbox().getMessageCount()); + IEmailManager instance = Lookup.getDefault().lookup(IEmailManager.class); + instance.sendEmail(to, cc, from, subject, bodyText); + assertEquals(1, toMailbox.getInbox().getMessageCount()); + for (Message m : toMailbox.getInbox().getMessages()) { + System.out.println(m.getMessageNumber()); + System.out.println("From: " + Arrays.toString(m.getFrom())); + assertEquals(1, m.getFrom().length); + assertEquals(from, m.getFrom()[0].toString()); + System.out.println("Sent: " + m.getSentDate()); + System.out.println(m.getSubject()); + assertEquals(subject, m.getSubject()); + System.out.println(m.getContent()); + assertEquals(bodyText, m.getContent()); + } + assertEquals(1, ccMailbox.getInbox().getMessageCount()); + for (Message m : ccMailbox.getInbox().getMessages()) { + System.out.println(m.getMessageNumber()); + System.out.println("From: " + Arrays.toString(m.getFrom())); + assertEquals(1, m.getFrom().length); + assertEquals(from, m.getFrom()[0].toString()); + System.out.println("Sent: " + m.getSentDate()); + System.out.println(m.getSubject()); + assertEquals(subject, m.getSubject()); + System.out.println(m.getContent()); + assertEquals(bodyText, m.getContent()); + } + assertEquals(0, fromMailbox.getInbox().getMessageCount()); + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/api/internationalization/InternationalizationProviderTest.java b/VM-Core/src/test/java/com/validation/manager/core/api/internationalization/InternationalizationProviderTest.java new file mode 100644 index 00000000..4f9e90bf --- /dev/null +++ b/VM-Core/src/test/java/com/validation/manager/core/api/internationalization/InternationalizationProviderTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.api.internationalization; + +import java.util.Locale; +import static junit.framework.TestCase.*; +import org.junit.Test; +import org.openide.util.Lookup; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class InternationalizationProviderTest { + + /** + * Test of translate method, of class InternationalizationProvider. + */ + @Test + public void testTranslate_String() { + System.out.println("translate"); + String mess = "general.active"; + InternationalizationProvider instance + = Lookup.getDefault().lookup(InternationalizationProvider.class); + assertNotNull(instance.translate(mess)); + } + + /** + * Test of translate method, of class InternationalizationProvider. + */ + @Test + public void testTranslate_String_Locale() { + System.out.println("translate"); + String mess = "general.active"; + Locale l = new Locale("es"); + InternationalizationProvider instance + = Lookup.getDefault().lookup(InternationalizationProvider.class); + assertNotNull(instance.translate(mess, l)); + assertNotSame(instance.translate(mess), instance.translate(mess, l)); + } + + /** + * Test of getResourceBundle method, of class InternationalizationProvider. + */ + @Test + public void testGetResourceBundle() { + System.out.println("getResourceBundle"); + InternationalizationProvider instance + = Lookup.getDefault().lookup(InternationalizationProvider.class); + assertNotNull(instance.getResourceBundle()); + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/db/ProjectTest.java b/VM-Core/src/test/java/com/validation/manager/core/db/ProjectTest.java index 45820285..52caed5a 100755 --- a/VM-Core/src/test/java/com/validation/manager/core/db/ProjectTest.java +++ b/VM-Core/src/test/java/com/validation/manager/core/db/ProjectTest.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,119 +13,110 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.VMException; -import com.validation.manager.core.db.controller.ProjectJpaController; -import com.validation.manager.core.server.core.ProjectServer; -import static com.validation.manager.core.server.core.ProjectServer.deleteProject; -import com.validation.manager.core.server.core.StepServer; -import com.validation.manager.core.server.core.TestCaseServer; -import com.validation.manager.core.tool.Tool; -import com.validation.manager.test.AbstractVMTestCase; -import static com.validation.manager.test.TestHelper.addRequirementToStep; -import static com.validation.manager.test.TestHelper.addStep; -import static com.validation.manager.test.TestHelper.addTestCaseToPlan; -import static com.validation.manager.test.TestHelper.createProject; -import static com.validation.manager.test.TestHelper.createRequirement; -import static com.validation.manager.test.TestHelper.createRequirementSpec; -import static com.validation.manager.test.TestHelper.createRequirementSpecNode; -import static com.validation.manager.test.TestHelper.createTestCase; -import static com.validation.manager.test.TestHelper.createTestPlan; -import static com.validation.manager.test.TestHelper.createTestProject; -import java.text.MessageFormat; -import java.util.logging.Level; -import java.util.logging.Logger; -import static java.util.logging.Logger.getLogger; -import static junit.framework.TestCase.assertEquals; -import org.junit.After; -import org.junit.Test; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class ProjectTest extends AbstractVMTestCase { - - private Project p; - private static final Logger LOG - = getLogger(ProjectTest.class.getName()); - - @After - public void clear() { - if (p != null) { - try { - deleteProject(p); - } - catch (VMException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - } - - /** - * Test of toString method, of class Project. - */ - @Test - public void testCreateAndDestroy() { - try { - p = createProject("New Project", "Notes"); - assertEquals(0, Tool.extractRequirements(p).size()); - ProjectServer project = new ProjectServer(p); - project.setNotes("Notes 2"); - project.write2DB(); - Project temp = new ProjectJpaController( - getEntityManagerFactory()) - .findProject(project.getId()); - assertTrue(temp.getNotes().equals(project.getNotes())); - //Create requirements - LOG.info("Create Requirement Spec"); - RequirementSpec rss = null; - try { - rss = createRequirementSpec("Test", "Test", - project, 1); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - LOG.info("Create Requirement Spec Node"); - RequirementSpecNode rsns = null; - try { - rsns = createRequirementSpecNode( - rss, "Test", "Test", "Test"); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - Requirement r = createRequirement("SRS-SW-0001", - "Sample requirement", rsns.getRequirementSpecNodePK(), - "Notes", 1, 1); - //Create Test Case - TestCase tc = createTestCase("Dummy", "Summary"); - //Add steps - for (int i = 1; i < 6; i++) { - LOG.info(MessageFormat.format("Adding step: {0}", i)); - tc = addStep(tc, i, "Step " + i, "Note " + i, "Result " + i); - Step step = tc.getStepList().get(i - 1); - addRequirementToStep(step, r); - new TestCaseServer(tc).write2DB(); - assertEquals(1, new StepServer(step).getRequirementList().size()); - } - //Create test Project - TestProject tp = createTestProject("Test Project"); - //Create test plan - TestPlan plan = createTestPlan(tp, "Notes", true, true); - //Add test to plan - addTestCaseToPlan(plan, tc); - project.write2DB(); - assertEquals(1, Tool.extractRequirements(project.getEntity()).size()); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - } -} +package com.validation.manager.core.db; + +import com.validation.manager.core.DataBaseManager; +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.db.controller.ProjectJpaController; +import com.validation.manager.core.db.controller.TestPlanJpaController; +import com.validation.manager.core.server.core.ProjectServer; +import com.validation.manager.core.server.core.StepServer; +import com.validation.manager.core.server.core.TestCaseServer; +import com.validation.manager.core.server.core.TestPlanServer; +import com.validation.manager.core.tool.Tool; +import com.validation.manager.test.AbstractVMTestCase; +import static com.validation.manager.test.TestHelper.addRequirementToStep; +import static com.validation.manager.test.TestHelper.addStep; +import static com.validation.manager.test.TestHelper.addTestCaseToPlan; +import static com.validation.manager.test.TestHelper.createProject; +import static com.validation.manager.test.TestHelper.createRequirement; +import static com.validation.manager.test.TestHelper.createRequirementSpec; +import static com.validation.manager.test.TestHelper.createRequirementSpecNode; +import static com.validation.manager.test.TestHelper.createTestCase; +import static com.validation.manager.test.TestHelper.createTestPlan; +import static com.validation.manager.test.TestHelper.createTestProject; +import java.text.MessageFormat; +import java.util.logging.Level; +import java.util.logging.Logger; +import static java.util.logging.Logger.getLogger; +import static junit.framework.TestCase.assertEquals; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ProjectTest extends AbstractVMTestCase { + + private Project p; + private static final Logger LOG + = getLogger(ProjectTest.class.getName()); + + /** + * Test of toString method, of class Project. + */ + @Test + public void testCreateAndDestroy() { + try { + p = createProject("New Project", "Notes"); + assertEquals(0, Tool.extractRequirements(p).size()); + ProjectServer project = new ProjectServer(p); + project.setNotes("Notes 2"); + project.write2DB(); + Project temp = new ProjectJpaController( + getEntityManagerFactory()) + .findProject(project.getId()); + assertTrue(temp.getNotes().equals(project.getNotes())); + //Create requirements + LOG.info("Create Requirement Spec"); + RequirementSpec rss = null; + try { + rss = createRequirementSpec("Test", "Test", + project, 1); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + LOG.info("Create Requirement Spec Node"); + RequirementSpecNode rsns; + try { + rsns = createRequirementSpecNode( + rss, "Test", "Test", "Test"); + Requirement r = createRequirement("SRS-SW-0001", + "Sample requirement", rsns.getRequirementSpecNodePK(), + "Notes", 1, 1); + //Create Test Case + TestCase tc = createTestCase("Dummy", "Summary"); + //Add steps + for (int i = 1; i < 6; i++) { + LOG.info(MessageFormat.format("Adding step: {0}", i)); + tc = addStep(tc, i, "Step " + i, "Note " + i, "Result " + i); + Step step = tc.getStepList().get(i - 1); + addRequirementToStep(step, r); + new TestCaseServer(tc).write2DB(); + assertEquals(1, new StepServer(step).getRequirementList().size()); + } + //Create test Project + TestProject tp = createTestProject("Test Project"); + //Create test plan + TestPlan plan = createTestPlan(tp, "Notes", true, true); + //Add test to plan + addTestCaseToPlan(plan, tc); + project.write2DB(); + assertEquals(1, Tool.extractRequirements(project.getEntity()).size()); + TestPlanServer.deleteTestPlan(plan); + assertNull(new TestPlanJpaController(DataBaseManager + .getEntityManagerFactory()).findTestPlan(plan.getTestPlanPK())); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/db/RequirementHierarchyTest.java b/VM-Core/src/test/java/com/validation/manager/core/db/RequirementHierarchyTest.java index a65b802d..3e6f1ac0 100755 --- a/VM-Core/src/test/java/com/validation/manager/core/db/RequirementHierarchyTest.java +++ b/VM-Core/src/test/java/com/validation/manager/core/db/RequirementHierarchyTest.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,175 +13,180 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.db.controller.RequirementJpaController; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.server.core.ProjectServer; -import com.validation.manager.core.server.core.RequirementServer; -import com.validation.manager.core.server.core.RequirementSpecNodeServer; -import com.validation.manager.core.server.core.RequirementSpecServer; -import com.validation.manager.core.server.core.SpecLevelServer; -import com.validation.manager.test.AbstractVMTestCase; -import com.validation.manager.test.TestHelper; -import static com.validation.manager.test.TestHelper.createRequirement; -import static com.validation.manager.test.TestHelper.createRequirementSpecNode; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import static java.util.logging.Logger.getLogger; -import org.junit.Test; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RequirementHierarchyTest extends AbstractVMTestCase { - - private static final Logger LOG - = getLogger(RequirementHierarchyTest.class.getName()); - private ProjectServer project; - - @Test - public void testHierarchy() { - System.out.println("Test Requirement Hierarchy"); - System.out.println("Create Project"); - project = new ProjectServer("Test product", "Project Notes"); - try { - project.write2DB(); - } catch (IllegalOrphanException ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } catch (NonexistentEntityException ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - System.out.println("Create Requirement Spec"); - RequirementSpec rss = null; - try { - rss = TestHelper.createRequirementSpec("Test", "Test", - project, 1); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - System.out.println("Create Requirement Spec Node"); - RequirementSpecNode rsns = null; - try { - rsns = createRequirementSpecNode( - rss, "Test", "Test", "Test"); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - System.out.println("Create Requirements"); - List requirements = new ArrayList<>(); - int requirementAmount = 15; - for (int i = 0; i < requirementAmount; i++) { - try { - Requirement reqs - = createRequirement("SRS-SW-00" + i, - "Description " + i, - rsns.getRequirementSpecNodePK(), - "Notes " + i, 2, 1); - requirements.add(new RequirementJpaController( - getEntityManagerFactory()) - .findRequirement(reqs.getId())); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - } - System.out.println("Done!"); - System.out.println("Create Requirement Spec Levels"); - SpecLevelServer userSpecLevel = createSpecLevel("User Requirement"); - SpecLevelServer functionalSpecLevel - = createSpecLevel("Functional Requirement"); - SpecLevelServer unitSpecLevel = createSpecLevel("Unit Requirement"); - System.out.println("Done!"); - System.out.println("Create Requirement Specs"); - RequirementSpecServer productSpec = createRequirementSpec( - "Project Spec", userSpecLevel); - RequirementSpecServer archSpec = createRequirementSpec( - "Architectural Spec", functionalSpecLevel); - RequirementSpecServer swSpec = createRequirementSpec( - "Software Spec", unitSpecLevel); - System.out.println("Done!"); - System.out.println("Adding requirements to spec nodes"); - try { - RequirementSpecNodeServer n1 - = productSpec.addSpecNode("Node 1", "description", "scope"); - requirements.subList(0, 5).forEach((r) -> { - n1.getRequirementList().add(r); - }); - n1.write2DB(); - assertEquals(1, productSpec.getRequirementSpecNodeList().size()); - RequirementSpecNodeServer n2 - = archSpec.addSpecNode("Node 2", "description", "scope"); - requirements.subList(5, 10).forEach((r) -> { - n2.getRequirementList().add(r); - }); - n2.write2DB(); - assertEquals(1, archSpec.getRequirementSpecNodeList().size()); - RequirementSpecNodeServer n3 - = swSpec.addSpecNode("Node 3", "description", "scope"); - requirements.subList(10, 15).forEach((r) -> { - n3.getRequirementList().add(r); - }); - n3.write2DB(); - assertEquals(1, swSpec.getRequirementSpecNodeList().size()); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - System.out.println("Done!"); - System.out.println("Adding requirements to requirements"); - int count = 0; - for (Requirement req : requirements) { - try { - req.getRequirementList().add(requirements.get(requirementAmount - count - 1)); - new RequirementServer(req).write2DB(); - count++; - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - } - System.out.println("Done!"); - } - - private SpecLevelServer createSpecLevel(String name) { - SpecLevelServer sl = new SpecLevelServer(name, name + " Level"); - try { - assertTrue(sl.write2DB() > 0); - } catch (IllegalOrphanException ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } catch (NonexistentEntityException ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - return sl; - } - - private RequirementSpecServer createRequirementSpec(String name, SpecLevelServer sl) { - RequirementSpecServer rss = new RequirementSpecServer(name, - "description", project.getId(), sl.getId()); - try { - rss.write2DB(); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - return rss; - } -} +package com.validation.manager.core.db; + +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.controller.RequirementJpaController; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.server.core.ProjectServer; +import com.validation.manager.core.server.core.RequirementServer; +import com.validation.manager.core.server.core.RequirementSpecNodeServer; +import com.validation.manager.core.server.core.RequirementSpecServer; +import com.validation.manager.core.server.core.SpecLevelServer; +import com.validation.manager.test.AbstractVMTestCase; +import com.validation.manager.test.TestHelper; +import static com.validation.manager.test.TestHelper.createRequirement; +import static com.validation.manager.test.TestHelper.createRequirementSpecNode; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import static java.util.logging.Logger.getLogger; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RequirementHierarchyTest extends AbstractVMTestCase { + + private static final Logger LOG + = getLogger(RequirementHierarchyTest.class.getName()); + private ProjectServer project; + + @Test + public void testHierarchy() { + System.out.println("Test Requirement Hierarchy"); + System.out.println("Create Project"); + project = new ProjectServer("Test product", "Project Notes"); + try { + project.write2DB(); + } + catch (VMException ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + System.out.println("Create Requirement Spec"); + RequirementSpec rss = null; + try { + rss = TestHelper.createRequirementSpec("Test", "Test", + project, 1); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + System.out.println("Create Requirement Spec Node"); + RequirementSpecNode rsns = null; + try { + rsns = createRequirementSpecNode( + rss, "Test", "Test", "Test"); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + System.out.println("Create Requirements"); + List requirements = new ArrayList<>(); + int requirementAmount = 15; + for (int i = 0; i < requirementAmount; i++) { + try { + Requirement reqs + = createRequirement("SRS-SW-00" + i, + "Description " + i, + rsns.getRequirementSpecNodePK(), + "Notes " + i, 2, 1); + requirements.add(new RequirementJpaController( + getEntityManagerFactory()) + .findRequirement(reqs.getId())); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } + System.out.println("Done!"); + System.out.println("Create Requirement Spec Levels"); + SpecLevelServer userSpecLevel = createSpecLevel("User Requirement"); + SpecLevelServer functionalSpecLevel + = createSpecLevel("Functional Requirement"); + SpecLevelServer unitSpecLevel = createSpecLevel("Unit Requirement"); + System.out.println("Done!"); + System.out.println("Create Requirement Specs"); + RequirementSpecServer productSpec = createRequirementSpec( + "Project Spec", userSpecLevel); + RequirementSpecServer archSpec = createRequirementSpec( + "Architectural Spec", functionalSpecLevel); + RequirementSpecServer swSpec = createRequirementSpec( + "Software Spec", unitSpecLevel); + System.out.println("Done!"); + System.out.println("Adding requirements to spec nodes"); + try { + RequirementSpecNodeServer n1 + = productSpec.addSpecNode("Node 1", "description", "scope"); + requirements.subList(0, 5).forEach((r) -> { + n1.getRequirementList().add(r); + }); + n1.write2DB(); + assertEquals(1, productSpec.getRequirementSpecNodeList().size()); + RequirementSpecNodeServer n2 + = archSpec.addSpecNode("Node 2", "description", "scope"); + requirements.subList(5, 10).forEach((r) -> { + n2.getRequirementList().add(r); + }); + n2.write2DB(); + assertEquals(1, archSpec.getRequirementSpecNodeList().size()); + RequirementSpecNodeServer n3 + = swSpec.addSpecNode("Node 3", "description", "scope"); + requirements.subList(10, 15).forEach((r) -> { + n3.getRequirementList().add(r); + }); + n3.write2DB(); + assertEquals(1, swSpec.getRequirementSpecNodeList().size()); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + System.out.println("Done!"); + System.out.println("Adding requirements to requirements"); + int count = 0; + for (Requirement req : requirements) { + try { + req.getRequirementList().add(requirements.get(requirementAmount - count - 1)); + new RequirementServer(req).write2DB(); + count++; + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } + System.out.println("Done!"); + } + + private SpecLevelServer createSpecLevel(String name) { + SpecLevelServer sl = new SpecLevelServer(name, name + " Level"); + try { + assertTrue(sl.write2DB() > 0); + } + catch (IllegalOrphanException ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + catch (NonexistentEntityException ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + return sl; + } + + private RequirementSpecServer createRequirementSpec(String name, SpecLevelServer sl) { + RequirementSpecServer rss = new RequirementSpecServer(name, + "description", project.getId(), sl.getId()); + try { + rss.write2DB(); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + return rss; + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/db/UserTest.java b/VM-Core/src/test/java/com/validation/manager/core/db/UserTest.java index c90d9e84..f70f626c 100755 --- a/VM-Core/src/test/java/com/validation/manager/core/db/UserTest.java +++ b/VM-Core/src/test/java/com/validation/manager/core/db/UserTest.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,57 +13,56 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.db; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import static com.validation.manager.core.DataBaseManager.namedQuery; -import com.validation.manager.core.db.controller.UserStatusJpaController; -import com.validation.manager.core.db.controller.VmUserJpaController; -import static com.validation.manager.core.tool.MD5.encrypt; -import com.validation.manager.test.AbstractVMTestCase; -import java.util.Date; -import java.util.logging.Level; -import static java.util.logging.Logger.getLogger; -import org.junit.Test; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class UserTest extends AbstractVMTestCase { - - @Test - @SuppressWarnings({"unchecked"}) - public void testCreateAndDeleteUser() { - try { - getLogger(UserTest.class.getSimpleName()).log(Level.INFO, - "Available users: {0}", - new VmUserJpaController(getEntityManagerFactory()) - .getVmUserCount()); - getLogger(UserTest.class.getSimpleName()).log(Level.INFO, - "Create an user"); - VmUser u = new VmUser("test", - encrypt("password"), "test@test.com", - "first", "last", "en", new Date(), - new UserStatusJpaController(getEntityManagerFactory()) - .findUserStatus(1), 0); - u.setUserStatusId(new UserStatusJpaController( - getEntityManagerFactory()).findUserStatus(1)); - new VmUserJpaController(getEntityManagerFactory()).create(u); - parameters.clear(); - parameters.put("username", "test"); - result = namedQuery("VmUser.findByUsername", parameters); - assertTrue(result.size() > 0); - u = (VmUser) result.get(0); - getLogger(UserTest.class.getSimpleName()).log(Level.INFO, - "Delete an user"); - new VmUserJpaController(getEntityManagerFactory()) - .destroy(u.getId()); - result = namedQuery("VmUser.findByUsername", parameters); - assertTrue(result.isEmpty()); - } - catch (Exception e) { - fail(e.getMessage()); - } - } -} +package com.validation.manager.core.db; + +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import static com.validation.manager.core.DataBaseManager.namedQuery; +import com.validation.manager.core.db.controller.UserStatusJpaController; +import com.validation.manager.core.db.controller.VmUserJpaController; +import static com.validation.manager.core.tool.MD5.encrypt; +import com.validation.manager.test.AbstractVMTestCase; +import java.util.logging.Level; +import static java.util.logging.Logger.getLogger; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class UserTest extends AbstractVMTestCase { + + @Test + @SuppressWarnings({"unchecked"}) + public void testCreateAndDeleteUser() { + try { + getLogger(UserTest.class.getSimpleName()).log(Level.INFO, + "Available users: {0}", + new VmUserJpaController(getEntityManagerFactory()) + .getVmUserCount()); + getLogger(UserTest.class.getSimpleName()).log(Level.INFO, + "Create an user"); + VmUser u = new VmUser("test", + encrypt("password"), "test@test.com", + "first", "last", "en", + new UserStatusJpaController(getEntityManagerFactory()) + .findUserStatus(1), 0); + u.setUserStatusId(new UserStatusJpaController( + getEntityManagerFactory()).findUserStatus(1)); + new VmUserJpaController(getEntityManagerFactory()).create(u); + parameters.clear(); + parameters.put("username", "test"); + result = namedQuery("VmUser.findByUsername", parameters); + assertTrue(result.size() > 0); + u = (VmUser) result.get(0); + getLogger(UserTest.class.getSimpleName()).log(Level.INFO, + "Delete an user"); + new VmUserJpaController(getEntityManagerFactory()) + .destroy(u.getId()); + result = namedQuery("VmUser.findByUsername", parameters); + assertTrue(result.isEmpty()); + } + catch (Exception e) { + fail(e.getMessage()); + } + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/history/VersionableTest.java b/VM-Core/src/test/java/com/validation/manager/core/history/VersionableTest.java new file mode 100644 index 00000000..bd07119c --- /dev/null +++ b/VM-Core/src/test/java/com/validation/manager/core/history/VersionableTest.java @@ -0,0 +1,289 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.history; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.DemoBuilder; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.controller.HistoryJpaController; +import com.validation.manager.test.AbstractVMTestCase; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.metamodel.EntityType; +import static junit.framework.TestCase.assertEquals; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.junit.Test; +import org.openide.util.Exceptions; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class VersionableTest extends AbstractVMTestCase { + + /** + * Test of increaseMajorVersion method, of class Versionable. + */ + @Test + public void testIncreaseMajorVersion() { + System.out.println("increaseMajorVersion"); + Versionable instance = new VersionableImpl(); + assertEquals(0, (int) instance.getMajorVersion()); + assertEquals(0, (int) instance.getMidVersion()); + assertEquals(1, (int) instance.getMinorVersion()); + instance.increaseMajorVersion(); + assertEquals(1, (int) instance.getMajorVersion()); + assertEquals(0, (int) instance.getMidVersion()); + assertEquals(0, (int) instance.getMinorVersion()); + assertEquals(2, instance.getHistoryList().size()); + checkHistory(instance); + } + + /** + * Test of increaseMidVersion method, of class Versionable. + */ + @Test + public void testIncreaseMidVersion() { + System.out.println("increaseMidVersion"); + Versionable instance = new VersionableImpl(); + assertEquals(0, (int) instance.getMajorVersion()); + assertEquals(0, (int) instance.getMidVersion()); + assertEquals(1, (int) instance.getMinorVersion()); + instance.increaseMidVersion(); + assertEquals(0, (int) instance.getMajorVersion()); + assertEquals(1, (int) instance.getMidVersion()); + assertEquals(0, (int) instance.getMinorVersion()); + assertEquals(2, instance.getHistoryList().size()); + checkHistory(instance); + } + + /** + * Test of toString method, of class Versionable. + */ + @Test + public void testToString() { + System.out.println("toString"); + Versionable instance = new VersionableImpl(); + String r = instance.toString(); + assertEquals("Version: " + instance.getMajorVersion() + + "." + instance.getMidVersion() + "." + + instance.getMinorVersion(), instance.toString()); + instance.increaseMajorVersion(); + assertEquals("Version: " + instance.getMajorVersion() + + "." + instance.getMidVersion() + "." + + instance.getMinorVersion(), instance.toString()); + instance.increaseMidVersion(); + assertEquals("Version: " + instance.getMajorVersion() + + "." + instance.getMidVersion() + "." + + instance.getMinorVersion(), instance.toString()); + } + + /** + * Test of compareTo method, of class Versionable. + */ + @Test + public void testCompareTo() { + System.out.println("compareTo"); + Versionable instance = new VersionableImpl(); + assertEquals(0, instance.compareTo(new VersionableImpl())); + instance.increaseMidVersion(); + assertEquals(1, instance.compareTo(new VersionableImpl())); + Versionable instance2 = new VersionableImpl(); + instance2.increaseMajorVersion(); + assertEquals(-1, instance.compareTo(instance2)); + } + + /** + * Test of auditable method, of class Versionable. + */ + @Test + public void testAuditable() { + try { + System.out.println("auditable"); + VersionableImpl v = new VersionableImpl(); + assertEquals(true, Versionable.auditable(v)); + v.updateHistory(); + assertEquals(1, v.getHistoryList().size()); + assertEquals(false, Versionable.auditable(v)); + v.setField1(2); + v.updateHistory(); + assertEquals(1, v.getHistoryList().size()); + assertEquals(false, Versionable.auditable(v)); + v.setField2("new value"); + assertEquals(true, Versionable.auditable(v)); + v.updateHistory(); + assertEquals(2, v.getHistoryList().size()); + } + catch (Exception ex) { + Exceptions.printStackTrace(ex); + fail(); + } + } + + @Test + public void testVersioning() { + try { + DemoBuilder.buildDemoProject(); + EntityManager em = DataBaseManager.getEntityManager(); + //Populate with demo classes. + for (EntityType entity : em.getMetamodel().getEntities()) { + if (Versionable.class.isAssignableFrom(entity.getJavaType())) { + final String className = entity.getName(); + System.out.println("Testing class: " + className); + //Make sure they have at least one auditable field. + List fields = FieldUtils + .getFieldsListWithAnnotation(entity.getJavaType(), + Auditable.class); + assertEquals(false, fields.isEmpty()); + //Get one from the demo data + Versionable v = (Versionable) DataBaseManager.createdQuery("Select a from " + + entity.getJavaType().getSimpleName() + + " a").get(0); + assertNotNull(v); + v.updateHistory(); + int count = v.getHistoryList().size(); + for (Field f : fields) { + //Now pick one of the Auditable fields + assertEquals(count, v.getHistoryList().size()); + History history = v.getHistoryList().get(v + .getHistoryList().size() - 1); + assertEquals(count == 1 ? "audit.general.creation" + : "audit.general.modified", history.getReason()); + assertEquals(0, history.getMajorVersion()); + assertEquals(0, history.getMidVersion()); + assertEquals(count++, history.getMinorVersion()); + assertEquals(1, (int) history.getModifierId().getId()); + assertNotNull(history.getModificationTime()); + assertTrue(checkHistory(v)); + assertFalse(Versionable.auditable(v)); + System.out.println("Changing field: " + + f.getName() + " Type: " + + f.getType().getSimpleName()); + f.setAccessible(true); + if (f.getType() == Integer.class) { + Integer current = (Integer) f.get(v); + Integer newValue = current + 1; + showChange(current, newValue); + f.set(v, newValue); + } else if (f.getType() == String.class) { + String current = (String) f.get(v); + String newValue = current + 1; + showChange(current, newValue); + f.set(v, newValue); + } else if (f.getType() == byte[].class) { + byte[] current = (byte[]) f.get(v); + byte[] append = "1".getBytes(); + byte[] newValue = new byte[current.length + append.length]; + showChange(current, newValue); + f.set(v, newValue); + } else if (f.getType() == Boolean.class) { + Boolean current = (Boolean) f.get(v); + Boolean newValue = !current; + showChange(current, newValue); + f.set(v, newValue); + } else { + fail("Unexpected field type: " + + f.getType().getSimpleName()); + } + assertTrue(Versionable.auditable(v)); + v.updateHistory(); + assertEquals(count, v.getHistoryList().size()); + history = v.getHistoryList().get(v.getHistoryList().size() - 1); + assertEquals(0, history.getMajorVersion()); + assertEquals(0, history.getMidVersion()); + assertEquals(count, history.getMinorVersion()); + assertEquals(1, (int) history.getModifierId().getId()); + assertEquals("audit.general.modified", history.getReason()); + assertNotNull(history.getModificationTime()); + assertTrue(checkHistory(v)); + assertFalse(Versionable.auditable(v)); + int total = new HistoryJpaController(DataBaseManager + .getEntityManagerFactory()).getHistoryCount(); + //Test for issue #25 https://github.com/javydreamercsw/validation-manager/issues/25 + + v = (Versionable) DataBaseManager.getEntityManager().find(entity.getJavaType(), + DataBaseManager.getEntityManagerFactory() + .getPersistenceUnitUtil().getIdentifier(v)); + assertTrue(checkHistory(v)); + assertEquals(total, new HistoryJpaController(DataBaseManager + .getEntityManagerFactory()).getHistoryCount()); + assertEquals(count, v.getHistoryList().size()); + } + } + } + } + catch (Exception ex) { + Exceptions.printStackTrace(ex); + fail(); + } + } + + private void showChange(Object current, Object newValue) { + System.out.println("Changing int value from: " + + current + " to: " + + newValue); + } + + public class VersionableImpl extends Versionable { + + private List history = new ArrayList<>(); + + private int field1; + + @Auditable + private String field2; + + @Override + public List getHistoryList() { + return history; + } + + @Override + public void setHistoryList(List historyList) { + this.history = historyList; + } + + /** + * @return the field1 + */ + public int getField1() { + return field1; + } + + /** + * @param field1 the field1 to set + */ + public void setField1(int field1) { + this.field1 = field1; + } + + /** + * @return the field2 + */ + public String getField2() { + return field2; + } + + /** + * @param field2 the field2 to set + */ + public void setField2(String field2) { + this.field2 = field2; + } + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/server/core/AttachmentTypeServerTest.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/AttachmentTypeServerTest.java new file mode 100644 index 00000000..1367279c --- /dev/null +++ b/VM-Core/src/test/java/com/validation/manager/core/server/core/AttachmentTypeServerTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.server.core; + +import com.validation.manager.test.AbstractVMTestCase; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class AttachmentTypeServerTest extends AbstractVMTestCase { + + /** + * Test of write2DB method, of class AttachmentTypeServer. + * + * @throws java.lang.Exception + */ + @Test + public void testWrite2DB() throws Exception { + System.out.println("write2DB"); + AttachmentTypeServer instance = new AttachmentTypeServer(1); + instance.setType("Type2"); + instance.setDescription("Desc2"); + instance.write2DB(); + assertEquals("Type2", instance.getEntity().getType()); + assertEquals("Desc2", instance.getEntity().getDescription()); + } + + /** + * Test of getTypeForExtension method, of class AttachmentTypeServer. + */ + @Test + public void testGetTypeForExtension() { + System.out.println("getTypeForExtension"); + assertNotNull(AttachmentTypeServer.getTypeForExtension("txt")); + assertNull(AttachmentTypeServer.getTypeForExtension("dummy")); + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/server/core/ExecutionResultServerTest.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/ExecutionResultServerTest.java new file mode 100644 index 00000000..ef69233b --- /dev/null +++ b/VM-Core/src/test/java/com/validation/manager/core/server/core/ExecutionResultServerTest.java @@ -0,0 +1,63 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.db.controller.ExecutionResultJpaController; +import com.validation.manager.test.AbstractVMTestCase; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ExecutionResultServerTest extends AbstractVMTestCase { + + /** + * Test of write2DB method, of class ExecutionResultServer. + * + * @throws java.lang.Exception + */ + @Test + public void testWrite2DB() throws Exception { + System.out.println("write2DB"); + ExecutionResultServer instance = new ExecutionResultServer(1); + instance.setResultName("test"); + instance.write2DB(); + assertEquals("test", instance.getEntity().getResultName()); + } + + /** + * Test of getResult method, of class ExecutionResultServer. + */ + @Test + public void testGetResult() { + System.out.println("getResult"); + assertNotNull(ExecutionResultServer.getResult("result.pass")); + assertNull(ExecutionResultServer.getResult("result.dummy")); + } + + /** + * Test of getResults method, of class ExecutionResultServer. + */ + @Test + public void testGetResults() { + System.out.println("getResults"); + assertEquals(new ExecutionResultJpaController(DataBaseManager + .getEntityManagerFactory()).getExecutionResultCount(), + ExecutionResultServer.getResults().size()); + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/server/core/IssueTypeServerTest.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/IssueTypeServerTest.java new file mode 100644 index 00000000..653d9733 --- /dev/null +++ b/VM-Core/src/test/java/com/validation/manager/core/server/core/IssueTypeServerTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.server.core; + +import com.validation.manager.test.AbstractVMTestCase; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class IssueTypeServerTest extends AbstractVMTestCase { + + /** + * Test of write2DB method, of class IssueTypeServer. + * + * @throws java.lang.Exception + */ + @Test + public void testWrite2DB() throws Exception { + System.out.println("write2DB"); + IssueTypeServer instance = new IssueTypeServer(1); + instance.setTypeName("test"); + instance.setDescription("desc"); + instance.write2DB(); + assertEquals("test", instance.getEntity().getTypeName()); + assertEquals("desc", instance.getEntity().getDescription()); + } + + /** + * Test of getType method, of class IssueTypeServer. + */ + @Test + public void testGetType() { + System.out.println("getType"); + assertNotNull(IssueTypeServer.getType("bug.name")); + assertNull(IssueTypeServer.getType("dummy")); + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/server/core/NotificationServerTest.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/NotificationServerTest.java index 7c753cb8..72685e34 100644 --- a/VM-Core/src/test/java/com/validation/manager/core/server/core/NotificationServerTest.java +++ b/VM-Core/src/test/java/com/validation/manager/core/server/core/NotificationServerTest.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,52 +13,60 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.test.AbstractVMTestCase; -import java.util.Date; -import org.junit.Test; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class NotificationServerTest extends AbstractVMTestCase { - - /** - * Test of write2DB method, of class NotificationServer. - * - * @throws java.lang.Exception - */ - @Test - public void testWrite2DB() throws Exception { - System.out.println("write2DB"); - VMUserServer author = new VMUserServer(1); - VMUserServer target = new VMUserServer(2); - NotificationServer instance = new NotificationServer(); - instance.setAuthor(author.getEntity()); - instance.setContent("Hello there!"); - instance.setCreationDate(new Date()); - instance.setNotificationType(NotificationTypeServer - .getType("notification.test.pending")); - instance.setTargetUser(target.getEntity()); - assertEquals(0, author.getNotificationList().size()); - assertEquals(0, target.getNotificationList().size()); - assertEquals(0, author.getNotificationList1().size()); - assertEquals(0, target.getNotificationList1().size()); - instance.write2DB(); - author.update(); - target.update(); - assertEquals(0, author.getNotificationList().size()); - assertEquals(1, target.getNotificationList().size()); - assertEquals(1, author.getNotificationList1().size()); - assertEquals(0, target.getNotificationList1().size()); - assertEquals(0, author.getPendingNotifications().size()); - assertEquals(1, target.getPendingNotifications().size()); - NotificationServer ns = new NotificationServer(target - .getNotificationList().get(0)); - ns.setAcknowledgeDate(new Date()); - ns.write2DB(); - assertEquals(0, target.getPendingNotifications().size()); - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.test.AbstractVMTestCase; +import java.util.Date; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class NotificationServerTest extends AbstractVMTestCase { + + /** + * Test of write2DB method, of class NotificationServer. + * + * @throws java.lang.Exception + */ + @Test + public void testWrite2DB() throws Exception { + System.out.println("write2DB"); + VMUserServer author = new VMUserServer(1); + VMUserServer target = new VMUserServer(2); + NotificationServer instance = new NotificationServer(); + instance.setAuthor(author.getEntity()); + instance.setContent("Hello there!"); + instance.setCreationDate(new Date()); + instance.setNotificationType(NotificationTypeServer + .getType("notification.test.pending")); + instance.setTargetUser(target.getEntity()); + assertEquals(0, author.getNotificationList().size()); + assertEquals(0, target.getNotificationList().size()); + assertEquals(0, author.getNotificationList1().size()); + assertEquals(0, target.getNotificationList1().size()); + instance.write2DB(); + author.update(); + target.update(); + assertEquals(0, author.getNotificationList().size()); + assertEquals(1, target.getNotificationList().size()); + assertEquals(1, author.getNotificationList1().size()); + assertEquals(0, target.getNotificationList1().size()); + assertEquals(0, author.getPendingNotifications().size()); + assertEquals(1, target.getPendingNotifications().size()); + NotificationServer ns = new NotificationServer(target + .getNotificationList().get(0)); + ns.setAcknowledgeDate(new Date()); + ns.write2DB(); + assertEquals(0, target.getPendingNotifications().size()); + NotificationServer instance2 = new NotificationServer(); + instance2.setAuthor(author.getEntity()); + instance2.setContent("Hello there!"); + instance2.setCreationDate(new Date()); + instance2.setNotificationType(NotificationTypeServer + .getType("notification.test.pending")); + instance2.setTargetUser(target.getEntity()); + instance2.write2DB(); + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/server/core/ProjectServerTest.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/ProjectServerTest.java index 2acc3e88..dda0d483 100644 --- a/VM-Core/src/test/java/com/validation/manager/core/server/core/ProjectServerTest.java +++ b/VM-Core/src/test/java/com/validation/manager/core/server/core/ProjectServerTest.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,159 +13,92 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.VMException; -import com.validation.manager.core.db.Project; -import com.validation.manager.core.db.Requirement; -import com.validation.manager.core.db.RequirementSpec; -import com.validation.manager.core.db.RequirementSpecNode; -import com.validation.manager.core.db.controller.ProjectJpaController; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.tool.Tool; -import com.validation.manager.test.AbstractVMTestCase; -import com.validation.manager.test.TestHelper; -import java.util.logging.Level; -import java.util.logging.Logger; -import static junit.framework.TestCase.assertTrue; -import static junit.framework.TestCase.fail; -import org.junit.Test; -import org.openide.util.Exceptions; -import static org.openide.util.Exceptions.printStackTrace; - -/** - * - * @author jortiz00 - */ -public class ProjectServerTest extends AbstractVMTestCase { - - private Project p; - private static final Logger LOG - = Logger.getLogger(ProjectServerTest.class.getSimpleName()); - - @Override - protected void postSetUp() { - try { - RequirementSpec rss = null; - p = TestHelper.createProject("New Project", "Notes"); - ProjectServer project = new ProjectServer(p); - project.setNotes("Notes 2"); - project.write2DB(); - assertTrue(new ProjectJpaController( - DataBaseManager.getEntityManagerFactory()) - .findProject(project.getId()).getNotes().equals(project.getNotes())); - //Create requirements - System.out.println("Create Requirement Spec"); - try { - rss = TestHelper.createRequirementSpec("Test", "Test", - project, 1); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - System.out.println("Create Requirement Spec Node"); - try { - TestHelper.createRequirementSpecNode( - rss, "Test", "Test", "Test"); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - } - catch (NonexistentEntityException ex) { - Exceptions.printStackTrace(ex); - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - } - - /** - * Test of create and deleteProject method, of class ProjectServer. - */ - @Test - public void testCreateAndDeleteProject() { - try { - System.out.println("Create a project"); - Project root = TestHelper.createProject("Test", "Notes"); - System.out.println("Add a sub project"); - Project sub = TestHelper.addProject(root, "Sub", "Notes"); - System.out.println("Create Spec for main project."); - //No errors, nothing dependent - try { - ProjectServer.deleteProject(sub); - } - catch (VMException ex) { - printStackTrace(ex); - fail(); - } - assertTrue(Tool.extractRequirements(root).isEmpty()); - RequirementSpec mainSpec - = TestHelper.createRequirementSpec("Spec", "Desc", root, 1); - assertTrue(!root.getRequirementSpecList().isEmpty()); - assertEquals(0, Tool.extractRequirements(root).size()); - sub = TestHelper.addProject(root, "Sub", "Notes"); - System.out.println("Create Spec for sub project."); - RequirementSpec spec = TestHelper.createRequirementSpec("Spec 2", - "Desc", sub, 1); - RequirementSpecNode node = TestHelper.createRequirementSpecNode(mainSpec, - "Requirement Doc", "Desc", "Scope"); - Requirement req1 = TestHelper.createRequirement("REQ-001", "Desc", - node.getRequirementSpecNodePK(), "Notes", 1, 1); - assertEquals(1, Tool.extractRequirements(root).size()); - Requirement req2 = TestHelper.createRequirement("REQ-002", "Desc", - node.getRequirementSpecNodePK(), "Notes", 1, 1); - assertEquals(2, Tool.extractRequirements(root).size()); - TestHelper.addChildToRequirement(req1, req2); - try { - ProjectServer.deleteProject(sub); - } - catch (VMException ex) { - //Expected failure - System.out.println("Expected failure!"); - } - RequirementSpecServer.deleteRequirementSpec(spec); - try { - ProjectServer.deleteProject(new ProjectServer(sub).getEntity()); - } - catch (VMException ex) { - printStackTrace(ex); - fail(); - } - } - catch (Exception ex) { - printStackTrace(ex); - fail(); - } - } - - @Test - public void testExtractTestProjects() { - try { - System.out.println("Add Test Project"); - TestHelper.addTestProjectToProject(TestHelper - .createTestProject("Test"), p); - for (int i = 0; i < 5; i++) { - Project sub = TestHelper.addProject(p, "Sub #" + i, - "Notes #" + i); - TestHelper.addTestProjectToProject(TestHelper - .createTestProject("Test"), sub); - } - ProjectServer ps = new ProjectServer(p); - assertEquals(1, ps.getTestProjects(false).size()); - assertEquals(1 + ps.getProjectList().size(), - ps.getTestProjects(true).size()); - } - catch (NonexistentEntityException ex) { - Exceptions.printStackTrace(ex); - fail(); - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - fail(); - } - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.Project; +import com.validation.manager.core.db.RequirementSpec; +import com.validation.manager.core.db.controller.ProjectJpaController; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.test.AbstractVMTestCase; +import com.validation.manager.test.TestHelper; +import java.util.logging.Level; +import java.util.logging.Logger; +import static junit.framework.TestCase.assertTrue; +import static junit.framework.TestCase.fail; +import org.junit.Test; + +/** + * + * @author jortiz00 + */ +public class ProjectServerTest extends AbstractVMTestCase { + + private Project p; + private static final Logger LOG + = Logger.getLogger(ProjectServerTest.class.getSimpleName()); + + @Override + protected void postSetUp() { + try { + RequirementSpec rss = null; + p = TestHelper.createProject("New Project", "Notes"); + ProjectServer project = new ProjectServer(p); + project.setNotes("Notes 2"); + project.write2DB(); + assertTrue(new ProjectJpaController( + DataBaseManager.getEntityManagerFactory()) + .findProject(project.getId()).getNotes().equals(project.getNotes())); + //Create requirements + System.out.println("Create Requirement Spec"); + try { + rss = TestHelper.createRequirementSpec("Test", "Test", + project, 1); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + System.out.println("Create Requirement Spec Node"); + try { + TestHelper.createRequirementSpecNode( + rss, "Test", "Test", "Test"); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } + catch (VMException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + + @Test + public void testExtractTestProjects() { + try { + System.out.println("Add Test Project"); + TestHelper.addTestProjectToProject(TestHelper + .createTestProject("Test"), p); + for (int i = 0; i < 5; i++) { + Project sub = TestHelper.addProject(p, "Sub #" + i, + "Notes #" + i); + TestHelper.addTestProjectToProject(TestHelper + .createTestProject("Test"), sub); + } + ProjectServer ps = new ProjectServer(p); + assertEquals(1, ps.getTestProjects(false).size()); + assertEquals(1 + ps.getProjectList().size(), + ps.getTestProjects(true).size()); + } + catch (NonexistentEntityException ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/server/core/RequirementServerTest.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/RequirementServerTest.java index 38b8e36e..aa5dab43 100644 --- a/VM-Core/src/test/java/com/validation/manager/core/server/core/RequirementServerTest.java +++ b/VM-Core/src/test/java/com/validation/manager/core/server/core/RequirementServerTest.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,390 +13,313 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.Project; -import com.validation.manager.core.db.Requirement; -import com.validation.manager.core.db.RequirementSpec; -import com.validation.manager.core.db.RequirementSpecNode; -import com.validation.manager.core.db.Step; -import com.validation.manager.core.db.TestCase; -import com.validation.manager.core.db.TestPlan; -import com.validation.manager.core.db.TestProject; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.controller.HistoryJpaController; -import com.validation.manager.core.db.controller.ProjectJpaController; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.test.AbstractVMTestCase; -import com.validation.manager.test.TestHelper; -import java.util.logging.Level; -import java.util.logging.Logger; -import static java.util.logging.Logger.getLogger; -import org.junit.Test; -import org.openide.util.Exceptions; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class RequirementServerTest extends AbstractVMTestCase { - - private static final Logger LOG - = getLogger(RequirementServerTest.class.getName()); - private Project p; - private RequirementSpecNode rsn; - - @Override - protected void postSetUp() { - try { - RequirementSpec rss = null; - p = TestHelper.createProject("New Project", "Notes"); - ProjectServer project = new ProjectServer(p); - project.setNotes("Notes 2"); - project.write2DB(); - assertTrue(new ProjectJpaController( - DataBaseManager.getEntityManagerFactory()) - .findProject(project.getId()).getNotes().equals(project.getNotes())); - //Create requirements - System.out.println("Create Requirement Spec"); - try { - rss = TestHelper.createRequirementSpec("Test", "Test", - project, 1); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - System.out.println("Create Requirement Spec Node"); - try { - rsn = TestHelper.createRequirementSpecNode( - rss, "Test", "Test", "Test"); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - } - catch (NonexistentEntityException ex) { - Exceptions.printStackTrace(ex); - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - } - - /** - * Test of update method, of class RequirementServer. - */ - @Test - public void testUpdate() { - try { - System.out.println("update"); - Requirement source = TestHelper.createRequirement("SRS-SW-0001", - "Sample requirement", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - RequirementServer instance = new RequirementServer(source); - assertEquals(1, instance.getHistoryList().size()); - int count = 1; - for (History h : instance.getHistoryList()) { - assertEquals(0, h.getMajorVersion()); - assertEquals(0, h.getMidVersion()); - assertEquals(count, h.getMinorVersion()); - count++; - } - Requirement target = new Requirement(); - instance.update(target, source); - assertEquals(instance.getUniqueId(), target.getUniqueId()); - assertEquals(instance.getDescription(), target.getDescription()); - assertEquals(instance.getNotes(), target.getNotes()); - assertEquals(instance.getRequirementTypeId().getId(), - target.getRequirementTypeId().getId()); - assertEquals(instance.getRequirementStatusId().getId(), - target.getRequirementStatusId().getId()); - assertEquals(instance.getHistoryList().size(), - target.getHistoryList().size()); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - } - - /** - * Test of isDuplicate method, of class RequirementServer. - */ - @Test - public void testIsDuplicate() { - try { - System.out.println("isDuplicate"); - Requirement source = TestHelper.createRequirement("SRS-SW-0001", - "Sample requirement", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - Requirement source2 = TestHelper.createRequirement("SRS-SW-0002", - "Sample requirement", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - assertEquals(false, RequirementServer.isDuplicate(source)); - assertEquals(false, RequirementServer.isDuplicate(source2)); - Requirement source3 = TestHelper.createRequirement("SRS-SW-0002", - "Sample requirement", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - assertEquals(true, RequirementServer.isDuplicate(source3)); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - } - - /** - * Test of getTestCoverage method, of class RequirementServer. - */ - @Test - public void testGetTestCoverage() { - try { - System.out.println("getTestCoverage"); - Requirement req = TestHelper.createRequirement("SRS-SW-0001", - "Sample requirement", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - Requirement req2 = TestHelper.createRequirement("SRS-SW-0002", - "Sample requirement", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - Requirement req3 = TestHelper.createRequirement("SRS-SW-0003", - "Sample requirement", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - Requirement req4 = TestHelper.createRequirement("SRS-SW-0004", - "Sample requirement", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - Requirement userReq = TestHelper.createRequirement("PS-SW-0001", - "Sample User requirement", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - RequirementServer rs = new RequirementServer(req); - assertEquals(0, rs.getTestCoverage()); - //Create Test Case - TestCase tc = TestHelper.createTestCase("Dummy", "Summary"); - //Add steps - int i = 1; - for (; i < 6; i++) { - LOG.log(Level.INFO, "Adding step: {0}", i); - tc = TestHelper.addStep(tc, i, "Step " + i, "Note " + i, "Result " + i); - Step step = tc.getStepList().get(i - 1); - TestHelper.addRequirementToStep(step, req); - new TestCaseServer(tc).write2DB(); - assertEquals(1, new StepServer(step).getRequirementList().size()); - } - LOG.log(Level.INFO, "Adding step: {0}", i); - tc = TestHelper.addStep(tc, i, "Step " + i, "Note " + i, "Result " + i); - Step step = tc.getStepList().get(i - 1); - TestHelper.addRequirementToStep(step, req3); - new TestCaseServer(tc).write2DB(); - //Create test Project - TestProject tp = TestHelper.createTestProject("Test Project"); - //Create test plan - TestPlan plan = TestHelper.createTestPlan(tp, "Notes", true, true); - //Add test to plan - TestHelper.addTestCaseToPlan(plan, tc); - rs.update(); - assertEquals(100, rs.getTestCoverage()); - //Add a related requirement - rs.addChildRequirement(req3); - assertEquals(100, rs.getTestCoverage()); - rs.addChildRequirement(req2); - assertEquals(50, rs.getTestCoverage()); - rs.addChildRequirement(req4); - assertEquals(33, rs.getTestCoverage()); - //Add related requirements to test coverage - RequirementServer ur = new RequirementServer(userReq); - assertEquals(0, ur.getTestCoverage()); - ur.addChildRequirement(req); - assertEquals(33, ur.getTestCoverage()); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - } - - /** - * Test of getChildrenRequirement method, of class RequirementServer. - */ - @Test - public void testChildAndParentRequirements() { - try { - System.out.println("Child And Parent Requirements"); - Requirement req = TestHelper.createRequirement("SRS-SW-0001", - "Sample requirement", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - Requirement req2 = TestHelper.createRequirement("SRS-SW-0002", - "Sample requirement", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - assertTrue(req.getRequirementList().isEmpty()); - //Add a child - RequirementServer rs = new RequirementServer(req); - //Add a version to the requirement - DataBaseManager.setVersioningEnabled(true); - rs.setDescription("Modified requirement"); - rs.write2DB(); - rs.addChildRequirement(req2); - RequirementServer rs2 = new RequirementServer(req2); - //Should have one children now - assertEquals(1, rs.getEntity().getRequirementList().size()); - //No parents - assertNull(rs.getEntity().getParentRequirementId()); - //One parent - assertNotNull(rs2.getEntity().getParentRequirementId()); - //No children - assertEquals(0, rs2.getEntity().getRequirementList().size()); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - } - - /** - * Test of requirement coverage with versioning method, of class - * RequirementServer. - */ - @Test - public void testRequirementCoverage() { - try { - System.out.println("Requirement Coverage and Versioning"); - //Enable versioning - DataBaseManager.setVersioningEnabled(true); - Requirement req = TestHelper.createRequirement("SRS-SW-0001", - "Description", rsn.getRequirementSpecNodePK(), "Notes", 1, 1); - RequirementServer rs = new RequirementServer(req); - //Add a test case covering this test case - TestProject tp = TestHelper.createTestProject("Test Project"); - TestHelper.addTestProjectToProject(tp, p); - TestPlan plan = TestHelper.createTestPlan(tp, "Plan", true, true); - TestCase tc = TestHelper.createTestCase("TC #1", - "Summary"); - TestHelper.addTestCaseToPlan(plan, tc); - TestCase step = TestHelper.addStep(tc, 1, "Test", "Test", "Result "); - rs.getStepList().add(step.getStepList().get(0)); - rs.write2DB(); - assertEquals(1, rs.getStepList().size()); - assertEquals(100, rs.getTestCoverage()); - //Update version and remove test coverage - rs.setDescription("New version"); - rs.getStepList().clear(); - rs.write2DB(); - assertEquals(0, rs.getStepList().size()); - rs.update(); - assertEquals(0, rs.getTestCoverage()); - rs.setDescription("New version 2"); - StepServer ss = new StepServer(step.getStepList().get(0)); - ss.removeRequirement(req); - ss.write2DB(); - ss.addRequirement(rs.getEntity()); - rs.update(); - rs.write2DB(); - assertEquals(1, rs.getStepList().size()); - assertEquals(100, rs.getTestCoverage()); - //Add a parent requirement - Requirement r = TestHelper.createRequirement("PS-0001", - "Description", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - RequirementServer parent = new RequirementServer(r); - parent.addChildRequirement(req); - parent.write2DB(); - assertEquals(100, parent.getTestCoverage()); - assertEquals(100, rs.getTestCoverage()); - //Version parent - parent.setDescription("Version 2"); - parent.write2DB(); - assertEquals(100, parent.getTestCoverage()); - assertEquals(100, rs.getTestCoverage()); - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - fail(); - } - } - - @Test - public void testVersioning() { - try { - Requirement req = TestHelper.createRequirement("SRS-SW-0001", - "Description", rsn.getRequirementSpecNodePK(), - "Notes", 1, 1); - RequirementServer rs = new RequirementServer(req); - int historyCount = 1; - assertEquals(historyCount++, rs.getHistoryList().size()); - History history = rs.getHistoryList().get(rs - .getHistoryList().size() - 1); - assertEquals(0, history.getMajorVersion()); - assertEquals(0, history.getMidVersion()); - assertEquals(1, history.getMinorVersion()); - assertEquals(1, (int) history.getModifierId().getId()); - assertEquals("audit.general.creation", history.getReason()); - assertNotNull(history.getModificationTime()); - assertTrue(checkHistory(rs)); - rs.setDescription("desc 2"); - rs.write2DB(); - assertEquals(historyCount++, rs.getHistoryList().size()); - history = rs.getHistoryList().get(rs.getHistoryList().size() - 1); - assertEquals(0, history.getMajorVersion()); - assertEquals(0, history.getMidVersion()); - assertEquals(2, history.getMinorVersion()); - assertEquals(1, (int) history.getModifierId().getId()); - assertEquals("audit.general.modified", history.getReason()); - assertNotNull(history.getModificationTime()); - assertTrue(checkHistory(rs)); - rs.setDescription("desc 3"); - VmUser test = TestHelper.createUser("Test", "pass", "email", - "first", "last"); - rs.setModifierId(test.getId()); - rs.setReason("Test"); - rs.write2DB(); - assertEquals(historyCount++, rs.getHistoryList().size()); - history = rs.getHistoryList().get(rs.getHistoryList().size() - 1); - assertEquals(0, history.getMajorVersion()); - assertEquals(0, history.getMidVersion()); - assertEquals(3, history.getMinorVersion()); - assertEquals((int) test.getId(), (int) history.getModifierId().getId()); - assertEquals("Test", history.getReason()); - assertNotNull(history.getModificationTime()); - assertTrue(checkHistory(rs)); - rs.increaseMidVersion(); - assertEquals(historyCount++, rs.getHistoryList().size()); - history = rs.getHistoryList().get(rs.getHistoryList().size() - 1); - assertEquals(0, history.getMajorVersion()); - assertEquals(1, history.getMidVersion()); - assertEquals(0, history.getMinorVersion()); - //TODO: Handle mid and major changes on system - //assertEquals(1, (int) history.getModifierId().getId()); - //assertEquals("tbd", history.getReason()); - assertNotNull(history.getModificationTime()); - assertTrue(checkHistory(rs)); - rs.increaseMajorVersion(); - assertEquals(historyCount, rs.getHistoryList().size()); - history = rs.getHistoryList().get(rs.getHistoryList().size() - 1); - assertEquals(1, history.getMajorVersion()); - assertEquals(0, history.getMidVersion()); - assertEquals(0, history.getMinorVersion()); - //TODO: Handle mid and major changes on system - //assertEquals(1, (int) history.getModifierId().getId()); - //assertEquals("tbd", history.getReason()); - assertNotNull(history.getModificationTime()); - assertTrue(checkHistory(rs)); - int total = new HistoryJpaController(DataBaseManager - .getEntityManagerFactory()).getHistoryCount(); - //Test for issue #25 - //Disconnet to the database - DataBaseManager.close(); - //Reconnect - rs.update(); - assertEquals(total, new HistoryJpaController(DataBaseManager - .getEntityManagerFactory()).getHistoryCount()); - assertEquals(historyCount, rs.getHistoryList().size()); - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - fail(); - } - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.Project; +import com.validation.manager.core.db.Requirement; +import com.validation.manager.core.db.RequirementSpec; +import com.validation.manager.core.db.RequirementSpecNode; +import com.validation.manager.core.db.Step; +import com.validation.manager.core.db.TestCase; +import com.validation.manager.core.db.TestPlan; +import com.validation.manager.core.db.TestProject; +import com.validation.manager.core.db.controller.ProjectJpaController; +import com.validation.manager.test.AbstractVMTestCase; +import com.validation.manager.test.TestHelper; +import java.util.logging.Level; +import java.util.logging.Logger; +import static java.util.logging.Logger.getLogger; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RequirementServerTest extends AbstractVMTestCase { + + private static final Logger LOG + = getLogger(RequirementServerTest.class.getName()); + private Project p; + private RequirementSpecNode rsn; + private RequirementSpec rss; + + @Override + protected void postSetUp() { + try { + p = TestHelper.createProject("New Project", "Notes"); + ProjectServer project = new ProjectServer(p); + project.setNotes("Notes 2"); + project.write2DB(); + assertTrue(new ProjectJpaController( + DataBaseManager.getEntityManagerFactory()) + .findProject(project.getId()).getNotes().equals(project.getNotes())); + //Create requirements + System.out.println("Create Requirement Spec"); + try { + rss = TestHelper.createRequirementSpec("Test", "Test", + project, 1); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + System.out.println("Create Requirement Spec Node"); + try { + rsn = TestHelper.createRequirementSpecNode( + rss, "Test", "Test", "Test"); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } + catch (VMException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + + /** + * Test of update method, of class RequirementServer. + */ + @Test + public void testUpdate() { + try { + System.out.println("update"); + Requirement source = TestHelper.createRequirement("SRS-SW-0001", + "Sample requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + RequirementServer instance = new RequirementServer(source); + assertEquals(1, instance.getHistoryList().size()); + int count = 1; + for (History h : instance.getHistoryList()) { + assertEquals(0, h.getMajorVersion()); + assertEquals(0, h.getMidVersion()); + assertEquals(count, h.getMinorVersion()); + count++; + } + Requirement target = new Requirement(); + instance.update(target, source); + assertEquals(instance.getUniqueId(), target.getUniqueId()); + assertEquals(instance.getDescription(), target.getDescription()); + assertEquals(instance.getNotes(), target.getNotes()); + assertEquals(instance.getRequirementTypeId().getId(), + target.getRequirementTypeId().getId()); + assertEquals(instance.getRequirementStatusId().getId(), + target.getRequirementStatusId().getId()); + assertEquals(instance.getHistoryList().size(), + target.getHistoryList().size()); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } + + /** + * Test of isDuplicate method, of class RequirementServer. + */ + @Test + public void testIsDuplicate() { + try { + System.out.println("isDuplicate"); + Requirement source = TestHelper.createRequirement("SRS-SW-0001", + "Sample requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + Requirement source2 = TestHelper.createRequirement("SRS-SW-0002", + "Sample requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + assertEquals(false, RequirementServer.isDuplicate(source)); + assertEquals(false, RequirementServer.isDuplicate(source2)); + Requirement source3 = TestHelper.createRequirement("SRS-SW-0002", + "Sample requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + assertEquals(true, RequirementServer.isDuplicate(source3)); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } + + /** + * Test of getTestCoverage method, of class RequirementServer. + */ + @Test + public void testGetTestCoverage() { + try { + System.out.println("getTestCoverage"); + Requirement req = TestHelper.createRequirement("SRS-SW-0001", + "Sample requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + Requirement req2 = TestHelper.createRequirement("SRS-SW-0002", + "Sample requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + Requirement req3 = TestHelper.createRequirement("SRS-SW-0003", + "Sample requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + Requirement req4 = TestHelper.createRequirement("SRS-SW-0004", + "Sample requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + Requirement userReq = TestHelper.createRequirement("PS-SW-0001", + "Sample User requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + RequirementServer rs = new RequirementServer(req); + assertEquals(0, rs.getTestCoverage()); + //Create Test Case + TestCase tc = TestHelper.createTestCase("Dummy", "Summary"); + //Add steps + int i = 1; + for (; i < 6; i++) { + LOG.log(Level.INFO, "Adding step: {0}", i); + tc = TestHelper.addStep(tc, i, "Step " + i, "Note " + i, "Result " + i); + Step step = tc.getStepList().get(i - 1); + TestHelper.addRequirementToStep(step, req); + new TestCaseServer(tc).write2DB(); + assertEquals(1, new StepServer(step).getRequirementList().size()); + } + LOG.log(Level.INFO, "Adding step: {0}", i); + tc = TestHelper.addStep(tc, i, "Step " + i, "Note " + i, "Result " + i); + Step step = tc.getStepList().get(i - 1); + TestHelper.addRequirementToStep(step, req3); + new TestCaseServer(tc).write2DB(); + //Create test Project + TestProject tp = TestHelper.createTestProject("Test Project"); + //Create test plan + TestPlan plan = TestHelper.createTestPlan(tp, "Notes", true, true); + //Add test to plan + TestHelper.addTestCaseToPlan(plan, tc); + rs.update(); + assertEquals(100, rs.getTestCoverage()); + //Add a related requirement + rs.addChildRequirement(req3); + assertEquals(100, rs.getTestCoverage()); + rs.addChildRequirement(req2); + assertEquals(50, rs.getTestCoverage()); + rs.addChildRequirement(req4); + assertEquals(33, rs.getTestCoverage()); + //Add related requirements to test coverage + RequirementServer ur = new RequirementServer(userReq); + assertEquals(0, ur.getTestCoverage()); + ur.addChildRequirement(req); + assertEquals(33, ur.getTestCoverage()); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } + + /** + * Test of getChildrenRequirement method, of class RequirementServer. + */ + @Test + public void testChildAndParentRequirements() { + try { + System.out.println("Child And Parent Requirements"); + Requirement req = TestHelper.createRequirement("SRS-SW-0001", + "Sample requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + Requirement req2 = TestHelper.createRequirement("SRS-SW-0002", + "Sample requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + assertTrue(req.getRequirementList().isEmpty()); + //Add a child + RequirementServer rs = new RequirementServer(req); + //Add a version to the requirement + DataBaseManager.setVersioningEnabled(true); + rs.setDescription("Modified requirement"); + rs.write2DB(); + rs.addChildRequirement(req2); + RequirementServer rs2 = new RequirementServer(req2); + //Should have one children now + assertEquals(1, rs.getEntity().getRequirementList().size()); + //No parents + assertNull(rs.getEntity().getParentRequirementId()); + //One parent + assertNotNull(rs2.getEntity().getParentRequirementId()); + //No children + assertEquals(0, rs2.getEntity().getRequirementList().size()); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } + + @Test + public void testGetRequirements() throws Exception { + assertEquals(0, RequirementSpecServer.getRequirements(rss).size()); + TestHelper.createRequirement("SRS-SW-0001", + "Sample requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + TestHelper.createRequirement("SRS-SW-0002", + "Sample requirement", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + assertEquals(2, RequirementSpecServer.getRequirements(rss).size()); + } + + /** + * Test of requirement coverage with versioning method, of class + * RequirementServer. + */ + @Test + public void testRequirementCoverage() { + try { + System.out.println("Requirement Coverage and Versioning"); + //Enable versioning + DataBaseManager.setVersioningEnabled(true); + Requirement req = TestHelper.createRequirement("SRS-SW-0001", + "Description", rsn.getRequirementSpecNodePK(), "Notes", 1, 1); + RequirementServer rs = new RequirementServer(req); + //Add a test case covering this test case + TestProject tp = TestHelper.createTestProject("Test Project"); + TestHelper.addTestProjectToProject(tp, p); + TestPlan plan = TestHelper.createTestPlan(tp, "Plan", true, true); + TestCase tc = TestHelper.createTestCase("TC #1", + "Summary"); + TestHelper.addTestCaseToPlan(plan, tc); + TestCase step = TestHelper.addStep(tc, 1, "Test", "Test", "Result "); + rs.getStepList().add(step.getStepList().get(0)); + rs.write2DB(); + assertEquals(1, rs.getStepList().size()); + assertEquals(100, rs.getTestCoverage()); + //Update version and remove test coverage + rs.setDescription("New version"); + rs.getStepList().clear(); + rs.write2DB(); + assertEquals(0, rs.getStepList().size()); + rs.update(); + assertEquals(0, rs.getTestCoverage()); + rs.setDescription("New version 2"); + StepServer ss = new StepServer(step.getStepList().get(0)); + ss.removeRequirement(req); + ss.write2DB(); + ss.addRequirement(rs.getEntity()); + rs.update(); + rs.write2DB(); + assertEquals(1, rs.getStepList().size()); + assertEquals(100, rs.getTestCoverage()); + //Add a parent requirement + Requirement r = TestHelper.createRequirement("PS-0001", + "Description", rsn.getRequirementSpecNodePK(), + "Notes", 1, 1); + RequirementServer parent = new RequirementServer(r); + parent.addChildRequirement(req); + parent.write2DB(); + assertEquals(100, parent.getTestCoverage()); + assertEquals(100, rs.getTestCoverage()); + //Version parent + parent.setDescription("Version 2"); + parent.write2DB(); + assertEquals(100, parent.getTestCoverage()); + assertEquals(100, rs.getTestCoverage()); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } +} diff --git a/VM-Core/src/main/java/com/validation/manager/core/tool/Timer.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/RequirementStatusServerTest.java similarity index 50% rename from VM-Core/src/main/java/com/validation/manager/core/tool/Timer.java rename to VM-Core/src/test/java/com/validation/manager/core/server/core/RequirementStatusServerTest.java index d55690d1..30692cef 100644 --- a/VM-Core/src/main/java/com/validation/manager/core/tool/Timer.java +++ b/VM-Core/src/test/java/com/validation/manager/core/server/core/RequirementStatusServerTest.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,34 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.tool; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class Timer { - - private long start, end; - - public Timer() { - reset(); - } - - public void stop() { - end = System.nanoTime(); - } - - public final void reset() { - start = System.nanoTime(); - } - - public String elapsedTime() { - long timeelapsed = (end - start); - long milliseconds = timeelapsed / 1000; - long seconds = (timeelapsed / 1000) % 60; - long minutes = (timeelapsed / 60000) % 60; - return " (" + minutes + ":" + seconds - + ":" + milliseconds + ")"; - } -} +package com.validation.manager.core.server.core; + +import com.validation.manager.test.AbstractVMTestCase; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RequirementStatusServerTest extends AbstractVMTestCase { + + /** + * Test of write2DB method, of class RequirementStatusServer. + * + * @throws java.lang.Exception + */ + @Test + public void testWrite2DB() throws Exception { + System.out.println("write2DB"); + RequirementStatusServer instance = new RequirementStatusServer("test"); + instance.write2DB(); + assertEquals(instance.getStatus(), instance.getEntity().getStatus()); + assertTrue(instance.getId() > 0); + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/server/core/RequirementTypeServerTest.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/RequirementTypeServerTest.java new file mode 100644 index 00000000..3e43cdbf --- /dev/null +++ b/VM-Core/src/test/java/com/validation/manager/core/server/core/RequirementTypeServerTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.db.controller.RequirementTypeJpaController; +import com.validation.manager.test.AbstractVMTestCase; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RequirementTypeServerTest extends AbstractVMTestCase { + + /** + * Test of write2DB method, of class RequirementTypeServer. + * + * @throws java.lang.Exception + */ + @Test + public void testWrite2DB() throws Exception { + System.out.println("write2DB"); + RequirementTypeServer instance = new RequirementTypeServer("test"); + instance.write2DB(); + assertEquals(instance.getName(), instance.getEntity().getName()); + } + + /** + * Test of getRequirementTypes method, of class RequirementTypeServer. + */ + @Test + public void testGetRequirementTypes() { + System.out.println("getRequirementTypes"); + assertEquals(new RequirementTypeJpaController(DataBaseManager + .getEntityManagerFactory()).getRequirementTypeCount(), + RequirementTypeServer.getRequirementTypes().size()); + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/server/core/ReviewResultServerTest.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/ReviewResultServerTest.java new file mode 100644 index 00000000..6952a830 --- /dev/null +++ b/VM-Core/src/test/java/com/validation/manager/core/server/core/ReviewResultServerTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.server.core; + +import com.validation.manager.test.AbstractVMTestCase; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ReviewResultServerTest extends AbstractVMTestCase { + + /** + * Test of getReview method, of class ReviewResultServer. + */ + @Test + public void testGetReview() { + System.out.println("getReview"); + assertNotNull(ReviewResultServer.getReview("result.pass")); + assertNull(ReviewResultServer.getReview("result.dummy")); + } + + /** + * Test of write2DB method, of class ReviewResultServer. + * + * @throws java.lang.Exception + */ + @Test + public void testWrite2DB() throws Exception { + System.out.println("write2DB"); + ReviewResultServer instance = new ReviewResultServer(1); + instance.setReviewName("test"); + instance.write2DB(); + assertEquals(instance.getReviewName(), + instance.getEntity().getReviewName()); + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/server/core/RoleServerTest.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/RoleServerTest.java new file mode 100644 index 00000000..d7612dd3 --- /dev/null +++ b/VM-Core/src/test/java/com/validation/manager/core/server/core/RoleServerTest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.server.core; + +import com.validation.manager.test.AbstractVMTestCase; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class RoleServerTest extends AbstractVMTestCase { + + /** + * Test of getRole method, of class RoleServer. + */ + @Test + public void testGetRole() { + System.out.println("getRole"); + assertNotNull(RoleServer.getRole("admin")); + assertNull(RoleServer.getRole("dummy")); + } + + /** + * Test of write2DB method, of class RoleServer. + * + * @throws java.lang.Exception + */ + @Test + public void testWrite2DB() throws Exception { + System.out.println("write2DB"); + RoleServer instance = new RoleServer(1); + instance.setRoleName("test"); + instance.write2DB(); + assertEquals(instance.getRoleName(), instance.getEntity().getRoleName()); + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/server/core/UserTestProjectRoleServerTest.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/UserTestProjectRoleServerTest.java new file mode 100644 index 00000000..c0be1f2e --- /dev/null +++ b/VM-Core/src/test/java/com/validation/manager/core/server/core/UserTestProjectRoleServerTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.server.core; + +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.db.TestProject; +import com.validation.manager.core.db.controller.UserTestProjectRoleJpaController; +import com.validation.manager.test.AbstractVMTestCase; +import com.validation.manager.test.TestHelper; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class UserTestProjectRoleServerTest extends AbstractVMTestCase { + + /** + * Test of write2DB method, of class UserTestProjectRoleServer. + * + * @throws java.lang.Exception + */ + @Test + public void testWrite2DB() throws Exception { + System.out.println("write2DB"); + createTestUsers(); + TestProject tp = TestHelper.createTestProject("Test"); + UserTestProjectRoleServer instance + = new UserTestProjectRoleServer(tp.getId(), leader.getId(), 1); + instance.write2DB(); + assertEquals(instance.getEntity().getVmUser().getId(), leader.getId()); + assertEquals(instance.getEntity().getTestProject().getId(), tp.getId()); + } + + /** + * Test of deleteUserTestProjectRole method, of class + * UserTestProjectRoleServer. + * + * @throws java.lang.Exception + */ + @Test + public void testDelete() throws Exception { + System.out.println("write2DB"); + createTestUsers(); + TestProject tp = TestHelper.createTestProject("Test"); + UserTestProjectRoleServer instance + = new UserTestProjectRoleServer(tp.getId(), leader.getId(), 1); + instance.write2DB(); + assertEquals(instance.getEntity().getVmUser().getId(), leader.getId()); + assertEquals(instance.getEntity().getTestProject().getId(), tp.getId()); + UserTestProjectRoleServer.deleteUserTestProjectRole(instance.getEntity()); + assertNull(new UserTestProjectRoleJpaController(DataBaseManager + .getEntityManagerFactory()) + .findUserTestProjectRole(instance.getUserTestProjectRolePK())); + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/server/core/VMUserServerTest.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/VMUserServerTest.java new file mode 100644 index 00000000..7ea84d9b --- /dev/null +++ b/VM-Core/src/test/java/com/validation/manager/core/server/core/VMUserServerTest.java @@ -0,0 +1,264 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.server.core; + +import com.validation.manager.core.VMException; +import com.validation.manager.core.tool.MD5; +import com.validation.manager.test.AbstractVMTestCase; +import java.util.Date; +import org.junit.Test; +import org.openide.util.Exceptions; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class VMUserServerTest extends AbstractVMTestCase { + + /** + * Test of write2DB method, of class VMUserServer. + * + * @throws java.lang.Exception + */ + @Test + public void testWrite2DB() throws Exception { + System.out.println("write2DB"); + String user = "test"; + String pw = "test"; + String name = "Test"; + String lastname = "User"; + String email = "test.user@test.com"; + VMUserServer instance = new VMUserServer(user, pw, name, lastname, email); + instance.write2DB(); + assertTrue(instance.getId() > 0); + assertEquals(instance.getId(), instance.getEntity().getId()); + assertEquals(user, instance.getEntity().getUsername()); + assertEquals(MD5.encrypt(pw), instance.getEntity().getPassword()); + assertEquals(name, instance.getEntity().getFirstName()); + assertEquals(lastname, instance.getEntity().getLastName()); + assertEquals(email, instance.getEntity().getEmail()); + assertEquals(1, instance.getHistoryList().size()); + assertEquals(1, instance.getEntity().getHistoryList().size()); + email = "test2@test.com"; + instance.setEmail(email); + instance.write2DB(); + int modifiedAmount = instance.getHistoryModificationList().size(); + assertEquals(instance.getId(), instance.getEntity().getId()); + assertEquals(user, instance.getEntity().getUsername()); + assertEquals(MD5.encrypt(pw), instance.getEntity().getPassword()); + assertEquals(name, instance.getEntity().getFirstName()); + assertEquals(lastname, instance.getEntity().getLastName()); + assertEquals(email, instance.getEntity().getEmail()); + assertEquals(2, instance.getHistoryList().size()); + assertEquals(2, instance.getEntity().getHistoryList().size()); + VMUserServer instance2 = new VMUserServer(user + 2, pw + 2, name + 2, + lastname + 2, email + 2); + instance2.write2DB(); + assertEquals(instance2.getId(), instance2.getEntity().getId()); + assertEquals(user + 2, instance2.getEntity().getUsername()); + assertEquals(MD5.encrypt(pw + 2), instance2.getEntity().getPassword()); + assertEquals(name + 2, instance2.getEntity().getFirstName()); + assertEquals(lastname + 2, instance2.getEntity().getLastName()); + assertEquals(email + 2, instance2.getEntity().getEmail()); + assertEquals(1, instance2.getHistoryList().size()); + assertEquals(1, instance2.getEntity().getHistoryList().size()); + instance2.setEmail(email + 3); + instance2.setModifierId(instance.getId()); + instance2.write2DB(); + assertEquals(instance2.getId(), instance2.getEntity().getId()); + assertEquals(user + 2, instance2.getEntity().getUsername()); + assertEquals(MD5.encrypt(pw + 2), instance2.getEntity().getPassword()); + assertEquals(name + 2, instance2.getEntity().getFirstName()); + assertEquals(lastname + 2, instance2.getEntity().getLastName()); + assertEquals(email + 3, instance2.getEntity().getEmail()); + assertEquals(2, instance2.getHistoryList().size()); + assertEquals(2, instance2.getEntity().getHistoryList().size()); + instance.update(); + assertEquals(modifiedAmount + 1, + instance.getHistoryModificationList().size()); + } + + /** + * Test of getVMUsers method, of class VMUserServer. + */ + @Test + public void testGetVMUsers() { + System.out.println("getVMUsers"); + assertTrue(!VMUserServer.getVMUsers().isEmpty()); + } + + /** + * Test of isPasswordUsable method, of class VMUserServer. + * + * @throws java.lang.Exception + */ + @Test + public void testIsPasswordUsable_String_boolean() throws Exception { + System.out.println("isPasswordUsable"); + String newPass = "test2"; + String user = "test"; + String pw = "test"; + String name = "Test"; + String lastname = "User"; + String email = "test.user@test.com"; + VMUserServer instance = new VMUserServer(user, pw, name, + lastname, email); + instance.write2DB(); + assertEquals(false, instance.isPasswordUsable(pw)); + assertEquals(true, instance.isPasswordUsable(newPass)); + } + + /** + * Test of validCredentials method, of class VMUserServer. + * + */ + @Test + public void testValidCredentials() { + System.out.println("validCredentials"); + String user = "test"; + String pw = "test"; + String name = "Test"; + String lastname = "User"; + String email = "test.user@test.com"; + VMUserServer instance; + try { + instance = new VMUserServer(user, pw, name, + lastname, email); + instance.write2DB(); + assertEquals(1, (int) instance.getEntity().getUserStatusId().getId()); + assertEquals(true, VMUserServer.validCredentials(user, pw, true)); + assertEquals(false, VMUserServer.validCredentials(user, pw + 1, true)); + assertEquals(false, VMUserServer.validCredentials(user + 1, pw + 1, + true)); + assertEquals(false, VMUserServer.validCredentials(user + 1, pw, true)); + assertEquals(true, VMUserServer.validCredentials(user, MD5.encrypt(pw), + false)); + assertEquals(false, VMUserServer.validCredentials(user, + MD5.encrypt(pw) + 1, false)); + try { + assertNotNull(new VMUserServer(user, pw)); + } + catch (VMException ex) { + Exceptions.printStackTrace(ex); + fail(); + } + int attempts = 0; + try { + assertEquals(attempts, instance.getAttempts()); + new VMUserServer(user, pw + 1); + instance.update(); + assertEquals(++attempts, instance.getEntity().getAttempts()); + } + catch (VMException ex) { + Exceptions.printStackTrace(ex); + fail(); + } + try { + new VMUserServer(user + 1, pw + 1); + //Wrong user name so can't be linked with account + instance.update(); + assertEquals(attempts, instance.getEntity().getAttempts()); + } + catch (VMException ex) { + Exceptions.printStackTrace(ex); + fail(); + } + try { + new VMUserServer(user + 1, pw); + //Wrong user name so can't be linked with account + instance.update(); + assertEquals(attempts, instance.getEntity().getAttempts()); + } + catch (VMException ex) { + Exceptions.printStackTrace(ex); + fail(); + } + //Lock the account + try { + for (int i = attempts; i < VMSettingServer + .getSetting("password.attempts").getIntVal(); i++) { + System.out.println("Attempts: " + attempts); + new VMUserServer(user, pw + 1); + instance.update(); + assertEquals(++attempts, instance.getEntity().getAttempts()); + assertEquals(1, (int) instance.getEntity().getUserStatusId().getId()); + } + new VMUserServer(user, pw + 1); + instance.update(); + assertEquals(++attempts, instance.getEntity().getAttempts()); + assertEquals(4, (int) instance.getEntity().getUserStatusId().getId()); + } + catch (VMException ex) { + Exceptions.printStackTrace(ex); + fail(); + } + } + catch (Exception ex) { + Exceptions.printStackTrace(ex); + fail(); + } + } + + /** + * Test of getPendingNotifications method, of class VMUserServer. + * + * @throws java.lang.Exception + */ + @Test + public void testGetPendingNotifications() throws Exception { + System.out.println("getPendingNotifications"); + String user = "test"; + String pw = "test"; + String name = "Test"; + String lastname = "User"; + String email = "test.user@test.com"; + VMUserServer instance = new VMUserServer(user, pw, name, + lastname, email); + instance.write2DB(); + assertEquals(0, instance.getPendingNotifications().size()); + NotificationServer ns = new NotificationServer(); + ns.setAuthor(new VMUserServer(1).getEntity()); + ns.setContent("Hello there!"); + ns.setCreationDate(new Date()); + ns.setNotificationType(NotificationTypeServer + .getType("notification.test.pending")); + ns.setTargetUser(instance.getEntity()); + ns.write2DB(); + assertEquals(1, instance.getPendingNotifications().size()); + ns.setAcknowledgeDate(new Date()); + ns.write2DB(); + assertEquals(0, instance.getPendingNotifications().size()); + } + + /** + * Test of getUser method, of class VMUserServer. + * + * @throws java.lang.Exception + */ + @Test + public void testGetUser() throws Exception { + System.out.println("getUser"); + String username = "test"; + String password = "test"; + String name = "Test"; + String lastname = "User"; + String email = "test.user@test.com"; + VMUserServer instance = new VMUserServer(username, password, name, + lastname, email); + instance.write2DB(); + assertNotNull(VMUserServer.getUser(username, password, true)); + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/server/core/VersionListenerIT.java b/VM-Core/src/test/java/com/validation/manager/core/server/core/VersionListenerIT.java deleted file mode 100644 index 2c8a6c9e..00000000 --- a/VM-Core/src/test/java/com/validation/manager/core/server/core/VersionListenerIT.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.validation.manager.core.server.core; - -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.db.Requirement; -import com.validation.manager.core.db.controller.RequirementJpaController; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.test.AbstractVMTestCase; -import static junit.framework.TestCase.*; -import org.junit.Test; -import org.openide.util.Exceptions; - -/** - * - * @author Javier Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class VersionListenerIT extends AbstractVMTestCase { - - /** - * Test of onChange method, of class VersionListener. - */ - @Test - public void testOnChange() { - System.out.println("onChange"); - DataBaseManager.setVersioningEnabled(true); - int count = 0; - int max = 10; - Requirement entity = new Requirement("SRS0001", "Description " - + (++count)); - RequirementJpaController controller - = new RequirementJpaController(DataBaseManager - .getEntityManagerFactory()); - assertEquals(0, controller.findRequirementEntities().size()); - controller.create(entity); - assertEquals(count, controller.findRequirementEntities().size()); - for (int i = 0; i < max; i++) { - try { - System.out.println("Modification: " + (i + 1)); - entity.setDescription("Description " + (++count)); - controller.edit(entity); - } - catch (NonexistentEntityException ex) { - Exceptions.printStackTrace(ex); - fail(); - } - catch (Exception ex) { - Exceptions.printStackTrace(ex); - fail(); - } - } - assertEquals(max + 1, controller.getRequirementCount()); - Requirement prev = null; - int x = 0; -// for (Requirement r : controller.findRequirementEntities()) { -// assertNotNull(r.getModificationTime()); -// assertNotNull(r.getDescription()); -// assertEquals(x == 0, r.isDirty()); -// if (x > 0) { -// //First one is the oldest one (version 0.0.max+1) -// if (prev != null) { -// assertTrue(r.compareTo(prev) > 0); -// } -// prev = r; -// } -// x++; -// } - } -} diff --git a/VM-Core/src/test/java/com/validation/manager/core/tool/ToolTest.java b/VM-Core/src/test/java/com/validation/manager/core/tool/ToolTest.java new file mode 100644 index 00000000..0187141a --- /dev/null +++ b/VM-Core/src/test/java/com/validation/manager/core/tool/ToolTest.java @@ -0,0 +1,100 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.validation.manager.core.tool; + +import com.validation.manager.core.server.core.TestCaseExecutionServer; +import com.validation.manager.core.server.core.TestCaseServer; +import com.validation.manager.test.AbstractVMTestCase; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import javax.swing.ImageIcon; +import static junit.framework.TestCase.*; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ToolTest extends AbstractVMTestCase { + + /** + * Test of createImageIcon method, of class Tool. + */ + @Test + public void testCreateImageIcon_String_String() { + System.out.println("createImageIcon"); + String path = "/com/validation/manager/resources/icons/VMSmall.png"; + String description = "Test"; + ImageIcon result = Tool.createImageIcon(path, description); + assertNotNull(result); + } + + /** + * Test of createImageIcon method, of class Tool. + */ + @Test + public void testCreateImageIcon_3args() { + System.out.println("createImageIcon"); + String path = "/com/validation/manager/resources/icons/VMSmall.png"; + String description = "Test"; + ImageIcon result = Tool.createImageIcon(path, description, Tool.class); + assertNotNull(result); + } + + /** + * Test of removeDuplicates method, of class Tool. + */ + @Test + public void testRemoveDuplicates() { + System.out.println("removeDuplicates"); + List list = new ArrayList<>(); + list.add(1); + list.add(2); + list.add(2); + list.add(2); + list.add(2); + list.add(3); + Tool.removeDuplicates(list); + assertEquals(3, list.size()); + } + + /** + * Test of extractTCE method, of class Tool. + * + * @throws java.lang.Exception + */ + @Test + public void testExtractTCE() throws Exception { + System.out.println("extractTCE"); + TestCaseExecutionServer tce = new TestCaseExecutionServer("Test Name", + "Test Scope"); + TestCaseServer tc = new TestCaseServer("Test Case", new Date()); + tc.write2DB(); + tce.addTestCase(tc); + tce.write2DB(); + String key = "tce-" + tce.getId() + "-" + tc.getId(); + TCEExtraction r = Tool.extractTCE(key); + assertEquals(tce.getId(), r.getTestCaseExecution().getId()); + try { + Tool.extractTCE(key + 1); + fail(); + } + catch (Exception ex) { + //Expected + } + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/tool/table/extractor/TableExtractorTest.java b/VM-Core/src/test/java/com/validation/manager/core/tool/table/extractor/TableExtractorTest.java index 62979467..baa4c9bc 100644 --- a/VM-Core/src/test/java/com/validation/manager/core/tool/table/extractor/TableExtractorTest.java +++ b/VM-Core/src/test/java/com/validation/manager/core/tool/table/extractor/TableExtractorTest.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,77 +13,92 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.core.tool.table.extractor; - -import java.io.File; -import static java.lang.System.getProperty; -import java.util.List; -import javax.swing.table.DefaultTableModel; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class TableExtractorTest { - - /** - * Test of extractTables method, of class TableExtractor. - * - * @throws java.lang.Exception - */ - @Test - public void testExtractTables() throws Exception { - System.out.println("extractTables"); - String name = TableExtractorTest.class.getCanonicalName(); - name = name.substring(0, name.lastIndexOf(".")); - name = name.replace(".", getProperty("file.separator")); - File file = new File(getProperty("user.dir") - + getProperty("file.separator") + "src" - + getProperty("file.separator") + "test" - + getProperty("file.separator") + "java" - + getProperty("file.separator") - + name - + getProperty("file.separator") + "Tables.docx"); - assert file.exists(); - TableExtractor te = new TableExtractor(file); - List tables = te.extractTables(); - assertEquals(2, tables.size()); - for (DefaultTableModel model : tables) { - //Has header - assertEquals(4, model.getRowCount()); - assertEquals(5, model.getColumnCount()); - } - file = new File(getProperty("user.dir") - + getProperty("file.separator") + "src" - + getProperty("file.separator") + "test" - + getProperty("file.separator") + "java" - + getProperty("file.separator") - + name - + getProperty("file.separator") + "Tables.xls"); - assert file.exists(); - te = new TableExtractor(file); - tables = te.extractTables(); - assertEquals(1, tables.size()); - for (DefaultTableModel model : tables) { - assertEquals(3, model.getRowCount()); - assertEquals(3, model.getColumnCount()); - } - file = new File(getProperty("user.dir") - + getProperty("file.separator") + "src" - + getProperty("file.separator") + "test" - + getProperty("file.separator") + "java" - + getProperty("file.separator") - + name - + getProperty("file.separator") + "Tables.xlsx"); - assert file.exists(); - te = new TableExtractor(file); - tables = te.extractTables(); - assertEquals(1, tables.size()); - for (DefaultTableModel model : tables) { - assertEquals(3, model.getRowCount()); - assertEquals(3, model.getColumnCount()); - } - } -} +package com.validation.manager.core.tool.table.extractor; + +import java.io.File; +import static java.lang.System.getProperty; +import java.util.List; +import javax.swing.table.DefaultTableModel; +import static org.junit.Assert.*; +import org.junit.Test; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class TableExtractorTest { + + /** + * Test of extractTables method, of class TableExtractor. + * + * @throws java.lang.Exception + */ + @Test + public void testExtractTables() throws Exception { + System.out.println("extractTables"); + String name = TableExtractorTest.class.getCanonicalName(); + name = name.substring(0, name.lastIndexOf(".")); + name = name.replace(".", getProperty("file.separator")); + File file = new File(getProperty("user.dir") + + getProperty("file.separator") + "src" + + getProperty("file.separator") + "test" + + getProperty("file.separator") + "java" + + getProperty("file.separator") + + name + + getProperty("file.separator") + "Tables.docx"); + assert file.exists(); + TableExtractor te = new TableExtractor(file); + List tables = te.extractTables(); + assertEquals(2, tables.size()); + for (DefaultTableModel model : tables) { + //Has header + assertEquals(4, model.getRowCount()); + assertEquals(5, model.getColumnCount()); + } + file = new File(getProperty("user.dir") + + getProperty("file.separator") + "src" + + getProperty("file.separator") + "test" + + getProperty("file.separator") + "java" + + getProperty("file.separator") + + name + + getProperty("file.separator") + "Tables.xls"); + assert file.exists(); + te = new TableExtractor(file); + tables = te.extractTables(); + assertEquals(1, tables.size()); + for (DefaultTableModel model : tables) { + assertEquals(3, model.getRowCount()); + assertEquals(3, model.getColumnCount()); + } + file = new File(getProperty("user.dir") + + getProperty("file.separator") + "src" + + getProperty("file.separator") + "test" + + getProperty("file.separator") + "java" + + getProperty("file.separator") + + name + + getProperty("file.separator") + "Tables.xlsx"); + assert file.exists(); + te = new TableExtractor(file); + tables = te.extractTables(); + assertEquals(1, tables.size()); + for (DefaultTableModel model : tables) { + assertEquals(3, model.getRowCount()); + assertEquals(3, model.getColumnCount()); + } + file = new File(getProperty("user.dir") + + getProperty("file.separator") + "src" + + getProperty("file.separator") + "test" + + getProperty("file.separator") + "java" + + getProperty("file.separator") + + name + + getProperty("file.separator") + "Tables.xlsm"); + assert file.exists(); + te = new TableExtractor(file); + tables = te.extractTables(); + assertEquals(1, tables.size()); + for (DefaultTableModel model : tables) { + assertEquals(3, model.getRowCount()); + assertEquals(3, model.getColumnCount()); + } + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/core/tool/table/extractor/Tables.xlsm b/VM-Core/src/test/java/com/validation/manager/core/tool/table/extractor/Tables.xlsm new file mode 100644 index 00000000..e72a00a6 Binary files /dev/null and b/VM-Core/src/test/java/com/validation/manager/core/tool/table/extractor/Tables.xlsm differ diff --git a/VM-Core/src/test/java/com/validation/manager/test/AbstractVMTestCase.java b/VM-Core/src/test/java/com/validation/manager/test/AbstractVMTestCase.java index b677a25d..ae7f3bb4 100755 --- a/VM-Core/src/test/java/com/validation/manager/test/AbstractVMTestCase.java +++ b/VM-Core/src/test/java/com/validation/manager/test/AbstractVMTestCase.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,203 +13,195 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.test; - -import com.validation.manager.core.DBState; -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.history.Auditable; -import com.validation.manager.core.db.History; -import com.validation.manager.core.db.HistoryField; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.controller.VmUserJpaController; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.history.Versionable; -import com.validation.manager.core.server.core.VMUserServer; -import static com.validation.manager.core.tool.MD5.encrypt; -import static com.validation.manager.test.TestHelper.deleteUser; -import static java.lang.Class.forName; -import java.lang.reflect.Field; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.sql.DataSource; -import junit.framework.TestCase; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.h2.jdbcx.JdbcDataSource; -import org.junit.After; -import org.junit.Before; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public abstract class AbstractVMTestCase extends TestCase { - - protected VmUser designer, tester, leader; - /** - * Parameters for queries. - */ - protected HashMap parameters = new HashMap<>(); - /** - * Query results. - */ - protected List result; - public static boolean deleteDatabase = true; - private static final Logger LOG - = Logger.getLogger(AbstractVMTestCase.class.getSimpleName()); - - @Before - @Override - protected void setUp() throws Exception { - LOG.info("Setting up database!"); - DataBaseManager.setPersistenceUnitName("TestVMPU"); - assertEquals(DBState.VALID, DataBaseManager.getState()); - postSetUp(); - LOG.info("Done!"); - } - - @After - @Override - protected void tearDown() throws Exception { - LOG.info("Deleting database!"); - deleteTestUsers(); - Connection conn = null; - Statement stmt = null; - try { - Map properties - = DataBaseManager.getEntityManagerFactory() - .getProperties(); - DataSource ds = new JdbcDataSource(); - ((JdbcDataSource) ds).setPassword((String) properties - .get("javax.persistence.jdbc.password")); - ((JdbcDataSource) ds).setUser((String) properties - .get("javax.persistence.jdbc.user")); - ((JdbcDataSource) ds).setURL((String) properties - .get("javax.persistence.jdbc.url")); - //Load the H2 driver - forName("org.h2.Driver"); - conn = ds.getConnection(); - stmt = conn.createStatement(); - stmt.executeUpdate("DROP ALL OBJECTS DELETE FILES"); - } - catch (SQLException | ClassNotFoundException ex) { - LOG.log(Level.SEVERE, - null, ex); - } - finally { - try { - if (stmt != null) { - stmt.close(); - } - } - catch (SQLException ex) { - fail(); - } - try { - if (conn != null) { - conn.close(); - } - } - catch (SQLException ex) { - fail(); - } - } - DataBaseManager.close(); - postTearDown(); - LOG.info("Done!"); - } - - protected void createTestUsers() { - try { - VMUserServer temp = new VMUserServer("test1", - "password", "test@test.com", "first", "last"); - temp.write2DB(); - designer = new VmUserJpaController(DataBaseManager - .getEntityManagerFactory()) - .findVmUser(temp.getId()); - temp = new VMUserServer("test2", - "password", "test@test.com", "first", "last"); - temp.write2DB(); - tester = new VmUserJpaController(DataBaseManager - .getEntityManagerFactory()) - .findVmUser(temp.getId()); - temp = new VMUserServer("test3", - encrypt("password"), "test@test.com", "first", "last"); - temp.write2DB(); - leader = new VmUserJpaController(DataBaseManager - .getEntityManagerFactory()) - .findVmUser(temp.getId()); - LOG.log(Level.INFO, "Done!"); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - - /** - * Code to be performed after set up. - */ - protected void postSetUp() { - - } - - /** - * Code to be performed after set teardown. - */ - protected void postTearDown() { - - } - - protected void deleteTestUsers() { - try { - deleteUser(designer); - deleteUser(tester); - deleteUser(leader); - designer = null; - tester = null; - leader = null; - } - catch (IllegalOrphanException | NonexistentEntityException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - - public List getAuditableFields(Versionable v) { - List r = new ArrayList<>(); - FieldUtils.getFieldsListWithAnnotation(v.getClass(), Auditable.class) - .stream().filter((field) - -> (field.isAnnotationPresent(Auditable.class))) - .forEachOrdered((field) -> { - r.add(field); - }); - return r; - } - - public boolean checkHistory(Versionable v) { - History current = v.getHistoryList().get(v.getHistoryList().size() - 1); - List af = getAuditableFields(v); - assertEquals(af.size(), current.getHistoryFieldList().size()); - assertTrue(af.size() > 0); - for (HistoryField hf : current.getHistoryFieldList()) { - try { - //Compare audit field vs. the record in history. - Object o = FieldUtils.readField(FieldUtils.getField(v.getClass(), - hf.getFieldName(), true), v); - if (!o.toString().equals(hf.getFieldValue())) { - return false; - } - } - catch (SecurityException | IllegalArgumentException | IllegalAccessException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - return true; - } -} +package com.validation.manager.test; + +import com.validation.manager.core.DBState; +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.db.History; +import com.validation.manager.core.db.HistoryField; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.VmUserJpaController; +import com.validation.manager.core.history.Auditable; +import com.validation.manager.core.history.Versionable; +import com.validation.manager.core.server.core.VMUserServer; +import static com.validation.manager.core.tool.MD5.encrypt; +import static java.lang.Class.forName; +import java.lang.reflect.Field; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.sql.DataSource; +import junit.framework.TestCase; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.h2.jdbcx.JdbcDataSource; +import org.junit.After; +import org.junit.Before; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public abstract class AbstractVMTestCase extends TestCase { + + protected VmUser designer, tester, leader; + /** + * Parameters for queries. + */ + protected HashMap parameters = new HashMap<>(); + /** + * Query results. + */ + protected List result; + public static boolean deleteDatabase = true; + private static final Logger LOG + = Logger.getLogger(AbstractVMTestCase.class.getSimpleName()); + + @Before + @Override + protected void setUp() throws Exception { + LOG.info("Setting up database!"); + DataBaseManager.setPersistenceUnitName("TestVMPU"); + assertEquals(DBState.VALID, DataBaseManager.getState()); + postSetUp(); + LOG.info("Done!"); + } + + @After + @Override + protected void tearDown() throws Exception { + LOG.info("Deleting database!"); + deleteTestUsers(); + Connection conn = null; + Statement stmt = null; + try { + Map properties + = DataBaseManager.getEntityManagerFactory() + .getProperties(); + DataSource ds = new JdbcDataSource(); + ((JdbcDataSource) ds).setPassword((String) properties + .get("javax.persistence.jdbc.password")); + ((JdbcDataSource) ds).setUser((String) properties + .get("javax.persistence.jdbc.user")); + ((JdbcDataSource) ds).setURL((String) properties + .get("javax.persistence.jdbc.url")); + //Load the H2 driver + forName("org.h2.Driver"); + conn = ds.getConnection(); + stmt = conn.createStatement(); + stmt.executeUpdate("DROP ALL OBJECTS DELETE FILES"); + } + catch (SQLException | ClassNotFoundException ex) { + LOG.log(Level.SEVERE, + null, ex); + } + finally { + try { + if (stmt != null) { + stmt.close(); + } + } + catch (SQLException ex) { + fail(); + } + try { + if (conn != null) { + conn.close(); + } + } + catch (SQLException ex) { + fail(); + } + } + DataBaseManager.close(); + postTearDown(); + LOG.info("Done!"); + } + + protected void createTestUsers() { + try { + VMUserServer temp = new VMUserServer("test1", + "password", "test@test.com", "first", "last"); + temp.write2DB(); + designer = new VmUserJpaController(DataBaseManager + .getEntityManagerFactory()) + .findVmUser(temp.getId()); + temp = new VMUserServer("test2", + "password", "test@test.com", "first", "last"); + temp.write2DB(); + tester = new VmUserJpaController(DataBaseManager + .getEntityManagerFactory()) + .findVmUser(temp.getId()); + temp = new VMUserServer("test3", + encrypt("password"), "test@test.com", "first", "last"); + temp.write2DB(); + leader = new VmUserJpaController(DataBaseManager + .getEntityManagerFactory()) + .findVmUser(temp.getId()); + LOG.log(Level.INFO, "Done!"); + } + catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + + /** + * Code to be performed after set up. + */ + protected void postSetUp() { + + } + + /** + * Code to be performed after set teardown. + */ + protected void postTearDown() { + + } + + protected void deleteTestUsers() { + designer = null; + tester = null; + leader = null; + } + + public List getAuditableFields(Versionable v) { + List r = new ArrayList<>(); + FieldUtils.getFieldsListWithAnnotation(v.getClass(), Auditable.class) + .stream().filter((field) + -> (field.isAnnotationPresent(Auditable.class))) + .forEachOrdered((field) -> { + r.add(field); + }); + return r; + } + + public boolean checkHistory(Versionable v) { + History current = v.getHistoryList().get(v.getHistoryList().size() - 1); + List af = getAuditableFields(v); + assertEquals(af.size(), current.getHistoryFieldList().size()); + assertTrue(af.size() > 0); + for (HistoryField hf : current.getHistoryFieldList()) { + try { + //Compare audit field vs. the record in history. + Object o = FieldUtils.readField(FieldUtils.getField(v.getClass(), + hf.getFieldName(), true), v); + if (!Versionable.fieldMatchHistory(hf, o)) { + return false; + } + } + catch (SecurityException | IllegalArgumentException | IllegalAccessException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + v.getHistoryList().forEach(h -> { + LOG.info(h.toString()); + }); + return true; + } +} diff --git a/VM-Core/src/test/java/com/validation/manager/test/TestHelper.java b/VM-Core/src/test/java/com/validation/manager/test/TestHelper.java index 695c2a5e..67712e52 100755 --- a/VM-Core/src/test/java/com/validation/manager/test/TestHelper.java +++ b/VM-Core/src/test/java/com/validation/manager/test/TestHelper.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,223 +13,200 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.validation.manager.test; - -import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; -import com.validation.manager.core.VMException; -import com.validation.manager.core.db.Project; -import com.validation.manager.core.db.Requirement; -import com.validation.manager.core.db.RequirementSpec; -import com.validation.manager.core.db.RequirementSpecNode; -import com.validation.manager.core.db.RequirementSpecNodePK; -import com.validation.manager.core.db.Step; -import com.validation.manager.core.db.TestCase; -import com.validation.manager.core.db.TestPlan; -import com.validation.manager.core.db.TestProject; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.controller.ProjectJpaController; -import com.validation.manager.core.db.controller.RequirementJpaController; -import com.validation.manager.core.db.controller.UserStatusJpaController; -import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; -import com.validation.manager.core.server.core.ProjectServer; -import com.validation.manager.core.server.core.RequirementServer; -import com.validation.manager.core.server.core.RequirementSpecNodeServer; -import com.validation.manager.core.server.core.RequirementSpecServer; -import com.validation.manager.core.server.core.StepServer; -import com.validation.manager.core.server.core.TestCaseServer; -import com.validation.manager.core.server.core.TestPlanServer; -import com.validation.manager.core.server.core.TestProjectServer; -import com.validation.manager.core.server.core.VMUserServer; -import java.util.ArrayList; -import java.util.Date; -import java.util.logging.Level; -import java.util.logging.Logger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class TestHelper { - - private static final Logger LOG - = Logger.getLogger(TestHelper.class.getName()); - - public static VmUser createUser(String name, String pass, String email, - String first, String last) throws Exception { - VMUserServer temp = new VMUserServer(name, - pass, first, last, email); - temp.setUserStatusId(new UserStatusJpaController( - getEntityManagerFactory()).findUserStatus(1)); - temp.write2DB(); - return temp.getEntity(); - } - - public static void deleteUser(VmUser user) throws NonexistentEntityException, - IllegalOrphanException { - if (user != null) { - VMUserServer.deleteUser(user); - } - } - - public static Project createProject(String name, String notes) { - ProjectServer ps = new ProjectServer(name, notes); - try { - ps.write2DB(); - } - catch (IllegalOrphanException ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - catch (NonexistentEntityException ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - assertTrue(ps.getEntity() != null); - return ps.getEntity(); - } - - public static void destroyProject(Project p) throws IllegalOrphanException, - NonexistentEntityException, VMException { - ProjectServer.deleteProject(p); - assertTrue(new ProjectJpaController( - getEntityManagerFactory()).findProject(p.getId()) == null); - } - - public static TestCase createTestCase(String name, String summary) - throws PreexistingEntityException, Exception { - TestCaseServer tc = new TestCaseServer(name, new Date()); - tc.setRiskControlHasTestCaseList(new ArrayList<>()); - tc.setActive(true); - tc.setIsOpen(true); - tc.setSummary(summary.getBytes()); - tc.write2DB(); - return tc.getEntity(); - } - - public static Requirement createRequirement(String id, String desc, - RequirementSpecNodePK p, String notes, int requirementType, - int requirementStatus) throws Exception { - RequirementServer req = new RequirementServer(id, desc, p, notes, - requirementType, requirementStatus); - req.write2DB(); - assert req.getEntity().getRequirementSpecNode() != null; - return req.getEntity(); - } - - public static void destroyRequirement(Requirement r) - throws NonexistentEntityException { - try { - RequirementServer.deleteRequirement(r); - assertTrue(new RequirementJpaController( - getEntityManagerFactory()) - .findRequirement(r.getId()) == null); - } - catch (IllegalOrphanException ex) { - LOG.log(Level.SEVERE, null, ex); - fail(); - } - } - - public static TestCase addStep(TestCase tc, int sequence, - String text, String note, String result) throws PreexistingEntityException, - Exception { - TestCaseServer tcs = new TestCaseServer(tc.getId()); - int amount = tcs.getStepList().size(); - tcs.addStep(sequence, text, note, note, null); - assertEquals(amount + 1, tcs.getStepList().size()); - return tcs.getEntity(); - } - - public static TestProject createTestProject(String name) - throws IllegalOrphanException, NonexistentEntityException, - Exception { - TestProjectServer tps = new TestProjectServer("Test Project", true); - tps.write2DB(); - return tps.getEntity(); - } - - public static TestPlan createTestPlan(TestProject tp, String notes, - boolean active, boolean open) throws PreexistingEntityException, - Exception { - TestPlanServer plan = new TestPlanServer(tp, active, open); - plan.setNotes(notes); - plan.setTestProject(tp); - plan.write2DB(); - tp.getTestPlanList().add(plan.getEntity()); - return plan.getEntity(); - } - - public static void addTestCaseToPlan(TestPlan plan, TestCase testCase) - throws PreexistingEntityException, Exception { - int testInPlan = plan.getTestCaseList().size(); - TestPlanServer tps = new TestPlanServer(plan); - tps.getTestCaseList().add(testCase); - tps.write2DB(); - tps.update(plan, tps); - testCase.getTestPlanList().add(plan); - assertTrue(plan.getTestCaseList().size() > testInPlan); - } - - public static RequirementSpec createRequirementSpec(String name, - String description, Project project, int specLevelId) - throws Exception { - RequirementSpecServer rss = new RequirementSpecServer(name, description, - project.getId(), specLevelId); - rss.write2DB(); - project.getRequirementSpecList().add(rss.getEntity()); - new ProjectServer(project).write2DB(); - return rss.getEntity(); - } - - public static RequirementSpecNode createRequirementSpecNode( - RequirementSpec rss, String name, String description, String scope) - throws Exception { - RequirementSpecNodeServer rsns = new RequirementSpecNodeServer(rss, - name, description, scope); - rsns.write2DB(); - return rsns.getEntity(); - } - - public static void addTestProjectToProject(TestProject tp, Project project) - throws IllegalOrphanException, NonexistentEntityException, - Exception { - ProjectServer ps = new ProjectServer(project); - int current = ps.getTestProjectList().size(); - ps.getTestProjectList().add(tp); - ps.write2DB(); - assertTrue(ps.getEntity().getTestProjectList().size() > current); - tp.getProjectList().add(project); - } - - public static void addRequirementToStep(Step step, Requirement req) - throws Exception { - StepServer ss = new StepServer(step); - ss.addRequirement(req); - ss.write2DB(); - } - - public static Project addProject(Project root, String name, String notes) - throws NonexistentEntityException, Exception { - Project sub = createProject(name, notes); - ProjectServer ps = new ProjectServer(root); - ps.getProjectList().add(sub); - ps.write2DB(); - return new ProjectServer(sub).getEntity(); - } - - public static Requirement addChildToRequirement(Requirement parent, - Requirement child) throws Exception { - RequirementServer rs = new RequirementServer(parent); - rs.addChildRequirement(child); - return rs.getEntity(); - } -} +package com.validation.manager.test; + +import static com.validation.manager.core.DataBaseManager.getEntityManagerFactory; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.Project; +import com.validation.manager.core.db.Requirement; +import com.validation.manager.core.db.RequirementSpec; +import com.validation.manager.core.db.RequirementSpecNode; +import com.validation.manager.core.db.RequirementSpecNodePK; +import com.validation.manager.core.db.Step; +import com.validation.manager.core.db.TestCase; +import com.validation.manager.core.db.TestPlan; +import com.validation.manager.core.db.TestProject; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.RequirementJpaController; +import com.validation.manager.core.db.controller.UserStatusJpaController; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.db.controller.exceptions.PreexistingEntityException; +import com.validation.manager.core.server.core.ProjectServer; +import com.validation.manager.core.server.core.RequirementServer; +import com.validation.manager.core.server.core.RequirementSpecNodeServer; +import com.validation.manager.core.server.core.RequirementSpecServer; +import com.validation.manager.core.server.core.StepServer; +import com.validation.manager.core.server.core.TestCaseServer; +import com.validation.manager.core.server.core.TestPlanServer; +import com.validation.manager.core.server.core.TestProjectServer; +import com.validation.manager.core.server.core.VMUserServer; +import java.util.ArrayList; +import java.util.Date; +import java.util.logging.Level; +import java.util.logging.Logger; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class TestHelper { + + private static final Logger LOG + = Logger.getLogger(TestHelper.class.getName()); + + public static VmUser createUser(String name, String pass, String email, + String first, String last) throws Exception { + VMUserServer temp = new VMUserServer(name, + pass, first, last, email); + temp.setUserStatusId(new UserStatusJpaController( + getEntityManagerFactory()).findUserStatus(1)); + temp.write2DB(); + return temp.getEntity(); + } + + public static Project createProject(String name, String notes) { + ProjectServer ps = new ProjectServer(name, notes); + try { + ps.write2DB(); + } + catch (VMException ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + assertTrue(ps.getEntity() != null); + return ps.getEntity(); + } + + public static TestCase createTestCase(String name, String summary) + throws PreexistingEntityException, Exception { + TestCaseServer tc = new TestCaseServer(name, new Date()); + tc.setRiskControlHasTestCaseList(new ArrayList<>()); + tc.setActive(true); + tc.setIsOpen(true); + tc.setSummary(summary.getBytes()); + tc.write2DB(); + return tc.getEntity(); + } + + public static Requirement createRequirement(String id, String desc, + RequirementSpecNodePK p, String notes, int requirementType, + int requirementStatus) throws Exception { + RequirementServer req = new RequirementServer(id, desc, p, notes, + requirementType, requirementStatus); + req.write2DB(); + assert req.getEntity().getRequirementSpecNode() != null; + return req.getEntity(); + } + + public static void destroyRequirement(Requirement r) + throws NonexistentEntityException { + try { + RequirementServer.deleteRequirement(r); + assertTrue(new RequirementJpaController( + getEntityManagerFactory()) + .findRequirement(r.getId()) == null); + } + catch (IllegalOrphanException ex) { + LOG.log(Level.SEVERE, null, ex); + fail(); + } + } + + public static TestCase addStep(TestCase tc, int sequence, + String text, String note, String result) throws PreexistingEntityException, + Exception { + TestCaseServer tcs = new TestCaseServer(tc.getId()); + int amount = tcs.getStepList().size(); + tcs.addStep(sequence, text, note, note, null); + assertEquals(amount + 1, tcs.getStepList().size()); + return tcs.getEntity(); + } + + public static TestProject createTestProject(String name) + throws IllegalOrphanException, NonexistentEntityException, + Exception { + TestProjectServer tps = new TestProjectServer("Test Project", true); + tps.write2DB(); + return tps.getEntity(); + } + + public static TestPlan createTestPlan(TestProject tp, String notes, + boolean active, boolean open) throws PreexistingEntityException, + Exception { + TestPlanServer plan = new TestPlanServer(tp, active, open); + plan.setNotes(notes); + plan.setTestProject(tp); + plan.write2DB(); + tp.getTestPlanList().add(plan.getEntity()); + return plan.getEntity(); + } + + public static void addTestCaseToPlan(TestPlan plan, TestCase testCase) + throws PreexistingEntityException, Exception { + int testInPlan = plan.getTestCaseList().size(); + TestPlanServer tps = new TestPlanServer(plan); + tps.getTestCaseList().add(testCase); + tps.write2DB(); + tps.update(plan, tps); + testCase.getTestPlanList().add(plan); + assertTrue(plan.getTestCaseList().size() > testInPlan); + } + + public static RequirementSpec createRequirementSpec(String name, + String description, Project project, int specLevelId) + throws Exception { + RequirementSpecServer rss = new RequirementSpecServer(name, description, + project.getId(), specLevelId); + rss.write2DB(); + project.getRequirementSpecList().add(rss.getEntity()); + new ProjectServer(project).write2DB(); + return rss.getEntity(); + } + + public static RequirementSpecNode createRequirementSpecNode( + RequirementSpec rss, String name, String description, String scope) + throws Exception { + RequirementSpecNodeServer rsns = new RequirementSpecNodeServer(rss, + name, description, scope); + rsns.write2DB(); + return rsns.getEntity(); + } + + public static void addTestProjectToProject(TestProject tp, Project project) + throws IllegalOrphanException, NonexistentEntityException, + Exception { + ProjectServer ps = new ProjectServer(project); + int current = ps.getTestProjectList().size(); + ps.getTestProjectList().add(tp); + ps.write2DB(); + assertTrue(ps.getEntity().getTestProjectList().size() > current); + tp.getProjectList().add(project); + } + + public static void addRequirementToStep(Step step, Requirement req) + throws Exception { + StepServer ss = new StepServer(step); + ss.addRequirement(req); + ss.write2DB(); + } + + public static Project addProject(Project root, String name, String notes) + throws NonexistentEntityException, Exception { + Project sub = createProject(name, notes); + ProjectServer ps = new ProjectServer(root); + ps.getProjectList().add(sub); + ps.write2DB(); + return new ProjectServer(sub).getEntity(); + } + + public static Requirement addChildToRequirement(Requirement parent, + Requirement child) throws Exception { + RequirementServer rs = new RequirementServer(parent); + rs.addChildRequirement(child); + return rs.getEntity(); + } +} diff --git a/Validation-Manager-Web/pom.xml b/Validation-Manager-Web/pom.xml index b1968668..ba06e2c3 100644 --- a/Validation-Manager-Web/pom.xml +++ b/Validation-Manager-Web/pom.xml @@ -4,7 +4,7 @@ Validation-Manager net.sourceforge.javydreamercsw - 0.3.2 + 0.3.3 Validation-Manager-Web @@ -112,6 +112,11 @@ jodconverter-core 4.0.0-RELEASE + + org.apache.poi + poi-scratchpad + ${poi.version} + com.vaadin @@ -136,18 +141,13 @@ pl.pdfviewer pdfviewer - 1.3.1 + 1.3.2 org.vaadin.addons imageviewer 0.6.0.v8 - - org.apache.poi - poi-scratchpad - ${poi.version} - de.steinwedel.vaadin.addon messagebox diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/LoginDialog.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/LoginDialog.java index b3260abe..94d59fd1 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/LoginDialog.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/LoginDialog.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,141 +13,191 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web; - -import com.vaadin.data.validator.StringLengthValidator; -import com.vaadin.event.Action; -import com.vaadin.event.Action.Handler; -import com.vaadin.event.ShortcutAction; -import com.vaadin.server.Page; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Notification; -import com.vaadin.ui.PasswordField; -import com.vaadin.ui.TextField; -import com.validation.manager.core.api.internationalization.InternationalizationProvider; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.server.core.VMUserServer; -import org.openide.util.Lookup; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@SuppressWarnings("serial") -public final class LoginDialog extends VMWindow { - - private final ShortcutAction enterKey - = new ShortcutAction(Lookup.getDefault() - .lookup(InternationalizationProvider.class) - .translate("general.login"), - ShortcutAction.KeyCode.ENTER, null); - - private final TextField name = new TextField(Lookup.getDefault() - .lookup(InternationalizationProvider.class) - .translate("general.username")); - private final PasswordField password = new PasswordField(Lookup.getDefault() - .lookup(InternationalizationProvider.class) - .translate("general.password")); - - private final Button loginButton = new Button(Lookup.getDefault() - .lookup(InternationalizationProvider.class) - .translate("general.login"), - (ClickEvent event) -> { - tryToLogIn(); - }); - - private final Button cancelButton = new Button(Lookup.getDefault() - .lookup(InternationalizationProvider.class) - .translate("general.cancel"), - (ClickEvent event) -> { - LoginDialog.this.close(); - }); - - public LoginDialog(ValidationManagerUI menu) { - super(menu, Lookup.getDefault() - .lookup(InternationalizationProvider.class) - .translate("general.login")); - init(); - } - - public void init() { - //Layout - FormLayout layout = new FormLayout(); - setContent(layout); - HorizontalLayout hlayout = new HorizontalLayout(); - hlayout.addComponent(loginButton); - hlayout.addComponent(cancelButton); - layout.addComponent(name); - layout.addComponent(password); - name.focus(); - StringLengthValidator nameVal = new StringLengthValidator( - Lookup.getDefault() - .lookup(InternationalizationProvider.class). - translate("password.length.message")); - nameVal.setMinLength(5); - name.addValidator(nameVal); - name.setImmediate(true); - StringLengthValidator passVal = new StringLengthValidator( - Lookup.getDefault() - .lookup(InternationalizationProvider.class). - translate("password.empty.message")); - passVal.setMinLength(3); - password.addValidator(passVal); - password.setImmediate(true); - layout.addComponent(hlayout); - layout.setComponentAlignment(name, Alignment.TOP_LEFT); - layout.setComponentAlignment(password, Alignment.MIDDLE_LEFT); - layout.setComponentAlignment(hlayout, Alignment.BOTTOM_LEFT); - layout.setSpacing(true); - layout.setMargin(true); - - // Keyboard navigation - enter key is a shortcut to login - addActionHandler(new Handler() { - @Override - public Action[] getActions(Object target, Object sender) { - return new Action[]{enterKey}; - } - - @Override - public void handleAction(Action action, Object sender, - Object target) { - tryToLogIn(); - } - }); - } - - private void tryToLogIn() { - if (VMUserServer.validCredentials(name.getValue(), - password.getValue(), true)) { - VmUser user - = VMUserServer.getUser(name.getValue(), - password.getValue(), true); - if (menu != null) { - menu.setUser(new VMUserServer(user)); - } - close(); - } else { - if (menu != null) { - menu.setUser(null); - } - new Notification(Lookup.getDefault() - .lookup(InternationalizationProvider.class). - translate("general.login.invalid.title"), - Lookup.getDefault() - .lookup(InternationalizationProvider.class). - translate("general.login.invalid.message"), - Notification.Type.WARNING_MESSAGE, true) - .show(Page.getCurrent()); - password.setValue(""); - } - } - - public void clear() { - name.clear(); - password.clear(); - } -} +package net.sourceforge.javydreamercsw.validation.manager.web; + +import com.vaadin.data.validator.StringLengthValidator; +import com.vaadin.event.Action; +import com.vaadin.event.Action.Handler; +import com.vaadin.event.ShortcutAction; +import com.vaadin.server.Page; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.FormLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Notification; +import com.vaadin.ui.PasswordField; +import com.vaadin.ui.TextField; +import com.vaadin.ui.UI; +import com.validation.manager.core.VMException; +import com.validation.manager.core.VMUI; +import com.validation.manager.core.api.internationalization.InternationalizationProvider; +import com.validation.manager.core.server.core.VMUserServer; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.openide.util.Lookup; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@SuppressWarnings("serial") +public final class LoginDialog extends VMWindow { + + private static final InternationalizationProvider TRANSLATOR + = Lookup.getDefault().lookup(InternationalizationProvider.class); + private static final Logger LOG + = Logger.getLogger(LoginDialog.class.getSimpleName()); + private final ShortcutAction enterKey + = new ShortcutAction(Lookup.getDefault() + .lookup(InternationalizationProvider.class) + .translate("general.login"), + ShortcutAction.KeyCode.ENTER, null); + + private final TextField name = new TextField(Lookup.getDefault() + .lookup(InternationalizationProvider.class) + .translate("general.username")); + private final PasswordField password = new PasswordField(Lookup.getDefault() + .lookup(InternationalizationProvider.class) + .translate("general.password")); + + private final Button loginButton = new Button(Lookup.getDefault() + .lookup(InternationalizationProvider.class) + .translate("general.login"), + (ClickEvent event) -> { + tryToLogIn(); + }); + + private final Button cancelButton = new Button(Lookup.getDefault() + .lookup(InternationalizationProvider.class) + .translate("general.cancel"), + (ClickEvent event) -> { + LoginDialog.this.close(); + }); + + public LoginDialog(ValidationManagerUI menu) { + super(menu, Lookup.getDefault() + .lookup(InternationalizationProvider.class) + .translate("general.login")); + init(); + } + + public void init() { + //Layout + FormLayout layout = new FormLayout(); + setContent(layout); + HorizontalLayout hlayout = new HorizontalLayout(); + hlayout.addComponent(loginButton); + hlayout.addComponent(cancelButton); + layout.addComponent(name); + layout.addComponent(password); + name.focus(); + StringLengthValidator nameVal = new StringLengthValidator( + Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("password.length.message")); + nameVal.setMinLength(5); + name.addValidator(nameVal); + name.setImmediate(true); + StringLengthValidator passVal = new StringLengthValidator( + Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("password.empty.message")); + passVal.setMinLength(3); + password.addValidator(passVal); + password.setImmediate(true); + layout.addComponent(hlayout); + layout.setComponentAlignment(name, Alignment.TOP_LEFT); + layout.setComponentAlignment(password, Alignment.MIDDLE_LEFT); + layout.setComponentAlignment(hlayout, Alignment.BOTTOM_LEFT); + layout.setSpacing(true); + layout.setMargin(true); + + // Keyboard navigation - enter key is a shortcut to login + addActionHandler(new Handler() { + @Override + public Action[] getActions(Object target, Object sender) { + return new Action[]{enterKey}; + } + + @Override + public void handleAction(Action action, Object sender, + Object target) { + tryToLogIn(); + } + }); + } + + private void tryToLogIn() { + try { + //Throws exception if credentials are wrong. + VMUserServer user = new VMUserServer(name.getValue(), + password.getValue()); + if (menu != null) { + switch (user.getUserStatusId().getId()) { + case 1: + //Everything OK + menu.setUser(user); + break; + case 2: + //TODO: Inactive. Right now no special behavior + menu.setUser(user); + break; + case 3: + //Locked + new Notification(Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("audit.user.account.lock"), + Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("menu.connection.error.user"), + Notification.Type.ERROR_MESSAGE, true) + .show(Page.getCurrent()); + break; + case 4: + //Password Aged + new Notification(Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("user.status.aged"), + Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("user.status.aged"), + Notification.Type.WARNING_MESSAGE, true) + .show(Page.getCurrent()); + menu.setUser(user); + //Open the profile page + ((VMUI) UI.getCurrent()).showTab("message.admin.userProfile"); + break; + default: + LOG.log(Level.SEVERE, "Unexpected User Status: {0}", + user.getUserStatusId().getId()); + Notification.show("Unexpected User Status", + "Unexpected User Status: " + + user.getUserStatusId().getId() + + "\n" + TRANSLATOR.translate("message.db.error"), + Notification.Type.ERROR_MESSAGE); + break; + } + } + close(); + } catch (VMException ex) { + if (menu != null) { + menu.setUser(null); + } + new Notification(Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("general.login.invalid.title"), + Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("general.login.invalid.message"), + Notification.Type.WARNING_MESSAGE, true) + .show(Page.getCurrent()); + password.setValue(""); + } + } + + public void clear() { + name.clear(); + password.clear(); + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/ValidationManagerUI.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/ValidationManagerUI.java index 43af4eb7..0263ef77 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/ValidationManagerUI.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/ValidationManagerUI.java @@ -164,9 +164,10 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.annotation.WebServlet; +import net.sourceforge.javydreamercsw.validation.manager.web.component.ByteToStringConverter; import net.sourceforge.javydreamercsw.validation.manager.web.dashboard.ExecutionDashboard; +import net.sourceforge.javydreamercsw.validation.manager.web.demo.DemoProvider; import net.sourceforge.javydreamercsw.validation.manager.web.importer.FileUploader; -import net.sourceforge.javydreamercsw.validation.manager.web.provider.DemoProvider; import net.sourceforge.javydreamercsw.validation.manager.web.provider.DesignerScreenProvider; import net.sourceforge.javydreamercsw.validation.manager.web.traceability.TraceMatrix; import net.sourceforge.javydreamercsw.validation.manager.web.wizard.assign.AssignUserStep; @@ -257,7 +258,7 @@ public void setUser(VMUserServer user) { user.setLocale(l.getLanguage()); try { user.write2DB(); - } catch (Exception ex) { + } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } } else { @@ -529,7 +530,7 @@ public void wizardCancelled(WizardCancelledEvent event) { ess.getHistoryList().add(history.get(r)); }); ess.write2DB(); - } catch (Exception ex) { + } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } }); @@ -1983,16 +1984,18 @@ private Component getMenu() { gl.addComponent(new Label(TRANSLATOR.translate("general.version") + ": " + getVersion()), 2, 2); if (getUser() != null) { + getUser().update(); //Logout button Button logout = new Button(TRANSLATOR.translate("general.logout")); logout.addClickListener((Button.ClickEvent event) -> { try { + user.update(); user.write2DB(); user = null; main = null; setLocale(Locale.ENGLISH); updateScreen(); - } catch (Exception ex) { + } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } }); @@ -2818,8 +2821,7 @@ private Grid getHistoryTable(String title, String... fields) { Grid grid = new Grid(title); BeanItemContainer histories - = new BeanItemContainer<>(History.class - ); + = new BeanItemContainer<>(History.class); GeneratedPropertyContainer wrapperCont = new GeneratedPropertyContainer(histories); histories.addAll(historyItems); diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/admin/AdminScreenProvider.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/admin/AdminScreenProvider.java index cd99cc8c..e8785470 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/admin/AdminScreenProvider.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/admin/AdminScreenProvider.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,151 +13,565 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web.admin; - -import com.vaadin.data.Property; -import com.vaadin.data.fieldgroup.BeanFieldGroup; -import com.vaadin.data.fieldgroup.FieldGroup; -import com.vaadin.ui.Button; -import com.vaadin.ui.Component; -import com.vaadin.ui.Field; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.HorizontalSplitPanel; -import com.vaadin.ui.Notification; -import com.vaadin.ui.Panel; -import com.vaadin.ui.TabSheet; -import com.vaadin.ui.TextArea; -import com.vaadin.ui.TextField; -import com.vaadin.ui.Tree; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.themes.ValoTheme; -import com.validation.manager.core.IMainContentProvider; -import com.validation.manager.core.api.internationalization.InternationalizationProvider; -import com.validation.manager.core.db.VmSetting; -import com.validation.manager.core.server.core.VMSettingServer; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; -import net.sourceforge.javydreamercsw.validation.manager.web.provider.AbstractProvider; -import org.openide.util.Lookup; -import org.openide.util.lookup.ServiceProvider; - -@ServiceProvider(service = IMainContentProvider.class, position = 4) -public class AdminScreenProvider extends AbstractProvider { - - private static final Logger LOG - = Logger.getLogger(IMainContentProvider.class.getSimpleName()); - - @Override - public Component getContent() { - TabSheet adminSheet = new TabSheet(); - VerticalLayout layout = new VerticalLayout(); - //Build setting tab - VerticalLayout sl = new VerticalLayout(); - HorizontalSplitPanel split = new HorizontalSplitPanel(); - sl.addComponent(split); - //Build left side - Tree sTree = new Tree(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("general.settings")); - adminSheet.addTab(sl, Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("general.settings")); - VMSettingServer.getSettings().stream().map((s) -> { - sTree.addItem(s); - sTree.setChildrenAllowed(s, false); - return s; - }).forEachOrdered((s) -> { - sTree.setItemCaption(s, Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate(s.getSetting())); - }); - split.setFirstComponent(sTree); - layout.addComponent(adminSheet); - sTree.addValueChangeListener((Property.ValueChangeEvent event) -> { - if (sTree.getValue() instanceof VmSetting) { - split.setSecondComponent( - displaySetting((VmSetting) sTree.getValue())); - } - }); - layout.setId(getComponentCaption()); - return layout; - } - - @Override - public String getComponentCaption() { - return "admin.tab.name"; - } - - @Override - public boolean shouldDisplay() { - return ValidationManagerUI.getInstance().getUser() != null - && ValidationManagerUI.getInstance() - .checkRight("system.configuration"); - } - - private Component displaySetting(VmSetting s) { - Panel form = new Panel(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("setting.detail")); - FormLayout layout = new FormLayout(); - form.setContent(layout); - form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); - BeanFieldGroup binder = new BeanFieldGroup(s.getClass()); - binder.setItemDataSource(s); - Field id = (TextField) binder.buildAndBind(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("general.setting"), "setting"); - layout.addComponent(id); - Field bool = binder.buildAndBind(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("bool.value"), "boolVal"); - bool.setSizeFull(); - layout.addComponent(bool); - Field integerVal = binder.buildAndBind(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("int.value"), "intVal"); - integerVal.setSizeFull(); - layout.addComponent(integerVal); - Field longVal = binder.buildAndBind(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("long.val"), "longVal"); - longVal.setSizeFull(); - layout.addComponent(longVal); - Field stringVal = binder.buildAndBind(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("string.val"), "stringVal", - TextArea.class); - stringVal.setStyleName(ValoTheme.TEXTAREA_LARGE); - stringVal.setSizeFull(); - layout.addComponent(stringVal); - Button cancel = new Button(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("general.cancel")); - cancel.addClickListener((Button.ClickEvent event) -> { - binder.discard(); - }); - //Editing existing one - Button update = new Button(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("general.update")); - update.addClickListener((Button.ClickEvent event) -> { - try { - binder.commit(); - displaySetting(s); - } catch (FieldGroup.CommitException ex) { - LOG.log(Level.SEVERE, null, ex); - Notification.show(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("general.error.record.update"), - ex.getLocalizedMessage(), - Notification.Type.ERROR_MESSAGE); - } - }); - boolean blocked = !s.getSetting().startsWith("version."); - if (blocked) { - HorizontalLayout hl = new HorizontalLayout(); - hl.addComponent(update); - hl.addComponent(cancel); - layout.addComponent(hl); - } - binder.setBuffered(true); - binder.setReadOnly(false); - binder.bindMemberFields(form); - //The version settigns are not modifiable from the GUI - binder.setEnabled(blocked); - //Id is always blocked. - id.setEnabled(false); - form.setSizeFull(); - return form; - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.admin; + +import com.vaadin.data.Property; +import com.vaadin.data.fieldgroup.BeanFieldGroup; +import com.vaadin.data.fieldgroup.FieldGroup; +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.icons.VaadinIcons; +import com.vaadin.server.Sizeable; +import com.vaadin.shared.ui.grid.HeightMode; +import com.vaadin.ui.Button; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.Field; +import com.vaadin.ui.FormLayout; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.Grid.SingleSelectionModel; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.HorizontalSplitPanel; +import com.vaadin.ui.Notification; +import com.vaadin.ui.Panel; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.TextField; +import com.vaadin.ui.Tree; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.themes.ValoTheme; +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.IMainContentProvider; +import com.validation.manager.core.VMUI; +import com.validation.manager.core.api.email.IEmailManager; +import com.validation.manager.core.db.IssueResolution; +import com.validation.manager.core.db.IssueType; +import com.validation.manager.core.db.RequirementType; +import com.validation.manager.core.db.VmSetting; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.IssueResolutionJpaController; +import com.validation.manager.core.db.controller.IssueTypeJpaController; +import com.validation.manager.core.db.controller.RequirementTypeJpaController; +import com.validation.manager.core.db.controller.exceptions.IllegalOrphanException; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.server.core.VMSettingServer; +import com.validation.manager.core.server.core.VMUserServer; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.sourceforge.javydreamercsw.validation.manager.web.VMWindow; +import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; +import net.sourceforge.javydreamercsw.validation.manager.web.component.IssueResolutionComponent; +import net.sourceforge.javydreamercsw.validation.manager.web.component.IssueTypeComponent; +import net.sourceforge.javydreamercsw.validation.manager.web.component.RequirementTypeComponent; +import net.sourceforge.javydreamercsw.validation.manager.web.component.TranslationConverter; +import net.sourceforge.javydreamercsw.validation.manager.web.component.UserComponent; +import net.sourceforge.javydreamercsw.validation.manager.web.provider.AbstractProvider; +import org.openide.util.Lookup; +import org.openide.util.lookup.ServiceProvider; + +@ServiceProvider(service = IMainContentProvider.class, position = 4) +public class AdminScreenProvider extends AbstractProvider { + + private static final Logger LOG + = Logger.getLogger(IMainContentProvider.class.getSimpleName()); + private final TabSheet adminSheet = new TabSheet(); + private final String ISSUE_TYPE = "issue.type", + ISSUE_RESOLUTION = "issue.resolution", + REQUIREMENT_TYPE = "requirement.type", + DESC = "description", + DELETE_ERROR = "delete.error", + NAME = "name"; + + @Override + public Component getContent() { + VerticalLayout layout = new VerticalLayout(); + adminSheet.removeAllComponents(); + //Build left side + //Build setting tab + adminSheet.addTab(getSettingTab(), TRANSLATOR + .translate("general.settings")); + //Build email setting tab + adminSheet.addTab(getEmailSettingTab(), TRANSLATOR + .translate("general.email.settings")); + //Build user management tab + adminSheet.addTab(getUserManagementTab(), TRANSLATOR + .translate("menu.user")); + //Build configurable items management tab + adminSheet.addTab(getConfigurableTab(), TRANSLATOR + .translate("general.configuration")); + layout.addComponent(adminSheet); + layout.setId(getComponentCaption()); + return layout; + } + + @Override + public void update() { + adminSheet.removeAllComponents(); + adminSheet.addTab(getSettingTab(), TRANSLATOR + .translate("general.settings")); + //Build email setting tab + adminSheet.addTab(getEmailSettingTab(), TRANSLATOR + .translate("general.email.settings")); + //Build user management tab + adminSheet.addTab(getUserManagementTab(), TRANSLATOR + .translate("menu.user")); + //Build configurable items management tab + adminSheet.addTab(getConfigurableTab(), TRANSLATOR + .translate("general.configuration")); + super.update(); + } + + @Override + public String getComponentCaption() { + return "admin.tab.name"; + } + + @Override + public boolean shouldDisplay() { + return ValidationManagerUI.getInstance().getUser() != null + && ValidationManagerUI.getInstance() + .checkRight("system.configuration"); + } + + private Component displaySetting(VmSetting s) { + return displaySetting(s, false); + } + + private Component displaySetting(VmSetting s, boolean edit) { + Panel form = new Panel(TRANSLATOR + .translate("setting.detail")); + FormLayout layout = new FormLayout(); + form.setContent(layout); + form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); + BeanFieldGroup binder = new BeanFieldGroup(s.getClass()); + binder.setItemDataSource(s); + Field id = (TextField) binder.buildAndBind(TRANSLATOR + .translate("general.setting"), "setting"); + layout.addComponent(id); + Field bool = binder.buildAndBind(TRANSLATOR + .translate("bool.value"), "boolVal"); + bool.setSizeFull(); + layout.addComponent(bool); + Field integerVal = binder.buildAndBind(TRANSLATOR + .translate("int.value"), "intVal"); + integerVal.setSizeFull(); + layout.addComponent(integerVal); + Field longVal = binder.buildAndBind(TRANSLATOR + .translate("long.val"), "longVal"); + longVal.setSizeFull(); + layout.addComponent(longVal); + Field stringVal = binder.buildAndBind(TRANSLATOR + .translate("string.val"), "stringVal", + TextArea.class); + stringVal.setSizeFull(); + layout.addComponent(stringVal); + Button cancel = new Button(TRANSLATOR + .translate("general.cancel")); + cancel.addClickListener((Button.ClickEvent event) -> { + binder.discard(); + }); + //Editing existing one + Button update = new Button(TRANSLATOR + .translate("general.update")); + update.addClickListener((Button.ClickEvent event) -> { + try { + binder.commit(); + displaySetting(s); + } catch (FieldGroup.CommitException ex) { + LOG.log(Level.SEVERE, null, ex); + Notification.show(TRANSLATOR + .translate("general.error.record.update"), + ex.getLocalizedMessage(), + Notification.Type.ERROR_MESSAGE); + } + }); + boolean blocked = !s.getSetting().startsWith("version."); + if (blocked) { + HorizontalLayout hl = new HorizontalLayout(); + hl.addComponent(update); + hl.addComponent(cancel); + layout.addComponent(hl); + } + binder.setBuffered(true); + binder.setReadOnly(edit); + binder.bindMemberFields(form); + //The version settigns are not modifiable from the GUI + binder.setEnabled(blocked); + //Id is always blocked. + id.setEnabled(false); + form.setSizeFull(); + return form; + } + + private Component getEmailSettingTab() { + VerticalLayout s2 = new VerticalLayout(); + HorizontalSplitPanel split2 = new HorizontalSplitPanel(); + s2.addComponent(split2); + Tree sTree2 = new Tree(TRANSLATOR + .translate("general.email.settings")); + sTree2.addValueChangeListener((Property.ValueChangeEvent event) -> { + if (sTree2.getValue() instanceof VmSetting) { + VmSetting vmSetting = (VmSetting) sTree2.getValue(); + split2.setSecondComponent( + displaySetting(vmSetting, + !vmSetting.getSetting().equals("mail.enable"))); + } + }); + split2.setFirstComponent(sTree2); + VMSettingServer.getSettings().forEach(s -> { + if (s.getSetting().startsWith("mail")) { + sTree2.addItem(s); + sTree2.setChildrenAllowed(s, false); + sTree2.setItemCaption(s, TRANSLATOR + .translate(s.getSetting())); + } + }); + Button testEmail = new Button(TRANSLATOR + .translate("general.email.settings.test"), + listener -> { + //Show a window to test email settings + VMWindow w = new VMWindow(TRANSLATOR + .translate("general.email.settings.test")); + w.setModal(true); + VerticalLayout vl = new VerticalLayout(); + TextField to = new TextField(TRANSLATOR.translate("general.email.to")); + TextField from = new TextField(TRANSLATOR.translate("general.email.from")); + TextField subject = new TextField(TRANSLATOR.translate("general.email.subject")); + TextArea mess = new TextArea(TRANSLATOR.translate("general.email.message")); + mess.setSizeFull(); + TextArea output = new TextArea(TRANSLATOR.translate("general.output")); + output.setReadOnly(true); + output.setSizeFull(); + Button send = new Button(TRANSLATOR.translate("general.email.send"), + l -> { + try { + Lookup.getDefault().lookup(IEmailManager.class) + .sendEmail(to.getValue(), null, + from.getValue(), + subject.getValue(), + mess.getValue()); + output.setValue(TRANSLATOR.translate("general.email.settings.test.success")); + //Successful, update the enable setting. + VMSettingServer enable = new VMSettingServer("mail.enable"); + enable.setBoolVal(true); + enable.write2DB(); + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + StringWriter sw = new StringWriter(); + ex.printStackTrace(new PrintWriter(sw)); + output.setReadOnly(false); + output.setValue(sw.toString()); + output.setReadOnly(true); + } + }); + vl.addComponent(to); + vl.addComponent(from); + vl.addComponent(subject); + vl.addComponent(mess); + vl.addComponent(send); + vl.addComponent(output); + w.setContent(vl); + w.setHeight(75, Sizeable.Unit.PERCENTAGE); + w.setWidth(75, Sizeable.Unit.PERCENTAGE); + ValidationManagerUI.getInstance().addWindow(w); + }); + s2.addComponent(testEmail); + return s2; + } + + private Component getSettingTab() { + VerticalLayout sl = new VerticalLayout(); + HorizontalSplitPanel split1 = new HorizontalSplitPanel(); + sl.addComponent(split1); + Tree sTree = new Tree(TRANSLATOR + .translate("general.settings")); + split1.setFirstComponent(sTree); + sTree.addValueChangeListener((Property.ValueChangeEvent event) -> { + if (sTree.getValue() instanceof VmSetting) { + split1.setSecondComponent( + displaySetting((VmSetting) sTree.getValue())); + } + }); + VMSettingServer.getSettings().forEach(s -> { + if (!s.getSetting().startsWith("mail")) { + sTree.addItem(s); + sTree.setChildrenAllowed(s, false); + sTree.setItemCaption(s, TRANSLATOR + .translate(s.getSetting())); + } + }); + return sl; + } + + private Component getUserManagementTab() { + VerticalLayout vl = new VerticalLayout(); + HorizontalSplitPanel split = new HorizontalSplitPanel(); + vl.addComponent(split); + //Create left side + Tree users = new Tree(); + //Menu + VerticalLayout main = new VerticalLayout(); + main.addComponent(users); + HorizontalLayout hl = new HorizontalLayout(); + Button addUser = new Button(TRANSLATOR.translate("add.user")); + addUser.addClickListener(listener -> { + VmUser user = new VmUser(); + split.setSecondComponent(new UserComponent(user, true)); + }); + hl.addComponent(addUser); + main.addComponent(hl); + split.setFirstComponent(main); + VMUserServer.getVMUsers().forEach(user -> { + if (!Objects.equals(user.getId(), + ((VMUI) UI.getCurrent()).getUser().getId())) { + users.addItem(user.getEntity()); + users.setItemCaption(user.getEntity(), user.toString()); + users.setItemIcon(user.getEntity(), VaadinIcons.USER); + users.setChildrenAllowed(user.getEntity(), false); + } + }); + users.addValueChangeListener((Property.ValueChangeEvent event) -> { + VmUser user = (VmUser) users.getValue(); + split.setSecondComponent(new UserComponent(user, true)); + }); + vl.setSizeFull(); + return vl; + } + + private Component getConfigurableTab() { + VerticalLayout vl = new VerticalLayout(); + ComboBox options = new ComboBox(); + options.addItem(ISSUE_TYPE); + options.setItemCaption(ISSUE_TYPE, + TRANSLATOR.translate(ISSUE_TYPE)); + options.addItem(ISSUE_RESOLUTION); + options.setItemCaption(ISSUE_RESOLUTION, + TRANSLATOR.translate(ISSUE_RESOLUTION)); + options.addItem(REQUIREMENT_TYPE); + options.setItemCaption(REQUIREMENT_TYPE, + TRANSLATOR.translate(REQUIREMENT_TYPE)); + options.setTextInputAllowed(false); + options.addValueChangeListener((Property.ValueChangeEvent event) -> { + Component nextComp = null; + if (options.getValue() != null) { + switch ((String) options.getValue()) { + case ISSUE_TYPE: + nextComp = displayIssueTypes(); + break; + case ISSUE_RESOLUTION: + nextComp = displayIssueResolutions(); + break; + case REQUIREMENT_TYPE: + nextComp = displayRequirementTypes(); + break; + default: + //Do nothing + } + } + if (nextComp != null) { + vl.removeAllComponents(); + vl.addComponent(options); + vl.addComponent(nextComp); + } + }); + vl.addComponent(options); + vl.setSizeFull(); + return vl; + } + + private Component displayIssueTypes() { + VerticalLayout vl = new VerticalLayout(); + Grid grid = new Grid(TRANSLATOR.translate(ISSUE_TYPE)); + BeanItemContainer types + = new BeanItemContainer<>(IssueType.class); + types.addAll(new IssueTypeJpaController(DataBaseManager + .getEntityManagerFactory()) + .findIssueTypeEntities()); + grid.setContainerDataSource(types); + grid.setSelectionMode(SelectionMode.SINGLE); + grid.setColumns("typeName", DESC); + Grid.Column name = grid.getColumn("typeName"); + name.setHeaderCaption(TRANSLATOR.translate("general.name")); + name.setConverter(new TranslationConverter()); + Grid.Column desc = grid.getColumn(DESC); + desc.setHeaderCaption(TRANSLATOR.translate("general.description")); + desc.setConverter(new TranslationConverter()); + grid.setSizeFull(); + vl.addComponent(grid); + grid.setHeightMode(HeightMode.ROW); + grid.setHeightByRows(types.size() > 5 ? 5 : types.size()); + //Menu + HorizontalLayout hl = new HorizontalLayout(); + Button add = new Button(TRANSLATOR.translate("general.create")); + add.addClickListener(listener -> { + VMWindow w = new VMWindow(); + w.setContent(new IssueTypeComponent(new IssueType(), true)); + w.setModal(true); + ((VMUI) UI.getCurrent()).addWindow(w); + w.addCloseListener(l -> { + ((VMUI) UI.getCurrent()).updateScreen(); + }); + }); + hl.addComponent(add); + Button delete = new Button(TRANSLATOR.translate("general.delete")); + delete.setEnabled(false); + delete.addClickListener(listener -> { + IssueType selected = (IssueType) ((SingleSelectionModel) grid. + getSelectionModel()).getSelectedRow(); + if (selected != null && selected.getId() >= 1000) { + try { + new IssueTypeJpaController(DataBaseManager + .getEntityManagerFactory()) + .destroy(selected.getId()); + ((VMUI) UI.getCurrent()).updateScreen(); + } catch (IllegalOrphanException | NonexistentEntityException ex) { + LOG.log(Level.SEVERE, null, ex); + Notification.show(TRANSLATOR.translate(DELETE_ERROR), + TRANSLATOR.translate(DELETE_ERROR), + Notification.Type.ERROR_MESSAGE); + } + } + }); + hl.addComponent(delete); + vl.addComponent(hl); + grid.addSelectionListener(event -> { // Java 8 + // Get selection from the selection model + IssueType selected = (IssueType) ((SingleSelectionModel) grid. + getSelectionModel()).getSelectedRow(); + //Only delete custom ones. + delete.setEnabled(selected != null && selected.getId() >= 1000); + }); + return vl; + } + + private Component displayIssueResolutions() { + VerticalLayout vl = new VerticalLayout(); + Grid grid = new Grid(TRANSLATOR.translate(ISSUE_RESOLUTION)); + BeanItemContainer types + = new BeanItemContainer<>(IssueResolution.class); + types.addAll(new IssueResolutionJpaController(DataBaseManager + .getEntityManagerFactory()) + .findIssueResolutionEntities()); + grid.setContainerDataSource(types); + grid.setSelectionMode(SelectionMode.SINGLE); + grid.setColumns(NAME); + Grid.Column name = grid.getColumn(NAME); + name.setHeaderCaption(TRANSLATOR.translate("general.name")); + name.setConverter(new TranslationConverter()); + grid.setSizeFull(); + vl.addComponent(grid); + grid.setHeightMode(HeightMode.ROW); + grid.setHeightByRows(types.size() > 5 ? 5 : types.size()); + //Menu + HorizontalLayout hl = new HorizontalLayout(); + Button add = new Button(TRANSLATOR.translate("general.create")); + add.addClickListener(listener -> { + VMWindow w = new VMWindow(); + w.setContent(new IssueResolutionComponent(new IssueResolution(), true)); + w.setModal(true); + ((VMUI) UI.getCurrent()).addWindow(w); + w.addCloseListener(l -> { + ((VMUI) UI.getCurrent()).updateScreen(); + }); + }); + hl.addComponent(add); + Button delete = new Button(TRANSLATOR.translate("general.delete")); + delete.setEnabled(false); + delete.addClickListener(listener -> { + IssueResolution selected = (IssueResolution) ((SingleSelectionModel) grid. + getSelectionModel()).getSelectedRow(); + if (selected != null && selected.getId() >= 1000) { + try { + new IssueResolutionJpaController(DataBaseManager + .getEntityManagerFactory()) + .destroy(selected.getId()); + ((VMUI) UI.getCurrent()).updateScreen(); + } catch (IllegalOrphanException | NonexistentEntityException ex) { + LOG.log(Level.SEVERE, null, ex); + Notification.show(TRANSLATOR.translate(DELETE_ERROR), + TRANSLATOR.translate(DELETE_ERROR), + Notification.Type.ERROR_MESSAGE); + } + } + }); + hl.addComponent(delete); + vl.addComponent(hl); + grid.addSelectionListener(event -> { // Java 8 + // Get selection from the selection model + IssueResolution selected = (IssueResolution) ((SingleSelectionModel) grid. + getSelectionModel()).getSelectedRow(); + //Only delete custom ones. + delete.setEnabled(selected != null && selected.getId() >= 1000); + }); + return vl; + } + + private Component displayRequirementTypes() { + VerticalLayout vl = new VerticalLayout(); + Grid grid = new Grid(TRANSLATOR.translate(REQUIREMENT_TYPE)); + BeanItemContainer types + = new BeanItemContainer<>(RequirementType.class); + types.addAll(new RequirementTypeJpaController(DataBaseManager + .getEntityManagerFactory()) + .findRequirementTypeEntities()); + grid.setContainerDataSource(types); + grid.setSelectionMode(SelectionMode.SINGLE); + grid.setColumns(NAME, DESC); + Grid.Column name = grid.getColumn(NAME); + name.setHeaderCaption(TRANSLATOR.translate("general.name")); + name.setConverter(new TranslationConverter()); + Grid.Column desc = grid.getColumn(DESC); + desc.setHeaderCaption(TRANSLATOR.translate("general.description")); + desc.setConverter(new TranslationConverter()); + grid.setSizeFull(); + vl.addComponent(grid); + grid.setHeightMode(HeightMode.ROW); + grid.setHeightByRows(types.size() > 5 ? 5 : types.size()); + //Menu + HorizontalLayout hl = new HorizontalLayout(); + Button add = new Button(TRANSLATOR.translate("general.create")); + add.addClickListener(listener -> { + VMWindow w = new VMWindow(); + w.setContent(new RequirementTypeComponent(new RequirementType(), true)); + w.setModal(true); + ((VMUI) UI.getCurrent()).addWindow(w); + w.addCloseListener(l -> { + ((VMUI) UI.getCurrent()).updateScreen(); + }); + }); + hl.addComponent(add); + Button delete = new Button(TRANSLATOR.translate("general.delete")); + delete.setEnabled(false); + delete.addClickListener(listener -> { + RequirementType selected = (RequirementType) ((SingleSelectionModel) grid. + getSelectionModel()).getSelectedRow(); + if (selected != null && selected.getId() >= 1000) { + try { + new RequirementTypeJpaController(DataBaseManager + .getEntityManagerFactory()) + .destroy(selected.getId()); + ((VMUI) UI.getCurrent()).updateScreen(); + } catch (IllegalOrphanException | NonexistentEntityException ex) { + LOG.log(Level.SEVERE, null, ex); + Notification.show(TRANSLATOR.translate(DELETE_ERROR), + TRANSLATOR.translate(DELETE_ERROR), + Notification.Type.ERROR_MESSAGE); + } + } + }); + hl.addComponent(delete); + vl.addComponent(hl); + grid.addSelectionListener(event -> { // Java 8 + // Get selection from the selection model + RequirementType selected = (RequirementType) ((SingleSelectionModel) grid. + getSelectionModel()).getSelectedRow(); + //Only delete custom ones. + delete.setEnabled(selected != null && selected.getId() >= 1000); + }); + return vl; + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/ByteToStringConverter.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/ByteToStringConverter.java similarity index 93% rename from Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/ByteToStringConverter.java rename to Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/ByteToStringConverter.java index 6f43a582..f4893775 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/ByteToStringConverter.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/ByteToStringConverter.java @@ -13,54 +13,54 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web; - -import com.vaadin.data.util.converter.Converter; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; -import java.util.Locale; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class ByteToStringConverter implements Converter { - - private static final Logger LOG - = Logger.getLogger(ByteToStringConverter.class.getSimpleName()); - - @Override - public byte[] convertToModel(String value, - Class targetType, Locale locale) - throws ConversionException { - try { - String result = value; - if (value == null) { - result = "null"; - } - return result.getBytes("UTF-8"); - } catch (UnsupportedEncodingException ex) { - LOG.log(Level.SEVERE, null, ex); - } - return null; - } - - @Override - public String convertToPresentation(byte[] value, - Class targetType, Locale locale) - throws ConversionException { - return value == null ? "null" : new String(value, StandardCharsets.UTF_8); - } - - @Override - public Class getModelType() { - return byte[].class; - } - - @Override - public Class getPresentationType() { - return String.class; - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.component; + +import com.vaadin.data.util.converter.Converter; +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; +import java.util.Locale; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ByteToStringConverter implements Converter { + + private static final Logger LOG + = Logger.getLogger(ByteToStringConverter.class.getSimpleName()); + + @Override + public byte[] convertToModel(String value, + Class targetType, Locale locale) + throws ConversionException { + try { + String result = value; + if (value == null) { + result = "null"; + } + return result.getBytes("UTF-8"); + } catch (UnsupportedEncodingException ex) { + LOG.log(Level.SEVERE, null, ex); + } + return null; + } + + @Override + public String convertToPresentation(byte[] value, + Class targetType, Locale locale) + throws ConversionException { + return value == null ? "null" : new String(value, StandardCharsets.UTF_8); + } + + @Override + public Class getModelType() { + return byte[].class; + } + + @Override + public Class getPresentationType() { + return String.class; + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/IssueResolutionComponent.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/IssueResolutionComponent.java new file mode 100644 index 00000000..a35f0a15 --- /dev/null +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/IssueResolutionComponent.java @@ -0,0 +1,127 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sourceforge.javydreamercsw.validation.manager.web.component; + +import com.vaadin.data.fieldgroup.BeanFieldGroup; +import com.vaadin.data.fieldgroup.FieldGroup; +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.Field; +import com.vaadin.ui.FormLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Panel; +import com.vaadin.ui.UI; +import com.vaadin.ui.themes.ValoTheme; +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.VMUI; +import com.validation.manager.core.api.internationalization.InternationalizationProvider; +import com.validation.manager.core.db.IssueResolution; +import com.validation.manager.core.db.controller.IssueResolutionJpaController; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.openide.util.Lookup; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class IssueResolutionComponent extends Panel { + + private final IssueResolution ir; + private boolean edit = false; + private static final InternationalizationProvider TRANSLATOR + = Lookup.getDefault().lookup(InternationalizationProvider.class); + private static final Logger LOG + = Logger.getLogger(IssueResolutionComponent.class.getSimpleName()); + + public IssueResolutionComponent(IssueResolution ir, boolean edit) { + setCaption(TRANSLATOR.translate("issue.resolution")); + this.ir = ir; + this.edit = edit; + init(); + } + + public IssueResolutionComponent(IssueResolution ir, Component content, + boolean edit) { + super(content); + setCaption(TRANSLATOR.translate("issue.resolution")); + this.ir = ir; + this.edit = edit; + init(); + } + + public IssueResolutionComponent(IssueResolution ir, String caption, + boolean edit) { + super(caption); + this.ir = ir; + this.edit = edit; + init(); + } + + public IssueResolutionComponent(IssueResolution ir, String caption, + Component content, boolean edit) { + super(caption, content); + this.ir = ir; + this.edit = edit; + init(); + } + + private void init() { + FormLayout layout = new FormLayout(); + setContent(layout); + addStyleName(ValoTheme.FORMLAYOUT_LIGHT); + BeanFieldGroup binder = new BeanFieldGroup(ir.getClass()); + binder.setItemDataSource(ir); + Field name = binder.buildAndBind(TRANSLATOR + .translate("general.name"), "name"); + layout.addComponent(name); + if (edit) { + Button update = new Button(ir.getId() == null + ? TRANSLATOR. + translate("general.create") + : TRANSLATOR. + translate("general.update")); + update.addClickListener((Button.ClickEvent event) -> { + IssueResolutionJpaController c + = new IssueResolutionJpaController(DataBaseManager. + getEntityManagerFactory()); + if (ir.getId() == null) { + ir.setName((String) name.getValue()); + c.create(ir); + } else { + try { + binder.commit(); + } catch (FieldGroup.CommitException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + }); + Button cancel = new Button(Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("general.cancel")); + cancel.addClickListener((Button.ClickEvent event) -> { + binder.discard(); + ((VMUI) UI.getCurrent()).updateScreen(); + }); + binder.setReadOnly(!edit); + binder.setBuffered(true); + HorizontalLayout hl = new HorizontalLayout(); + hl.addComponent(update); + hl.addComponent(cancel); + layout.addComponent(hl); + } + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/IssueTypeComponent.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/IssueTypeComponent.java new file mode 100644 index 00000000..1cf08b34 --- /dev/null +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/IssueTypeComponent.java @@ -0,0 +1,124 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sourceforge.javydreamercsw.validation.manager.web.component; + +import com.vaadin.data.fieldgroup.BeanFieldGroup; +import com.vaadin.data.fieldgroup.FieldGroup; +import com.vaadin.ui.Button; +import com.vaadin.ui.Field; +import com.vaadin.ui.FormLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Panel; +import com.vaadin.ui.UI; +import com.vaadin.ui.themes.ValoTheme; +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.VMUI; +import com.validation.manager.core.api.internationalization.InternationalizationProvider; +import com.validation.manager.core.db.IssueType; +import com.validation.manager.core.db.controller.IssueTypeJpaController; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.openide.util.Lookup; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class IssueTypeComponent extends Panel { + + private final IssueType it; + private boolean edit = false; + private static final InternationalizationProvider TRANSLATOR + = Lookup.getDefault().lookup(InternationalizationProvider.class); + private static final Logger LOG + = Logger.getLogger(IssueTypeComponent.class.getSimpleName()); + + public IssueTypeComponent(IssueType it, boolean edit) { + setCaption(TRANSLATOR.translate("issue.type")); + this.it = it; + this.edit = edit; + init(); + } + + public IssueTypeComponent(IssueType it, String caption, boolean edit) { + super(caption); + this.it = it; + this.edit = edit; + init(); + } + + public IssueTypeComponent(IssueType it) { + setCaption(TRANSLATOR.translate("issue.type")); + this.it = it; + init(); + } + + public IssueTypeComponent(IssueType it, String caption) { + super(caption); + this.it = it; + init(); + } + + private void init() { + FormLayout layout = new FormLayout(); + setContent(layout); + addStyleName(ValoTheme.FORMLAYOUT_LIGHT); + BeanFieldGroup binder = new BeanFieldGroup(it.getClass()); + binder.setItemDataSource(it); + Field name = binder.buildAndBind(TRANSLATOR + .translate("general.name"), "typeName"); + layout.addComponent(name); + Field desc = binder.buildAndBind(TRANSLATOR + .translate("general.description"), "description"); + layout.addComponent(desc); + if (edit) { + Button update = new Button(it.getId() == null + ? TRANSLATOR. + translate("general.create") + : TRANSLATOR. + translate("general.update")); + update.addClickListener((Button.ClickEvent event) -> { + IssueTypeJpaController c + = new IssueTypeJpaController(DataBaseManager. + getEntityManagerFactory()); + if (it.getId() == null) { + it.setDescription((String) desc.getValue()); + it.setTypeName((String) name.getValue()); + c.create(it); + } else { + try { + binder.commit(); + } catch (FieldGroup.CommitException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + }); + Button cancel = new Button(Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("general.cancel")); + cancel.addClickListener((Button.ClickEvent event) -> { + binder.discard(); + ((VMUI) UI.getCurrent()).updateScreen(); + }); + binder.setReadOnly(!edit); + binder.setBuffered(true); + HorizontalLayout hl = new HorizontalLayout(); + hl.addComponent(update); + hl.addComponent(cancel); + layout.addComponent(hl); + } + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/RequirementTypeComponent.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/RequirementTypeComponent.java new file mode 100644 index 00000000..99523d9e --- /dev/null +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/RequirementTypeComponent.java @@ -0,0 +1,131 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sourceforge.javydreamercsw.validation.manager.web.component; + +import com.vaadin.data.fieldgroup.BeanFieldGroup; +import com.vaadin.data.fieldgroup.FieldGroup; +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.Field; +import com.vaadin.ui.FormLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Panel; +import com.vaadin.ui.UI; +import com.vaadin.ui.themes.ValoTheme; +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.VMUI; +import com.validation.manager.core.api.internationalization.InternationalizationProvider; +import com.validation.manager.core.db.RequirementType; +import com.validation.manager.core.db.controller.RequirementTypeJpaController; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.openide.util.Lookup; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class RequirementTypeComponent extends Panel { + + private final RequirementType rt; + private boolean edit = false; + private static final InternationalizationProvider TRANSLATOR + = Lookup.getDefault().lookup(InternationalizationProvider.class); + private static final Logger LOG + = Logger.getLogger(RequirementTypeComponent.class.getSimpleName()); + + public RequirementTypeComponent(RequirementType rt, boolean edit) { + setCaption(TRANSLATOR.translate("issue.resolution")); + this.rt = rt; + this.edit = edit; + init(); + } + + public RequirementTypeComponent(RequirementType rt, Component content, + boolean edit) { + super(content); + setCaption(TRANSLATOR.translate("issue.resolution")); + this.rt = rt; + this.edit = edit; + init(); + } + + public RequirementTypeComponent(RequirementType rt, String caption, + boolean edit) { + super(caption); + this.rt = rt; + this.edit = edit; + init(); + } + + public RequirementTypeComponent(RequirementType rt, String caption, + Component content, boolean edit) { + super(caption, content); + this.rt = rt; + this.edit = edit; + init(); + } + + private void init() { + FormLayout layout = new FormLayout(); + setContent(layout); + addStyleName(ValoTheme.FORMLAYOUT_LIGHT); + BeanFieldGroup binder = new BeanFieldGroup(rt.getClass()); + binder.setItemDataSource(rt); + Field name = binder.buildAndBind(TRANSLATOR + .translate("general.name"), "name"); + layout.addComponent(name); + Field desc = binder.buildAndBind(TRANSLATOR + .translate("general.description"), "description"); + layout.addComponent(desc); + if (edit) { + Button update = new Button(rt.getId() == null + ? TRANSLATOR. + translate("general.create") + : TRANSLATOR. + translate("general.update")); + update.addClickListener((Button.ClickEvent event) -> { + RequirementTypeJpaController c + = new RequirementTypeJpaController(DataBaseManager. + getEntityManagerFactory()); + if (rt.getId() == null) { + rt.setName((String) name.getValue()); + rt.setDescription((String) desc.getValue()); + c.create(rt); + } else { + try { + binder.commit(); + } catch (FieldGroup.CommitException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + }); + Button cancel = new Button(Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("general.cancel")); + cancel.addClickListener((Button.ClickEvent event) -> { + binder.discard(); + ((VMUI) UI.getCurrent()).updateScreen(); + }); + binder.setReadOnly(!edit); + binder.setBuffered(true); + HorizontalLayout hl = new HorizontalLayout(); + hl.addComponent(update); + hl.addComponent(cancel); + layout.addComponent(hl); + } + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/TranslationConverter.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/TranslationConverter.java new file mode 100644 index 00000000..f53b992f --- /dev/null +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/TranslationConverter.java @@ -0,0 +1,55 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sourceforge.javydreamercsw.validation.manager.web.component; + +import com.vaadin.data.util.converter.Converter; +import com.validation.manager.core.api.internationalization.InternationalizationProvider; +import java.util.Locale; +import org.openide.util.Lookup; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class TranslationConverter implements Converter { + + private static final InternationalizationProvider TRANSLATOR + = Lookup.getDefault().lookup(InternationalizationProvider.class); + + @Override + public String convertToModel(String value, + Class targetType, Locale locale) + throws ConversionException { + return value; + } + + @Override + public String convertToPresentation(String value, + Class targetType, Locale locale) + throws ConversionException { + return TRANSLATOR.translate(value); + } + + @Override + public Class getModelType() { + return String.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/TreeTableCheckBox.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/TreeTableCheckBox.java similarity index 95% rename from Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/TreeTableCheckBox.java rename to Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/TreeTableCheckBox.java index db88c1a4..f1ceb69a 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/TreeTableCheckBox.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/TreeTableCheckBox.java @@ -13,90 +13,90 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web; - -import com.vaadin.data.Item; -import com.vaadin.sebastian.indeterminatecheckbox.IndeterminateCheckBox; -import com.vaadin.ui.TreeTable; -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public final class TreeTableCheckBox extends IndeterminateCheckBox { - - private final TreeTable tt; - private final static Logger LOG - = Logger.getLogger(TreeTableCheckBox.class.getSimpleName()); - private final Object objectId; - - public TreeTableCheckBox(TreeTable tt, Object objectId) { - this.tt = tt; - this.objectId = objectId; - initialize(); - } - - public TreeTableCheckBox(TreeTable tt, String caption, Object objectId) { - super(caption); - this.tt = tt; - this.objectId = objectId; - initialize(); - } - - public TreeTableCheckBox(TreeTable tt, String caption, - boolean initialState, Object objectId) { - super(caption, initialState); - this.tt = tt; - this.objectId = objectId; - initialize(); - } - - private void initialize() { - setUserCanToggleIndeterminate(false); - } - - @Override - protected void setInternalValue(Boolean value) { - if (tt != null - && value != null - && !Objects.equals(value, getState().value)) { - if (tt.hasChildren(getObjectId()) - && getState().value != null) { - //Switching from false to true. Select all children - tt.getChildren(getObjectId()).forEach((o) -> { - Item item = tt.getItem(o); - Object val = item.getItemProperty("Name").getValue(); - if (val instanceof TreeTableCheckBox) { - TreeTableCheckBox ttcb = (TreeTableCheckBox) val; - ttcb.setValue(value); - } - }); - } - Object parentId = tt.getParent(getObjectId()); - if (!value && parentId != null) { - //Switching from true to false. Mark parent as undeterminated - TreeTableCheckBox parent - = ((TreeTableCheckBox) tt.getItem(parentId) - .getItemProperty("Name").getValue()); - if (parent.getValue() != null && parent.getValue()) { - LOG.log(Level.INFO, "Setting {0} to undetermined.", - parentId); - parent.setValue(null); - } else { - LOG.info("Parent not selected!"); - } - } - } - super.setInternalValue(value); - } - - /** - * @return the objectId - */ - public Object getObjectId() { - return objectId; - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.component; + +import com.vaadin.data.Item; +import com.vaadin.sebastian.indeterminatecheckbox.IndeterminateCheckBox; +import com.vaadin.ui.TreeTable; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public final class TreeTableCheckBox extends IndeterminateCheckBox { + + private final TreeTable tt; + private final static Logger LOG + = Logger.getLogger(TreeTableCheckBox.class.getSimpleName()); + private final Object objectId; + + public TreeTableCheckBox(TreeTable tt, Object objectId) { + this.tt = tt; + this.objectId = objectId; + initialize(); + } + + public TreeTableCheckBox(TreeTable tt, String caption, Object objectId) { + super(caption); + this.tt = tt; + this.objectId = objectId; + initialize(); + } + + public TreeTableCheckBox(TreeTable tt, String caption, + boolean initialState, Object objectId) { + super(caption, initialState); + this.tt = tt; + this.objectId = objectId; + initialize(); + } + + private void initialize() { + setUserCanToggleIndeterminate(false); + } + + @Override + protected void setInternalValue(Boolean value) { + if (tt != null + && value != null + && !Objects.equals(value, getState().value)) { + if (tt.hasChildren(getObjectId()) + && getState().value != null) { + //Switching from false to true. Select all children + tt.getChildren(getObjectId()).forEach((o) -> { + Item item = tt.getItem(o); + Object val = item.getItemProperty("Name").getValue(); + if (val instanceof TreeTableCheckBox) { + TreeTableCheckBox ttcb = (TreeTableCheckBox) val; + ttcb.setValue(value); + } + }); + } + Object parentId = tt.getParent(getObjectId()); + if (!value && parentId != null) { + //Switching from true to false. Mark parent as undeterminated + TreeTableCheckBox parent + = ((TreeTableCheckBox) tt.getItem(parentId) + .getItemProperty("Name").getValue()); + if (parent.getValue() != null && parent.getValue()) { + LOG.log(Level.INFO, "Setting {0} to undetermined.", + parentId); + parent.setValue(null); + } else { + LOG.info("Parent not selected!"); + } + } + } + super.setInternalValue(value); + } + + /** + * @return the objectId + */ + public Object getObjectId() { + return objectId; + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/UserComponent.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/UserComponent.java new file mode 100644 index 00000000..6934e8df --- /dev/null +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/UserComponent.java @@ -0,0 +1,302 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sourceforge.javydreamercsw.validation.manager.web.component; + +import com.vaadin.data.fieldgroup.BeanFieldGroup; +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.event.FieldEvents; +import com.vaadin.event.FieldEvents.TextChangeListener; +import com.vaadin.icons.VaadinIcons; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Field; +import com.vaadin.ui.FormLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; +import com.vaadin.ui.Panel; +import com.vaadin.ui.PasswordField; +import com.vaadin.ui.Table; +import com.vaadin.ui.TextField; +import com.vaadin.ui.TwinColSelect; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.themes.ValoTheme; +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.VMException; +import com.validation.manager.core.VMUI; +import com.validation.manager.core.api.internationalization.InternationalizationProvider; +import com.validation.manager.core.db.Role; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.RoleJpaController; +import com.validation.manager.core.db.controller.UserStatusJpaController; +import com.validation.manager.core.server.core.VMUserServer; +import com.validation.manager.core.tool.MD5; +import de.steinwedel.messagebox.ButtonOption; +import de.steinwedel.messagebox.MessageBox; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class UserComponent extends Panel { + + private final VmUser user; + private static final Logger LOG + = Logger.getLogger(UserComponent.class.getSimpleName()); + private static final InternationalizationProvider TRANSLATOR + = Lookup.getDefault().lookup(InternationalizationProvider.class); + private boolean edit = false; + + public UserComponent(VmUser user, boolean edit) { + this.user = user; + this.edit = edit; + init(); + } + + public UserComponent(VmUser user, String caption, boolean edit) { + super(caption); + this.user = user; + this.edit = edit; + init(); + } + + private void init() { + FormLayout layout = new FormLayout(); + setContent(layout); + addStyleName(ValoTheme.FORMLAYOUT_LIGHT); + BeanFieldGroup binder = new BeanFieldGroup(user.getClass()); + binder.setItemDataSource(user); + Field fn = binder.buildAndBind(TRANSLATOR. + translate("general.first.name"), + "firstName", TextField.class); + layout.addComponent(fn); + Field ln = binder.buildAndBind(TRANSLATOR. + translate("general.last.name"), + "lastName", TextField.class); + layout.addComponent(ln); + Field username = binder.buildAndBind(TRANSLATOR. + translate("general.username"), + "username", TextField.class); + layout.addComponent(username); + PasswordField pw = (PasswordField) binder.buildAndBind( + TRANSLATOR. + translate("general.password"), + "password", PasswordField.class); + PasswordChangeListener listener = new PasswordChangeListener(); + pw.addTextChangeListener(listener); + pw.setConverter(new UserPasswordConverter()); + layout.addComponent(pw); + Field email = binder.buildAndBind(TRANSLATOR. + translate("general.email"), + "email", TextField.class); + layout.addComponent(email); + ComboBox locale = new ComboBox(TRANSLATOR. + translate("general.locale")); + locale.setTextInputAllowed(false); + ValidationManagerUI.getAvailableLocales().forEach(l -> { + locale.addItem(l.toString()); + }); + if (user.getLocale() != null) { + locale.setValue(user.getLocale()); + } + binder.bind(locale, "locale"); + layout.addComponent(locale); + //Status + ComboBox status = new ComboBox(TRANSLATOR. + translate("general.status")); + new UserStatusJpaController(DataBaseManager.getEntityManagerFactory()) + .findUserStatusEntities().forEach(us -> { + status.addItem(us); + status.setItemCaption(us, + TRANSLATOR.translate(us.getStatus())); + }); + binder.bind(status, "userStatusId"); + status.setTextInputAllowed(false); + layout.addComponent(status); + //Roles + if (edit && ((VMUI) UI.getCurrent()).checkRight("system.configuration")) { + List list = new RoleJpaController(DataBaseManager + .getEntityManagerFactory()) + .findRoleEntities(); + Collections.sort(list, (Role r1, Role r2) + -> TRANSLATOR.translate(r1.getRoleName()) + .compareTo(TRANSLATOR + .translate(r2.getRoleName()))); + BeanItemContainer roleContainer + = new BeanItemContainer<>(Role.class, list); + TwinColSelect roles + = new TwinColSelect(TRANSLATOR.translate("general.role")); + roles.setContainerDataSource(roleContainer); + roles.setRows(5); + roles.setLeftColumnCaption(TRANSLATOR.translate("available.roles")); + roles.setRightColumnCaption(TRANSLATOR.translate("current.roles")); + list.forEach(r -> { + roles.setItemCaption(r, TRANSLATOR.translate(r.getDescription())); + }); + if (user.getRoleList() != null) { + user.getRoleList().forEach(r -> { + roles.select(r); + }); + } + roles.addValueChangeListener(event -> { + Set selected + = (Set) event.getProperty().getValue(); + if (user.getRoleList() == null) { + user.setRoleList(new ArrayList<>()); + } + user.getRoleList().clear(); + selected.forEach(r -> { + user.getRoleList().add(r); + }); + }); + layout.addComponent(roles); + } else { + if (!user.getRoleList().isEmpty()) { + Table roles = new Table(TRANSLATOR.translate("general.role")); + user.getRoleList().forEach(role -> { + roles.addItem(role); + roles.setItemCaption(role, + TRANSLATOR.translate(role.getRoleName())); + roles.setItemIcon(role, VaadinIcons.USER_STAR); + }); + layout.addComponent(roles); + } + } + Button update = new Button(user.getId() == null + ? TRANSLATOR. + translate("general.create") + : TRANSLATOR. + translate("general.update")); + update.addClickListener((Button.ClickEvent event) -> { + try { + VMUserServer us; + String password = (String) pw.getValue(); + if (user.getId() == null) { + us = new VMUserServer((String) username.getValue(), + password, + (String) fn.getValue(), + (String) ln.getValue(), + (String) email.getValue()); + } else { + us = new VMUserServer(user); + us.setFirstName((String) fn.getValue()); + us.setLastName((String) ln.getValue()); + us.setEmail((String) email.getValue()); + us.setUsername((String) username.getValue()); + } + us.setLocale((String) locale.getValue()); + if (listener.isChanged() + && !password.equals(user.getPassword())) { + //Different password. Prompt for confirmation + MessageBox mb = MessageBox.create(); + VerticalLayout vl = new VerticalLayout(); + Label l = new Label(TRANSLATOR. + translate("password.confirm.pw.message")); + vl.addComponent(l); + PasswordField np = new PasswordField(Lookup.getDefault() + .lookup(InternationalizationProvider.class) + .translate("general.password")); + vl.addComponent(np); + mb.asModal(true) + .withCaption(Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("password.confirm.pw")) + .withMessage(vl) + .withButtonAlignment(Alignment.MIDDLE_CENTER) + .withOkButton(() -> { + try { + if (password.equals(MD5.encrypt(np.getValue()))) { + us.setHashPassword(true); + us.setPassword(np.getValue()); + us.write2DB(); + Notification.show(TRANSLATOR. + translate("audit.user.account.password.change"), + Notification.Type.ASSISTIVE_NOTIFICATION); + ((VMUI) UI.getCurrent()).updateScreen(); + } else { + Notification.show(TRANSLATOR. + translate("password.does.not.match"), + Notification.Type.WARNING_MESSAGE); + } + mb.close(); + } catch (VMException ex) { + Exceptions.printStackTrace(ex); + } + }, ButtonOption.focus(), + ButtonOption.closeOnClick(false), + ButtonOption.icon(VaadinIcons.CHECK)) + .withCancelButton( + ButtonOption.icon(VaadinIcons.CLOSE) + ).getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); + mb.open(); + } else { + us.write2DB(); + } + ((VMUI) UI.getCurrent()).getUser().update(); + ((VMUI) UI.getCurrent()).setLocale(new Locale(us.getLocale())); + ((VMUI) UI.getCurrent()).updateScreen(); + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + Notification.show(TRANSLATOR. + translate("general.error.record.update"), + ex.getLocalizedMessage(), + Notification.Type.ERROR_MESSAGE); + } + }); + Button cancel = new Button(Lookup.getDefault() + .lookup(InternationalizationProvider.class). + translate("general.cancel")); + cancel.addClickListener((Button.ClickEvent event) -> { + binder.discard(); + ((VMUI) UI.getCurrent()).updateScreen(); + }); + binder.setReadOnly(!edit); + binder.setBuffered(true); + HorizontalLayout hl = new HorizontalLayout(); + hl.addComponent(update); + hl.addComponent(cancel); + layout.addComponent(hl); + } + + private class PasswordChangeListener implements TextChangeListener { + + private boolean changed = false; + + @Override + public void textChange(FieldEvents.TextChangeEvent event) { + changed = true; + } + + /** + * @return the changed + */ + public boolean isChanged() { + return changed; + } + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/profile/UserPasswordConverter.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/UserPasswordConverter.java similarity index 83% rename from Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/profile/UserPasswordConverter.java rename to Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/UserPasswordConverter.java index 5e120135..724716c3 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/profile/UserPasswordConverter.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/UserPasswordConverter.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,48 +13,46 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web.profile; - -import com.vaadin.data.util.converter.Converter; -import com.validation.manager.core.tool.MD5; -import java.util.Locale; -import org.openide.util.Exceptions; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class UserPasswordConverter implements Converter { - - private String pw; - - @Override - public String convertToModel(String value, - Class targetType, Locale locale) - throws ConversionException { - pw = value; - return pw; - } - - @Override - public String convertToPresentation(String value, - Class targetType, Locale locale) - throws ConversionException { - try { - return MD5.encrypt(value); - } catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - return ""; - } - - @Override - public Class getModelType() { - return String.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.component; + +import com.vaadin.data.util.converter.Converter; +import com.validation.manager.core.VMException; +import com.validation.manager.core.tool.MD5; +import java.util.Locale; +import org.openide.util.Exceptions; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class UserPasswordConverter implements Converter { + + @Override + public String convertToModel(String value, + Class targetType, Locale locale) + throws ConversionException { + return value; + } + + @Override + public String convertToPresentation(String value, + Class targetType, Locale locale) + throws ConversionException { + try { + return value == null ? "" : MD5.encrypt(value); + } catch (VMException ex) { + Exceptions.printStackTrace(ex); + } + return ""; + } + + @Override + public Class getModelType() { + return String.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/UserStatusConverter.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/UserStatusConverter.java new file mode 100644 index 00000000..dbd4791f --- /dev/null +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/UserStatusConverter.java @@ -0,0 +1,67 @@ +/* + * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sourceforge.javydreamercsw.validation.manager.web.component; + +import com.vaadin.data.util.converter.Converter; +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.api.internationalization.InternationalizationProvider; +import com.validation.manager.core.db.UserStatus; +import com.validation.manager.core.db.controller.UserStatusJpaController; +import java.util.Locale; +import org.openide.util.Lookup; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class UserStatusConverter implements Converter { + + private static final InternationalizationProvider TRANSLATOR + = Lookup.getDefault().lookup(InternationalizationProvider.class); + + @Override + public UserStatus convertToModel(String value, + Class targetType, + Locale locale) throws Converter.ConversionException { + UserStatus status = null; + for (UserStatus us + : new UserStatusJpaController(DataBaseManager + .getEntityManagerFactory()).findUserStatusEntities()) { + if (TRANSLATOR.translate(us.getStatus()).equals(value)) { + status = us; + break; + } + } + return status; + } + + @Override + public String convertToPresentation(UserStatus value, + Class targetType, + Locale locale) throws Converter.ConversionException { + return value == null ? "" : TRANSLATOR.translate(value.getStatus()); + } + + @Override + public Class getModelType() { + return UserStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/UserToStringConverter.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/UserToStringConverter.java similarity index 92% rename from Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/UserToStringConverter.java rename to Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/UserToStringConverter.java index b6ddeed3..7dbf2bc5 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/UserToStringConverter.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/component/UserToStringConverter.java @@ -13,41 +13,41 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web; - -import com.vaadin.data.util.converter.Converter; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.server.core.VMUserServer; -import java.util.Locale; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class UserToStringConverter implements Converter { - - private VmUser user; - - @Override - public Class getModelType() { - return VmUser.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - - @Override - public VmUser convertToModel(String value, - Class targetType, Locale locale) throws ConversionException { - return user; - } - - @Override - public String convertToPresentation(VmUser value, - Class targetType, Locale locale) throws ConversionException { - user = value; - return new VMUserServer(value).toString(); - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.component; + +import com.vaadin.data.util.converter.Converter; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.server.core.VMUserServer; +import java.util.Locale; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class UserToStringConverter implements Converter { + + private VmUser user; + + @Override + public Class getModelType() { + return VmUser.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + @Override + public VmUser convertToModel(String value, + Class targetType, Locale locale) throws ConversionException { + return user; + } + + @Override + public String convertToPresentation(VmUser value, + Class targetType, Locale locale) throws ConversionException { + user = value; + return new VMUserServer(value).toString(); + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/provider/DemoProvider.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/demo/DemoProvider.java similarity index 79% rename from Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/provider/DemoProvider.java rename to Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/demo/DemoProvider.java index 02d70eaa..49a3835e 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/provider/DemoProvider.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/demo/DemoProvider.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,91 +13,92 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web.provider; - -import com.vaadin.shared.ui.label.ContentMode; -import com.vaadin.ui.Component; -import com.vaadin.ui.Label; -import com.vaadin.ui.VerticalLayout; -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.IMainContentProvider; -import com.validation.manager.core.api.internationalization.InternationalizationProvider; -import com.validation.manager.core.db.controller.VmUserJpaController; -import com.validation.manager.core.tool.MD5; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.openide.util.Lookup; -import org.openide.util.lookup.ServiceProvider; - -@ServiceProvider(service = IMainContentProvider.class) -public class DemoProvider extends AbstractProvider { - - private static final Logger LOG - = Logger.getLogger(DemoProvider.class.getSimpleName()); - private VerticalLayout layout; - - @Override - public Component getContent() { - if (layout == null) { - layout = new VerticalLayout(); - update(); - } - return layout; - } - - @Override - public void update() { - layout.removeAllComponents(); - VmUserJpaController controller - = new VmUserJpaController(DataBaseManager - .getEntityManagerFactory()); - layout.addComponent(new Label("

demo.tab.title

", - ContentMode.HTML)); - Label l = new Label(); - l.setId("demo.tab.message"); - layout.addComponent(l); - StringBuilder sb = new StringBuilder("
    "); - controller.findVmUserEntities().stream().filter((u) - -> (u.getId() < 1000)).forEachOrdered((u) -> { - try { - //Default accounts - if (u.getPassword() != null - && u.getPassword().equals(MD5 - .encrypt(u.getUsername()))) { - sb.append("
  • ") - .append("general.username") - .append(": ") - .append(u.getUsername()).append(", ") - .append("general.password") - .append(": ") - .append(u.getUsername()) - .append(" ") - .append("general.role") - .append(": ") - .append(Lookup.getDefault() - .lookup(InternationalizationProvider.class) - .translate(u.getRoleList().get(0) - .getDescription())) - .append("
  • "); - } - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - }); - sb.append("
"); - layout.addComponent(new Label(sb.toString(), - ContentMode.HTML)); - layout.setId(getComponentCaption()); - super.update(); - } - - @Override - public String getComponentCaption() { - return "demo.tab.name"; - } - - @Override - public boolean shouldDisplay() { - return DataBaseManager.isDemo(); - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.demo; + +import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.ui.Component; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.IMainContentProvider; +import com.validation.manager.core.VMException; +import com.validation.manager.core.db.controller.VmUserJpaController; +import com.validation.manager.core.tool.MD5; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.sourceforge.javydreamercsw.validation.manager.web.provider.AbstractProvider; +import org.openide.util.lookup.ServiceProvider; + +@ServiceProvider(service = IMainContentProvider.class) +public class DemoProvider extends AbstractProvider { + + private static final Logger LOG + = Logger.getLogger(DemoProvider.class.getSimpleName()); + private VerticalLayout layout; + + @Override + public Component getContent() { + if (layout == null) { + layout = new VerticalLayout(); + update(); + } + return layout; + } + + @Override + public void update() { + layout.removeAllComponents(); + VmUserJpaController controller + = new VmUserJpaController(DataBaseManager + .getEntityManagerFactory()); + layout.addComponent(new Label("

" + + TRANSLATOR.translate("demo.tab.title") + "

", + ContentMode.HTML)); + Label l = new Label(); + l.setId("demo.tab.message"); + layout.addComponent(l); + StringBuilder sb = new StringBuilder("
    "); + controller.findVmUserEntities().stream().filter((u) + -> (u.getId() < 1000)).forEachOrdered((u) -> { + try { + //Default accounts + if (u.getPassword() != null + && u.getPassword().equals(MD5 + .encrypt(u.getUsername()))) { + sb.append("
  • ") + .append(TRANSLATOR.translate("general.username")) + .append(": ") + .append(u.getUsername()) + .append(", ") + .append(TRANSLATOR.translate("general.password")) + .append(": ") + .append(u.getUsername()) + .append(" ") + .append(TRANSLATOR.translate("general.role")) + .append(": ") + .append(TRANSLATOR + .translate(u.getRoleList().get(0) + .getDescription())) + .append("
  • "); + } + } catch (VMException ex) { + LOG.log(Level.SEVERE, null, ex); + } + }); + sb.append("
"); + layout.addComponent(new Label(sb.toString(), + ContentMode.HTML)); + layout.setId(getComponentCaption()); + super.update(); + } + + @Override + public String getComponentCaption() { + return "demo.tab.name"; + } + + @Override + public boolean shouldDisplay() { + return DataBaseManager.isDemo(); + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/execution/ExecutionWizardStep.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/execution/ExecutionWizardStep.java index 7f672082..aa8fa979 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/execution/ExecutionWizardStep.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/execution/ExecutionWizardStep.java @@ -13,748 +13,748 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web.execution; - -import com.vaadin.data.fieldgroup.BeanFieldGroup; -import com.vaadin.event.FieldEvents.TextChangeEvent; -import com.vaadin.icons.VaadinIcons; -import com.vaadin.server.Resource; -import com.vaadin.server.Sizeable; -import com.vaadin.shared.ui.datefield.Resolution; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.ComboBox; -import com.vaadin.ui.Component; -import com.vaadin.ui.DateField; -import com.vaadin.ui.Field; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Notification; -import com.vaadin.ui.Panel; -import com.vaadin.ui.TextArea; -import com.vaadin.ui.TextField; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.Window; -import com.vaadin.ui.themes.ValoTheme; -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.api.internationalization.InternationalizationProvider; -import com.validation.manager.core.db.AttachmentType; -import com.validation.manager.core.db.ExecutionResult; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.ExecutionStepHasAttachment; -import com.validation.manager.core.db.ExecutionStepHasIssue; -import com.validation.manager.core.db.ReviewResult; -import com.validation.manager.core.db.controller.ExecutionResultJpaController; -import com.validation.manager.core.db.controller.IssueTypeJpaController; -import com.validation.manager.core.db.controller.ReviewResultJpaController; -import com.validation.manager.core.server.core.AttachmentServer; -import com.validation.manager.core.server.core.AttachmentTypeServer; -import com.validation.manager.core.server.core.ExecutionResultServer; -import com.validation.manager.core.server.core.ExecutionStepServer; -import com.validation.manager.core.server.core.IssueServer; -import com.validation.manager.core.server.core.IssueTypeServer; -import com.validation.manager.core.server.core.ReviewResultServer; -import com.validation.manager.core.server.core.VMSettingServer; -import de.steinwedel.messagebox.ButtonOption; -import de.steinwedel.messagebox.ButtonType; -import de.steinwedel.messagebox.MessageBox; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.sourceforge.javydreamercsw.validation.manager.web.ByteToStringConverter; -import net.sourceforge.javydreamercsw.validation.manager.web.VMWindow; -import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; -import net.sourceforge.javydreamercsw.validation.manager.web.file.IFileDisplay; -import net.sourceforge.javydreamercsw.validation.manager.web.file.PDFDisplay; -import org.jodconverter.OfficeDocumentConverter; -import org.jodconverter.office.DefaultOfficeManagerBuilder; -import org.jodconverter.office.OfficeException; -import org.jodconverter.office.OfficeManager; -import org.openide.util.Lookup; -import org.vaadin.easyuploads.MultiFileUpload; -import org.vaadin.teemu.wizards.Wizard; -import org.vaadin.teemu.wizards.WizardStep; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class ExecutionWizardStep implements WizardStep { - - private final Wizard w; - private final ExecutionStepServer step; - private final ComboBox result = new ComboBox("general.result"); - private final ComboBox review = new ComboBox("quality.review"); - private final ComboBox issueType = new ComboBox("issue.type"); - private Button attach; - private Button bug; - private Button comment; - private DateField start; - private DateField end; - private DateField reviewDate; - private static final Logger LOG - = Logger.getLogger(ExecutionWizardStep.class.getSimpleName()); - private boolean reviewer = false; - - public ExecutionWizardStep(Wizard w, ExecutionStep step, - boolean reviewer) { - this.reviewer = reviewer; - this.w = w; - this.step = new ExecutionStepServer(step); - issueType.setSizeFull(); - issueType.setReadOnly(false); - issueType.setRequired(true); - issueType.setRequiredError("missing.type"); - IssueTypeJpaController it - = new IssueTypeJpaController(DataBaseManager - .getEntityManagerFactory()); - it.findIssueTypeEntities().forEach(type -> { - String item = Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate(type.getTypeName()); - issueType.addItem(type.getTypeName()); - issueType.setItemCaption(type.getTypeName(), item); - switch (type.getId()) { - case 1: - issueType.setItemIcon(type.getTypeName(), VaadinIcons.BUG); - break; - case 2: - issueType.setItemIcon(type.getTypeName(), VaadinIcons.EYE); - break; - case 3: - issueType.setItemIcon(type.getTypeName(), VaadinIcons.QUESTION); - break; - } - }); - result.setReadOnly(false); - result.setRequired(true); - result.setRequiredError("missing.result"); - result.setTextInputAllowed(false); - review.setReadOnly(false); - review.setRequired(true); - review.setRequiredError("missing.reviiew.result"); - review.setTextInputAllowed(false); - ReviewResultJpaController c2 - = new ReviewResultJpaController(DataBaseManager - .getEntityManagerFactory()); - c2.findReviewResultEntities().forEach(r -> { - String item = Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate(r.getReviewName()); - review.addItem(r.getReviewName()); - review.setItemCaption(r.getReviewName(), item); - Resource icon; - switch (r.getId()) { - case 1: - icon = VaadinIcons.CHECK; - break; - case 2: - icon = VaadinIcons.CLOSE; - break; - default: - icon = VaadinIcons.CLOCK; - break; - } - review.setItemIcon(r.getReviewName(), icon); - }); - ExecutionResultJpaController c - = new ExecutionResultJpaController(DataBaseManager - .getEntityManagerFactory()); - c.findExecutionResultEntities().forEach(r -> { - String item = Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate(r.getResultName()); - result.addItem(r.getResultName()); - result.setItemCaption(r.getResultName(), item); - Resource icon; - switch (r.getId()) { - case 1: - icon = VaadinIcons.CHECK; - break; - case 2: - icon = VaadinIcons.CLOSE; - break; - case 3: - icon = VaadinIcons.PAUSE; - break; - default: - icon = VaadinIcons.CLOCK; - break; - } - result.setItemIcon(r.getResultName(), icon); - }); - } - - @Override - public String getCaption() { - return getStep().getStep().getTestCase().getName() + " Step:" - + getStep().getStep().getStepSequence(); - } - - @Override - public Component getContent() { - getStep().update(); - Panel form = new Panel("step.detail"); - if (getStep().getExecutionStart() == null) { - //Set the start date. - getStep().setExecutionStart(new Date()); - } - FormLayout layout = new FormLayout(); - form.setContent(layout); - form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); - BeanFieldGroup binder = new BeanFieldGroup(getStep().getStep().getClass()); - binder.setItemDataSource(getStep().getStep()); - TextArea text = new TextArea("general.text"); - text.setConverter(new ByteToStringConverter()); - binder.bind(text, "text"); - text.setSizeFull(); - layout.addComponent(text); - Field notes = binder.buildAndBind("general.notes", "notes", - TextArea.class); - notes.setSizeFull(); - layout.addComponent(notes); - if (getStep().getExecutionStart() != null) { - start = new DateField("start.date"); - start.setResolution(Resolution.SECOND); - start.setDateFormat(VMSettingServer.getSetting("date.format") - .getStringVal()); - start.setValue(getStep().getExecutionStart()); - start.setReadOnly(true); - layout.addComponent(start); - } - if (getStep().getExecutionEnd() != null) { - end = new DateField(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("end.date")); - end.setDateFormat(VMSettingServer.getSetting("date.format") - .getStringVal()); - end.setResolution(Resolution.SECOND); - end.setValue(getStep().getExecutionEnd()); - end.setReadOnly(true); - layout.addComponent(end); - } - binder.setReadOnly(true); - //Space to record result - if (getStep().getResultId() != null) { - result.setValue(getStep().getResultId().getResultName()); - } - layout.addComponent(result); - if (reviewer) {//Space to record review - if (getStep().getReviewResultId() != null) { - review.setValue(getStep().getReviewResultId().getReviewName()); - } - layout.addComponent(review); - } - //Add Reviewer name - if (getStep().getReviewer() != null) { - TextField reviewerField = new TextField(Lookup.getDefault() - .lookup(InternationalizationProvider.class) - .translate("general.reviewer")); - reviewerField.setValue(getStep().getReviewer().getFirstName() + " " - + getStep().getReviewer().getLastName()); - reviewerField.setReadOnly(true); - layout.addComponent(reviewerField); - } - if (getStep().getReviewDate() != null) { - reviewDate = new DateField(Lookup.getDefault() - .lookup(InternationalizationProvider.class) - .translate("review.date")); - reviewDate.setDateFormat(VMSettingServer.getSetting("date.format") - .getStringVal()); - reviewDate.setResolution(Resolution.SECOND); - reviewDate.setValue(getStep().getReviewDate()); - reviewDate.setReadOnly(true); - layout.addComponent(reviewDate); - } - if (VMSettingServer.getSetting("show.expected.result").getBoolVal()) { - TextArea expectedResult = new TextArea("expected.result"); - expectedResult.setConverter(new ByteToStringConverter()); - binder.bind(expectedResult, "expectedResult"); - expectedResult.setSizeFull(); - layout.addComponent(expectedResult); - } - //Add the Attachments - HorizontalLayout attachments = new HorizontalLayout(); - attachments.setCaption("general.attachment"); - HorizontalLayout comments = new HorizontalLayout(); - comments.setCaption("general.comments"); - HorizontalLayout issues = new HorizontalLayout(); - issues.setCaption("general.issue"); - int commentCounter = 0; - int issueCounter = 0; - for (ExecutionStepHasIssue ei : getStep().getExecutionStepHasIssueList()) { - issueCounter++; - Button a = new Button("Issue #" + issueCounter); - a.setIcon(VaadinIcons.BUG); - a.addClickListener((Button.ClickEvent event) -> { - displayIssue(new IssueServer(ei.getIssue())); - }); - a.setEnabled(!step.getLocked()); - issues.addComponent(a); - } - for (ExecutionStepHasAttachment attachment - : getStep().getExecutionStepHasAttachmentList()) { - switch (attachment.getAttachment().getAttachmentType().getType()) { - case "comment": { - //Comments go in a different section - commentCounter++; - Button a = new Button("Comment #" + commentCounter); - a.setIcon(VaadinIcons.CLIPBOARD_TEXT); - a.addClickListener((Button.ClickEvent event) -> { - if (!step.getLocked()) { - //Prompt if user wants this removed - MessageBox mb = getDeletionPrompt(attachment); - mb.open(); - } else { - displayComment(new AttachmentServer(attachment - .getAttachment().getAttachmentPK())); - } - }); - a.setEnabled(!step.getLocked()); - comments.addComponent(a); - break; - } - default: { - Button a = new Button(attachment.getAttachment().getFileName()); - a.setEnabled(!step.getLocked()); - a.setIcon(VaadinIcons.PAPERCLIP); - a.addClickListener((Button.ClickEvent event) -> { - if (!step.getLocked()) { - //Prompt if user wants this removed - MessageBox mb = getDeletionPrompt(attachment); - mb.open(); - } else { - displayAttachment( - new AttachmentServer(attachment.getAttachment() - .getAttachmentPK())); - } - }); - attachments.addComponent(a); - break; - } - } - } - if (attachments.getComponentCount() > 0) { - layout.addComponent(attachments); - } - if (comments.getComponentCount() > 0) { - layout.addComponent(comments); - } - if (issues.getComponentCount() > 0) { - layout.addComponent(issues); - } - //Add the menu - HorizontalLayout hl = new HorizontalLayout(); - attach = new Button("add.attachment"); - attach.setIcon(VaadinIcons.PAPERCLIP); - attach.addClickListener((Button.ClickEvent event) -> { - //Show dialog to upload file. - Window dialog = new VMWindow("attach.file"); - VerticalLayout vl = new VerticalLayout(); - MultiFileUpload multiFileUpload = new MultiFileUpload() { - @Override - protected void handleFile(File file, String fileName, - String mimeType, long length) { - try { - LOG.log(Level.FINE, "Received file {1} at: {0}", - new Object[]{file.getAbsolutePath(), fileName}); - //Process the file - //Create the attachment - AttachmentServer a = new AttachmentServer(); - a.addFile(file, fileName); - //Overwrite the default file name set in addFile. It'll be a temporary file name - a.setFileName(fileName); - a.write2DB(); - //Now add it to this Execution Step - if (getStep().getExecutionStepHasAttachmentList() == null) { - getStep().setExecutionStepHasAttachmentList(new ArrayList<>()); - } - getStep().addAttachment(a); - getStep().write2DB(); - w.updateCurrentStep(); - } catch (Exception ex) { - LOG.log(Level.SEVERE, "Error creating attachment!", ex); - } - } - }; - multiFileUpload.setCaption("select.files.attach"); - vl.addComponent(multiFileUpload); - dialog.setContent(vl); - dialog.setHeight(25, Sizeable.Unit.PERCENTAGE); - dialog.setWidth(25, Sizeable.Unit.PERCENTAGE); - dialog.center(); - ValidationManagerUI.getInstance().addWindow(dialog); - }); - hl.addComponent(attach); - bug = new Button("create.issue"); - bug.setIcon(VaadinIcons.BUG); - bug.addClickListener((Button.ClickEvent event) -> { - displayIssue(new IssueServer()); - }); - hl.addComponent(bug); - comment = new Button("add.comment"); - comment.setIcon(VaadinIcons.CLIPBOARD_TEXT); - comment.addClickListener((Button.ClickEvent event) -> { - AttachmentServer as = new AttachmentServer(); - //Get comment type - AttachmentType type = AttachmentTypeServer - .getTypeForExtension("comment"); - as.setAttachmentType(type); - displayComment(as); - }); - hl.addComponent(comment); - step.update(); - attach.setEnabled(!step.getLocked()); - bug.setEnabled(!step.getLocked()); - comment.setEnabled(!step.getLocked()); - result.setEnabled(!step.getLocked()); - layout.addComponent(hl); - return layout; - } - - private void displayIssue(IssueServer is) { - Panel form = new Panel("general.issue"); - FormLayout layout = new FormLayout(); - form.setContent(layout); - if (is.getIssuePK() == null) { - //Set creation date - is.setCreationTime(new Date()); - } - BeanFieldGroup binder = new BeanFieldGroup(is.getClass()); - binder.setItemDataSource(is); - Field title = binder.buildAndBind("general.summary", "title", - TextField.class); - title.setSizeFull(); - layout.addComponent(title); - Field desc = binder.buildAndBind("general.description", "description", - TextArea.class); - desc.setSizeFull(); - layout.addComponent(desc); - DateField creation = (DateField) binder.buildAndBind("creation.time", - "creationTime", - DateField.class); - creation.setReadOnly(true); - creation.setDateFormat(VMSettingServer.getSetting("date.format") - .getStringVal()); - creation.setResolution(Resolution.SECOND); - layout.addComponent(creation); - //Add the result - layout.addComponent(issueType); - if (is.getIssueType() != null) { - issueType.setValue(is.getIssueType().getTypeName()); - } else { - //Set it as observation - issueType.setValue("observation.name"); - } - //Lock if being created - issueType.setReadOnly(is.getIssueType() == null); - MessageBox mb = MessageBox.create(); - mb.setData(is); - mb.asModal(true) - .withMessage(layout) - .withButtonAlignment(Alignment.MIDDLE_CENTER) - .withOkButton(() -> { - try { - //Create the attachment - IssueServer issue = (IssueServer) mb.getData(); - issue.setDescription(((TextArea) desc).getValue().trim()); - issue.setIssueType(IssueTypeServer.getType((String) issueType.getValue())); - issue.setCreationTime(creation.getValue()); - issue.setTitle((String) title.getValue()); - boolean toAdd = issue.getIssuePK() == null; - issue.write2DB(); - if (toAdd) { - //Now add it to this Execution Step - if (getStep().getExecutionStepHasIssueList() == null) { - getStep().setExecutionStepHasIssueList(new ArrayList<>()); - } - getStep().addIssue(issue, ValidationManagerUI - .getInstance().getUser()); - getStep().write2DB(); - } - w.updateCurrentStep(); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - }, ButtonOption.focus(), - ButtonOption.icon(VaadinIcons.CHECK), - ButtonOption.disable()) - .withCancelButton(ButtonOption.icon(VaadinIcons.CLOSE)); - mb.getWindow().setCaption("issue.detail"); - mb.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); - ((TextArea) desc).addTextChangeListener((TextChangeEvent event1) -> { - //Enable if there is a description change. - mb.getButton(ButtonType.OK) - .setEnabled(!step.getLocked() - && !event1.getText().trim().isEmpty()); - }); - ((TextField) title).addTextChangeListener((TextChangeEvent event1) -> { - //Enable if there is a title change. - mb.getButton(ButtonType.OK) - .setEnabled(!step.getLocked() - && !event1.getText().trim().isEmpty()); - }); - mb.open(); - } - - private void displayComment(AttachmentServer as) { - Panel form = new Panel("general.comment"); - FormLayout layout = new FormLayout(); - form.setContent(layout); - BeanFieldGroup binder = new BeanFieldGroup(as.getClass()); - binder.setItemDataSource(as); - Field desc = binder.buildAndBind("general.text", "textValue", - TextArea.class); - desc.setSizeFull(); - layout.addComponent(desc); - MessageBox mb = MessageBox.create(); - mb.setData(as); - mb.asModal(true) - .withMessage(desc) - .withButtonAlignment(Alignment.MIDDLE_CENTER) - .withOkButton(() -> { - try { - //Create the attachment - AttachmentServer a = (AttachmentServer) mb.getData(); - a.setTextValue(((TextArea) desc).getValue().trim()); - boolean toAdd = a.getAttachmentPK() == null; - a.write2DB(); - if (toAdd) { - //Now add it to this Execution Step - if (getStep().getExecutionStepHasAttachmentList() == null) { - getStep().setExecutionStepHasAttachmentList(new ArrayList<>()); - } - getStep().addAttachment(a); - getStep().write2DB(); - } - w.updateCurrentStep(); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - }, ButtonOption.focus(), - ButtonOption.icon(VaadinIcons.CHECK), - ButtonOption.disable()) - .withCancelButton(ButtonOption.icon(VaadinIcons.CLOSE)); - mb.getWindow().setCaption("enter.comment"); - mb.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); - ((TextArea) desc).addTextChangeListener((TextChangeEvent event1) -> { - //Enable only when there is a comment. - mb.getButton(ButtonType.OK) - .setEnabled(!step.getLocked() - && !event1.getText().trim().isEmpty()); - }); - mb.open(); - } - - @Override - public boolean onAdvance() { - //Can only proceed after the current step is executed and documented. - String answer = ((String) result.getValue()); - String answer2 = ((String) review.getValue()); - if (answer == null) { - Notification.show("unable.to.proceed", - result.getRequiredError(), - Notification.Type.WARNING_MESSAGE); - } else if (reviewer && answer2 == null) { - Notification.show("unable.to.proceed", - review.getRequiredError(), - Notification.Type.WARNING_MESSAGE); - } else { - try { - //Save the result - ExecutionResult newResult = ExecutionResultServer - .getResult(answer); - ReviewResult newReview = ReviewResultServer.getReview(answer2); - getStep().setExecutionStart(start.getValue()); - if (getStep().getResultId() == null - || !Objects.equals(step.getResultId().getId(), - newResult.getId())) { - getStep().setResultId(newResult); - //Set end date to null to reflect update - getStep().setExecutionEnd(null); - } - if (getStep().getReviewResultId() == null - || !Objects.equals(step.getReviewResultId().getId(), - newReview.getId())) { - getStep().setReviewResultId(newReview); - //Set end date to null to reflect update - getStep().setReviewer(ValidationManagerUI.getInstance().getUser()); - } - if (getStep().getExecutionEnd() == null) { - getStep().setExecutionEnd(new Date()); - } - if (reviewer && getStep().getReviewDate() == null) { - getStep().setReviewDate(new Date()); - } - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - boolean validAnswer = result.getValue() != null - && !((String) result.getValue()).trim().isEmpty(); - boolean validReview = review.getValue() != null - && !((String) review.getValue()).trim().isEmpty(); - return reviewer ? validReview && validAnswer : validAnswer; - } - - @Override - public boolean onBack() { - return getStep().getStep().getStepSequence() > 1; - } - - /** - * @return the step - */ - public ExecutionStepServer getStep() { - return step; - } - - public static boolean getPDFRendering(File source, File dest) - throws IllegalStateException { - OfficeManager officeManager = null; - try { - File home = new File(VMSettingServer.getSetting("openoffice.home") - .getStringVal()); - int port = VMSettingServer - .getSetting("openoffice.port").getIntVal(); - if (!home.isDirectory() || !home.exists()) { - LOG.log(Level.WARNING, - "Unable to find OpenOffice and/or LibreOffice " - + "installation at: {0}", home); - Notification.show("unable.to.render.pdf.title", - "unable.to.render.pdf.message", - Notification.Type.ERROR_MESSAGE); - return false; - } - if (port <= 0) { - LOG.log(Level.WARNING, - "Unable to find OpenOffice and/or LibreOffice " - + "installation at port: {0}", port); - Notification.show("unable.to.render.pdf.title", - "unable.to.render.pdf.port", - Notification.Type.ERROR_MESSAGE); - return false; - } - // Connect to an OpenOffice.org instance running on available port - try { - officeManager = new DefaultOfficeManagerBuilder() - .setPortNumber(port) - .setOfficeHome(home) - .build(); - officeManager.start(); - - OfficeDocumentConverter converter - = new OfficeDocumentConverter(officeManager); - converter.convert(source, dest); - // close the connection - officeManager.stop(); - return true; - } catch (IllegalStateException ise) { - //Looks like OpenOffice or LibreOffice is not installed - LOG.log(Level.WARNING, - "Unable to find OpenOffice and/or LibreOffice " - + "installation.", ise); - } - } catch (OfficeException e) { - if (officeManager != null) { - try { - officeManager.stop(); - } catch (OfficeException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - LOG.log(Level.SEVERE, null, e); - } - return false; - } - - private void displayAttachment(AttachmentServer attachment) { - String name = attachment.getFileName(); - byte[] bytes = attachment.getFile(); - boolean ableToDisplay = false; - try { - for (IFileDisplay fd : Lookup.getDefault() - .lookupAll(IFileDisplay.class)) { - if (fd.supportFile(new File(name))) { - ValidationManagerUI.getInstance() - .addWindow(fd.getViewer(fd.loadFile(name, - bytes))); - ableToDisplay = true; - break; - } - } - if (!ableToDisplay) { - //Convert file to pfd - PDFDisplay pdf = new PDFDisplay(); - File source = pdf.loadFile(name, bytes); - File dest = new File(System.getProperty("java.io.tmpdir") - + System.getProperty("file.separator") - + name.substring(0, name.lastIndexOf(".")) - + ".pdf"); - getPDFRendering(source, dest); - if (dest.exists()) { - ValidationManagerUI.getInstance().addWindow(pdf.getViewer(dest)); - ableToDisplay = true; - } - } - } catch (IOException ex) { - LOG.log(Level.SEVERE, - "Error loading attachment file: " - + name, ex); - } - if (!ableToDisplay) { - Notification.show("unable.to.render.pdf.title", - "unable.to.render.pdf.message", - Notification.Type.ERROR_MESSAGE); - } - } - - private MessageBox getDeletionPrompt(Object data) { - MessageBox mb = MessageBox.createQuestion(); - mb.setData(data); - mb.asModal(true) - .withMessage(new Label("remove.item.title")) - .withButtonAlignment(Alignment.MIDDLE_CENTER) - .withYesButton(() -> { - try { - if (mb.getData() instanceof ExecutionStepHasAttachment) { - getStep().removeAttachment(new AttachmentServer( - ((ExecutionStepHasAttachment) mb.getData()) - .getAttachment().getAttachmentPK())); - } - if (mb.getData() instanceof ExecutionStepHasIssue) { - getStep().removeIssue(new IssueServer( - ((ExecutionStepHasIssue) mb.getData()) - .getIssue())); - } - getStep().write2DB(); - getStep().update(); - w.updateCurrentStep(); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - }, ButtonOption.focus(), - ButtonOption.icon(VaadinIcons.CHECK)) - .withNoButton(() -> { - if (mb.getData() instanceof ExecutionStepHasAttachment) { - ExecutionStepHasAttachment esha = (ExecutionStepHasAttachment) mb.getData(); - if (esha.getAttachment().getAttachmentType().getType().equals("comment")) { - displayComment(new AttachmentServer(esha - .getAttachment().getAttachmentPK())); - } else { - displayAttachment(new AttachmentServer(esha - .getAttachment().getAttachmentPK())); - } - } - if (mb.getData() instanceof ExecutionStepHasIssue) { - ExecutionStepHasIssue eshi = (ExecutionStepHasIssue) mb.getData(); - displayIssue(new IssueServer(eshi.getIssue())); - } - }, - ButtonOption.icon(VaadinIcons.CLOSE)); - mb.getWindow().setCaption("issue.details"); - mb.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); - return mb; - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.execution; + +import com.vaadin.data.fieldgroup.BeanFieldGroup; +import com.vaadin.event.FieldEvents.TextChangeEvent; +import com.vaadin.icons.VaadinIcons; +import com.vaadin.server.Resource; +import com.vaadin.server.Sizeable; +import com.vaadin.shared.ui.datefield.Resolution; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.DateField; +import com.vaadin.ui.Field; +import com.vaadin.ui.FormLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; +import com.vaadin.ui.Panel; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; +import com.vaadin.ui.themes.ValoTheme; +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.api.internationalization.InternationalizationProvider; +import com.validation.manager.core.db.AttachmentType; +import com.validation.manager.core.db.ExecutionResult; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.ExecutionStepHasAttachment; +import com.validation.manager.core.db.ExecutionStepHasIssue; +import com.validation.manager.core.db.ReviewResult; +import com.validation.manager.core.db.controller.ExecutionResultJpaController; +import com.validation.manager.core.db.controller.IssueTypeJpaController; +import com.validation.manager.core.db.controller.ReviewResultJpaController; +import com.validation.manager.core.server.core.AttachmentServer; +import com.validation.manager.core.server.core.AttachmentTypeServer; +import com.validation.manager.core.server.core.ExecutionResultServer; +import com.validation.manager.core.server.core.ExecutionStepServer; +import com.validation.manager.core.server.core.IssueServer; +import com.validation.manager.core.server.core.IssueTypeServer; +import com.validation.manager.core.server.core.ReviewResultServer; +import com.validation.manager.core.server.core.VMSettingServer; +import de.steinwedel.messagebox.ButtonOption; +import de.steinwedel.messagebox.ButtonType; +import de.steinwedel.messagebox.MessageBox; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.sourceforge.javydreamercsw.validation.manager.web.component.ByteToStringConverter; +import net.sourceforge.javydreamercsw.validation.manager.web.VMWindow; +import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; +import net.sourceforge.javydreamercsw.validation.manager.web.file.IFileDisplay; +import net.sourceforge.javydreamercsw.validation.manager.web.file.PDFDisplay; +import org.jodconverter.OfficeDocumentConverter; +import org.jodconverter.office.DefaultOfficeManagerBuilder; +import org.jodconverter.office.OfficeException; +import org.jodconverter.office.OfficeManager; +import org.openide.util.Lookup; +import org.vaadin.easyuploads.MultiFileUpload; +import org.vaadin.teemu.wizards.Wizard; +import org.vaadin.teemu.wizards.WizardStep; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class ExecutionWizardStep implements WizardStep { + + private final Wizard w; + private final ExecutionStepServer step; + private final ComboBox result = new ComboBox("general.result"); + private final ComboBox review = new ComboBox("quality.review"); + private final ComboBox issueType = new ComboBox("issue.type"); + private Button attach; + private Button bug; + private Button comment; + private DateField start; + private DateField end; + private DateField reviewDate; + private static final Logger LOG + = Logger.getLogger(ExecutionWizardStep.class.getSimpleName()); + private boolean reviewer = false; + + public ExecutionWizardStep(Wizard w, ExecutionStep step, + boolean reviewer) { + this.reviewer = reviewer; + this.w = w; + this.step = new ExecutionStepServer(step); + issueType.setSizeFull(); + issueType.setReadOnly(false); + issueType.setRequired(true); + issueType.setRequiredError("missing.type"); + IssueTypeJpaController it + = new IssueTypeJpaController(DataBaseManager + .getEntityManagerFactory()); + it.findIssueTypeEntities().forEach(type -> { + String item = Lookup.getDefault().lookup(InternationalizationProvider.class) + .translate(type.getTypeName()); + issueType.addItem(type.getTypeName()); + issueType.setItemCaption(type.getTypeName(), item); + switch (type.getId()) { + case 1: + issueType.setItemIcon(type.getTypeName(), VaadinIcons.BUG); + break; + case 2: + issueType.setItemIcon(type.getTypeName(), VaadinIcons.EYE); + break; + case 3: + issueType.setItemIcon(type.getTypeName(), VaadinIcons.QUESTION); + break; + } + }); + result.setReadOnly(false); + result.setRequired(true); + result.setRequiredError("missing.result"); + result.setTextInputAllowed(false); + review.setReadOnly(false); + review.setRequired(true); + review.setRequiredError("missing.reviiew.result"); + review.setTextInputAllowed(false); + ReviewResultJpaController c2 + = new ReviewResultJpaController(DataBaseManager + .getEntityManagerFactory()); + c2.findReviewResultEntities().forEach(r -> { + String item = Lookup.getDefault().lookup(InternationalizationProvider.class) + .translate(r.getReviewName()); + review.addItem(r.getReviewName()); + review.setItemCaption(r.getReviewName(), item); + Resource icon; + switch (r.getId()) { + case 1: + icon = VaadinIcons.CHECK; + break; + case 2: + icon = VaadinIcons.CLOSE; + break; + default: + icon = VaadinIcons.CLOCK; + break; + } + review.setItemIcon(r.getReviewName(), icon); + }); + ExecutionResultJpaController c + = new ExecutionResultJpaController(DataBaseManager + .getEntityManagerFactory()); + c.findExecutionResultEntities().forEach(r -> { + String item = Lookup.getDefault().lookup(InternationalizationProvider.class) + .translate(r.getResultName()); + result.addItem(r.getResultName()); + result.setItemCaption(r.getResultName(), item); + Resource icon; + switch (r.getId()) { + case 1: + icon = VaadinIcons.CHECK; + break; + case 2: + icon = VaadinIcons.CLOSE; + break; + case 3: + icon = VaadinIcons.PAUSE; + break; + default: + icon = VaadinIcons.CLOCK; + break; + } + result.setItemIcon(r.getResultName(), icon); + }); + } + + @Override + public String getCaption() { + return getStep().getStep().getTestCase().getName() + " Step:" + + getStep().getStep().getStepSequence(); + } + + @Override + public Component getContent() { + getStep().update(); + Panel form = new Panel("step.detail"); + if (getStep().getExecutionStart() == null) { + //Set the start date. + getStep().setExecutionStart(new Date()); + } + FormLayout layout = new FormLayout(); + form.setContent(layout); + form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); + BeanFieldGroup binder = new BeanFieldGroup(getStep().getStep().getClass()); + binder.setItemDataSource(getStep().getStep()); + TextArea text = new TextArea("general.text"); + text.setConverter(new ByteToStringConverter()); + binder.bind(text, "text"); + text.setSizeFull(); + layout.addComponent(text); + Field notes = binder.buildAndBind("general.notes", "notes", + TextArea.class); + notes.setSizeFull(); + layout.addComponent(notes); + if (getStep().getExecutionStart() != null) { + start = new DateField("start.date"); + start.setResolution(Resolution.SECOND); + start.setDateFormat(VMSettingServer.getSetting("date.format") + .getStringVal()); + start.setValue(getStep().getExecutionStart()); + start.setReadOnly(true); + layout.addComponent(start); + } + if (getStep().getExecutionEnd() != null) { + end = new DateField(Lookup.getDefault().lookup(InternationalizationProvider.class) + .translate("end.date")); + end.setDateFormat(VMSettingServer.getSetting("date.format") + .getStringVal()); + end.setResolution(Resolution.SECOND); + end.setValue(getStep().getExecutionEnd()); + end.setReadOnly(true); + layout.addComponent(end); + } + binder.setReadOnly(true); + //Space to record result + if (getStep().getResultId() != null) { + result.setValue(getStep().getResultId().getResultName()); + } + layout.addComponent(result); + if (reviewer) {//Space to record review + if (getStep().getReviewResultId() != null) { + review.setValue(getStep().getReviewResultId().getReviewName()); + } + layout.addComponent(review); + } + //Add Reviewer name + if (getStep().getReviewer() != null) { + TextField reviewerField = new TextField(Lookup.getDefault() + .lookup(InternationalizationProvider.class) + .translate("general.reviewer")); + reviewerField.setValue(getStep().getReviewer().getFirstName() + " " + + getStep().getReviewer().getLastName()); + reviewerField.setReadOnly(true); + layout.addComponent(reviewerField); + } + if (getStep().getReviewDate() != null) { + reviewDate = new DateField(Lookup.getDefault() + .lookup(InternationalizationProvider.class) + .translate("review.date")); + reviewDate.setDateFormat(VMSettingServer.getSetting("date.format") + .getStringVal()); + reviewDate.setResolution(Resolution.SECOND); + reviewDate.setValue(getStep().getReviewDate()); + reviewDate.setReadOnly(true); + layout.addComponent(reviewDate); + } + if (VMSettingServer.getSetting("show.expected.result").getBoolVal()) { + TextArea expectedResult = new TextArea("expected.result"); + expectedResult.setConverter(new ByteToStringConverter()); + binder.bind(expectedResult, "expectedResult"); + expectedResult.setSizeFull(); + layout.addComponent(expectedResult); + } + //Add the Attachments + HorizontalLayout attachments = new HorizontalLayout(); + attachments.setCaption("general.attachment"); + HorizontalLayout comments = new HorizontalLayout(); + comments.setCaption("general.comments"); + HorizontalLayout issues = new HorizontalLayout(); + issues.setCaption("general.issue"); + int commentCounter = 0; + int issueCounter = 0; + for (ExecutionStepHasIssue ei : getStep().getExecutionStepHasIssueList()) { + issueCounter++; + Button a = new Button("Issue #" + issueCounter); + a.setIcon(VaadinIcons.BUG); + a.addClickListener((Button.ClickEvent event) -> { + displayIssue(new IssueServer(ei.getIssue())); + }); + a.setEnabled(!step.getLocked()); + issues.addComponent(a); + } + for (ExecutionStepHasAttachment attachment + : getStep().getExecutionStepHasAttachmentList()) { + switch (attachment.getAttachment().getAttachmentType().getType()) { + case "comment": { + //Comments go in a different section + commentCounter++; + Button a = new Button("Comment #" + commentCounter); + a.setIcon(VaadinIcons.CLIPBOARD_TEXT); + a.addClickListener((Button.ClickEvent event) -> { + if (!step.getLocked()) { + //Prompt if user wants this removed + MessageBox mb = getDeletionPrompt(attachment); + mb.open(); + } else { + displayComment(new AttachmentServer(attachment + .getAttachment().getAttachmentPK())); + } + }); + a.setEnabled(!step.getLocked()); + comments.addComponent(a); + break; + } + default: { + Button a = new Button(attachment.getAttachment().getFileName()); + a.setEnabled(!step.getLocked()); + a.setIcon(VaadinIcons.PAPERCLIP); + a.addClickListener((Button.ClickEvent event) -> { + if (!step.getLocked()) { + //Prompt if user wants this removed + MessageBox mb = getDeletionPrompt(attachment); + mb.open(); + } else { + displayAttachment( + new AttachmentServer(attachment.getAttachment() + .getAttachmentPK())); + } + }); + attachments.addComponent(a); + break; + } + } + } + if (attachments.getComponentCount() > 0) { + layout.addComponent(attachments); + } + if (comments.getComponentCount() > 0) { + layout.addComponent(comments); + } + if (issues.getComponentCount() > 0) { + layout.addComponent(issues); + } + //Add the menu + HorizontalLayout hl = new HorizontalLayout(); + attach = new Button("add.attachment"); + attach.setIcon(VaadinIcons.PAPERCLIP); + attach.addClickListener((Button.ClickEvent event) -> { + //Show dialog to upload file. + Window dialog = new VMWindow("attach.file"); + VerticalLayout vl = new VerticalLayout(); + MultiFileUpload multiFileUpload = new MultiFileUpload() { + @Override + protected void handleFile(File file, String fileName, + String mimeType, long length) { + try { + LOG.log(Level.FINE, "Received file {1} at: {0}", + new Object[]{file.getAbsolutePath(), fileName}); + //Process the file + //Create the attachment + AttachmentServer a = new AttachmentServer(); + a.addFile(file, fileName); + //Overwrite the default file name set in addFile. It'll be a temporary file name + a.setFileName(fileName); + a.write2DB(); + //Now add it to this Execution Step + if (getStep().getExecutionStepHasAttachmentList() == null) { + getStep().setExecutionStepHasAttachmentList(new ArrayList<>()); + } + getStep().addAttachment(a); + getStep().write2DB(); + w.updateCurrentStep(); + } catch (Exception ex) { + LOG.log(Level.SEVERE, "Error creating attachment!", ex); + } + } + }; + multiFileUpload.setCaption("select.files.attach"); + vl.addComponent(multiFileUpload); + dialog.setContent(vl); + dialog.setHeight(25, Sizeable.Unit.PERCENTAGE); + dialog.setWidth(25, Sizeable.Unit.PERCENTAGE); + dialog.center(); + ValidationManagerUI.getInstance().addWindow(dialog); + }); + hl.addComponent(attach); + bug = new Button("create.issue"); + bug.setIcon(VaadinIcons.BUG); + bug.addClickListener((Button.ClickEvent event) -> { + displayIssue(new IssueServer()); + }); + hl.addComponent(bug); + comment = new Button("add.comment"); + comment.setIcon(VaadinIcons.CLIPBOARD_TEXT); + comment.addClickListener((Button.ClickEvent event) -> { + AttachmentServer as = new AttachmentServer(); + //Get comment type + AttachmentType type = AttachmentTypeServer + .getTypeForExtension("comment"); + as.setAttachmentType(type); + displayComment(as); + }); + hl.addComponent(comment); + step.update(); + attach.setEnabled(!step.getLocked()); + bug.setEnabled(!step.getLocked()); + comment.setEnabled(!step.getLocked()); + result.setEnabled(!step.getLocked()); + layout.addComponent(hl); + return layout; + } + + private void displayIssue(IssueServer is) { + Panel form = new Panel("general.issue"); + FormLayout layout = new FormLayout(); + form.setContent(layout); + if (is.getIssuePK() == null) { + //Set creation date + is.setCreationTime(new Date()); + } + BeanFieldGroup binder = new BeanFieldGroup(is.getClass()); + binder.setItemDataSource(is); + Field title = binder.buildAndBind("general.summary", "title", + TextField.class); + title.setSizeFull(); + layout.addComponent(title); + Field desc = binder.buildAndBind("general.description", "description", + TextArea.class); + desc.setSizeFull(); + layout.addComponent(desc); + DateField creation = (DateField) binder.buildAndBind("creation.time", + "creationTime", + DateField.class); + creation.setReadOnly(true); + creation.setDateFormat(VMSettingServer.getSetting("date.format") + .getStringVal()); + creation.setResolution(Resolution.SECOND); + layout.addComponent(creation); + //Add the result + layout.addComponent(issueType); + if (is.getIssueType() != null) { + issueType.setValue(is.getIssueType().getTypeName()); + } else { + //Set it as observation + issueType.setValue("observation.name"); + } + //Lock if being created + issueType.setReadOnly(is.getIssueType() == null); + MessageBox mb = MessageBox.create(); + mb.setData(is); + mb.asModal(true) + .withMessage(layout) + .withButtonAlignment(Alignment.MIDDLE_CENTER) + .withOkButton(() -> { + try { + //Create the attachment + IssueServer issue = (IssueServer) mb.getData(); + issue.setDescription(((TextArea) desc).getValue().trim()); + issue.setIssueType(IssueTypeServer.getType((String) issueType.getValue())); + issue.setCreationTime(creation.getValue()); + issue.setTitle((String) title.getValue()); + boolean toAdd = issue.getIssuePK() == null; + issue.write2DB(); + if (toAdd) { + //Now add it to this Execution Step + if (getStep().getExecutionStepHasIssueList() == null) { + getStep().setExecutionStepHasIssueList(new ArrayList<>()); + } + getStep().addIssue(issue, ValidationManagerUI + .getInstance().getUser()); + getStep().write2DB(); + } + w.updateCurrentStep(); + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + } + }, ButtonOption.focus(), + ButtonOption.icon(VaadinIcons.CHECK), + ButtonOption.disable()) + .withCancelButton(ButtonOption.icon(VaadinIcons.CLOSE)); + mb.getWindow().setCaption("issue.detail"); + mb.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); + ((TextArea) desc).addTextChangeListener((TextChangeEvent event1) -> { + //Enable if there is a description change. + mb.getButton(ButtonType.OK) + .setEnabled(!step.getLocked() + && !event1.getText().trim().isEmpty()); + }); + ((TextField) title).addTextChangeListener((TextChangeEvent event1) -> { + //Enable if there is a title change. + mb.getButton(ButtonType.OK) + .setEnabled(!step.getLocked() + && !event1.getText().trim().isEmpty()); + }); + mb.open(); + } + + private void displayComment(AttachmentServer as) { + Panel form = new Panel("general.comment"); + FormLayout layout = new FormLayout(); + form.setContent(layout); + BeanFieldGroup binder = new BeanFieldGroup(as.getClass()); + binder.setItemDataSource(as); + Field desc = binder.buildAndBind("general.text", "textValue", + TextArea.class); + desc.setSizeFull(); + layout.addComponent(desc); + MessageBox mb = MessageBox.create(); + mb.setData(as); + mb.asModal(true) + .withMessage(desc) + .withButtonAlignment(Alignment.MIDDLE_CENTER) + .withOkButton(() -> { + try { + //Create the attachment + AttachmentServer a = (AttachmentServer) mb.getData(); + a.setTextValue(((TextArea) desc).getValue().trim()); + boolean toAdd = a.getAttachmentPK() == null; + a.write2DB(); + if (toAdd) { + //Now add it to this Execution Step + if (getStep().getExecutionStepHasAttachmentList() == null) { + getStep().setExecutionStepHasAttachmentList(new ArrayList<>()); + } + getStep().addAttachment(a); + getStep().write2DB(); + } + w.updateCurrentStep(); + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + } + }, ButtonOption.focus(), + ButtonOption.icon(VaadinIcons.CHECK), + ButtonOption.disable()) + .withCancelButton(ButtonOption.icon(VaadinIcons.CLOSE)); + mb.getWindow().setCaption("enter.comment"); + mb.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); + ((TextArea) desc).addTextChangeListener((TextChangeEvent event1) -> { + //Enable only when there is a comment. + mb.getButton(ButtonType.OK) + .setEnabled(!step.getLocked() + && !event1.getText().trim().isEmpty()); + }); + mb.open(); + } + + @Override + public boolean onAdvance() { + //Can only proceed after the current step is executed and documented. + String answer = ((String) result.getValue()); + String answer2 = ((String) review.getValue()); + if (answer == null) { + Notification.show("unable.to.proceed", + result.getRequiredError(), + Notification.Type.WARNING_MESSAGE); + } else if (reviewer && answer2 == null) { + Notification.show("unable.to.proceed", + review.getRequiredError(), + Notification.Type.WARNING_MESSAGE); + } else { + try { + //Save the result + ExecutionResult newResult = ExecutionResultServer + .getResult(answer); + ReviewResult newReview = ReviewResultServer.getReview(answer2); + getStep().setExecutionStart(start.getValue()); + if (getStep().getResultId() == null + || !Objects.equals(step.getResultId().getId(), + newResult.getId())) { + getStep().setResultId(newResult); + //Set end date to null to reflect update + getStep().setExecutionEnd(null); + } + if (getStep().getReviewResultId() == null + || !Objects.equals(step.getReviewResultId().getId(), + newReview.getId())) { + getStep().setReviewResultId(newReview); + //Set end date to null to reflect update + getStep().setReviewer(ValidationManagerUI.getInstance().getUser()); + } + if (getStep().getExecutionEnd() == null) { + getStep().setExecutionEnd(new Date()); + } + if (reviewer && getStep().getReviewDate() == null) { + getStep().setReviewDate(new Date()); + } + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + boolean validAnswer = result.getValue() != null + && !((String) result.getValue()).trim().isEmpty(); + boolean validReview = review.getValue() != null + && !((String) review.getValue()).trim().isEmpty(); + return reviewer ? validReview && validAnswer : validAnswer; + } + + @Override + public boolean onBack() { + return getStep().getStep().getStepSequence() > 1; + } + + /** + * @return the step + */ + public ExecutionStepServer getStep() { + return step; + } + + public static boolean getPDFRendering(File source, File dest) + throws IllegalStateException { + OfficeManager officeManager = null; + try { + File home = new File(VMSettingServer.getSetting("openoffice.home") + .getStringVal()); + int port = VMSettingServer + .getSetting("openoffice.port").getIntVal(); + if (!home.isDirectory() || !home.exists()) { + LOG.log(Level.WARNING, + "Unable to find OpenOffice and/or LibreOffice " + + "installation at: {0}", home); + Notification.show("unable.to.render.pdf.title", + "unable.to.render.pdf.message", + Notification.Type.ERROR_MESSAGE); + return false; + } + if (port <= 0) { + LOG.log(Level.WARNING, + "Unable to find OpenOffice and/or LibreOffice " + + "installation at port: {0}", port); + Notification.show("unable.to.render.pdf.title", + "unable.to.render.pdf.port", + Notification.Type.ERROR_MESSAGE); + return false; + } + // Connect to an OpenOffice.org instance running on available port + try { + officeManager = new DefaultOfficeManagerBuilder() + .setPortNumber(port) + .setOfficeHome(home) + .build(); + officeManager.start(); + + OfficeDocumentConverter converter + = new OfficeDocumentConverter(officeManager); + converter.convert(source, dest); + // close the connection + officeManager.stop(); + return true; + } catch (IllegalStateException ise) { + //Looks like OpenOffice or LibreOffice is not installed + LOG.log(Level.WARNING, + "Unable to find OpenOffice and/or LibreOffice " + + "installation.", ise); + } + } catch (OfficeException e) { + if (officeManager != null) { + try { + officeManager.stop(); + } catch (OfficeException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + LOG.log(Level.SEVERE, null, e); + } + return false; + } + + private void displayAttachment(AttachmentServer attachment) { + String name = attachment.getFileName(); + byte[] bytes = attachment.getFile(); + boolean ableToDisplay = false; + try { + for (IFileDisplay fd : Lookup.getDefault() + .lookupAll(IFileDisplay.class)) { + if (fd.supportFile(new File(name))) { + ValidationManagerUI.getInstance() + .addWindow(fd.getViewer(fd.loadFile(name, + bytes))); + ableToDisplay = true; + break; + } + } + if (!ableToDisplay) { + //Convert file to pfd + PDFDisplay pdf = new PDFDisplay(); + File source = pdf.loadFile(name, bytes); + File dest = new File(System.getProperty("java.io.tmpdir") + + System.getProperty("file.separator") + + name.substring(0, name.lastIndexOf(".")) + + ".pdf"); + getPDFRendering(source, dest); + if (dest.exists()) { + ValidationManagerUI.getInstance().addWindow(pdf.getViewer(dest)); + ableToDisplay = true; + } + } + } catch (IOException ex) { + LOG.log(Level.SEVERE, + "Error loading attachment file: " + + name, ex); + } + if (!ableToDisplay) { + Notification.show("unable.to.render.pdf.title", + "unable.to.render.pdf.message", + Notification.Type.ERROR_MESSAGE); + } + } + + private MessageBox getDeletionPrompt(Object data) { + MessageBox mb = MessageBox.createQuestion(); + mb.setData(data); + mb.asModal(true) + .withMessage(new Label("remove.item.title")) + .withButtonAlignment(Alignment.MIDDLE_CENTER) + .withYesButton(() -> { + try { + if (mb.getData() instanceof ExecutionStepHasAttachment) { + getStep().removeAttachment(new AttachmentServer( + ((ExecutionStepHasAttachment) mb.getData()) + .getAttachment().getAttachmentPK())); + } + if (mb.getData() instanceof ExecutionStepHasIssue) { + getStep().removeIssue(new IssueServer( + ((ExecutionStepHasIssue) mb.getData()) + .getIssue())); + } + getStep().write2DB(); + getStep().update(); + w.updateCurrentStep(); + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + } + }, ButtonOption.focus(), + ButtonOption.icon(VaadinIcons.CHECK)) + .withNoButton(() -> { + if (mb.getData() instanceof ExecutionStepHasAttachment) { + ExecutionStepHasAttachment esha = (ExecutionStepHasAttachment) mb.getData(); + if (esha.getAttachment().getAttachmentType().getType().equals("comment")) { + displayComment(new AttachmentServer(esha + .getAttachment().getAttachmentPK())); + } else { + displayAttachment(new AttachmentServer(esha + .getAttachment().getAttachmentPK())); + } + } + if (mb.getData() instanceof ExecutionStepHasIssue) { + ExecutionStepHasIssue eshi = (ExecutionStepHasIssue) mb.getData(); + displayIssue(new IssueServer(eshi.getIssue())); + } + }, + ButtonOption.icon(VaadinIcons.CLOSE)); + mb.getWindow().setCaption("issue.details"); + mb.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); + return mb; + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/notification/NotificationManager.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/notification/NotificationManager.java index 2111d16b..f755a55c 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/notification/NotificationManager.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/notification/NotificationManager.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,39 +13,61 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web.notification; - -import com.validation.manager.core.api.notification.INotificationManager; -import com.validation.manager.core.api.notification.NotificationTypes; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.server.core.NotificationServer; -import com.validation.manager.core.server.core.NotificationTypeServer; -import java.util.Date; -import org.openide.util.lookup.ServiceProvider; - -@ServiceProvider(service = INotificationManager.class) -public class NotificationManager implements INotificationManager { - - @Override - public void addNotification(String message, NotificationTypes type, - VmUser target, VmUser author) throws Exception { - NotificationServer ns = new NotificationServer(); - ns.setAuthor(author); - ns.setTargetUser(target); - ns.setContent(message); - ns.setCreationDate(new Date()); - String selected; - switch (type) { - case TEST: - selected = "notification.test.pending"; - break; - case REVIEW: - selected = "notification.review.pending"; - break; - default: - selected = "general.notification"; - } - ns.setNotificationType(NotificationTypeServer.getType(selected)); - ns.write2DB(); - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.notification; + +import com.validation.manager.core.api.email.IEmailManager; +import com.validation.manager.core.api.internationalization.InternationalizationProvider; +import com.validation.manager.core.api.notification.INotificationManager; +import com.validation.manager.core.api.notification.NotificationTypes; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.server.core.NotificationServer; +import com.validation.manager.core.server.core.NotificationTypeServer; +import com.validation.manager.core.server.core.VMSettingServer; +import com.validation.manager.core.server.core.VMUserServer; +import java.util.Date; +import java.util.Locale; +import org.openide.util.Lookup; +import org.openide.util.lookup.ServiceProvider; + +@ServiceProvider(service = INotificationManager.class) +public class NotificationManager implements INotificationManager { + + private static final InternationalizationProvider TRANSLATOR + = Lookup.getDefault().lookup(InternationalizationProvider.class); + + @Override + public void addNotification(String message, NotificationTypes type, + VmUser target, VmUser author) throws Exception { + NotificationServer ns = new NotificationServer(); + ns.setAuthor(author); + ns.setTargetUser(target); + ns.setContent(message); + ns.setCreationDate(new Date()); + String selected; + switch (type) { + case TEST: + selected = "notification.test.pending"; + break; + case REVIEW: + selected = "notification.review.pending"; + break; + default: + selected = "general.notification"; + } + ns.setNotificationType(NotificationTypeServer.getType(selected)); + ns.write2DB(); + //If email is configured, send the user an email as well. + if (VMSettingServer.getSetting("mail.enable").getBoolVal() + && !target.getEmail().isEmpty()) { + Lookup.getDefault().lookup(IEmailManager.class) + .sendEmail(target.getEmail(), null, + author.getEmail().isEmpty() + ? new VMUserServer(1).getEmail() + : author.getEmail(), + TRANSLATOR.translate(selected, + new Locale(target.getLocale())), + TRANSLATOR.translate("notification.new", + new Locale(target.getLocale()))); + } + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/notification/NotificationScreenProvider.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/notification/NotificationScreenProvider.java index f6645f29..a1594c6b 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/notification/NotificationScreenProvider.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/notification/NotificationScreenProvider.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,6 +31,7 @@ import com.vaadin.ui.VerticalLayout; import com.validation.manager.core.DataBaseManager; import com.validation.manager.core.IMainContentProvider; +import com.validation.manager.core.VMException; import com.validation.manager.core.VMUI; import com.validation.manager.core.api.internationalization.InternationalizationProvider; import com.validation.manager.core.db.Notification; @@ -43,8 +44,8 @@ import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; -import net.sourceforge.javydreamercsw.validation.manager.web.UserToStringConverter; import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; +import net.sourceforge.javydreamercsw.validation.manager.web.component.UserToStringConverter; import net.sourceforge.javydreamercsw.validation.manager.web.provider.AbstractProvider; import org.openide.util.Lookup; import org.openide.util.lookup.ServiceProvider; @@ -59,9 +60,6 @@ public class NotificationScreenProvider extends AbstractProvider { private static final Logger LOG = Logger.getLogger(NotificationScreenProvider.class.getSimpleName()); - private VerticalLayout vs = null; - private final InternationalizationProvider TRANSLATOR = Lookup.getDefault() - .lookup(InternationalizationProvider.class); @Override public boolean shouldDisplay() { @@ -76,16 +74,7 @@ public String getComponentCaption() { @Override public Component getContent() { - if (vs == null) { - update(); - } - return vs; - } - - @Override - public void update() { - vs = new VerticalLayout(); - super.update(); + VerticalLayout vs = new VerticalLayout(); //On top put a list of notifications BeanItemContainer container = new BeanItemContainer<>(Notification.class); @@ -201,7 +190,7 @@ public Class getPresentationType() { ns.write2DB(); ((VMUI) UI.getCurrent()).updateScreen(); ((VMUI) UI.getCurrent()).showTab(getComponentCaption()); - } catch (Exception ex) { + } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } } @@ -217,7 +206,7 @@ public Class getPresentationType() { ns.write2DB(); ((VMUI) UI.getCurrent()).updateScreen(); ((VMUI) UI.getCurrent()).showTab(getComponentCaption()); - } catch (Exception ex) { + } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } } @@ -238,9 +227,7 @@ public Class getPresentationType() { = new NotificationServer((Notification) n); ns.setAcknowledgeDate(new Date()); ns.write2DB(); - ((VMUI) UI.getCurrent()).updateScreen(); - ((VMUI) UI.getCurrent()).showTab(getComponentCaption()); - } catch (Exception ex) { + } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } } @@ -250,6 +237,6 @@ public Class getPresentationType() { vs.addComponent(text); vs.setSizeFull(); vs.setId(getComponentCaption()); + return vs; } } - diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/profile/ProfileProvider.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/profile/ProfileProvider.java index 2b4145f4..944fe764 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/profile/ProfileProvider.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/profile/ProfileProvider.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,197 +13,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web.profile; - -import com.vaadin.data.fieldgroup.BeanFieldGroup; -import com.vaadin.event.FieldEvents; -import com.vaadin.event.FieldEvents.TextChangeListener; -import com.vaadin.icons.VaadinIcons; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.ComboBox; -import com.vaadin.ui.Component; -import com.vaadin.ui.Field; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Notification; -import com.vaadin.ui.Panel; -import com.vaadin.ui.PasswordField; -import com.vaadin.ui.TextField; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.themes.ValoTheme; -import com.validation.manager.core.IMainContentProvider; -import com.validation.manager.core.api.internationalization.InternationalizationProvider; -import com.validation.manager.core.server.core.VMUserServer; -import com.validation.manager.core.tool.MD5; -import de.steinwedel.messagebox.ButtonOption; -import de.steinwedel.messagebox.MessageBox; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; -import net.sourceforge.javydreamercsw.validation.manager.web.provider.AbstractProvider; -import org.openide.util.Exceptions; -import org.openide.util.Lookup; -import org.openide.util.lookup.ServiceProvider; - -/** - * The provider for the profile tab to manage your account. - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -@ServiceProvider(service = IMainContentProvider.class, position = 5) -public class ProfileProvider extends AbstractProvider { - - private static final Logger LOG - = Logger.getLogger(ProfileProvider.class.getSimpleName()); - - @Override - public boolean shouldDisplay() { - //Show whenever an user is logged in. - return ValidationManagerUI.getInstance().getUser() != null; - } - - @Override - public String getComponentCaption() { - return "message.admin.userProfile"; - } - - @Override - public Component getContent() { - VMUserServer user = ValidationManagerUI.getInstance().getUser(); - Panel form = new Panel(); - FormLayout layout = new FormLayout(); - form.setContent(layout); - form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); - BeanFieldGroup binder = new BeanFieldGroup(user.getClass()); - binder.setItemDataSource(user); - Field fn = binder.buildAndBind(Lookup.getDefault().lookup(InternationalizationProvider.class). - translate("general.first.name"), - "firstName", TextField.class); - layout.addComponent(fn); - Field ln = binder.buildAndBind(Lookup.getDefault().lookup(InternationalizationProvider.class). - translate("general.last.name"), - "lastName", TextField.class); - layout.addComponent(ln); - Field username = binder.buildAndBind(Lookup.getDefault().lookup(InternationalizationProvider.class). - translate("general.username"), - "username", TextField.class); - layout.addComponent(username); - PasswordField pw = (PasswordField) binder.buildAndBind( - Lookup.getDefault().lookup(InternationalizationProvider.class). - translate("general.password"), - "password", PasswordField.class); - PasswordChangeListener listener = new PasswordChangeListener(); - pw.addTextChangeListener(listener); - pw.setConverter(new UserPasswordConverter()); - layout.addComponent(pw); - Field email = binder.buildAndBind(Lookup.getDefault().lookup(InternationalizationProvider.class). - translate("general.email"), - "email", TextField.class); - layout.addComponent(email); - ComboBox locale = new ComboBox(Lookup.getDefault().lookup(InternationalizationProvider.class). - translate("general.locale")); - ValidationManagerUI.getAvailableLocales().forEach(l -> { - locale.addItem(l.toString()); - }); - if (user.getLocale() != null) { - locale.setValue(user.getLocale()); - } - layout.addComponent(locale); - Button update = new Button(Lookup.getDefault().lookup(InternationalizationProvider.class). - translate("general.update")); - update.addClickListener((Button.ClickEvent event) -> { - try { - VMUserServer us = new VMUserServer(user); - us.setFirstName((String) fn.getValue()); - us.setLastName((String) ln.getValue()); - us.setEmail((String) email.getValue()); - us.setUsername((String) username.getValue()); - us.setLocale((String) locale.getValue()); - String password = (String) pw.getValue(); - if (listener.isChanged() && !password.equals(user.getPassword())) { - //Different password. Prompt for confirmation - MessageBox mb = MessageBox.create(); - VerticalLayout vl = new VerticalLayout(); - Label l = new Label(Lookup.getDefault().lookup(InternationalizationProvider.class). - translate("password.confirm.pw.message")); - vl.addComponent(l); - PasswordField np = new PasswordField(Lookup.getDefault() - .lookup(InternationalizationProvider.class) - .translate("general.password")); - vl.addComponent(np); - mb.asModal(true) - .withCaption(Lookup.getDefault() - .lookup(InternationalizationProvider.class). - translate("password.confirm.pw")) - .withMessage(vl) - .withButtonAlignment(Alignment.MIDDLE_CENTER) - .withOkButton(() -> { - try { - if (password.equals(MD5.encrypt(np.getValue()))) { - us.setHashPassword(true); - us.setPassword(np.getValue()); - us.write2DB(); - Notification.show(Lookup.getDefault().lookup(InternationalizationProvider.class). - translate("audit.user.account.password.change"), - Notification.Type.ASSISTIVE_NOTIFICATION); - } else { - Notification.show(Lookup.getDefault().lookup(InternationalizationProvider.class). - translate("password.does.not.match"), - Notification.Type.WARNING_MESSAGE); - } - mb.close(); - } catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - }, ButtonOption.focus(), - ButtonOption.closeOnClick(false), - ButtonOption.icon(VaadinIcons.CHECK)) - .withCancelButton( - ButtonOption.icon(VaadinIcons.CLOSE) - ).getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON); - mb.open(); - } else { - us.write2DB(); - } - ValidationManagerUI.getInstance().setUser(us); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - Notification.show(Lookup.getDefault().lookup(InternationalizationProvider.class). - translate("general.error.record.update"), - ex.getLocalizedMessage(), - Notification.Type.ERROR_MESSAGE); - } - }); - Button cancel = new Button(Lookup.getDefault() - .lookup(InternationalizationProvider.class). - translate("general.cancel")); - cancel.addClickListener((Button.ClickEvent event) -> { - binder.discard(); - ValidationManagerUI.getInstance().updateScreen(); - }); - HorizontalLayout hl = new HorizontalLayout(); - hl.addComponent(update); - hl.addComponent(cancel); - layout.addComponent(hl); - return form; - } - - private class PasswordChangeListener implements TextChangeListener { - - private boolean changed = false; - - @Override - public void textChange(FieldEvents.TextChangeEvent event) { - changed = true; - } - - /** - * @return the changed - */ - public boolean isChanged() { - return changed; - } - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.profile; + +import com.vaadin.ui.Component; +import com.validation.manager.core.IMainContentProvider; +import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; +import net.sourceforge.javydreamercsw.validation.manager.web.component.UserComponent; +import net.sourceforge.javydreamercsw.validation.manager.web.provider.AbstractProvider; +import org.openide.util.lookup.ServiceProvider; + +/** + * The provider for the profile tab to manage your account. + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +@ServiceProvider(service = IMainContentProvider.class, position = 5) +public class ProfileProvider extends AbstractProvider { + + @Override + public boolean shouldDisplay() { + //Show whenever an user is logged in. + return ValidationManagerUI.getInstance().getUser() != null; + } + + @Override + public String getComponentCaption() { + return "message.admin.userProfile"; + } + + @Override + public Component getContent() { + return new UserComponent(ValidationManagerUI.getInstance().getUser(), + true); + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/tester/ExecutionScreen.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/tester/ExecutionScreen.java index bd560157..9cc270c3 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/tester/ExecutionScreen.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/tester/ExecutionScreen.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,367 +13,361 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web.tester; - -import com.vaadin.event.Action; -import com.vaadin.icons.VaadinIcons; -import com.vaadin.ui.Button; -import com.vaadin.ui.Component; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Table; -import com.vaadin.ui.TreeTable; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.themes.ValoTheme; -import com.validation.manager.core.api.internationalization.InternationalizationProvider; -import com.validation.manager.core.db.ExecutionStep; -import com.validation.manager.core.db.ExecutionStepPK; -import com.validation.manager.core.db.TestCase; -import com.validation.manager.core.db.TestCaseExecution; -import com.validation.manager.core.server.core.ExecutionStepServer; -import com.validation.manager.core.server.core.ProjectServer; -import com.validation.manager.core.server.core.TestCaseExecutionServer; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; -import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; -import net.sourceforge.javydreamercsw.validation.manager.web.execution.ExecutionWindow; -import net.sourceforge.javydreamercsw.validation.manager.web.provider.AbstractProvider; -import net.sourceforge.javydreamercsw.validation.manager.web.quality.QualityScreenProvider; -import org.openide.util.Lookup; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public abstract class ExecutionScreen extends AbstractProvider { - - private ExecutionWindow executionWindow = null; - private final TreeTable testCaseTree - = new TreeTable("available.tests"); - - public ExecutionScreen() { - testCaseTree.setAnimationsEnabled(true); - testCaseTree.addContainerProperty("general.name", - String.class, ""); - testCaseTree.addGeneratedColumn("general.status", - (Table source, Object itemId, Object columnId) -> { - if (Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("general.status").equals(columnId) - && itemId instanceof String) { - String id = (String) itemId; - String message; - HorizontalLayout icons = new HorizontalLayout(); - Button label = new Button(); - Button label2 = new Button(); - icons.addComponent(label2); - icons.addComponent(label); - label.addStyleName(ValoTheme.BUTTON_BORDERLESS - + " labelButton"); - label2.addStyleName(ValoTheme.BUTTON_BORDERLESS - + " labelButton"); - Map summary = new HashMap<>(); - boolean locked = false; - if (id.startsWith("tce")) { - TestCaseExecutionServer tce - = new TestCaseExecutionServer( - Integer.parseInt(id.substring(3))); - summary = getSummary(tce, -1); - locked = isLocked(tce); - } else if (id.startsWith("es")) { - ExecutionStepServer es - = new ExecutionStepServer(extractExecutionStepPK(id)); - summary = getSummary( - es.getTestCaseExecution(), - Integer.parseInt(id - .substring(id.lastIndexOf("-") + 1))); - locked = es.getLocked(); - } - if (locked) { - label2.setIcon(VaadinIcons.LOCK); - label2.setDescription(Lookup.getDefault() - .lookup(InternationalizationProvider.class).translate("message.locked")); - } - if (!summary.isEmpty()) { - if (summary.containsKey("result.fail")) { - //At least one failure means the test case is failing - message = "result.fail"; - } else if (summary.containsKey("result.blocked")) { - //It is blocked - message = "result.blocked"; - } else if (summary.containsKey("result.pending") - && !summary.containsKey("result.pass")) { - //Still not done - message = "result.pending"; - } else if (summary.containsKey("result.pending") - && summary.containsKey("result.pass")) { - //In progress - message = "result.progress"; - } else { - //All is pass - message = "result.pass"; - } - label.setCaption(Lookup.getDefault() - .lookup(InternationalizationProvider.class) - .translate(message)); - label.setDescription(Lookup.getDefault() - .lookup(InternationalizationProvider.class) - .translate(message)); - //Completed. Now check result - switch (message) { - case "result.pass": - label.setIcon(VaadinIcons.CHECK); - break; - case "result.fail": - label.setIcon(VaadinIcons.CLOSE); - break; - case "result.blocked": - label.setIcon(VaadinIcons.PAUSE); - break; - case "result.pending": - label.setIcon(VaadinIcons.CLOCK); - break; - case "result.progress": - label.setIcon(VaadinIcons.AUTOMATION); - break; - default: - label.setIcon(VaadinIcons.CLOCK); - break; - } - return icons; - } - } - return new Label(); - }); - testCaseTree.addContainerProperty("general.summary", - String.class, ""); - testCaseTree.addContainerProperty("general.assignment.date", - String.class, ""); - testCaseTree.setVisibleColumns(new Object[]{ - "general.name", - "general.status", - "general.summary", - "general.assignment.date"}); - testCaseTree.addActionHandler(new Action.Handler() { - @Override - public Action[] getActions(Object target, Object sender) { - List actions = new ArrayList<>(); - if (target instanceof String) { - String t = (String) target; - int tcID = -1; - TestCaseExecutionServer tce = null; - if (t.startsWith("es")) { - tce = new TestCaseExecutionServer(new ExecutionStepServer( - extractExecutionStepPK(t)) - .getTestCaseExecution().getId()); - tcID = Integer.parseInt(t - .substring(t.lastIndexOf("-") + 1)); - } else if (t.startsWith("tce")) { - tce = new TestCaseExecutionServer( - Integer.parseInt(t.substring(3))); - } - if (!isLocked(tce, tcID) - && ExecutionScreen.this instanceof TesterScreenProvider) { - actions.add(new Action(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("general.execute"))); - } else if (isLocked(tce, tcID) - && ExecutionScreen.this instanceof QualityScreenProvider) { - actions.add(new Action(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("general.review"))); - } - } - return actions.toArray(new Action[actions.size()]); - } - - @Override - public void handleAction(Action action, Object sender, Object target) { - //Parse the information to get the exact Execution Step - List executions = new ArrayList<>(); - int tcID = -1; - if (((String) target).startsWith("tce")) { - executions.add(new TestCaseExecutionServer( - Integer.parseInt(((String) target).substring(3)))); - } else if (((String) target).startsWith("es")) { - executions.add(new TestCaseExecutionServer(new ExecutionStepServer( - extractExecutionStepPK((String) target)) - .getTestCaseExecution().getId())); - tcID = Integer.parseInt(((String) target) - .substring(((String) target).lastIndexOf("-") + 1)); - } - showExecutionScreen(executions, tcID); - } - }); - } - - protected Map getSummary(TestCaseExecution tce, int tcId) { - Map summary = new HashMap<>(); - tce.getExecutionStepList().forEach((ExecutionStep es) -> { - if (tcId == -1 || es.getStep().getTestCase().getId() == tcId) { - if (es.getExecutionStart() != null && es.getExecutionEnd() == null) { - //In progress - if (!summary.containsKey("progress")) { - summary.put("progress", 0); - } - summary.put("progress", summary.get("progress") + 1); - } else if (es.getResultId() == null - || (es.getExecutionStart() == null - && es.getExecutionEnd() == null)) { - //Not started - if (!summary.containsKey("result.pending")) { - summary.put("result.pending", 0); - } - summary.put("result.pending", summary.get("result.pending") + 1); - } else if (es.getExecutionStart() != null && es.getExecutionEnd() != null) { - if (!summary.containsKey(es.getResultId().getResultName())) { - summary.put(es.getResultId().getResultName(), 0); - } - summary.put(es.getResultId().getResultName(), - summary.get(es.getResultId().getResultName()) + 1); - } - } - }); - return summary; - } - - @Override - public boolean shouldDisplay() { - return ValidationManagerUI.getInstance().getUser() != null - && ValidationManagerUI.getInstance() - .checkRight("system.configuration"); - } - - protected ExecutionStepPK extractExecutionStepPK(String itemId) { - String id = itemId.substring(2); //Remove es - int esId; - int sId; - int tcId; - StringTokenizer st = new StringTokenizer(id, "-"); - esId = Integer.parseInt(st.nextToken()); - sId = Integer.parseInt(st.nextToken()); - tcId = Integer.parseInt(st.nextToken()); - return new ExecutionStepPK(esId, sId, tcId); - } - - protected void showExecutionScreen(List executions, - int tcID) { - if (executionWindow == null) { - executionWindow = new ExecutionWindow(executions, tcID, - this instanceof QualityScreenProvider); - executionWindow.setCaption(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("test.execution")); - executionWindow.setVisible(true); - executionWindow.setClosable(false); - executionWindow.setResizable(false); - executionWindow.center(); - executionWindow.setModal(true); - executionWindow.setSizeFull(); - } - if (!ValidationManagerUI.getInstance().getWindows().contains(executionWindow)) { - ValidationManagerUI.getInstance().addWindow(executionWindow); - } - } - - @Override - public Component getContent() { - VerticalLayout vl = new VerticalLayout(); - update(); - vl.addComponent(testCaseTree); - return vl; - } - - @Override - public void update() { - if (executionWindow != null) { - executionWindow.setCaption(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("test.execution")); - } - testCaseTree.setCaption(Lookup.getDefault().lookup(InternationalizationProvider.class) - .translate("available.tests")); - testCaseTree.removeAllItems(); - if (ValidationManagerUI.getInstance().getUser() != null) { - ProjectServer.getProjects().forEach(p -> { - if (p.getParentProjectId() == null) { - testCaseTree.addItem(new Object[]{p.getName(), - "", "",}, "p" + p.getId()); - testCaseTree.setItemIcon("p" + p.getId(), - ValidationManagerUI.PROJECT_ICON); - p.getProjectList().forEach(sp -> { - //Add subprojects - testCaseTree.addItem(new Object[]{sp.getName(), - "", "",}, "p" + sp.getId()); - testCaseTree.setParent("p" + sp.getId(), "p" + p.getId()); - testCaseTree.setItemIcon("p" + sp.getId(), - ValidationManagerUI.PROJECT_ICON); - //Add applicable Executions - Map tests = new HashMap<>(); - sp.getTestProjectList().forEach(test -> { - test.getTestPlanList().forEach(tp -> { - tp.getTestCaseList().forEach(testCase -> { - List tcids = new ArrayList<>(); - testCase.getStepList().forEach(s -> { - s.getExecutionStepList().forEach(es -> { - TestCaseExecution tce = es.getTestCaseExecution(); - testCaseTree.addItem(new Object[]{tce.getName(), - "", "",}, "tce" + tce.getId()); - testCaseTree.setParent("tce" + tce.getId(), - "p" + sp.getId()); - testCaseTree.setItemIcon("tce" + tce.getId(), - ValidationManagerUI.EXECUTION_ICON); - if (this instanceof QualityScreenProvider - && es.getLocked() - || (es.getAssignee() != null - && es.getAssignee().getId() - .equals(ValidationManagerUI.getInstance() - .getUser().getId()))) { - TestCase tc = es.getStep().getTestCase(); - if (!tcids.contains(tc.getId())) { - tcids.add(tc.getId()); - DateTimeFormatter format - = DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a"); - LocalDateTime time - = LocalDateTime.ofInstant(es.getAssignedTime() - .toInstant(), ZoneId.systemDefault()); - String key = "es" + es.getExecutionStepPK().getTestCaseExecutionId() - + "-" + es.getStep().getStepPK().getId() - + "-" + tc.getId(); - testCaseTree.addItem(new Object[]{tc.getName(), - tc.getSummary(), format.format(time),}, - key); - testCaseTree.setParent(key, "tce" - + tce.getId()); - testCaseTree.setItemIcon(key, - ValidationManagerUI.TEST_ICON); - testCaseTree.setChildrenAllowed(key, false); - } - } - }); - }); - tcids.clear(); - }); - }); - }); - //Make columns autofit - int count = 0; - for (Object id : testCaseTree.getVisibleColumns()) { - if (count < 2) { - testCaseTree.setColumnExpandRatio(id, 1.0f); - } - count++; - } - testCaseTree.setSizeFull(); - }); - } - }); - } - //Update column titles - for (String h : testCaseTree.getColumnHeaders()) { - testCaseTree.setColumnHeader(h, Lookup.getDefault() - .lookup(InternationalizationProvider.class).translate(h)); - } - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.tester; + +import com.vaadin.event.Action; +import com.vaadin.icons.VaadinIcons; +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Table; +import com.vaadin.ui.TreeTable; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.themes.ValoTheme; +import com.validation.manager.core.db.ExecutionStep; +import com.validation.manager.core.db.ExecutionStepPK; +import com.validation.manager.core.db.TestCase; +import com.validation.manager.core.db.TestCaseExecution; +import com.validation.manager.core.server.core.ExecutionStepServer; +import com.validation.manager.core.server.core.ProjectServer; +import com.validation.manager.core.server.core.TestCaseExecutionServer; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; +import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; +import net.sourceforge.javydreamercsw.validation.manager.web.execution.ExecutionWindow; +import net.sourceforge.javydreamercsw.validation.manager.web.provider.AbstractProvider; +import net.sourceforge.javydreamercsw.validation.manager.web.quality.QualityScreenProvider; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public abstract class ExecutionScreen extends AbstractProvider { + + private ExecutionWindow executionWindow = null; + private final TreeTable testCaseTree + = new TreeTable("available.tests"); + + public ExecutionScreen() { + testCaseTree.setAnimationsEnabled(true); + testCaseTree.addContainerProperty("general.name", + String.class, ""); + testCaseTree.addGeneratedColumn("general.status", + (Table source, Object itemId, Object columnId) -> { + if (TRANSLATOR + .translate("general.status").equals(columnId) + && itemId instanceof String) { + String id = (String) itemId; + String message; + HorizontalLayout icons = new HorizontalLayout(); + Button label = new Button(); + Button label2 = new Button(); + icons.addComponent(label2); + icons.addComponent(label); + label.addStyleName(ValoTheme.BUTTON_BORDERLESS + + " labelButton"); + label2.addStyleName(ValoTheme.BUTTON_BORDERLESS + + " labelButton"); + Map summary = new HashMap<>(); + boolean locked = false; + if (id.startsWith("tce")) { + TestCaseExecutionServer tce + = new TestCaseExecutionServer( + Integer.parseInt(id.substring(3))); + summary = getSummary(tce, -1); + locked = isLocked(tce); + } else if (id.startsWith("es")) { + ExecutionStepServer es + = new ExecutionStepServer(extractExecutionStepPK(id)); + summary = getSummary( + es.getTestCaseExecution(), + Integer.parseInt(id + .substring(id.lastIndexOf("-") + 1))); + locked = es.getLocked(); + } + if (locked) { + label2.setIcon(VaadinIcons.LOCK); + label2.setDescription(TRANSLATOR.translate("message.locked")); + } + if (!summary.isEmpty()) { + if (summary.containsKey("result.fail")) { + //At least one failure means the test case is failing + message = "result.fail"; + } else if (summary.containsKey("result.blocked")) { + //It is blocked + message = "result.blocked"; + } else if (summary.containsKey("result.pending") + && !summary.containsKey("result.pass")) { + //Still not done + message = "result.pending"; + } else if (summary.containsKey("result.pending") + && summary.containsKey("result.pass")) { + //In progress + message = "result.progress"; + } else { + //All is pass + message = "result.pass"; + } + label.setCaption(TRANSLATOR + .translate(message)); + label.setDescription(TRANSLATOR + .translate(message)); + //Completed. Now check result + switch (message) { + case "result.pass": + label.setIcon(VaadinIcons.CHECK); + break; + case "result.fail": + label.setIcon(VaadinIcons.CLOSE); + break; + case "result.blocked": + label.setIcon(VaadinIcons.PAUSE); + break; + case "result.pending": + label.setIcon(VaadinIcons.CLOCK); + break; + case "result.progress": + label.setIcon(VaadinIcons.AUTOMATION); + break; + default: + label.setIcon(VaadinIcons.CLOCK); + break; + } + return icons; + } + } + return new Label(); + }); + testCaseTree.addContainerProperty("general.summary", + String.class, ""); + testCaseTree.addContainerProperty("general.assignment.date", + String.class, ""); + testCaseTree.setVisibleColumns(new Object[]{ + "general.name", + "general.status", + "general.summary", + "general.assignment.date"}); + testCaseTree.addActionHandler(new Action.Handler() { + @Override + public Action[] getActions(Object target, Object sender) { + List actions = new ArrayList<>(); + if (target instanceof String) { + String t = (String) target; + int tcID = -1; + TestCaseExecutionServer tce = null; + if (t.startsWith("es")) { + tce = new TestCaseExecutionServer(new ExecutionStepServer( + extractExecutionStepPK(t)) + .getTestCaseExecution().getId()); + tcID = Integer.parseInt(t + .substring(t.lastIndexOf("-") + 1)); + } else if (t.startsWith("tce")) { + tce = new TestCaseExecutionServer( + Integer.parseInt(t.substring(3))); + } + if (!isLocked(tce, tcID) + && ExecutionScreen.this instanceof TesterScreenProvider) { + actions.add(new Action(TRANSLATOR + .translate("general.execute"))); + } else if (isLocked(tce, tcID) + && ExecutionScreen.this instanceof QualityScreenProvider) { + actions.add(new Action(TRANSLATOR + .translate("general.review"))); + } + } + return actions.toArray(new Action[actions.size()]); + } + + @Override + public void handleAction(Action action, Object sender, Object target) { + //Parse the information to get the exact Execution Step + List executions = new ArrayList<>(); + int tcID = -1; + if (((String) target).startsWith("tce")) { + executions.add(new TestCaseExecutionServer( + Integer.parseInt(((String) target).substring(3)))); + } else if (((String) target).startsWith("es")) { + executions.add(new TestCaseExecutionServer(new ExecutionStepServer( + extractExecutionStepPK((String) target)) + .getTestCaseExecution().getId())); + tcID = Integer.parseInt(((String) target) + .substring(((String) target).lastIndexOf("-") + 1)); + } + showExecutionScreen(executions, tcID); + } + }); + } + + protected Map getSummary(TestCaseExecution tce, int tcId) { + Map summary = new HashMap<>(); + tce.getExecutionStepList().forEach((ExecutionStep es) -> { + if (tcId == -1 || es.getStep().getTestCase().getId() == tcId) { + if (es.getExecutionStart() != null && es.getExecutionEnd() == null) { + //In progress + if (!summary.containsKey("progress")) { + summary.put("progress", 0); + } + summary.put("progress", summary.get("progress") + 1); + } else if (es.getResultId() == null + || (es.getExecutionStart() == null + && es.getExecutionEnd() == null)) { + //Not started + if (!summary.containsKey("result.pending")) { + summary.put("result.pending", 0); + } + summary.put("result.pending", summary.get("result.pending") + 1); + } else if (es.getExecutionStart() != null && es.getExecutionEnd() != null) { + if (!summary.containsKey(es.getResultId().getResultName())) { + summary.put(es.getResultId().getResultName(), 0); + } + summary.put(es.getResultId().getResultName(), + summary.get(es.getResultId().getResultName()) + 1); + } + } + }); + return summary; + } + + @Override + public boolean shouldDisplay() { + return ValidationManagerUI.getInstance().getUser() != null + && ValidationManagerUI.getInstance() + .checkRight("system.configuration"); + } + + protected ExecutionStepPK extractExecutionStepPK(String itemId) { + String id = itemId.substring(2); //Remove es + int esId; + int sId; + int tcId; + StringTokenizer st = new StringTokenizer(id, "-"); + esId = Integer.parseInt(st.nextToken()); + sId = Integer.parseInt(st.nextToken()); + tcId = Integer.parseInt(st.nextToken()); + return new ExecutionStepPK(esId, sId, tcId); + } + + protected void showExecutionScreen(List executions, + int tcID) { + if (executionWindow == null) { + executionWindow = new ExecutionWindow(executions, tcID, + this instanceof QualityScreenProvider); + executionWindow.setCaption(TRANSLATOR + .translate("test.execution")); + executionWindow.setVisible(true); + executionWindow.setClosable(false); + executionWindow.setResizable(false); + executionWindow.center(); + executionWindow.setModal(true); + executionWindow.setSizeFull(); + } + if (!ValidationManagerUI.getInstance().getWindows().contains(executionWindow)) { + ValidationManagerUI.getInstance().addWindow(executionWindow); + } + } + + @Override + public Component getContent() { + VerticalLayout vl = new VerticalLayout(); + update(); + vl.addComponent(testCaseTree); + return vl; + } + + @Override + public void update() { + if (executionWindow != null) { + executionWindow.setCaption(TRANSLATOR + .translate("test.execution")); + } + testCaseTree.setCaption(TRANSLATOR + .translate("available.tests")); + testCaseTree.removeAllItems(); + if (ValidationManagerUI.getInstance().getUser() != null) { + ProjectServer.getProjects().forEach(p -> { + if (p.getParentProjectId() == null) { + testCaseTree.addItem(new Object[]{p.getName(), + "", "",}, "p" + p.getId()); + testCaseTree.setItemIcon("p" + p.getId(), + ValidationManagerUI.PROJECT_ICON); + p.getProjectList().forEach(sp -> { + //Add subprojects + testCaseTree.addItem(new Object[]{sp.getName(), + "", "",}, "p" + sp.getId()); + testCaseTree.setParent("p" + sp.getId(), "p" + p.getId()); + testCaseTree.setItemIcon("p" + sp.getId(), + ValidationManagerUI.PROJECT_ICON); + //Add applicable Executions + Map tests = new HashMap<>(); + sp.getTestProjectList().forEach(test -> { + test.getTestPlanList().forEach(tp -> { + tp.getTestCaseList().forEach(testCase -> { + List tcids = new ArrayList<>(); + testCase.getStepList().forEach(s -> { + s.getExecutionStepList().forEach(es -> { + TestCaseExecution tce = es.getTestCaseExecution(); + testCaseTree.addItem(new Object[]{tce.getName(), + "", "",}, "tce" + tce.getId()); + testCaseTree.setParent("tce" + tce.getId(), + "p" + sp.getId()); + testCaseTree.setItemIcon("tce" + tce.getId(), + ValidationManagerUI.EXECUTION_ICON); + if (this instanceof QualityScreenProvider + && es.getLocked() + || (es.getAssignee() != null + && es.getAssignee().getId() + .equals(ValidationManagerUI.getInstance() + .getUser().getId()))) { + TestCase tc = es.getStep().getTestCase(); + if (!tcids.contains(tc.getId())) { + tcids.add(tc.getId()); + DateTimeFormatter format + = DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a"); + LocalDateTime time + = LocalDateTime.ofInstant(es.getAssignedTime() + .toInstant(), ZoneId.systemDefault()); + String key = "es" + es.getExecutionStepPK().getTestCaseExecutionId() + + "-" + es.getStep().getStepPK().getId() + + "-" + tc.getId(); + testCaseTree.addItem(new Object[]{tc.getName(), + tc.getSummary(), format.format(time),}, + key); + testCaseTree.setParent(key, "tce" + + tce.getId()); + testCaseTree.setItemIcon(key, + ValidationManagerUI.TEST_ICON); + testCaseTree.setChildrenAllowed(key, false); + } + } + }); + }); + tcids.clear(); + }); + }); + }); + //Make columns autofit + int count = 0; + for (Object id : testCaseTree.getVisibleColumns()) { + if (count < 2) { + testCaseTree.setColumnExpandRatio(id, 1.0f); + } + count++; + } + testCaseTree.setSizeFull(); + }); + } + }); + } + //Update column titles + for (String h : testCaseTree.getColumnHeaders()) { + testCaseTree.setColumnHeader(h, TRANSLATOR.translate(h)); + } + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/wizard/assign/AssignUserStep.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/wizard/assign/AssignUserStep.java index e232e945..21c86d77 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/wizard/assign/AssignUserStep.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/wizard/assign/AssignUserStep.java @@ -13,150 +13,150 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web.wizard.assign; - -import com.vaadin.data.Item; -import com.vaadin.data.util.BeanItemContainer; -import com.vaadin.icons.VaadinIcons; -import com.vaadin.ui.AbstractSelect.ItemCaptionMode; -import com.vaadin.ui.Component; -import com.vaadin.ui.Notification; -import com.vaadin.ui.OptionGroup; -import com.vaadin.ui.TreeTable; -import com.vaadin.ui.VerticalLayout; -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.db.TestCase; -import com.validation.manager.core.db.VmUser; -import com.validation.manager.core.db.controller.TestCaseJpaController; -import com.validation.manager.core.server.core.RoleServer; -import com.validation.manager.core.server.core.TestCaseExecutionServer; -import com.validation.manager.core.server.core.TestCaseServer; -import com.validation.manager.core.server.core.VMUserServer; -import com.validation.manager.core.tool.TCEExtraction; -import com.validation.manager.core.tool.Tool; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.sourceforge.javydreamercsw.validation.manager.web.TreeTableCheckBox; -import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; -import org.vaadin.teemu.wizards.WizardStep; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class AssignUserStep implements WizardStep { - - private final Object key; - private final TreeTable testTree - = new TreeTable("available.tests"); - private final OptionGroup userGroup - = new OptionGroup("available.tester"); - private TestCaseExecutionServer tce = null; - private TestCaseServer tc = null; - private static final Logger LOG - = Logger.getLogger(AssignUserStep.class.getSimpleName()); - private final ValidationManagerUI ui; - - public AssignUserStep(ValidationManagerUI ui, Object item) { - this.key = item; - this.ui = ui; - } - - @Override - public String getCaption() { - return "assign.test.case"; - } - - @Override - public Component getContent() { - VerticalLayout l = new VerticalLayout(); - List testCases = new ArrayList<>(); - List users = new ArrayList<>(); - TCEExtraction extracted = Tool.extractTCE(key); - tc = extracted.getTestCase(); - tce = extracted.getTestCaseExecution(); - if (tc != null) { - testCases.add(tc.getEntity()); - } else if (tce != null) { - tce.getExecutionStepList().stream().filter((es) - -> (!testCases.contains(es.getStep().getTestCase()))) - .forEachOrdered((es) -> { - testCases.add(es.getStep().getTestCase()); - }); - } - testTree.addContainerProperty("general.name", - TreeTableCheckBox.class, ""); - testTree.addContainerProperty("general.description", - String.class, ""); - testTree.setWidth("20em"); - testCases.forEach((t) -> { - testTree.addItem(new Object[]{new TreeTableCheckBox(testTree, - t.getName(), t.getId()), - t.getSummary() == null ? "" : new String(t.getSummary(), - StandardCharsets.UTF_8)}, t.getId()); - testTree.setChildrenAllowed(t.getId(), false); - }); - testTree.setPageLength(testCases.size() + 1); - testTree.setSizeFull(); - l.addComponent(testTree); - //Add list of testers - users.addAll(RoleServer.getRole("tester").getVmUserList()); - BeanItemContainer userContainer - = new BeanItemContainer<>(VmUser.class); - userContainer.addAll(users); - userGroup.setContainerDataSource(userContainer); - userGroup.setItemCaptionMode(ItemCaptionMode.EXPLICIT); - userGroup.getItemIds().forEach(id -> { - VmUser u = (VmUser) id; - userGroup.setItemCaption(id, u.getFirstName() + " " - + u.getLastName()); - userGroup.setItemIcon(id, VaadinIcons.USER); - }); - l.addComponent(userGroup); - return l; - } - - @Override - public boolean onAdvance() { - boolean selectedTestCase = false; - List testCaseIds = new ArrayList<>(); - for (Object id : testTree.getItemIds()) { - Item item = testTree.getItem(id); - Object val = item.getItemProperty("general.name").getValue(); - if (val instanceof TreeTableCheckBox) { - TreeTableCheckBox ttcb = (TreeTableCheckBox) val; - if (ttcb.getValue()) { - selectedTestCase = true; - testCaseIds.add((Integer) id); - } - } - } - if (!selectedTestCase) { - Notification.show("unable.to.proceed", - "select.test.case.message", - Notification.Type.WARNING_MESSAGE); - return false; - } - try { - //Now process the data - VMUserServer user = new VMUserServer((VmUser) userGroup.getValue()); - TestCaseJpaController c - = new TestCaseJpaController(DataBaseManager - .getEntityManagerFactory()); - testCaseIds.forEach((id) -> { - user.assignTestCase(tce, c.findTestCase(id), ui.getUser()); - }); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - return true; - } - - @Override - public boolean onBack() { - return false; - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.wizard.assign; + +import com.vaadin.data.Item; +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.icons.VaadinIcons; +import com.vaadin.ui.AbstractSelect.ItemCaptionMode; +import com.vaadin.ui.Component; +import com.vaadin.ui.Notification; +import com.vaadin.ui.OptionGroup; +import com.vaadin.ui.TreeTable; +import com.vaadin.ui.VerticalLayout; +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.db.TestCase; +import com.validation.manager.core.db.VmUser; +import com.validation.manager.core.db.controller.TestCaseJpaController; +import com.validation.manager.core.server.core.RoleServer; +import com.validation.manager.core.server.core.TestCaseExecutionServer; +import com.validation.manager.core.server.core.TestCaseServer; +import com.validation.manager.core.server.core.VMUserServer; +import com.validation.manager.core.tool.TCEExtraction; +import com.validation.manager.core.tool.Tool; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.sourceforge.javydreamercsw.validation.manager.web.component.TreeTableCheckBox; +import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; +import org.vaadin.teemu.wizards.WizardStep; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class AssignUserStep implements WizardStep { + + private final Object key; + private final TreeTable testTree + = new TreeTable("available.tests"); + private final OptionGroup userGroup + = new OptionGroup("available.tester"); + private TestCaseExecutionServer tce = null; + private TestCaseServer tc = null; + private static final Logger LOG + = Logger.getLogger(AssignUserStep.class.getSimpleName()); + private final ValidationManagerUI ui; + + public AssignUserStep(ValidationManagerUI ui, Object item) { + this.key = item; + this.ui = ui; + } + + @Override + public String getCaption() { + return "assign.test.case"; + } + + @Override + public Component getContent() { + VerticalLayout l = new VerticalLayout(); + List testCases = new ArrayList<>(); + List users = new ArrayList<>(); + TCEExtraction extracted = Tool.extractTCE(key); + tc = extracted.getTestCase(); + tce = extracted.getTestCaseExecution(); + if (tc != null) { + testCases.add(tc.getEntity()); + } else if (tce != null) { + tce.getExecutionStepList().stream().filter((es) + -> (!testCases.contains(es.getStep().getTestCase()))) + .forEachOrdered((es) -> { + testCases.add(es.getStep().getTestCase()); + }); + } + testTree.addContainerProperty("general.name", + TreeTableCheckBox.class, ""); + testTree.addContainerProperty("general.description", + String.class, ""); + testTree.setWidth("20em"); + testCases.forEach((t) -> { + testTree.addItem(new Object[]{new TreeTableCheckBox(testTree, + t.getName(), t.getId()), + t.getSummary() == null ? "" : new String(t.getSummary(), + StandardCharsets.UTF_8)}, t.getId()); + testTree.setChildrenAllowed(t.getId(), false); + }); + testTree.setPageLength(testCases.size() + 1); + testTree.setSizeFull(); + l.addComponent(testTree); + //Add list of testers + users.addAll(RoleServer.getRole("tester").getVmUserList()); + BeanItemContainer userContainer + = new BeanItemContainer<>(VmUser.class); + userContainer.addAll(users); + userGroup.setContainerDataSource(userContainer); + userGroup.setItemCaptionMode(ItemCaptionMode.EXPLICIT); + userGroup.getItemIds().forEach(id -> { + VmUser u = (VmUser) id; + userGroup.setItemCaption(id, u.getFirstName() + " " + + u.getLastName()); + userGroup.setItemIcon(id, VaadinIcons.USER); + }); + l.addComponent(userGroup); + return l; + } + + @Override + public boolean onAdvance() { + boolean selectedTestCase = false; + List testCaseIds = new ArrayList<>(); + for (Object id : testTree.getItemIds()) { + Item item = testTree.getItem(id); + Object val = item.getItemProperty("general.name").getValue(); + if (val instanceof TreeTableCheckBox) { + TreeTableCheckBox ttcb = (TreeTableCheckBox) val; + if (ttcb.getValue()) { + selectedTestCase = true; + testCaseIds.add((Integer) id); + } + } + } + if (!selectedTestCase) { + Notification.show("unable.to.proceed", + "select.test.case.message", + Notification.Type.WARNING_MESSAGE); + return false; + } + try { + //Now process the data + VMUserServer user = new VMUserServer((VmUser) userGroup.getValue()); + TestCaseJpaController c + = new TestCaseJpaController(DataBaseManager + .getEntityManagerFactory()); + testCaseIds.forEach((id) -> { + user.assignTestCase(tce, c.findTestCase(id), ui.getUser()); + }); + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + } + return true; + } + + @Override + public boolean onBack() { + return false; + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/wizard/plan/DetailStep.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/wizard/plan/DetailStep.java index 6f91fa22..54c881c9 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/wizard/plan/DetailStep.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/wizard/plan/DetailStep.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2017 Javier A. Ortiz Bultron javier.ortiz.78@gmail.com. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,127 +13,127 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web.wizard.plan; - -import com.vaadin.data.fieldgroup.BeanFieldGroup; -import com.vaadin.ui.Component; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.Panel; -import com.vaadin.ui.TextArea; -import com.vaadin.ui.themes.ValoTheme; -import com.validation.manager.core.DataBaseManager; -import com.validation.manager.core.VMUI; -import com.validation.manager.core.db.TestCaseExecution; -import com.validation.manager.core.db.controller.TestCaseExecutionJpaController; -import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; -import com.validation.manager.core.server.core.TestCaseExecutionServer; -import com.validation.manager.core.server.core.TestCaseServer; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.sourceforge.javydreamercsw.validation.manager.web.ByteToStringConverter; -import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; -import org.vaadin.teemu.wizards.WizardStep; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class DetailStep implements WizardStep { - - private List testCases; - private final TestCaseExecution tce; - private static final Logger LOG - = Logger.getLogger(DetailStep.class.getSimpleName()); - - public DetailStep() { - this.tce = new TestCaseExecution(); - } - - @Override - public String getCaption() { - return "add.details"; - } - - @Override - public Component getContent() { - Panel form = new Panel("execution.detail"); - FormLayout layout = new FormLayout(); - form.setContent(layout); - form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); - BeanFieldGroup binder = new BeanFieldGroup(TestCaseExecution.class); - binder.setItemDataSource(tce); - TextArea name = new TextArea("general.name"); - name.setConverter(new ByteToStringConverter()); - binder.bind(name, "name"); - layout.addComponent(name); - TextArea scope = new TextArea("general.scope"); - scope.setConverter(new ByteToStringConverter()); - binder.bind(scope, "scope"); - layout.addComponent(scope); - if (tce.getId() != null) { - TextArea conclusion = new TextArea("general.comclusion"); - conclusion.setConverter(new ByteToStringConverter()); - binder.bind(conclusion, "conclusion"); - layout.addComponent(conclusion); - conclusion.setSizeFull(); - layout.addComponent(conclusion); - } - binder.setBuffered(false); - binder.bindMemberFields(form); - form.setSizeFull(); - return form; - } - - @Override - public boolean onAdvance() { - try { - //Create the record - new TestCaseExecutionJpaController(DataBaseManager - .getEntityManagerFactory()).create(tce); - TestCaseExecutionServer tces = new TestCaseExecutionServer(tce); - //Now create the execution records - TestCaseServer tc; - for (Integer id : testCases) { - //Retrieve the TestCase to get the steps - tc = new TestCaseServer(id); - tces.addTestCase(tc.getEntity()); - } - try { - tces.write2DB(); - VMUI ui = ValidationManagerUI.getInstance(); - ui.buildProjectTree(ui.getSelectdValue()); - ui.updateProjectList(); - ui.updateScreen(); - ui.displayObject(tces.getEntity(), false); - return true; - } catch (NonexistentEntityException ex) { - LOG.log(Level.SEVERE, null, ex); - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - } catch (Exception ex) { - LOG.log(Level.SEVERE, null, ex); - } - return false; - } - - @Override - public boolean onBack() { - return true; - } - - /** - * @return the testCases - */ - public List getTestCases() { - return testCases; - } - - /** - * @param testCases the testCases to set - */ - public void setTestCases(List testCases) { - this.testCases = testCases; - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.wizard.plan; + +import com.vaadin.data.fieldgroup.BeanFieldGroup; +import com.vaadin.ui.Component; +import com.vaadin.ui.FormLayout; +import com.vaadin.ui.Panel; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.themes.ValoTheme; +import com.validation.manager.core.DataBaseManager; +import com.validation.manager.core.VMUI; +import com.validation.manager.core.db.TestCaseExecution; +import com.validation.manager.core.db.controller.TestCaseExecutionJpaController; +import com.validation.manager.core.db.controller.exceptions.NonexistentEntityException; +import com.validation.manager.core.server.core.TestCaseExecutionServer; +import com.validation.manager.core.server.core.TestCaseServer; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; +import net.sourceforge.javydreamercsw.validation.manager.web.component.ByteToStringConverter; +import org.vaadin.teemu.wizards.WizardStep; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class DetailStep implements WizardStep { + + private List testCases; + private final TestCaseExecution tce; + private static final Logger LOG + = Logger.getLogger(DetailStep.class.getSimpleName()); + + public DetailStep() { + this.tce = new TestCaseExecution(); + } + + @Override + public String getCaption() { + return "add.details"; + } + + @Override + public Component getContent() { + Panel form = new Panel("execution.detail"); + FormLayout layout = new FormLayout(); + form.setContent(layout); + form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); + BeanFieldGroup binder = new BeanFieldGroup(TestCaseExecution.class); + binder.setItemDataSource(tce); + TextArea name = new TextArea("general.name"); + name.setConverter(new ByteToStringConverter()); + binder.bind(name, "name"); + layout.addComponent(name); + TextArea scope = new TextArea("general.scope"); + scope.setConverter(new ByteToStringConverter()); + binder.bind(scope, "scope"); + layout.addComponent(scope); + if (tce.getId() != null) { + TextArea conclusion = new TextArea("general.conclusion"); + conclusion.setConverter(new ByteToStringConverter()); + binder.bind(conclusion, "conclusion"); + layout.addComponent(conclusion); + conclusion.setSizeFull(); + layout.addComponent(conclusion); + } + binder.setBuffered(false); + binder.bindMemberFields(form); + form.setSizeFull(); + return form; + } + + @Override + public boolean onAdvance() { + try { + //Create the record + new TestCaseExecutionJpaController(DataBaseManager + .getEntityManagerFactory()).create(tce); + TestCaseExecutionServer tces = new TestCaseExecutionServer(tce); + //Now create the execution records + TestCaseServer tc; + for (Integer id : testCases) { + //Retrieve the TestCase to get the steps + tc = new TestCaseServer(id); + tces.addTestCase(tc.getEntity()); + } + try { + tces.write2DB(); + VMUI ui = ValidationManagerUI.getInstance(); + ui.buildProjectTree(ui.getSelectdValue()); + ui.updateProjectList(); + ui.updateScreen(); + ui.displayObject(tces.getEntity(), false); + return true; + } catch (NonexistentEntityException ex) { + LOG.log(Level.SEVERE, null, ex); + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + } + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + } + return false; + } + + @Override + public boolean onBack() { + return true; + } + + /** + * @return the testCases + */ + public List getTestCases() { + return testCases; + } + + /** + * @param testCases the testCases to set + */ + public void setTestCases(List testCases) { + this.testCases = testCases; + } +} diff --git a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/wizard/plan/SelectTestCasesStep.java b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/wizard/plan/SelectTestCasesStep.java index 54f95a96..b04cfca5 100644 --- a/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/wizard/plan/SelectTestCasesStep.java +++ b/Validation-Manager-Web/src/main/java/net/sourceforge/javydreamercsw/validation/manager/web/wizard/plan/SelectTestCasesStep.java @@ -13,198 +13,198 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sourceforge.javydreamercsw.validation.manager.web.wizard.plan; - -import com.vaadin.data.Item; -import com.vaadin.ui.Component; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Notification; -import com.vaadin.ui.TreeTable; -import com.vaadin.ui.VerticalLayout; -import com.validation.manager.core.db.Project; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.sourceforge.javydreamercsw.validation.manager.web.TreeTableCheckBox; -import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; -import org.vaadin.teemu.wizards.Wizard; -import org.vaadin.teemu.wizards.WizardStep; - -/** - * - * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com - */ -public class SelectTestCasesStep implements WizardStep { - - private final Project p; - private final Wizard w; - private final TreeTable testTree = new TreeTable("available.tests"); - private final List projects = new ArrayList<>(); - private static final Logger LOG - = Logger.getLogger(SelectTestCasesStep.class.getSimpleName()); - - public SelectTestCasesStep(Wizard w, Project p) { - this.p = p; - this.w = w; - } - - @Override - public String getCaption() { - return "select.test.case"; - } - - @Override - public Component getContent() { - VerticalLayout l = new VerticalLayout(); - //Add menu - HorizontalLayout menu = new HorizontalLayout(); - if (p != null) { - //Show the Test Plans for the selected project (including sub projects - testTree.addContainerProperty("general.name", - TreeTableCheckBox.class, ""); - testTree.addContainerProperty("general.description", - String.class, ""); - testTree.setWidth("20em"); - addProjectTestPlanning(testTree, p); - } - testTree.setSizeFull(); - l.addComponent(menu); - l.addComponent(testTree); - return l; - } - - @Override - public boolean onAdvance() { - //Get a list of selected test cases - List testCases - = processChildren("project" + p.getId()); - testCases.forEach((i) -> { - LOG.log(Level.FINE, "Test Case: {0}", i); - }); - if (testCases.isEmpty()) { - Notification.show("unable.to.proceed", - "select.test.case.message", - Notification.Type.WARNING_MESSAGE); - return false; - } - //update next step - DetailStep next = ((DetailStep) w.getSteps().get(1)); - next.setTestCases(testCases); - return true; - } - - @Override - public boolean onBack() { - return false; - } - - private void addProjectTestPlanning(TreeTable testTree, Project p) { - //Add the test projects - testTree.addItem(new Object[]{new TreeTableCheckBox(testTree, - p.getName(), "project" + p.getId()), ""}, - "project" + p.getId()); - if (p.getParentProjectId() != null) { - //Add as child - testTree.setParent("project" + p.getId(), - "project" + p.getParentProjectId().getId()); - } - p.getTestProjectList().stream().map((tp) -> { - TreeTableCheckBox cb = new TreeTableCheckBox(testTree, - tp.getName(), "testproject" + tp.getId()); - cb.setIcon(ValidationManagerUI.TEST_SUITE_ICON); - testTree.addItem(new Object[]{cb, ""}, - "testproject" + tp.getId()); - return tp; - }).map((tp) -> { - testTree.setParent("testproject" + tp.getId(), - "project" + p.getId()); - return tp; - }).map((tp) -> { - tp.getTestPlanList().stream().map((plan) -> { - TreeTableCheckBox pcb = new TreeTableCheckBox(testTree, - plan.getName(), plan.getTestPlanPK()); - pcb.setIcon(ValidationManagerUI.PLAN_ICON); - testTree.addItem(new Object[]{pcb, ""}, - plan.getTestPlanPK()); - return plan; - }).map((plan) -> { - testTree.setParent(plan.getTestPlanPK(), - "testproject" + tp.getId()); - return plan; - }).forEachOrdered((plan) -> { - plan.getTestCaseList().stream().map((tc) -> { - TreeTableCheckBox tccb = new TreeTableCheckBox(testTree, - tc.getName(), "tc" + tc.getId()); - tccb.setIcon(ValidationManagerUI.TEST_ICON); - testTree.addItem(new Object[]{tccb, - tc.getSummary() != null - ? new String(tc.getSummary()) : ""}, - "tc" + tc.getId()); - return tc; - }).map((tc) -> { - testTree.setParent("tc" + tc.getId(), - plan.getTestPlanPK()); - return tc; - }).forEachOrdered((tc) -> { - testTree.setChildrenAllowed("tc" + tc.getId(), false); - }); - }); - return tp; - }).forEachOrdered((tp) -> { - testTree.setCollapsed("testproject" + tp.getId(), false); - }); - p.getProjectList().forEach((sp) -> { - addProjectTestPlanning(testTree, sp); - }); - testTree.setCollapsed("project" + p.getId(), false); - } - - private List processChildren(Object parent) { - List testCases = new ArrayList<>(); - //Get a list of selected test cases - testTree.getChildren(parent).stream().map((o) -> { - if (o instanceof String) { - String id = (String) o; - if (id.startsWith("tc")) { - //Is a Test Case - Item item = testTree.getItem(id); - Object val = item.getItemProperty("general.name").getValue(); - if (val instanceof TreeTableCheckBox) { - TreeTableCheckBox ttcb = (TreeTableCheckBox) val; - if (ttcb.getValue()) { - //Selected - LOG.log(Level.FINE, "Included TC: {0}", - ttcb.getObjectId()); - testCases.add(Integer.parseInt(id.substring(2))); - Object pid = id; - //Add the related project to the list. - while (pid != null) { - if (pid instanceof String) { - String s = (String) pid; - if (s.startsWith("project")) { - LOG.log(Level.FINE, "Processing: {0}", s); - getProjects().add(Integer.parseInt(s.substring(7))); - break; - } - } - pid = testTree.getParent(pid); - } - } - } - } - } - return o; - }).filter((o) -> (testTree.hasChildren(o))).forEachOrdered((o) -> { - testCases.addAll(processChildren(o)); - }); - return testCases; - } - - /** - * @return the projects - */ - public List getProjects() { - return projects; - } -} +package net.sourceforge.javydreamercsw.validation.manager.web.wizard.plan; + +import com.vaadin.data.Item; +import com.vaadin.ui.Component; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Notification; +import com.vaadin.ui.TreeTable; +import com.vaadin.ui.VerticalLayout; +import com.validation.manager.core.db.Project; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.sourceforge.javydreamercsw.validation.manager.web.component.TreeTableCheckBox; +import net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI; +import org.vaadin.teemu.wizards.Wizard; +import org.vaadin.teemu.wizards.WizardStep; + +/** + * + * @author Javier A. Ortiz Bultron javier.ortiz.78@gmail.com + */ +public class SelectTestCasesStep implements WizardStep { + + private final Project p; + private final Wizard w; + private final TreeTable testTree = new TreeTable("available.tests"); + private final List projects = new ArrayList<>(); + private static final Logger LOG + = Logger.getLogger(SelectTestCasesStep.class.getSimpleName()); + + public SelectTestCasesStep(Wizard w, Project p) { + this.p = p; + this.w = w; + } + + @Override + public String getCaption() { + return "select.test.case"; + } + + @Override + public Component getContent() { + VerticalLayout l = new VerticalLayout(); + //Add menu + HorizontalLayout menu = new HorizontalLayout(); + if (p != null) { + //Show the Test Plans for the selected project (including sub projects + testTree.addContainerProperty("general.name", + TreeTableCheckBox.class, ""); + testTree.addContainerProperty("general.description", + String.class, ""); + testTree.setWidth("20em"); + addProjectTestPlanning(testTree, p); + } + testTree.setSizeFull(); + l.addComponent(menu); + l.addComponent(testTree); + return l; + } + + @Override + public boolean onAdvance() { + //Get a list of selected test cases + List testCases + = processChildren("project" + p.getId()); + testCases.forEach((i) -> { + LOG.log(Level.FINE, "Test Case: {0}", i); + }); + if (testCases.isEmpty()) { + Notification.show("unable.to.proceed", + "select.test.case.message", + Notification.Type.WARNING_MESSAGE); + return false; + } + //update next step + DetailStep next = ((DetailStep) w.getSteps().get(1)); + next.setTestCases(testCases); + return true; + } + + @Override + public boolean onBack() { + return false; + } + + private void addProjectTestPlanning(TreeTable testTree, Project p) { + //Add the test projects + testTree.addItem(new Object[]{new TreeTableCheckBox(testTree, + p.getName(), "project" + p.getId()), ""}, + "project" + p.getId()); + if (p.getParentProjectId() != null) { + //Add as child + testTree.setParent("project" + p.getId(), + "project" + p.getParentProjectId().getId()); + } + p.getTestProjectList().stream().map((tp) -> { + TreeTableCheckBox cb = new TreeTableCheckBox(testTree, + tp.getName(), "testproject" + tp.getId()); + cb.setIcon(ValidationManagerUI.TEST_SUITE_ICON); + testTree.addItem(new Object[]{cb, ""}, + "testproject" + tp.getId()); + return tp; + }).map((tp) -> { + testTree.setParent("testproject" + tp.getId(), + "project" + p.getId()); + return tp; + }).map((tp) -> { + tp.getTestPlanList().stream().map((plan) -> { + TreeTableCheckBox pcb = new TreeTableCheckBox(testTree, + plan.getName(), plan.getTestPlanPK()); + pcb.setIcon(ValidationManagerUI.PLAN_ICON); + testTree.addItem(new Object[]{pcb, ""}, + plan.getTestPlanPK()); + return plan; + }).map((plan) -> { + testTree.setParent(plan.getTestPlanPK(), + "testproject" + tp.getId()); + return plan; + }).forEachOrdered((plan) -> { + plan.getTestCaseList().stream().map((tc) -> { + TreeTableCheckBox tccb = new TreeTableCheckBox(testTree, + tc.getName(), "tc" + tc.getId()); + tccb.setIcon(ValidationManagerUI.TEST_ICON); + testTree.addItem(new Object[]{tccb, + tc.getSummary() != null + ? new String(tc.getSummary()) : ""}, + "tc" + tc.getId()); + return tc; + }).map((tc) -> { + testTree.setParent("tc" + tc.getId(), + plan.getTestPlanPK()); + return tc; + }).forEachOrdered((tc) -> { + testTree.setChildrenAllowed("tc" + tc.getId(), false); + }); + }); + return tp; + }).forEachOrdered((tp) -> { + testTree.setCollapsed("testproject" + tp.getId(), false); + }); + p.getProjectList().forEach((sp) -> { + addProjectTestPlanning(testTree, sp); + }); + testTree.setCollapsed("project" + p.getId(), false); + } + + private List processChildren(Object parent) { + List testCases = new ArrayList<>(); + //Get a list of selected test cases + testTree.getChildren(parent).stream().map((o) -> { + if (o instanceof String) { + String id = (String) o; + if (id.startsWith("tc")) { + //Is a Test Case + Item item = testTree.getItem(id); + Object val = item.getItemProperty("general.name").getValue(); + if (val instanceof TreeTableCheckBox) { + TreeTableCheckBox ttcb = (TreeTableCheckBox) val; + if (ttcb.getValue()) { + //Selected + LOG.log(Level.FINE, "Included TC: {0}", + ttcb.getObjectId()); + testCases.add(Integer.parseInt(id.substring(2))); + Object pid = id; + //Add the related project to the list. + while (pid != null) { + if (pid instanceof String) { + String s = (String) pid; + if (s.startsWith("project")) { + LOG.log(Level.FINE, "Processing: {0}", s); + getProjects().add(Integer.parseInt(s.substring(7))); + break; + } + } + pid = testTree.getParent(pid); + } + } + } + } + } + return o; + }).filter((o) -> (testTree.hasChildren(o))).forEachOrdered((o) -> { + testCases.addAll(processChildren(o)); + }); + return testCases; + } + + /** + * @return the projects + */ + public List getProjects() { + return projects; + } +} diff --git a/pom.xml b/pom.xml index 124264d9..e6c960e2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 Validation-Manager - 0.3.2 + 0.3.3 net.sourceforge.javydreamercsw pom @@ -176,24 +176,6 @@ false - - cy.github - github-release-plugin - 0.5.2 - - - ${project.artifactId}-${project.version} - true - - - - - gh-upload - - deploy - - -