diff --git a/.gitignore b/.gitignore index 04d4918..a293b5c 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ # MAVEN target/ +rebel.xml diff --git a/.travis.yml b/.travis.yml index d99f43b..d70e134 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,2 @@ language: java -jdk: - - oraclejdk7 - - openjdk7 - - openjdk6 +script: "mvn clean package" \ No newline at end of file diff --git a/commons-cilea-api/commons-cilea-genericdao/pom.xml b/commons-cilea-api/commons-cilea-genericdao/pom.xml index 542d96a..64b7f62 100644 --- a/commons-cilea-api/commons-cilea-genericdao/pom.xml +++ b/commons-cilea-api/commons-cilea-genericdao/pom.xml @@ -1,55 +1,54 @@ - - - commons-cilea-api - it.cilea - 2.2-SNAPSHOT - - 4.0.0 - it.cilea - commons-cilea-genericdao - - - - - - - org.hibernate - hibernate-entitymanager - - - - org.hibernate - hibernate-ehcache - - - - org.hibernate - hibernate-core - - - - org.hibernate.common - hibernate-commons-annotations - - - - commons-logging - commons-logging - - - - commons-lang - commons-lang - - - - org.springframework - spring-core - - - - org.springframework - spring-orm - - + + + commons-cilea-api + it.cilea + 2.6-SNAPSHOT + + 4.0.0 + it.cilea + commons-cilea-genericdao + + + + + + org.hibernate + hibernate-ehcache + + + + org.hibernate + hibernate-core + + + + org.hibernate.common + hibernate-commons-annotations + + + + commons-logging + commons-logging + + + + commons-lang + commons-lang + + + + org.springframework + spring-core + + + + org.springframework + spring-orm + + + + org.springframework + spring-aop + + \ No newline at end of file diff --git a/commons-cilea-api/commons-cilea-genericdao/src/META-INF/MANIFEST.MF b/commons-cilea-api/commons-cilea-genericdao/src/META-INF/MANIFEST.MF index 5e94951..254272e 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/META-INF/MANIFEST.MF +++ b/commons-cilea-api/commons-cilea-genericdao/src/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ -Manifest-Version: 1.0 -Class-Path: - +Manifest-Version: 1.0 +Class-Path: + diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/META-INF/MANIFEST.MF b/commons-cilea-api/commons-cilea-genericdao/src/main/java/META-INF/MANIFEST.MF index 5e94951..254272e 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/META-INF/MANIFEST.MF +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ -Manifest-Version: 1.0 -Class-Path: - +Manifest-Version: 1.0 +Class-Path: + diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/HasTimeStampInfo.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/HasTimeStampInfo.java index 2b2d1cb..b616ebb 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/HasTimeStampInfo.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/HasTimeStampInfo.java @@ -1,35 +1,35 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.core; - -public interface HasTimeStampInfo -{ - /** - * Return a "not null" object with creation/last update informations - * - * @return a "not null" object with creation/last update informations - */ - public ITimeStampInfo getTimeStampInfo(); -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.core; + +public interface HasTimeStampInfo +{ + /** + * Return a "not null" object with creation/last update informations + * + * @return a "not null" object with creation/last update informations + */ + public ITimeStampInfo getTimeStampInfo(); +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/ITimeStampInfo.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/ITimeStampInfo.java index 98f8bb4..e4032d4 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/ITimeStampInfo.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/ITimeStampInfo.java @@ -1,39 +1,39 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.core; - -/** - * Interface that persistent class should implements to support the - * automatically record of creation/last update information - * - * @author cilea - * - */ -public interface ITimeStampInfo { - public void setInfoCreated(SingleTimeStampInfo timestamp); - public void setInfoLastModified(SingleTimeStampInfo timestamp); - public SingleTimeStampInfo getTimestampCreated(); - public SingleTimeStampInfo getTimestampLastModified(); -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.core; + +/** + * Interface that persistent class should implements to support the + * automatically record of creation/last update information + * + * @author cilea + * + */ +public interface ITimeStampInfo { + public void setInfoCreated(SingleTimeStampInfo timestamp); + public void setInfoLastModified(SingleTimeStampInfo timestamp); + public SingleTimeStampInfo getTimestampCreated(); + public SingleTimeStampInfo getTimestampLastModified(); +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/SingleTimeStampInfo.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/SingleTimeStampInfo.java index 01fd210..6d04a0d 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/SingleTimeStampInfo.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/SingleTimeStampInfo.java @@ -1,83 +1,83 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.core; - -import java.io.Serializable; -import java.util.Date; - -import javax.persistence.MappedSuperclass; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; - -@MappedSuperclass -/** - * This class mantains basic information about an event. At the moment only the - * timestamp of the event is recorded but the class stay here for future - * extension. - */ -public class SingleTimeStampInfo implements Serializable { - - /** - * timestamp - */ - @Temporal(TemporalType.TIMESTAMP) - private Date timestamp; - - public SingleTimeStampInfo() { - - } - - /** - * Fast constructor. - * - * @param date - * the event timestamp - */ - public SingleTimeStampInfo(Date date) { - this.timestamp = date; - } - - - /** - * Getter method. - * - * return - * the event timestamp - */ - public Date getTimestamp() { - return timestamp; - } - - /** - * Setter method. - * - * @param date - * the event timestamp - */ - public void setTimestamp(Date timestamp) { - this.timestamp = timestamp; - } - -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.core; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.MappedSuperclass; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@MappedSuperclass +/** + * This class mantains basic information about an event. At the moment only the + * timestamp of the event is recorded but the class stay here for future + * extension. + */ +public class SingleTimeStampInfo implements Serializable { + + /** + * timestamp + */ + @Temporal(TemporalType.TIMESTAMP) + private Date timestamp; + + public SingleTimeStampInfo() { + + } + + /** + * Fast constructor. + * + * @param date + * the event timestamp + */ + public SingleTimeStampInfo(Date date) { + this.timestamp = date; + } + + + /** + * Getter method. + * + * return + * the event timestamp + */ + public Date getTimestamp() { + return timestamp; + } + + /** + * Setter method. + * + * @param date + * the event timestamp + */ + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/TimeStampInfo.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/TimeStampInfo.java index 1c92c1a..9eb090e 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/TimeStampInfo.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/core/TimeStampInfo.java @@ -1,115 +1,115 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.core; - -import java.io.Serializable; -import java.util.Date; - -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.Embedded; - -/** - * Simple embeddable object to mantains timestamp information on creation and - * lastupdate - * - * - * @author cilea - */ -@Embeddable -public class TimeStampInfo implements ITimeStampInfo, Serializable -{ - - @Embedded - @AttributeOverride(name = "timestamp", column = @Column(name = "timestampCreated")) - /** information about the creation of the object */ - private SingleTimeStampInfo timestampCreated; - - @Embedded - @AttributeOverride(name = "timestamp", column = @Column(name = "timestampLastModified")) - /** information about the last modification of the object */ - private SingleTimeStampInfo timestampLastModified; - - /** - * Setter method. - * - * @return information about the creation of the object - */ - public SingleTimeStampInfo getTimestampCreated() - { - return timestampCreated; - } - - /** - * Getter method. - * - * @return information about the last modification of the object - */ - public SingleTimeStampInfo getTimestampLastModified() - { - return timestampLastModified; - } - - /** - * Setter method. - * - * @param timestamp - * information about the creation of the object - */ - public void setInfoCreated(SingleTimeStampInfo timestamp) - { - this.timestampCreated = timestamp; - } - - /** - * Setter method. - * - * @param timestamp - * information about the last modification of the object - */ - public void setInfoLastModified(SingleTimeStampInfo timestamp) - { - this.timestampLastModified = timestamp; - } - - public Date getCreationTime() - { - if (timestampCreated == null || timestampCreated.getTimestamp() == null) - { - return null; - } - return timestampCreated.getTimestamp(); - } - - public Date getLastModificationTime() - { - if (timestampLastModified == null || timestampLastModified.getTimestamp() == null) - { - return getCreationTime(); - } - return timestampLastModified.getTimestamp(); - } -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.core; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.AttributeOverride; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Embedded; + +/** + * Simple embeddable object to mantains timestamp information on creation and + * lastupdate + * + * + * @author cilea + */ +@Embeddable +public class TimeStampInfo implements ITimeStampInfo, Serializable +{ + + @Embedded + @AttributeOverride(name = "timestamp", column = @Column(name = "timestampCreated")) + /** information about the creation of the object */ + private SingleTimeStampInfo timestampCreated; + + @Embedded + @AttributeOverride(name = "timestamp", column = @Column(name = "timestampLastModified")) + /** information about the last modification of the object */ + private SingleTimeStampInfo timestampLastModified; + + /** + * Setter method. + * + * @return information about the creation of the object + */ + public SingleTimeStampInfo getTimestampCreated() + { + return timestampCreated; + } + + /** + * Getter method. + * + * @return information about the last modification of the object + */ + public SingleTimeStampInfo getTimestampLastModified() + { + return timestampLastModified; + } + + /** + * Setter method. + * + * @param timestamp + * information about the creation of the object + */ + public void setInfoCreated(SingleTimeStampInfo timestamp) + { + this.timestampCreated = timestamp; + } + + /** + * Setter method. + * + * @param timestamp + * information about the last modification of the object + */ + public void setInfoLastModified(SingleTimeStampInfo timestamp) + { + this.timestampLastModified = timestamp; + } + + public Date getCreationTime() + { + if (timestampCreated == null || timestampCreated.getTimestamp() == null) + { + return null; + } + return timestampCreated.getTimestamp(); + } + + public Date getLastModificationTime() + { + if (timestampLastModified == null || timestampLastModified.getTimestamp() == null) + { + return getCreationTime(); + } + return timestampLastModified.getTimestamp(); + } +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/GenericDao.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/GenericDao.java index 15456c5..3647fea 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/GenericDao.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/GenericDao.java @@ -1,102 +1,102 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.dao; - -import java.io.Serializable; - -/** - *

- * Generic interface for the base "service" that a DAO MUST provide - *

- *

- * This source are based on the Per - * Mellqvist article: Don't repeat the DAO!
- *

- * - * @author cilea - * - * @param - * the class of the managed Entity - * @param - * the class of the primary key - */ -public interface GenericDao { - - /** - * Persist the newInstance object into database - * - * @param newInstance - * the instance to persist - * - * @return the primary key of the persisted instance - **/ - PK create(T newInstance); - - /** - * Retrieve an object that was previously persisted to the database using - * the indicated id as primary key - * - * @param id - * the primary key to lookup for - * - * @result the retrieved instance - */ - T read(PK id); - - /** - * Save changes made to a persistent object - * - * @param transientObject - * the instance to update - */ - void update(T transientObject); - - /** - * Merge a detached object against the persistent state - * - * @param transientObject - * the detached object - * @return a managed object - */ - T merge(T transientObject); - - /** - * Perform a save or update action on the object basis on the persistence - * state - * - * @param transientObject - * the object to persist or update - */ - void saveOrUpdate(T transientObject); - - /** - * Remove an object from persistent storage in the database - * - * @param persistentObject - * the object to remove - */ - void delete(T persistentObject); -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.dao; + +import java.io.Serializable; + +/** + *

+ * Generic interface for the base "service" that a DAO MUST provide + *

+ *

+ * This source are based on the Per + * Mellqvist article: Don't repeat the DAO!
+ *

+ * + * @author cilea + * + * @param + * the class of the managed Entity + * @param + * the class of the primary key + */ +public interface GenericDao { + + /** + * Persist the newInstance object into database + * + * @param newInstance + * the instance to persist + * + * @return the primary key of the persisted instance + **/ + PK create(T newInstance); + + /** + * Retrieve an object that was previously persisted to the database using + * the indicated id as primary key + * + * @param id + * the primary key to lookup for + * + * @result the retrieved instance + */ + T read(PK id); + + /** + * Save changes made to a persistent object + * + * @param transientObject + * the instance to update + */ + void update(T transientObject); + + /** + * Merge a detached object against the persistent state + * + * @param transientObject + * the detached object + * @return a managed object + */ + T merge(T transientObject); + + /** + * Perform a save or update action on the object basis on the persistence + * state + * + * @param transientObject + * the object to persist or update + */ + void saveOrUpdate(T transientObject); + + /** + * Remove an object from persistent storage in the database + * + * @param persistentObject + * the object to remove + */ + void delete(T persistentObject); +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/IApplicationDao.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/IApplicationDao.java index 02fc21f..aeedccd 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/IApplicationDao.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/IApplicationDao.java @@ -1,51 +1,51 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.dao; - -import java.io.Serializable; -import java.util.List; - -import it.cilea.osd.common.model.Identifiable; - -/** - * Common interface for interaction with the persistence engine - * - * @author cilea - * - */ -public interface IApplicationDao { - - /** - * Evict a managed object from the persistence context - * - * @param identifiable - * a managed object - */ - public void evict(Identifiable identifiable); - - public List getList(Class clazz, - List allIds); - -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.dao; + +import java.io.Serializable; +import java.util.List; + +import it.cilea.osd.common.model.Identifiable; + +/** + * Common interface for interaction with the persistence engine + * + * @author cilea + * + */ +public interface IApplicationDao { + + /** + * Evict a managed object from the persistence context + * + * @param identifiable + * a managed object + */ + public void evict(Identifiable identifiable); + + public List getList(Class clazz, + List allIds); + +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/NamedQueryExecutor.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/NamedQueryExecutor.java index 8d55eb0..3aaa7d1 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/NamedQueryExecutor.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/NamedQueryExecutor.java @@ -1,70 +1,70 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.dao; - -import java.lang.reflect.Method; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.List; - -/** - *

- * The interface that a genericDAO implementation needs to implement to support - * generic named query execution. - *

- *

- * This source are based on the Per - * Mellqvist article: Don't repeat the DAO!
- *

- * - * @author cilea - * - * @param - * the Entity class - */ -public interface NamedQueryExecutor { - - List executeFinder(Method method, Object[] queryArgs); - - List executePaginator(Method method, Object[] queryArgs, String sort, - boolean inverse, int firstResult, int maxResults); - - long executeCounter(Method method, Object[] queryArgs); - - Integer executeIdFinder(Method method, Object[] queryArgs); - - T executeUnique(Method method, Object[] queryArgs); - - Integer executeDelete(Method method, Object[] queryArgs); - - Boolean executeBoolean(Method method, Object[] queryArgs); - - Double executeDouble(Method method, Object[] queryArgs); - - T executeSingleResult(Method method, Object[] args); - - Integer executeMax(Method method, Object[] queryArgs); -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.dao; + +import java.lang.reflect.Method; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.List; + +/** + *

+ * The interface that a genericDAO implementation needs to implement to support + * generic named query execution. + *

+ *

+ * This source are based on the Per + * Mellqvist article: Don't repeat the DAO!
+ *

+ * + * @author cilea + * + * @param + * the Entity class + */ +public interface NamedQueryExecutor { + + List executeFinder(Method method, Object[] queryArgs); + + List executePaginator(Method method, Object[] queryArgs, String sort, + boolean inverse, int firstResult, int maxResults); + + long executeCounter(Method method, Object[] queryArgs); + + Integer executeIdFinder(Method method, Object[] queryArgs); + + T executeUnique(Method method, Object[] queryArgs); + + Integer executeDelete(Method method, Object[] queryArgs); + + Boolean executeBoolean(Method method, Object[] queryArgs); + + Double executeDouble(Method method, Object[] queryArgs); + + T executeSingleResult(Method method, Object[] args); + + Integer executeMax(Method method, Object[] queryArgs); +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/PaginableObjectDao.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/PaginableObjectDao.java index 6bb1cd7..61ce36d 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/PaginableObjectDao.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/PaginableObjectDao.java @@ -1,72 +1,72 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.dao; - - -import java.io.Serializable; -import java.util.List; - -/** - * Query methods that a DAO that want support pagination need to provide - * - * @author cilea - * - * @param - * the class of the managed Entity - * @param - * the class of the primary key - */ -public interface PaginableObjectDao extends GenericDao { - /** - * Return the full list of the objects in the database - * - * @return the full list of the objects in the database - */ - public List findAll(); - - /** - * Count the number of objects in the database - * - * @return the number of objects in the database - */ - public long count(); - - /** - * Run the named query: paginate.[sort].asc or desc if the inverse parameter - * is true - * - * @param sort - * the attribute to use for sorting (i.e "id") - * @param inverse - * true for desc order - * @param firstResult - * the offset to use in query - * @param maxResults - * the max number of results to return - * @return the "page" of objects in the requested order and position - */ - public List paginate(String sort, boolean inverse, int firstResult, - int maxResults); -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.dao; + + +import java.io.Serializable; +import java.util.List; + +/** + * Query methods that a DAO that want support pagination need to provide + * + * @author cilea + * + * @param + * the class of the managed Entity + * @param + * the class of the primary key + */ +public interface PaginableObjectDao extends GenericDao { + /** + * Return the full list of the objects in the database + * + * @return the full list of the objects in the database + */ + public List findAll(); + + /** + * Count the number of objects in the database + * + * @return the number of objects in the database + */ + public long count(); + + /** + * Run the named query: paginate.[sort].asc or desc if the inverse parameter + * is true + * + * @param sort + * the attribute to use for sorting (i.e "id") + * @param inverse + * true for desc order + * @param firstResult + * the offset to use in query + * @param maxResults + * the max number of results to return + * @return the "page" of objects in the requested order and position + */ + public List paginate(String sort, boolean inverse, int firstResult, + int maxResults); +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/impl/ApplicationDao.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/impl/ApplicationDao.java index 9c34a65..4bacfb6 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/impl/ApplicationDao.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/impl/ApplicationDao.java @@ -1,125 +1,125 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.dao.impl; - -import it.cilea.osd.common.dao.IApplicationDao; -import it.cilea.osd.common.model.Identifiable; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Criteria; -import org.hibernate.Hibernate; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.criterion.Disjunction; -import org.hibernate.criterion.Restrictions; - -/** - * {@link IApplicationDao} implementations based on Hibernate - * - * @author cilea - * - */ -public class ApplicationDao implements IApplicationDao { - /** - * The Log4J logger - */ - private static final Log log = LogFactory.getLog(ApplicationDao.class); - - private static final int MAX_IN_CLAUSE = 500; - - private SessionFactory sessionFactory; - - public SessionFactory getSessionFactory() { - return sessionFactory; - } - - public void setSessionFactory(SessionFactory sessionFactory) { - this.sessionFactory = sessionFactory; - } - - /** - * {@inheritDoc} - */ - public void evict(Identifiable identifiable) { - getSessionFactory().getCurrentSession().evict(identifiable); - } - - /** - * {@inheritDoc} - */ - public List getList(Class clazz, - List allIds) { - Session session = getSessionFactory().getCurrentSession(); - Criteria criteria = session.createCriteria(clazz); - - final int maxResults = allIds.size(); - if (maxResults == 0) - return null; - - int loop = maxResults / MAX_IN_CLAUSE; - boolean exact = maxResults % MAX_IN_CLAUSE == 0; - - if (!exact) - loop++; - - Disjunction disjunction = Restrictions.disjunction(); - - for (int index = 0; index < loop; index++) { - int max = index * MAX_IN_CLAUSE + MAX_IN_CLAUSE <= maxResults ? index - * MAX_IN_CLAUSE + MAX_IN_CLAUSE - : maxResults; - List ids = new ArrayList(max - index * MAX_IN_CLAUSE); - for (int entityInfoIndex = index * MAX_IN_CLAUSE; entityInfoIndex < max; entityInfoIndex++) { - ids.add(allIds.get(entityInfoIndex)); - } - disjunction.add(Restrictions.in("id", ids)); - } - criteria.add(disjunction); - criteria.list(); // load all objects - - // mandatory to keep the same ordering - List result = new ArrayList(allIds.size()); - for (PK id : allIds) { - T element = (T) session.load(clazz, id); - if (Hibernate.isInitialized(element)) { - // all existing elements should have been loaded by the query, - // the other ones are missing ones - result.add(element); - } else { - if (log.isDebugEnabled()) { - log.debug("Object with id: " + id + " not in database: " - + clazz); - } - } - } - return result; - } - -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.dao.impl; + +import it.cilea.osd.common.dao.IApplicationDao; +import it.cilea.osd.common.model.Identifiable; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Hibernate; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.criterion.Disjunction; +import org.hibernate.criterion.Restrictions; + +/** + * {@link IApplicationDao} implementations based on Hibernate + * + * @author cilea + * + */ +public class ApplicationDao implements IApplicationDao { + /** + * The Log4J logger + */ + private static final Log log = LogFactory.getLog(ApplicationDao.class); + + private static final int MAX_IN_CLAUSE = 500; + + private SessionFactory sessionFactory; + + public SessionFactory getSessionFactory() { + return sessionFactory; + } + + public void setSessionFactory(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + /** + * {@inheritDoc} + */ + public void evict(Identifiable identifiable) { + getSessionFactory().getCurrentSession().evict(identifiable); + } + + /** + * {@inheritDoc} + */ + public List getList(Class clazz, + List allIds) { + Session session = getSessionFactory().getCurrentSession(); + Criteria criteria = session.createCriteria(clazz); + + final int maxResults = allIds.size(); + if (maxResults == 0) + return null; + + int loop = maxResults / MAX_IN_CLAUSE; + boolean exact = maxResults % MAX_IN_CLAUSE == 0; + + if (!exact) + loop++; + + Disjunction disjunction = Restrictions.disjunction(); + + for (int index = 0; index < loop; index++) { + int max = index * MAX_IN_CLAUSE + MAX_IN_CLAUSE <= maxResults ? index + * MAX_IN_CLAUSE + MAX_IN_CLAUSE + : maxResults; + List ids = new ArrayList(max - index * MAX_IN_CLAUSE); + for (int entityInfoIndex = index * MAX_IN_CLAUSE; entityInfoIndex < max; entityInfoIndex++) { + ids.add(allIds.get(entityInfoIndex)); + } + disjunction.add(Restrictions.in("id", ids)); + } + criteria.add(disjunction); + criteria.list(); // load all objects + + // mandatory to keep the same ordering + List result = new ArrayList(allIds.size()); + for (PK id : allIds) { + T element = (T) session.load(clazz, id); + if (Hibernate.isInitialized(element)) { + // all existing elements should have been loaded by the query, + // the other ones are missing ones + result.add(element); + } else { + if (log.isDebugEnabled()) { + log.debug("Object with id: " + id + " not in database: " + + clazz); + } + } + } + return result; + } + +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/impl/NamedQueryIntroductionAdvisor.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/impl/NamedQueryIntroductionAdvisor.java index d912440..736ecf7 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/impl/NamedQueryIntroductionAdvisor.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/dao/impl/NamedQueryIntroductionAdvisor.java @@ -1,114 +1,114 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.dao.impl; - -import it.cilea.osd.common.dao.NamedQueryExecutor; - -import java.util.Arrays; - -import org.aopalliance.intercept.MethodInvocation; -import org.springframework.aop.IntroductionInterceptor; -import org.springframework.aop.support.DefaultIntroductionAdvisor; - -/** - * This class is the Advisor responsible to execute the appropriate named query - * when a method is invoked on a DAO interface. - * - * @author cilea - * - */ -public class NamedQueryIntroductionAdvisor extends DefaultIntroductionAdvisor { - - public NamedQueryIntroductionAdvisor() { - super(new IntroductionInterceptor() { - /** - * Execute the appropriate method of the genericDAO implementation - * basing on the start characters of the original invoked method on - * the DAO class - */ - public Object invoke(MethodInvocation mi) throws Throwable { - NamedQueryExecutor genericDao = (NamedQueryExecutor) mi - .getThis(); - String methodName = mi.getMethod().getName(); - if (methodName.startsWith("find")) { - Object[] args = mi.getArguments(); - return genericDao.executeFinder(mi.getMethod(), args); - } else if (methodName.startsWith("like")){ - Object[] args = mi.getArguments(); - Object[] newArgs = new Object[args.length]; - int i = 0; - for(Object arg : args) { - newArgs[i] = "%"+((String)arg)+"%"; - i++; - } - return genericDao.executeFinder(mi.getMethod(), newArgs); - } else if (methodName.startsWith("unique")){ - Object[] args = mi.getArguments(); - return genericDao.executeUnique(mi.getMethod(), args); - }else if (methodName.startsWith("count")) { - Object[] args = mi.getArguments(); - return genericDao.executeCounter(mi.getMethod(), args); - } else if (methodName.startsWith("delete") && !methodName.equals("delete")) { - Object[] args = mi.getArguments(); - return genericDao.executeDelete(mi.getMethod(), args); - }else if (methodName.startsWith("idFind")) { - Object[] args = mi.getArguments(); - return genericDao.executeIdFinder(mi.getMethod(), args); - } else if (methodName.startsWith("paginate")) { - Object[] args = mi.getArguments(); - String sort = (String) args[args.length - 4]; - boolean inverse = (Boolean) args[args.length - 3]; - int firstResult = (Integer) args[args.length - 2]; - int maxResults = (Integer) args[args.length - 1]; - args = Arrays.asList(args).subList(0, args.length - 4) - .toArray(); - return genericDao.executePaginator(mi.getMethod(), args, - sort, inverse, firstResult, maxResults); - } else if (methodName.startsWith("is") || methodName.startsWith("has") - || methodName.startsWith("check")){ - Object[] args = mi.getArguments(); - return genericDao.executeBoolean(mi.getMethod(), args); - } else if (methodName.startsWith("sum")){ - Object[] args = mi.getArguments(); - return genericDao.executeDouble(mi.getMethod(), args); - } else if (methodName.startsWith("singleResult")){ - Object[] args = mi.getArguments(); - return genericDao.executeSingleResult(mi.getMethod(), args); - } else if (methodName.startsWith("max")){ - Object[] args = mi.getArguments(); - return genericDao.executeMax(mi.getMethod(), args); - } else { - return mi.proceed(); - } - } - - public boolean implementsInterface(Class intf) { - return intf.isInterface() - && NamedQueryExecutor.class.isAssignableFrom(intf); - } - }); - } - -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.dao.impl; + +import it.cilea.osd.common.dao.NamedQueryExecutor; + +import java.util.Arrays; + +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.aop.IntroductionInterceptor; +import org.springframework.aop.support.DefaultIntroductionAdvisor; + +/** + * This class is the Advisor responsible to execute the appropriate named query + * when a method is invoked on a DAO interface. + * + * @author cilea + * + */ +public class NamedQueryIntroductionAdvisor extends DefaultIntroductionAdvisor { + + public NamedQueryIntroductionAdvisor() { + super(new IntroductionInterceptor() { + /** + * Execute the appropriate method of the genericDAO implementation + * basing on the start characters of the original invoked method on + * the DAO class + */ + public Object invoke(MethodInvocation mi) throws Throwable { + NamedQueryExecutor genericDao = (NamedQueryExecutor) mi + .getThis(); + String methodName = mi.getMethod().getName(); + if (methodName.startsWith("find")) { + Object[] args = mi.getArguments(); + return genericDao.executeFinder(mi.getMethod(), args); + } else if (methodName.startsWith("like")){ + Object[] args = mi.getArguments(); + Object[] newArgs = new Object[args.length]; + int i = 0; + for(Object arg : args) { + newArgs[i] = "%"+((String)arg)+"%"; + i++; + } + return genericDao.executeFinder(mi.getMethod(), newArgs); + } else if (methodName.startsWith("unique")){ + Object[] args = mi.getArguments(); + return genericDao.executeUnique(mi.getMethod(), args); + }else if (methodName.startsWith("count")) { + Object[] args = mi.getArguments(); + return genericDao.executeCounter(mi.getMethod(), args); + } else if (methodName.startsWith("delete") && !methodName.equals("delete")) { + Object[] args = mi.getArguments(); + return genericDao.executeDelete(mi.getMethod(), args); + }else if (methodName.startsWith("idFind")) { + Object[] args = mi.getArguments(); + return genericDao.executeIdFinder(mi.getMethod(), args); + } else if (methodName.startsWith("paginate")) { + Object[] args = mi.getArguments(); + String sort = (String) args[args.length - 4]; + boolean inverse = (Boolean) args[args.length - 3]; + int firstResult = (Integer) args[args.length - 2]; + int maxResults = (Integer) args[args.length - 1]; + args = Arrays.asList(args).subList(0, args.length - 4) + .toArray(); + return genericDao.executePaginator(mi.getMethod(), args, + sort, inverse, firstResult, maxResults); + } else if (methodName.startsWith("is") || methodName.startsWith("has") + || methodName.startsWith("check")){ + Object[] args = mi.getArguments(); + return genericDao.executeBoolean(mi.getMethod(), args); + } else if (methodName.startsWith("sum")){ + Object[] args = mi.getArguments(); + return genericDao.executeDouble(mi.getMethod(), args); + } else if (methodName.startsWith("singleResult")){ + Object[] args = mi.getArguments(); + return genericDao.executeSingleResult(mi.getMethod(), args); + } else if (methodName.startsWith("max")){ + Object[] args = mi.getArguments(); + return genericDao.executeMax(mi.getMethod(), args); + } else { + return mi.proceed(); + } + } + + public boolean implementsInterface(Class intf) { + return intf.isInterface() + && NamedQueryExecutor.class.isAssignableFrom(intf); + } + }); + } + +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/listener/NativeLoadEventListener.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/listener/NativeLoadEventListener.java new file mode 100644 index 0000000..b39ec3b --- /dev/null +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/listener/NativeLoadEventListener.java @@ -0,0 +1,8 @@ +package it.cilea.osd.common.listener; + +public interface NativeLoadEventListener +{ + + void onLoad(T entity); + +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/BaseObject.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/BaseObject.java index ea0726a..3d8278f 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/BaseObject.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/BaseObject.java @@ -1,96 +1,96 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.model; - -import java.io.Serializable; - -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ToStringBuilder; - -/** - * This class came from Ted Bergeron - * see: http://www.triview.com/articles/hibernate/validator/canmeetyourneeds.html - * - * Base class for model objects. - * - * @author Ted Bergeron - * @version $Id: BaseObject.java,v 1.2 2008-11-18 17:26:23 bollinicvs Exp $ - */ -public abstract class BaseObject implements Serializable { - - /** - * Used in hashCode methods - */ - protected static final int MAGICNUM1 = -48647637; - /** - * Used in hashCode methods - */ - protected static final int MAGICNUM2 = 1859709343; - - /** - * @see java.lang.Object#equals(Object) - */ - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - - if (!(object instanceof BaseObject)) { - return false; - } - - return new EqualsBuilder() - .appendSuper(super.equals(object)) - //.append(id, obj.getId()) Use this in subclasses that have properties - .isEquals(); - } - - - /** - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return new HashCodeBuilder(MAGICNUM1, MAGICNUM2) - .appendSuper(super.hashCode()) - // .append(id) Use this in subclasses that have properties - .toHashCode(); - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return new ToStringBuilder(this) - .appendSuper(super.toString()) - //.append(id) Use this in subclasses that have properties - .toString(); - } - - -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.model; + +import java.io.Serializable; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +/** + * This class came from Ted Bergeron + * see: http://www.triview.com/articles/hibernate/validator/canmeetyourneeds.html + * + * Base class for model objects. + * + * @author Ted Bergeron + * @version $Id: BaseObject.java,v 1.2 2008-11-18 17:26:23 bollinicvs Exp $ + */ +public abstract class BaseObject implements Serializable { + + /** + * Used in hashCode methods + */ + protected static final int MAGICNUM1 = -48647637; + /** + * Used in hashCode methods + */ + protected static final int MAGICNUM2 = 1859709343; + + /** + * @see java.lang.Object#equals(Object) + */ + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + + if (!(object instanceof BaseObject)) { + return false; + } + + return new EqualsBuilder() + .appendSuper(super.equals(object)) + //.append(id, obj.getId()) Use this in subclasses that have properties + .isEquals(); + } + + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return new HashCodeBuilder(MAGICNUM1, MAGICNUM2) + .appendSuper(super.hashCode()) + // .append(id) Use this in subclasses that have properties + .toHashCode(); + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return new ToStringBuilder(this) + .appendSuper(super.toString()) + //.append(id) Use this in subclasses that have properties + .toString(); + } + + +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/Identifiable.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/Identifiable.java index fcc5335..88c8cf0 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/Identifiable.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/Identifiable.java @@ -1,40 +1,40 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.model; - -import java.io.Serializable; - -/** - * This class came from Ted Bergeron - * see: http://www.triview.com/articles/hibernate/validator/canmeetyourneeds.html - * - * An object that can be identified by its ID. - * - * @author Ted Bergeron - * @version $Id: Identifiable.java,v 1.2 2008-11-18 17:26:23 bollinicvs Exp $ - */ -public interface Identifiable extends Serializable { - Integer getId(); -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.model; + +import java.io.Serializable; + +/** + * This class came from Ted Bergeron + * see: http://www.triview.com/articles/hibernate/validator/canmeetyourneeds.html + * + * An object that can be identified by its ID. + * + * @author Ted Bergeron + * @version $Id: Identifiable.java,v 1.2 2008-11-18 17:26:23 bollinicvs Exp $ + */ +public interface Identifiable extends Serializable { + Integer getId(); +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/IdentifiableObject.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/IdentifiableObject.java index a67200e..101aa2f 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/IdentifiableObject.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/IdentifiableObject.java @@ -1,89 +1,89 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.model; - -import java.io.Serializable; - -import javax.persistence.MappedSuperclass; - -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ToStringBuilder; - -/** - * This class came from Ted Bergeron - * see: http://www.triview.com/articles/hibernate/validator/canmeetyourneeds.html - * - * - * Base class for objects that can be uniquely identified via an Integer - * property, id. - * - * @author Ted Bergeron - * @version $Id: IdentifiableObject.java,v 1.2 2008-11-18 17:26:23 bollinicvs Exp $ - */ -@MappedSuperclass -public abstract class IdentifiableObject extends BaseObject implements - Identifiable, Serializable { - - public abstract Integer getId(); - - /** - * @see java.lang.Object#equals(Object) - */ - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - - if (!(object instanceof IdentifiableObject)) { - return false; - } - - IdentifiableObject obj = (IdentifiableObject) object; - - return new EqualsBuilder().appendSuper(super.equals(object)).append( - getId(), obj.getId()).isEquals(); - } - - /** - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return new HashCodeBuilder(MAGICNUM1, MAGICNUM2).appendSuper( - super.hashCode()).append(getId()).toHashCode(); - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return new ToStringBuilder(this).appendSuper(super.toString()).append( - getId()).toString(); - } - -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.model; + +import java.io.Serializable; + +import javax.persistence.MappedSuperclass; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +/** + * This class came from Ted Bergeron + * see: http://www.triview.com/articles/hibernate/validator/canmeetyourneeds.html + * + * + * Base class for objects that can be uniquely identified via an Integer + * property, id. + * + * @author Ted Bergeron + * @version $Id: IdentifiableObject.java,v 1.2 2008-11-18 17:26:23 bollinicvs Exp $ + */ +@MappedSuperclass +public abstract class IdentifiableObject extends BaseObject implements + Identifiable, Serializable { + + public abstract Integer getId(); + + /** + * @see java.lang.Object#equals(Object) + */ + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + + if (!(object instanceof IdentifiableObject)) { + return false; + } + + IdentifiableObject obj = (IdentifiableObject) object; + + return new EqualsBuilder().appendSuper(super.equals(object)).append( + getId(), obj.getId()).isEquals(); + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return new HashCodeBuilder(MAGICNUM1, MAGICNUM2).appendSuper( + super.hashCode()).append(getId()).toHashCode(); + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return new ToStringBuilder(this).appendSuper(super.toString()).append( + getId()).toString(); + } + +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/Selectable.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/Selectable.java index 71cd4bb..0f58120 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/Selectable.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/model/Selectable.java @@ -1,42 +1,42 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.model; - -/** - * This class came from Ted Bergeron - * see: http://www.triview.com/articles/hibernate/validator/canmeetyourneeds.html - * - * - * This interface defines an object that can be selected - * such as with a drop down list. - * - * @author Ted Bergeron - * @version $Id: Selectable.java,v 1.2 2008-11-18 17:26:23 bollinicvs Exp $ - */ -public interface Selectable { - String getIdentifyingValue(); - - String getDisplayValue(); -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.model; + +/** + * This class came from Ted Bergeron + * see: http://www.triview.com/articles/hibernate/validator/canmeetyourneeds.html + * + * + * This interface defines an object that can be selected + * such as with a drop down list. + * + * @author Ted Bergeron + * @version $Id: Selectable.java,v 1.2 2008-11-18 17:26:23 bollinicvs Exp $ + */ +public interface Selectable { + String getIdentifyingValue(); + + String getDisplayValue(); +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/service/IPersistenceService.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/service/IPersistenceService.java index 86cb430..e496ba0 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/service/IPersistenceService.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/service/IPersistenceService.java @@ -1,172 +1,172 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.service; - -import it.cilea.osd.common.model.Identifiable; - -import java.io.Serializable; -import java.util.List; - -import org.hibernate.Session; - -/** - * Minimal interface that an applicationService should provide to provide access - * to the persistente layer - * - * @author cilea - * - */ -public interface IPersistenceService { - - /** - * Retrive a managed object from its primary key - * - * @param - * the entity class - * @param - * the primary key class - * @param modelClass - * the entity class - * @param pkey - * the primary key - * @return the managed object - */ - public abstract T get(Class modelClass, - PK pkey); - - /** - * Persist or update an object basing on the object persistent state - * - * @param - * the entity class - * @param modelClass - * the entity class - * @param transientObject - * the object to persist or update - */ - public abstract void saveOrUpdate( - Class modelClass, T transientObject); - - /** - * Merge a detached object with his persistent state - * - * @param - * the entity class - * @param oggetto - * the detached object - * @param classe - * the entity class - * @return a managed object - */ - public abstract T merge(T oggetto, Class classe); - - /** - * Attach a detached object to the persistent context - * - * @param - * the entity class - * @param oggetto - * the detached object - * @param classe - * the entity class - * @return a managed object - */ - public abstract T refresh(T oggetto, - Class classe); - - /** - * Remove a managed object from the persistence datasource - * - * @param model - * the entity class - * @param pkey - * the primary key - **/ - public abstract void delete(Class

model, - PK pkey); - - /** - * Count the objects of a specific type - * - * @param - * the entity class - * @param classe - * the entity class - * @return the number of object of the requested type - */ - public abstract long count(Class classe); - - /** - * Check for existence of an object with the supplied primary key and type - * - * @param model - * the entity class - * @param id - * the primary key - * @return true if the object exists - * - */ - public abstract boolean exist(Class model, PK id); - - /** - * Return the list of objects of a specific type - * - * @param - * the entity class - * @param model - * the entity class - * @return the list of object of the requested class - */ - public abstract List getList(Class model); - - /** - * Return a paginated list of managed object - * - * @param - * the entity class - * @param model - * the entity class - * @param sort - * the sort criteria - * @param inverse - * asc or desc order - * @param page - * the page number - * @param maxResults - * the number of results per page - * @return a paginated list of managed object - */ - public abstract List getPaginateList(Class model, String sort, - boolean inverse, int page, int maxResults); - - /** - * Evict the object from the Persistente Context - * - * @see ApplicationDao#evict(Identifiable) - * @see Session#evict(Object) - * @param identifiable - */ - public void evict(Identifiable identifiable); -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.service; + +import it.cilea.osd.common.model.Identifiable; + +import java.io.Serializable; +import java.util.List; + +import org.hibernate.Session; + +/** + * Minimal interface that an applicationService should provide to provide access + * to the persistente layer + * + * @author cilea + * + */ +public interface IPersistenceService { + + /** + * Retrive a managed object from its primary key + * + * @param + * the entity class + * @param + * the primary key class + * @param modelClass + * the entity class + * @param pkey + * the primary key + * @return the managed object + */ + public abstract T get(Class modelClass, + PK pkey); + + /** + * Persist or update an object basing on the object persistent state + * + * @param + * the entity class + * @param modelClass + * the entity class + * @param transientObject + * the object to persist or update + */ + public abstract void saveOrUpdate( + Class modelClass, T transientObject); + + /** + * Merge a detached object with his persistent state + * + * @param + * the entity class + * @param oggetto + * the detached object + * @param classe + * the entity class + * @return a managed object + */ + public abstract T merge(T oggetto, Class classe); + + /** + * Attach a detached object to the persistent context + * + * @param + * the entity class + * @param oggetto + * the detached object + * @param classe + * the entity class + * @return a managed object + */ + public abstract T refresh(T oggetto, + Class classe); + + /** + * Remove a managed object from the persistence datasource + * + * @param model + * the entity class + * @param pkey + * the primary key + **/ + public abstract void delete(Class

model, + PK pkey); + + /** + * Count the objects of a specific type + * + * @param + * the entity class + * @param classe + * the entity class + * @return the number of object of the requested type + */ + public abstract long count(Class classe); + + /** + * Check for existence of an object with the supplied primary key and type + * + * @param model + * the entity class + * @param id + * the primary key + * @return true if the object exists + * + */ + public abstract boolean exist(Class model, PK id); + + /** + * Return the list of objects of a specific type + * + * @param + * the entity class + * @param model + * the entity class + * @return the list of object of the requested class + */ + public abstract List getList(Class model); + + /** + * Return a paginated list of managed object + * + * @param + * the entity class + * @param model + * the entity class + * @param sort + * the sort criteria + * @param inverse + * asc or desc order + * @param page + * the page number + * @param maxResults + * the number of results per page + * @return a paginated list of managed object + */ + public abstract List getPaginateList(Class model, String sort, + boolean inverse, int page, int maxResults); + + /** + * Evict the object from the Persistente Context + * + * @see ApplicationDao#evict(Identifiable) + * @see Session#evict(Object) + * @param identifiable + */ + public void evict(Identifiable identifiable); +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/service/PersistenceService.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/service/PersistenceService.java index aaf75c7..32bc2c3 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/service/PersistenceService.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/service/PersistenceService.java @@ -1,343 +1,366 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.service; - -import it.cilea.osd.common.core.HasTimeStampInfo; -import it.cilea.osd.common.core.ITimeStampInfo; -import it.cilea.osd.common.core.SingleTimeStampInfo; -import it.cilea.osd.common.core.TimeStampInfo; -import it.cilea.osd.common.dao.GenericDao; -import it.cilea.osd.common.dao.PaginableObjectDao; -import it.cilea.osd.common.listener.NativePostDeleteEventListener; -import it.cilea.osd.common.listener.NativePostUpdateEventListener; -import it.cilea.osd.common.listener.NativePreInsertEventListener; -import it.cilea.osd.common.listener.NativePreUpdateEventListener; -import it.cilea.osd.common.model.Identifiable; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * A {@link IPersistenceService} implementations based on the {@link GenericDao} - * framework - * - * @author cilea - * - */ -public abstract class PersistenceService implements IPersistenceService -{ - /** - * A map of generic dao. The key is the canonical name of the model class - * that the dao manage - */ - private Map modelDaos; - - /** - * log4j category - */ - protected final Log log = LogFactory.getLog(getClass()); - - private List listenerOnPostDelete; - - private List listenerOnPostUpdate; - - private List listenerOnPreInsert; - - private List listenerOnPreUpdate; - - public List getListenerOnPostDelete() - { - if (this.listenerOnPostDelete == null) - { - this.listenerOnPostDelete = new ArrayList(); - } - return listenerOnPostDelete; - } - - public void setListenerOnPostDelete( - List listenerOnPostDelete) - { - this.listenerOnPostDelete = listenerOnPostDelete; - } - - public List getListenerOnPostUpdate() - { - if (this.listenerOnPostUpdate == null) - { - this.listenerOnPostUpdate = new ArrayList(); - } - return listenerOnPostUpdate; - } - - public void setListenerOnPostUpdate( - List listenerOnPostUpdate) - { - this.listenerOnPostUpdate = listenerOnPostUpdate; - } - - /** - * Add timestamp information (creation, last update) to the object if it - * supports them - * - * @param - * the Entity class - * @param modelClass - * the Entity class - * @param transientObject - * the transient object - * @return true for creation operation, false for update operation - */ - protected Boolean recordTimeStampInfo( - Class modelClass, T transientObject) - { - if (transientObject instanceof HasTimeStampInfo) - { - log.debug("Added record TimeStampInfo: modelClass: " - + modelClass.getName() + " id: " + transientObject.getId()); - HasTimeStampInfo hrt = (HasTimeStampInfo) transientObject; - ITimeStampInfo rt = hrt.getTimeStampInfo(); - if (rt == null) - { - rt = new TimeStampInfo(); - } - if (rt.getTimestampCreated() == null) - { - rt.setInfoCreated(getCurrentTimeStampInfo()); - return true; - } - else - { - rt.setInfoLastModified(getCurrentTimeStampInfo()); - return false; - } - } - return null; - } - - /** - * Build a new {@link SingleTimeStampInfo} using the current date - * - * @return a new {@link SingleTimeStampInfo} using the current date - */ - protected SingleTimeStampInfo getCurrentTimeStampInfo() - { - return new SingleTimeStampInfo(new Date()); - } - - /** - * {@inheritDoc} - */ - public T get(Class modelClass, PK pkey) - { - GenericDao modelDao = modelDaos.get(modelClass.getName()); - log.debug("modelClass:" + modelClass); - log.debug("dao:" + modelDao); - return modelDao.read(pkey); - } - - - /** - * {@inheritDoc} - */ - public void saveOrUpdate(Class modelClass, - T transientObject) - { - saveOrUpdate(modelClass, transientObject, true); - } - - - public void saveOrUpdate(Class modelClass, - T transientObject, boolean listenerEnable) - { - final String modelClassName = modelClass.getName(); - - log.debug("saveOrUpdate: " + modelClassName + " id: " - + transientObject.getId()); - GenericDao modelDao = modelDaos.get(modelClassName); - if (listenerEnable) { - if (transientObject.getId() == null) { - for (NativePreInsertEventListener insert : getListenerOnPreInsert()) { - insert.onPreInsert(transientObject); - } - } else { - for (NativePreUpdateEventListener update : getListenerOnPreUpdate()) { - update.onPreUpdate(transientObject); - } - } - } - Boolean creation = recordTimeStampInfo(modelClass, transientObject); - modelDao.saveOrUpdate(transientObject); - if (listenerEnable) { - for (NativePostUpdateEventListener update : getListenerOnPostUpdate()) { - update.onPostUpdate(transientObject); - } - } - log.debug("after saveOrUpdate id: " + transientObject.getId()); - } - - /** - * {@inheritDoc} - */ - public T merge(T oggetto, Class classe) - { - log.debug("merge: " + classe.getName() + " -id: " + oggetto.getId()); - recordTimeStampInfo(classe, oggetto); - T result = getDaoByModel(classe).merge(oggetto); - log.debug("after merger id: " + oggetto.getId()); - return result; - } - - /** - * {@inheritDoc} - */ - public T refresh(T oggetto, Class classe) - { - return getDaoByModel(classe).merge(oggetto); - } - - /** - * {@inheritDoc} - */ - public void delete(Class

model, PK pkey) - { - GenericDao modelDao = modelDaos.get(model.getName()); - P toDeleteObject = modelDao.read(pkey); - modelDao.delete(toDeleteObject); - for (NativePostDeleteEventListener delete : getListenerOnPostDelete()) - { - delete.onPostDelete(toDeleteObject); - } - } - - /** - * Setter method. - * - * @param modelDaos - * A map of generic dao. The key is the canonical name of the - * model class that the dao manage - */ - public void setModelDaos(Map modelDaos) - { - log.debug("injection on PersistenceService"); - this.modelDaos = modelDaos; - } - - /** - * Return the {@link GenericDao} instance suitable for the request model - * class - * - * @param - * the Entity class - * @param model - * the Entity class - * @return the {@link GenericDao} instance suitable for the request model - * class - */ - protected GenericDao getDaoByModel(Class model) - { - String nome = model.getName(); - log.debug("CHIAMATO getDaoByModel " + nome); - return modelDaos.get(nome); - } - - /** - * {@inheritDoc} - */ - public boolean exist(Class model, PK id) - { - GenericDao modelDao = getDaoByModel(model); - if (modelDao.read(id) != null) - { - return true; - } - return false; - } - - /** - * {@inheritDoc} - */ - public List getList(Class model) - { - PaginableObjectDao modelDao = (PaginableObjectDao) getDaoByModel(model); - List modelList = modelDao.findAll(); - return modelList; - } - - /** - * {@inheritDoc} - */ - public List getPaginateList(Class model, String sort, - boolean inverse, int page, int maxResults) - { - PaginableObjectDao modelDao = (PaginableObjectDao) getDaoByModel(model); - List modelList = modelDao.paginate(sort, inverse, (page - 1) - * maxResults, maxResults); - return modelList; - } - - /** - * {@inheritDoc} - */ - public long count(Class classe) - { - return ((PaginableObjectDao) getDaoByModel(classe)).count(); - } - - public List getListenerOnPreInsert() - { - if (this.listenerOnPreInsert == null) - { - this.listenerOnPreInsert = new ArrayList(); - } - return listenerOnPreInsert; - } - - public void setListenerOnPreInsert( - List listenerOnPreInsert) - { - this.listenerOnPreInsert = listenerOnPreInsert; - } - - public List getListenerOnPreUpdate() - { - if (this.listenerOnPreUpdate == null) - { - this.listenerOnPreUpdate = new ArrayList(); - } - return listenerOnPreUpdate; - } - - public void setListenerOnPreUpdate( - List listenerOnPreUpdate) - { - this.listenerOnPreUpdate = listenerOnPreUpdate; - } -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.service; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import it.cilea.osd.common.core.HasTimeStampInfo; +import it.cilea.osd.common.core.ITimeStampInfo; +import it.cilea.osd.common.core.SingleTimeStampInfo; +import it.cilea.osd.common.core.TimeStampInfo; +import it.cilea.osd.common.dao.GenericDao; +import it.cilea.osd.common.dao.PaginableObjectDao; +import it.cilea.osd.common.listener.NativeLoadEventListener; +import it.cilea.osd.common.listener.NativePostDeleteEventListener; +import it.cilea.osd.common.listener.NativePostUpdateEventListener; +import it.cilea.osd.common.listener.NativePreInsertEventListener; +import it.cilea.osd.common.listener.NativePreUpdateEventListener; +import it.cilea.osd.common.model.Identifiable; + +/** + * A {@link IPersistenceService} implementations based on the {@link GenericDao} + * framework + * + * @author cilea + * + */ +public abstract class PersistenceService implements IPersistenceService +{ + /** + * A map of generic dao. The key is the canonical name of the model class + * that the dao manage + */ + private Map modelDaos; + + /** + * log4j category + */ + protected final Log log = LogFactory.getLog(getClass()); + + private List listenerOnPostDelete; + + private List listenerOnPostUpdate; + + private List listenerOnPreInsert; + + private List listenerOnPreUpdate; + + private List listenerOnLoad; + + public List getListenerOnLoad() + { + if (this.listenerOnLoad == null) + { + this.listenerOnLoad = new ArrayList(); + } + return listenerOnLoad; + } + + public void setListenerOnLoad(List listenerOnLoad) + { + this.listenerOnLoad = listenerOnLoad; + } + + public List getListenerOnPostDelete() + { + if (this.listenerOnPostDelete == null) + { + this.listenerOnPostDelete = new ArrayList(); + } + return listenerOnPostDelete; + } + + public void setListenerOnPostDelete( + List listenerOnPostDelete) + { + this.listenerOnPostDelete = listenerOnPostDelete; + } + + public List getListenerOnPostUpdate() + { + if (this.listenerOnPostUpdate == null) + { + this.listenerOnPostUpdate = new ArrayList(); + } + return listenerOnPostUpdate; + } + + public void setListenerOnPostUpdate( + List listenerOnPostUpdate) + { + this.listenerOnPostUpdate = listenerOnPostUpdate; + } + + /** + * Add timestamp information (creation, last update) to the object if it + * supports them + * + * @param + * the Entity class + * @param modelClass + * the Entity class + * @param transientObject + * the transient object + * @return true for creation operation, false for update operation + */ + protected Boolean recordTimeStampInfo( + Class modelClass, T transientObject) + { + if (transientObject instanceof HasTimeStampInfo) + { + log.debug("Added record TimeStampInfo: modelClass: " + + modelClass.getName() + " id: " + transientObject.getId()); + HasTimeStampInfo hrt = (HasTimeStampInfo) transientObject; + ITimeStampInfo rt = hrt.getTimeStampInfo(); + if (rt == null) + { + rt = new TimeStampInfo(); + } + if (rt.getTimestampCreated() == null) + { + rt.setInfoCreated(getCurrentTimeStampInfo()); + return true; + } + else + { + rt.setInfoLastModified(getCurrentTimeStampInfo()); + return false; + } + } + return null; + } + + /** + * Build a new {@link SingleTimeStampInfo} using the current date + * + * @return a new {@link SingleTimeStampInfo} using the current date + */ + protected SingleTimeStampInfo getCurrentTimeStampInfo() + { + return new SingleTimeStampInfo(new Date()); + } + + /** + * {@inheritDoc} + */ + public T get(Class modelClass, PK pkey) + { + GenericDao modelDao = modelDaos.get(modelClass.getName()); + log.debug("modelClass:" + modelClass); + log.debug("dao:" + modelDao); + T result = modelDao.read(pkey); + if(result != null) { + for (NativeLoadEventListener update : getListenerOnLoad()) { + update.onLoad(result); + } + } + return result; + } + + + /** + * {@inheritDoc} + */ + public void saveOrUpdate(Class modelClass, + T transientObject) + { + saveOrUpdate(modelClass, transientObject, true); + } + + + public void saveOrUpdate(Class modelClass, + T transientObject, boolean listenerEnable) + { + final String modelClassName = modelClass.getName(); + + log.debug("saveOrUpdate: " + modelClassName + " id: " + + transientObject.getId()); + GenericDao modelDao = modelDaos.get(modelClassName); + if (listenerEnable) { + if (transientObject.getId() == null) { + for (NativePreInsertEventListener insert : getListenerOnPreInsert()) { + insert.onPreInsert(transientObject); + } + } else { + for (NativePreUpdateEventListener update : getListenerOnPreUpdate()) { + update.onPreUpdate(transientObject); + } + } + } + Boolean creation = recordTimeStampInfo(modelClass, transientObject); + modelDao.saveOrUpdate(transientObject); + if (listenerEnable) { + for (NativePostUpdateEventListener update : getListenerOnPostUpdate()) { + update.onPostUpdate(transientObject); + } + } + log.debug("after saveOrUpdate id: " + transientObject.getId()); + } + + /** + * {@inheritDoc} + */ + public T merge(T oggetto, Class classe) + { + log.debug("merge: " + classe.getName() + " -id: " + oggetto.getId()); + recordTimeStampInfo(classe, oggetto); + T result = getDaoByModel(classe).merge(oggetto); + log.debug("after merger id: " + oggetto.getId()); + return result; + } + + /** + * {@inheritDoc} + */ + public T refresh(T oggetto, Class classe) + { + return getDaoByModel(classe).merge(oggetto); + } + + /** + * {@inheritDoc} + */ + public void delete(Class

model, PK pkey) + { + GenericDao modelDao = modelDaos.get(model.getName()); + P toDeleteObject = modelDao.read(pkey); + modelDao.delete(toDeleteObject); + for (NativePostDeleteEventListener delete : getListenerOnPostDelete()) + { + delete.onPostDelete(toDeleteObject); + } + } + + /** + * Setter method. + * + * @param modelDaos + * A map of generic dao. The key is the canonical name of the + * model class that the dao manage + */ + public void setModelDaos(Map modelDaos) + { + log.debug("injection on PersistenceService"); + this.modelDaos = modelDaos; + } + + /** + * Return the {@link GenericDao} instance suitable for the request model + * class + * + * @param + * the Entity class + * @param model + * the Entity class + * @return the {@link GenericDao} instance suitable for the request model + * class + */ + protected GenericDao getDaoByModel(Class model) + { + String nome = model.getName(); + log.debug("CHIAMATO getDaoByModel " + nome); + return modelDaos.get(nome); + } + + /** + * {@inheritDoc} + */ + public boolean exist(Class model, PK id) + { + GenericDao modelDao = getDaoByModel(model); + if (modelDao.read(id) != null) + { + return true; + } + return false; + } + + /** + * {@inheritDoc} + */ + public List getList(Class model) + { + PaginableObjectDao modelDao = (PaginableObjectDao) getDaoByModel(model); + List modelList = modelDao.findAll(); + return modelList; + } + + /** + * {@inheritDoc} + */ + public List getPaginateList(Class model, String sort, + boolean inverse, int page, int maxResults) + { + PaginableObjectDao modelDao = (PaginableObjectDao) getDaoByModel(model); + List modelList = modelDao.paginate(sort, inverse, (page - 1) + * maxResults, maxResults); + return modelList; + } + + /** + * {@inheritDoc} + */ + public long count(Class classe) + { + return ((PaginableObjectDao) getDaoByModel(classe)).count(); + } + + public List getListenerOnPreInsert() + { + if (this.listenerOnPreInsert == null) + { + this.listenerOnPreInsert = new ArrayList(); + } + return listenerOnPreInsert; + } + + public void setListenerOnPreInsert( + List listenerOnPreInsert) + { + this.listenerOnPreInsert = listenerOnPreInsert; + } + + public List getListenerOnPreUpdate() + { + if (this.listenerOnPreUpdate == null) + { + this.listenerOnPreUpdate = new ArrayList(); + } + return listenerOnPreUpdate; + } + + public void setListenerOnPreUpdate( + List listenerOnPreUpdate) + { + this.listenerOnPreUpdate = listenerOnPreUpdate; + } +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/util/CustomDateTimeEditor.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/util/CustomDateTimeEditor.java index 570e046..aceb1e1 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/util/CustomDateTimeEditor.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/util/CustomDateTimeEditor.java @@ -1,46 +1,46 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.util; - -import java.text.DateFormat; - -import org.springframework.beans.propertyeditors.CustomDateEditor; - -public class CustomDateTimeEditor extends CustomDateEditor { - - public CustomDateTimeEditor(DateFormat dateFormat, boolean allowEmpty, - int exactDateLength) { - super(dateFormat, allowEmpty, exactDateLength); - } - - @Override - public void setAsText(String text) throws IllegalArgumentException { - if (text.length() == 10) { - text += " 00:00"; - } - super.setAsText(text); - } - -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.util; + +import java.text.DateFormat; + +import org.springframework.beans.propertyeditors.CustomDateEditor; + +public class CustomDateTimeEditor extends CustomDateEditor { + + public CustomDateTimeEditor(DateFormat dateFormat, boolean allowEmpty, + int exactDateLength) { + super(dateFormat, allowEmpty, exactDateLength); + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + if (text.length() == 10) { + text += " 00:00"; + } + super.setAsText(text); + } + +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/util/Utils.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/util/Utils.java index 19e7269..c6b101d 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/util/Utils.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/util/Utils.java @@ -1,98 +1,98 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.util; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * Utility class - * - * @author pascarelli - * - */ -public class Utils { - - /** - * Compare two objects according to Collection semantics. - * - * @param o1 - * the first object - * @param o2 - * the second object - * @return o1 == o2 || (o1 != null && o1.equals(o2)) - */ - public static final boolean equals(Object o1, Object o2) { - return o1 == o2 || (o1 != null && o1.equals(o2)); - } - - /** - * - * Copy stream source to output destination in buffered mode, finally flush output stream. - * - * @param source input stream - * @param destination output stream - * @throws IOException - */ - public static void bufferedCopy(final InputStream source, - final OutputStream destination) throws IOException { - final BufferedInputStream input = new BufferedInputStream(source); - final BufferedOutputStream output = new BufferedOutputStream( - destination); - copy(input, output); - output.flush(); - } - - /** - * Copy stream source - * - * @param input - * @param output - * @throws IOException - */ - public static void copy(final InputStream input, final OutputStream output) - throws IOException { - final int BUFFER_SIZE = 1024 * 4; - final byte[] buffer = new byte[BUFFER_SIZE]; - - while (true) { - final int count = input.read(buffer, 0, BUFFER_SIZE); - - if (-1 == count) { - break; - } - - // write out those same bytes - output.write(buffer, 0, count); - } - - // needed to flush cache - // output.flush(); - } - -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.util; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * Utility class + * + * @author pascarelli + * + */ +public class Utils { + + /** + * Compare two objects according to Collection semantics. + * + * @param o1 + * the first object + * @param o2 + * the second object + * @return o1 == o2 || (o1 != null && o1.equals(o2)) + */ + public static final boolean equals(Object o1, Object o2) { + return o1 == o2 || (o1 != null && o1.equals(o2)); + } + + /** + * + * Copy stream source to output destination in buffered mode, finally flush output stream. + * + * @param source input stream + * @param destination output stream + * @throws IOException + */ + public static void bufferedCopy(final InputStream source, + final OutputStream destination) throws IOException { + final BufferedInputStream input = new BufferedInputStream(source); + final BufferedOutputStream output = new BufferedOutputStream( + destination); + copy(input, output); + output.flush(); + } + + /** + * Copy stream source + * + * @param input + * @param output + * @throws IOException + */ + public static void copy(final InputStream input, final OutputStream output) + throws IOException { + final int BUFFER_SIZE = 1024 * 4; + final byte[] buffer = new byte[BUFFER_SIZE]; + + while (true) { + final int count = input.read(buffer, 0, BUFFER_SIZE); + + if (-1 == count) { + break; + } + + // write out those same bytes + output.write(buffer, 0, count); + } + + // needed to flush cache + // output.flush(); + } + +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/utils/ClasspathEntityResolver.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/utils/ClasspathEntityResolver.java index 3478177..84cc9f3 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/utils/ClasspathEntityResolver.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/utils/ClasspathEntityResolver.java @@ -1,63 +1,63 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.utils; - -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.IOException; - -import org.xml.sax.SAXException; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; - -public class ClasspathEntityResolver implements EntityResolver { - - public InputSource resolveEntity(String publicId, String systemId) - throws SAXException, IOException { - - InputSource inputSource = null; - - if (systemId.startsWith("classpath://")) - { - try { - InputStream inputStream = - ClassLoader.getSystemResourceAsStream( - systemId.replaceFirst("classpath://", "")); - if (inputStream == null) - { - throw new FileNotFoundException(); - } - inputSource = new InputSource(inputStream); - return inputSource; - } catch (Exception e) { - // No action; just let the null InputSource pass through - throw new SAXException("The entity "+publicId + " " + systemId +" was not found in the classpath"); - } - } - else - // null is returned, for normal processing - return inputSource; - } -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.utils; + +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.IOException; + +import org.xml.sax.SAXException; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; + +public class ClasspathEntityResolver implements EntityResolver { + + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { + + InputSource inputSource = null; + + if (systemId.startsWith("classpath://")) + { + try { + InputStream inputStream = + ClassLoader.getSystemResourceAsStream( + systemId.replaceFirst("classpath://", "")); + if (inputStream == null) + { + throw new FileNotFoundException(); + } + inputSource = new InputSource(inputStream); + return inputSource; + } catch (Exception e) { + // No action; just let the null InputSource pass through + throw new SAXException("The entity "+publicId + " " + systemId +" was not found in the classpath"); + } + } + else + // null is returned, for normal processing + return inputSource; + } +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/utils/StringUtils.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/utils/StringUtils.java index 24b420f..fa57da0 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/utils/StringUtils.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/utils/StringUtils.java @@ -1,68 +1,68 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.utils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -public class StringUtils -{ - public static String convertStreamToString(InputStream is, String encoding) - throws IOException - { - /* - * To convert the InputStream to String we use the - * BufferedReader.readLine() method. We iterate until the BufferedReader - * return null which means there's no more data to read. Each line will - * appended to a StringBuilder and returned as String. - */ - if (is != null) - { - StringBuilder sb = new StringBuilder(); - String line; - - try - { - BufferedReader reader = new BufferedReader( - new InputStreamReader(is, encoding)); - while ((line = reader.readLine()) != null) - { - sb.append(line).append("\n"); - } - } - finally - { - is.close(); - } - return sb.toString(); - } - else - { - return ""; - } - } -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class StringUtils +{ + public static String convertStreamToString(InputStream is, String encoding) + throws IOException + { + /* + * To convert the InputStream to String we use the + * BufferedReader.readLine() method. We iterate until the BufferedReader + * return null which means there's no more data to read. Each line will + * appended to a StringBuilder and returned as String. + */ + if (is != null) + { + StringBuilder sb = new StringBuilder(); + String line; + + try + { + BufferedReader reader = new BufferedReader( + new InputStreamReader(is, encoding)); + while ((line = reader.readLine()) != null) + { + sb.append(line).append("\n"); + } + } + finally + { + is.close(); + } + return sb.toString(); + } + else + { + return ""; + } + } +} diff --git a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/utils/XMLUtils.java b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/utils/XMLUtils.java index 9c6316b..c1e2112 100644 --- a/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/utils/XMLUtils.java +++ b/commons-cilea-api/commons-cilea-genericdao/src/main/java/it/cilea/osd/common/utils/XMLUtils.java @@ -1,186 +1,186 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.utils; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import org.apache.commons.lang.StringUtils; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -public class XMLUtils -{ - - public static List getElementList(Element dataRoot, String name) - { - NodeList list = dataRoot.getElementsByTagName(name); - List listElements = new ArrayList(); - for (int i = 0; i < list.getLength(); i++) - { - listElements.add((Element) list.item(i)); - } - return listElements; - } - - public static String getElementAttribute(Element dataRoot, String name, - String attr) - { - NodeList nodeList = dataRoot.getElementsByTagName(name); - Element element = null; - if (nodeList != null && nodeList.getLength() > 0) - { - element = (Element) nodeList.item(0); - } - - String attrValue = null; - if (element != null) - { - attrValue = element.getAttribute(attr); - if (StringUtils.isNotBlank(attrValue)) - { - attrValue = attrValue.trim(); - } - else - attrValue = null; - } - return attrValue; - } - - public static String getElementValue(Element dataRoot, String name) - { - NodeList nodeList = dataRoot.getElementsByTagName(name); - Element element = null; - if (nodeList != null && nodeList.getLength() > 0) - { - element = (Element) nodeList.item(0); - } - String elementValue = null; - if (element != null) - { - elementValue = element.getTextContent(); - if (StringUtils.isNotBlank(elementValue)) - { - elementValue = elementValue.trim(); - } - else - elementValue = null; - } - return elementValue; - } - - /** - * Restituisce il primo sottoelemeto di xmlRoot trovato con il nome - * specificato - * - * @param xmlRoot - * l'elemento in cui cercare (NOT null) - * @param name - * il nome del sottoelemento da restituire - * @return il primo sottoelemento trovato o null se non presente - */ - public static Element getSingleElement(Element xmlRoot, String name) - { - NodeList nodeList = xmlRoot.getElementsByTagName(name); - Element element = null; - if (nodeList != null && nodeList.getLength() > 0) - { - element = (Element) nodeList.item(0); - } - return element; - } - - /** - * - * @param rootElement - * l'elemento in cui cercare - * @param subElementName - * il nome del sottoelemento di cui estrarre il valore - * @return una lista di stringhe contenente tutti i valori del sottoelemento - * cercato. Null se non sono presenti sottoelementi o l'elemento - * radice se null - */ - public static List getElementValueList( - Element rootElement, String subElementName) - { - if (rootElement == null) - return null; - - List subElements = getElementList(rootElement, subElementName); - if (subElements == null) - return null; - - List result = new LinkedList(); - for (Element el : subElements) - { - if (StringUtils.isNotBlank(el.getTextContent())) - { - result.add(el.getTextContent().trim()); - } - } - return result; - } - - /** - * root/subElement[]/field1, field2, fieldN - * - * @param rootElement - * l'elemnto radice - * @param subElementName - * il nome del sottoelemento di cui si vuole processare il - * contenuto - * @param fieldsName - * uno o piu' sotto-sotto-elementi xml di cui si vuole estrarre il - * valore testuale - * @return una lista di array di stringhe, la dimensione dell'array viene - * determinata dal numero di fields richiesti. Per ogni field viene - * inserita nella corrispondente posizione dell'array il valore - * testuale del primo soto-sotto-elemento xml trovato, null se non e' - * presente - */ - public static List getElementValueArrayList( - Element rootElement, String subElementName, String... fieldsName) - { - if (rootElement == null) - return null; - - List subElements = getElementList(rootElement, subElementName); - if (subElements == null) - return null; - - List result = new LinkedList(); - for (Element el : subElements) - { - String[] tmp = new String[fieldsName.length]; - for (int idx = 0; idx < fieldsName.length; idx++) - { - tmp[idx] = XMLUtils.getElementValue(el, fieldsName[idx]); - } - result.add(tmp); - } - return result; - } -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.utils; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class XMLUtils +{ + + public static List getElementList(Element dataRoot, String name) + { + NodeList list = dataRoot.getElementsByTagName(name); + List listElements = new ArrayList(); + for (int i = 0; i < list.getLength(); i++) + { + listElements.add((Element) list.item(i)); + } + return listElements; + } + + public static String getElementAttribute(Element dataRoot, String name, + String attr) + { + NodeList nodeList = dataRoot.getElementsByTagName(name); + Element element = null; + if (nodeList != null && nodeList.getLength() > 0) + { + element = (Element) nodeList.item(0); + } + + String attrValue = null; + if (element != null) + { + attrValue = element.getAttribute(attr); + if (StringUtils.isNotBlank(attrValue)) + { + attrValue = attrValue.trim(); + } + else + attrValue = null; + } + return attrValue; + } + + public static String getElementValue(Element dataRoot, String name) + { + NodeList nodeList = dataRoot.getElementsByTagName(name); + Element element = null; + if (nodeList != null && nodeList.getLength() > 0) + { + element = (Element) nodeList.item(0); + } + String elementValue = null; + if (element != null) + { + elementValue = element.getTextContent(); + if (StringUtils.isNotBlank(elementValue)) + { + elementValue = elementValue.trim(); + } + else + elementValue = null; + } + return elementValue; + } + + /** + * Restituisce il primo sottoelemeto di xmlRoot trovato con il nome + * specificato + * + * @param xmlRoot + * l'elemento in cui cercare (NOT null) + * @param name + * il nome del sottoelemento da restituire + * @return il primo sottoelemento trovato o null se non presente + */ + public static Element getSingleElement(Element xmlRoot, String name) + { + NodeList nodeList = xmlRoot.getElementsByTagName(name); + Element element = null; + if (nodeList != null && nodeList.getLength() > 0) + { + element = (Element) nodeList.item(0); + } + return element; + } + + /** + * + * @param rootElement + * l'elemento in cui cercare + * @param subElementName + * il nome del sottoelemento di cui estrarre il valore + * @return una lista di stringhe contenente tutti i valori del sottoelemento + * cercato. Null se non sono presenti sottoelementi o l'elemento + * radice se null + */ + public static List getElementValueList( + Element rootElement, String subElementName) + { + if (rootElement == null) + return null; + + List subElements = getElementList(rootElement, subElementName); + if (subElements == null) + return null; + + List result = new LinkedList(); + for (Element el : subElements) + { + if (StringUtils.isNotBlank(el.getTextContent())) + { + result.add(el.getTextContent().trim()); + } + } + return result; + } + + /** + * root/subElement[]/field1, field2, fieldN + * + * @param rootElement + * l'elemnto radice + * @param subElementName + * il nome del sottoelemento di cui si vuole processare il + * contenuto + * @param fieldsName + * uno o piu' sotto-sotto-elementi xml di cui si vuole estrarre il + * valore testuale + * @return una lista di array di stringhe, la dimensione dell'array viene + * determinata dal numero di fields richiesti. Per ogni field viene + * inserita nella corrispondente posizione dell'array il valore + * testuale del primo soto-sotto-elemento xml trovato, null se non e' + * presente + */ + public static List getElementValueArrayList( + Element rootElement, String subElementName, String... fieldsName) + { + if (rootElement == null) + return null; + + List subElements = getElementList(rootElement, subElementName); + if (subElements == null) + return null; + + List result = new LinkedList(); + for (Element el : subElements) + { + String[] tmp = new String[fieldsName.length]; + for (int idx = 0; idx < fieldsName.length; idx++) + { + tmp[idx] = XMLUtils.getElementValue(el, fieldsName[idx]); + } + result.add(tmp); + } + return result; + } +} diff --git a/commons-cilea-api/pom.xml b/commons-cilea-api/pom.xml index d9d4c68..5b1fa7a 100644 --- a/commons-cilea-api/pom.xml +++ b/commons-cilea-api/pom.xml @@ -1,15 +1,15 @@ - - 4.0.0 - - commons-cilea - it.cilea - 2.2-SNAPSHOT - - it.cilea - commons-cilea-api - pom - - - commons-cilea-genericdao - + + 4.0.0 + + commons-cilea + it.cilea + 2.6-SNAPSHOT + + it.cilea + commons-cilea-api + pom + + + commons-cilea-genericdao + \ No newline at end of file diff --git a/commons-cilea-webapi/pom.xml b/commons-cilea-webapi/pom.xml index ab9037f..4fbf720 100644 --- a/commons-cilea-webapi/pom.xml +++ b/commons-cilea-webapi/pom.xml @@ -1,114 +1,106 @@ - - 4.0.0 - - commons-cilea-webapi - it.cilea - - - commons-cilea - it.cilea - 2.2-SNAPSHOT - - - - - UTF-8 - 3.1.1.RELEASE - - - - - - displaytag - displaytag - - - - javax.servlet - servlet-api - - - - - org.hibernate - hibernate-entitymanager - - - - - commons-logging - commons-logging - - - - - commons-lang - commons-lang - - - - - spring-core - org.springframework - - - - - spring-beans - org.springframework - - - - - spring-aop - org.springframework - - - - - spring-context - org.springframework - - - - - spring-tx - org.springframework - - - - - spring-jdbc - org.springframework - - - - - spring-web - org.springframework - ${org.spring.version} - - - - spring-webmvc - org.springframework - ${org.spring.version} - - - - it.cilea - commons-cilea-genericdao - ${project.version} - - - - org.springframework - spring-webflow - 1.0.4 - - - - - - + + 4.0.0 + + commons-cilea-webapi + it.cilea + + + commons-cilea + it.cilea + 2.6-SNAPSHOT + + + + + UTF-8 + 3.2.16.RELEASE + + + + + + displaytag + displaytag + + + + javax.servlet + servlet-api + + + + commons-logging + commons-logging + + + + commons-lang + commons-lang + + + + + spring-core + org.springframework + + + + + spring-beans + org.springframework + + + + + spring-aop + org.springframework + + + + + spring-context + org.springframework + + + + + spring-tx + org.springframework + + + + + spring-jdbc + org.springframework + + + + + spring-web + org.springframework + ${org.spring.version} + + + + spring-webmvc + org.springframework + ${org.spring.version} + + + + it.cilea + commons-cilea-genericdao + ${project.version} + + + + org.springframework + spring-webflow + 1.0.4 + + + + + + \ No newline at end of file diff --git a/commons-cilea-webapi/src/META-INF/MANIFEST.MF b/commons-cilea-webapi/src/META-INF/MANIFEST.MF index 5e94951..254272e 100644 --- a/commons-cilea-webapi/src/META-INF/MANIFEST.MF +++ b/commons-cilea-webapi/src/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ -Manifest-Version: 1.0 -Class-Path: - +Manifest-Version: 1.0 +Class-Path: + diff --git a/commons-cilea-webapi/src/main/java/META-INF/MANIFEST.MF b/commons-cilea-webapi/src/main/java/META-INF/MANIFEST.MF index 5e94951..254272e 100644 --- a/commons-cilea-webapi/src/main/java/META-INF/MANIFEST.MF +++ b/commons-cilea-webapi/src/main/java/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ -Manifest-Version: 1.0 -Class-Path: - +Manifest-Version: 1.0 +Class-Path: + diff --git a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/constants/Constants.java b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/constants/Constants.java index 5f3c250..17eda25 100644 --- a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/constants/Constants.java +++ b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/constants/Constants.java @@ -1,38 +1,38 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.constants; - -public class Constants { - // ~ Static fields/initializers - // ============================================= - - /** The name of the ResourceBundle used in this application */ - public static final String BUNDLE_KEY = "ApplicationResources"; - - public static final String MESSAGES_KEY = "messages"; - - - -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.constants; + +public class Constants { + // ~ Static fields/initializers + // ============================================= + + /** The name of the ResourceBundle used in this application */ + public static final String BUNDLE_KEY = "ApplicationResources"; + + public static final String MESSAGES_KEY = "messages"; + + + +} diff --git a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/controller/BaseAbstractController.java b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/controller/BaseAbstractController.java index 9c8ce8a..4b8919b 100644 --- a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/controller/BaseAbstractController.java +++ b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/controller/BaseAbstractController.java @@ -1,158 +1,158 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.controller; - -import it.cilea.osd.common.constants.Constants; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.servlet.mvc.AbstractController; - -public abstract class BaseAbstractController extends AbstractController { - - protected Log log = LogFactory.getLog(getClass()); - - protected String method; - - private String detailsView; - - private String listView; - - private String errorView; - - public void setMethod(String method) { - this.method = method; - } - - public void saveMessage(HttpServletRequest request, String msg) { - List messages = (List) request.getSession().getAttribute( - Constants.MESSAGES_KEY); - - if (messages == null) { - messages = new ArrayList(); - } - - messages.add(msg); - request.getSession().setAttribute(Constants.MESSAGES_KEY, messages); - } - - public void removeLastMessage(HttpServletRequest request) { - List messages = (List) request.getSession().getAttribute( - Constants.MESSAGES_KEY); - - if (messages == null) { - messages = new ArrayList(); - } - if (!messages.isEmpty()) { - messages.remove(messages.size() - 1); - } - request.getSession().setAttribute(Constants.MESSAGES_KEY, messages); - } - - /** - * Convenient method for getting a default i18n key's value. - * - * @param msgKey - * - * @return - */ - public String getText(String msgKey) { - return getMessageSourceAccessor().getMessage(msgKey); - } - - /** - * Convenience method for getting a i18n key's value. Calling - * getMessageSourceAccessor() is used because the RequestContext variable is - * not set in unit tests b/c there's no DispatchServlet Request. - * - * @param msgKey - * @param locale - * the current locale - * @return - */ - public String getText(String msgKey, Locale locale) { - return getMessageSourceAccessor().getMessage(msgKey, locale); - } - - /** - * Convenient method for getting a i18n key's value with a single string - * argument. - * - * @param msgKey - * @param arg - * @param locale - * the current locale - * @return - */ - public String getText(String msgKey, String arg, Locale locale) { - return getText(msgKey, new Object[] { arg }, locale); - } - - /** - * Convenience method for getting a i18n key's value with arguments. - * - * @param msgKey - * @param args - * @param locale - * the current locale - * @return - */ - public String getText(String msgKey, Object[] args, Locale locale) { - return getMessageSourceAccessor().getMessage(msgKey, args, locale); - } - - public void setDetailsView(String detailsView) { - this.detailsView = detailsView; - } - - public void setListView(String listView) { - this.listView = listView; - } - - public String getErrorView() { - return errorView; - } - - public void setErrorView(String errorView) { - this.errorView = errorView; - } - - public String getDetailsView() - { - return detailsView; - } - - public String getListView() - { - return listView; - } - -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.controller; + +import it.cilea.osd.common.constants.Constants; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.web.servlet.mvc.AbstractController; + +public abstract class BaseAbstractController extends AbstractController { + + protected Log log = LogFactory.getLog(getClass()); + + protected String method; + + private String detailsView; + + private String listView; + + private String errorView; + + public void setMethod(String method) { + this.method = method; + } + + public void saveMessage(HttpServletRequest request, String msg) { + List messages = (List) request.getSession().getAttribute( + Constants.MESSAGES_KEY); + + if (messages == null) { + messages = new ArrayList(); + } + + messages.add(msg); + request.getSession().setAttribute(Constants.MESSAGES_KEY, messages); + } + + public void removeLastMessage(HttpServletRequest request) { + List messages = (List) request.getSession().getAttribute( + Constants.MESSAGES_KEY); + + if (messages == null) { + messages = new ArrayList(); + } + if (!messages.isEmpty()) { + messages.remove(messages.size() - 1); + } + request.getSession().setAttribute(Constants.MESSAGES_KEY, messages); + } + + /** + * Convenient method for getting a default i18n key's value. + * + * @param msgKey + * + * @return + */ + public String getText(String msgKey) { + return getMessageSourceAccessor().getMessage(msgKey); + } + + /** + * Convenience method for getting a i18n key's value. Calling + * getMessageSourceAccessor() is used because the RequestContext variable is + * not set in unit tests b/c there's no DispatchServlet Request. + * + * @param msgKey + * @param locale + * the current locale + * @return + */ + public String getText(String msgKey, Locale locale) { + return getMessageSourceAccessor().getMessage(msgKey, locale); + } + + /** + * Convenient method for getting a i18n key's value with a single string + * argument. + * + * @param msgKey + * @param arg + * @param locale + * the current locale + * @return + */ + public String getText(String msgKey, String arg, Locale locale) { + return getText(msgKey, new Object[] { arg }, locale); + } + + /** + * Convenience method for getting a i18n key's value with arguments. + * + * @param msgKey + * @param args + * @param locale + * the current locale + * @return + */ + public String getText(String msgKey, Object[] args, Locale locale) { + return getMessageSourceAccessor().getMessage(msgKey, args, locale); + } + + public void setDetailsView(String detailsView) { + this.detailsView = detailsView; + } + + public void setListView(String listView) { + this.listView = listView; + } + + public String getErrorView() { + return errorView; + } + + public void setErrorView(String errorView) { + this.errorView = errorView; + } + + public String getDetailsView() + { + return detailsView; + } + + public String getListView() + { + return listView; + } + +} diff --git a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/controller/BaseFormController.java b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/controller/BaseFormController.java index 5838942..d278cc3 100644 --- a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/controller/BaseFormController.java +++ b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/controller/BaseFormController.java @@ -1,164 +1,164 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.controller; - -import it.cilea.osd.common.constants.Constants; - -import java.beans.PropertyEditor; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.bind.ServletRequestDataBinder; -import org.springframework.web.servlet.mvc.SimpleFormController; - -/** - * Base form controller. - * - */ -public class BaseFormController extends SimpleFormController { - - protected Log log = LogFactory.getLog(getClass()); - - private Map customPropertyEditors; - - private String detailsView; - - private String listView; - - private String errorView; - - public BaseFormController() { - super(); - } - - public void setDetailsView(String detailsView) { - this.detailsView = detailsView; - } - - public void setListView(String listView) { - this.listView = listView; - } - - public void setErrorView(String errorView) { - this.errorView = errorView; - } - - - public void saveMessage(HttpServletRequest request, String msg) { - List messages = (List) request.getSession().getAttribute( - Constants.MESSAGES_KEY); - - if (messages == null) { - messages = new ArrayList(); - } - - messages.add(msg); - request.getSession().setAttribute(Constants.MESSAGES_KEY, messages); - } - - /** - * Convenience method for getting a i18n key's value. Calling - * getMessageSourceAccessor() is used because the RequestContext variable is - * not set in unit tests b/c there's no DispatchServlet Request. - * - * @param msgKey - * @param locale - * the current locale - * @return - */ - public String getText(String msgKey, Locale locale) { - return getMessageSourceAccessor().getMessage(msgKey, locale); - } - - /** - * Convenient method for getting a i18n key's value with a single string - * argument. - * - * @param msgKey - * @param arg - * @param locale - * the current locale - * @return - */ - public String getText(String msgKey, String arg, Locale locale) { - return getText(msgKey, new Object[] { arg }, locale); - } - - /** - * Convenience method for getting a i18n key's value with arguments. - * - * @param msgKey - * @param args - * @param locale - * the current locale - * @return - */ - public String getText(String msgKey, Object[] args, Locale locale) { - return getMessageSourceAccessor().getMessage(msgKey, args, locale); - } - - @Override - /** - * Registra i custom property editors come definiti nella mappa - * customPropertyEditors - */ - protected void initBinder(HttpServletRequest request, - ServletRequestDataBinder binder) { - if (customPropertyEditors != null) - { - for (Class propertyClass : customPropertyEditors.keySet()) { - log.debug("Register custom editor "+ customPropertyEditors.get(propertyClass).getClass() + " for the "+propertyClass); - binder.registerCustomEditor(propertyClass, customPropertyEditors - .get(propertyClass)); - } - } - } - - public void setCustomPropertyEditors( - Map customPropertyEditors) { - this.customPropertyEditors = customPropertyEditors; - } - - public String getDetailsView() - { - return detailsView; - } - - public String getListView() - { - return listView; - } - - public String getErrorView() - { - return errorView; - } -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.controller; + +import it.cilea.osd.common.constants.Constants; + +import java.beans.PropertyEditor; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.web.bind.ServletRequestDataBinder; +import org.springframework.web.servlet.mvc.SimpleFormController; + +/** + * Base form controller. + * + */ +public class BaseFormController extends SimpleFormController { + + protected Log log = LogFactory.getLog(getClass()); + + private Map customPropertyEditors; + + private String detailsView; + + private String listView; + + private String errorView; + + public BaseFormController() { + super(); + } + + public void setDetailsView(String detailsView) { + this.detailsView = detailsView; + } + + public void setListView(String listView) { + this.listView = listView; + } + + public void setErrorView(String errorView) { + this.errorView = errorView; + } + + + public void saveMessage(HttpServletRequest request, String msg) { + List messages = (List) request.getSession().getAttribute( + Constants.MESSAGES_KEY); + + if (messages == null) { + messages = new ArrayList(); + } + + messages.add(msg); + request.getSession().setAttribute(Constants.MESSAGES_KEY, messages); + } + + /** + * Convenience method for getting a i18n key's value. Calling + * getMessageSourceAccessor() is used because the RequestContext variable is + * not set in unit tests b/c there's no DispatchServlet Request. + * + * @param msgKey + * @param locale + * the current locale + * @return + */ + public String getText(String msgKey, Locale locale) { + return getMessageSourceAccessor().getMessage(msgKey, locale); + } + + /** + * Convenient method for getting a i18n key's value with a single string + * argument. + * + * @param msgKey + * @param arg + * @param locale + * the current locale + * @return + */ + public String getText(String msgKey, String arg, Locale locale) { + return getText(msgKey, new Object[] { arg }, locale); + } + + /** + * Convenience method for getting a i18n key's value with arguments. + * + * @param msgKey + * @param args + * @param locale + * the current locale + * @return + */ + public String getText(String msgKey, Object[] args, Locale locale) { + return getMessageSourceAccessor().getMessage(msgKey, args, locale); + } + + @Override + /** + * Registra i custom property editors come definiti nella mappa + * customPropertyEditors + */ + protected void initBinder(HttpServletRequest request, + ServletRequestDataBinder binder) { + if (customPropertyEditors != null) + { + for (Class propertyClass : customPropertyEditors.keySet()) { + log.debug("Register custom editor "+ customPropertyEditors.get(propertyClass).getClass() + " for the "+propertyClass); + binder.registerCustomEditor(propertyClass, customPropertyEditors + .get(propertyClass)); + } + } + } + + public void setCustomPropertyEditors( + Map customPropertyEditors) { + this.customPropertyEditors = customPropertyEditors; + } + + public String getDetailsView() + { + return detailsView; + } + + public String getListView() + { + return listView; + } + + public String getErrorView() + { + return errorView; + } +} diff --git a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/controller/SimpleController.java b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/controller/SimpleController.java index f5f390f..e71b320 100644 --- a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/controller/SimpleController.java +++ b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/controller/SimpleController.java @@ -1,106 +1,106 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.controller; - -import it.cilea.osd.common.service.IPersistenceService; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.servlet.ModelAndView; - -public class SimpleController extends BaseAbstractController { - - public SimpleController(Class objectClass) { - this.objectClass = objectClass; - } - - - protected IPersistenceService applicationService; - protected Class objectClass; - private String i18nPrefix = "action"; - - public void setI18nPrefix(String prefix) { - i18nPrefix = prefix; - } - - public void setApplicationService(IPersistenceService applicationService) { - this.applicationService = applicationService; - } - - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, - HttpServletResponse response) throws Exception { - ModelAndView retValue = null; - if ("details".equals(method)) - retValue = handleDetails(request); - else if ("list".equals(method)) - retValue = handleList(request); - else if ("delete".equals(method)) - retValue = handleDelete(request); - return retValue; - } - - protected ModelAndView handleDetails(HttpServletRequest request) throws InstantiationException, IllegalAccessException, ClassNotFoundException { - Map model = new HashMap(); - String paramId = request.getParameter("id"); - Integer objectId = Integer.valueOf(paramId); - - model.put("domainObject", applicationService.get(objectClass, objectId)); - return new ModelAndView(getDetailsView(),model); - } - - protected ModelAndView handleList(HttpServletRequest request) { - Map model = new HashMap(); - - List list = applicationService.getList(objectClass); - model.put("objectList", list); - return new ModelAndView(getListView(), model); - } - - private ModelAndView handleDelete(HttpServletRequest request) { - Map model = new HashMap(); - String paramId = request.getParameter("id"); - Integer id = Integer.valueOf(paramId); - - - try { - applicationService.delete(objectClass, id); - saveMessage(request, getText(i18nPrefix + ".deleted", request - .getLocale())); - } - catch (Exception e) { - saveMessage(request, getText(i18nPrefix + ".notdeleted", request - .getLocale())); - - return new ModelAndView(getErrorView(), model); - } - return new ModelAndView(getListView(), model); - } -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.controller; + +import it.cilea.osd.common.service.IPersistenceService; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.web.servlet.ModelAndView; + +public class SimpleController extends BaseAbstractController { + + public SimpleController(Class objectClass) { + this.objectClass = objectClass; + } + + + protected IPersistenceService applicationService; + protected Class objectClass; + private String i18nPrefix = "action"; + + public void setI18nPrefix(String prefix) { + i18nPrefix = prefix; + } + + public void setApplicationService(IPersistenceService applicationService) { + this.applicationService = applicationService; + } + + @Override + protected ModelAndView handleRequestInternal(HttpServletRequest request, + HttpServletResponse response) throws Exception { + ModelAndView retValue = null; + if ("details".equals(method)) + retValue = handleDetails(request); + else if ("list".equals(method)) + retValue = handleList(request); + else if ("delete".equals(method)) + retValue = handleDelete(request); + return retValue; + } + + protected ModelAndView handleDetails(HttpServletRequest request) throws InstantiationException, IllegalAccessException, ClassNotFoundException { + Map model = new HashMap(); + String paramId = request.getParameter("id"); + Integer objectId = Integer.valueOf(paramId); + + model.put("domainObject", applicationService.get(objectClass, objectId)); + return new ModelAndView(getDetailsView(),model); + } + + protected ModelAndView handleList(HttpServletRequest request) { + Map model = new HashMap(); + + List list = applicationService.getList(objectClass); + model.put("objectList", list); + return new ModelAndView(getListView(), model); + } + + private ModelAndView handleDelete(HttpServletRequest request) { + Map model = new HashMap(); + String paramId = request.getParameter("id"); + Integer id = Integer.valueOf(paramId); + + + try { + applicationService.delete(objectClass, id); + saveMessage(request, getText(i18nPrefix + ".deleted", request + .getLocale())); + } + catch (Exception e) { + saveMessage(request, getText(i18nPrefix + ".notdeleted", request + .getLocale())); + + return new ModelAndView(getErrorView(), model); + } + return new ModelAndView(getListView(), model); + } +} diff --git a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/util/displaytag/DisplayTagData.java b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/util/displaytag/DisplayTagData.java index c995fd7..afb03c5 100644 --- a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/util/displaytag/DisplayTagData.java +++ b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/util/displaytag/DisplayTagData.java @@ -1,125 +1,125 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.util.displaytag; - -import java.io.Serializable; -import java.util.Collections; -import java.util.List; - -import org.displaytag.pagination.PaginatedList; -import org.displaytag.properties.SortOrderEnum; - -public class DisplayTagData implements PaginatedList, Serializable { - - private long totalCount; - - private List pageItems; - - private int pageSize; - - private int page; - - private String sort; - - private String dir; - - public DisplayTagData() { - this(0, Collections.EMPTY_LIST, "id", "asc", 1, 10); - } - - public DisplayTagData(long count, List pageItems, String sort, String dir, - int page, int pageSize) { - this.totalCount = count; - this.pageItems = pageItems; - this.sort = sort; - this.dir = dir; - this.page = page; - this.pageSize = pageSize; - } - - public int getPage() { - return page; - } - - public void setPage(int page) { - this.page = page; - } - - public String getSort() { - return sort; - } - - public void setSort(String sort) { - this.sort = sort; - } - - public String getDir() { - return dir; - } - - public void setDir(String dir) { - this.dir = dir; - } - - public void setPageItems(List pageItems) { - this.pageItems = pageItems; - } - - public void setTotalCount(int totalCount) { - this.totalCount = totalCount; - } - - // PaginatedList - - public int getFullListSize() { - return new Long(totalCount).intValue(); - } - - public List getList() { - return pageItems; - } - - public int getObjectsPerPage() { - return pageSize; - } - - public int getPageNumber() { - return page; - } - - public String getSearchId() { - return null; - } - - public String getSortCriterion() { - return sort; - } - - public SortOrderEnum getSortDirection() { - return "asc".equals(dir) ? SortOrderEnum.ASCENDING : ("desc" - .equals(dir) ? SortOrderEnum.DESCENDING : null); - } - -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.util.displaytag; + +import java.io.Serializable; +import java.util.Collections; +import java.util.List; + +import org.displaytag.pagination.PaginatedList; +import org.displaytag.properties.SortOrderEnum; + +public class DisplayTagData implements PaginatedList, Serializable { + + private long totalCount; + + private List pageItems; + + private int pageSize; + + private int page; + + private String sort; + + private String dir; + + public DisplayTagData() { + this(0, Collections.EMPTY_LIST, "id", "asc", 1, 10); + } + + public DisplayTagData(long count, List pageItems, String sort, String dir, + int page, int pageSize) { + this.totalCount = count; + this.pageItems = pageItems; + this.sort = sort; + this.dir = dir; + this.page = page; + this.pageSize = pageSize; + } + + public int getPage() { + return page; + } + + public void setPage(int page) { + this.page = page; + } + + public String getSort() { + return sort; + } + + public void setSort(String sort) { + this.sort = sort; + } + + public String getDir() { + return dir; + } + + public void setDir(String dir) { + this.dir = dir; + } + + public void setPageItems(List pageItems) { + this.pageItems = pageItems; + } + + public void setTotalCount(int totalCount) { + this.totalCount = totalCount; + } + + // PaginatedList + + public int getFullListSize() { + return new Long(totalCount).intValue(); + } + + public List getList() { + return pageItems; + } + + public int getObjectsPerPage() { + return pageSize; + } + + public int getPageNumber() { + return page; + } + + public String getSearchId() { + return null; + } + + public String getSortCriterion() { + return sort; + } + + public SortOrderEnum getSortDirection() { + return "asc".equals(dir) ? SortOrderEnum.ASCENDING : ("desc" + .equals(dir) ? SortOrderEnum.DESCENDING : null); + } + +} diff --git a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/validation/BaseValidator.java b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/validation/BaseValidator.java index 1a20312..f07fbdb 100644 --- a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/validation/BaseValidator.java +++ b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/validation/BaseValidator.java @@ -1,96 +1,96 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.validation; - -import it.cilea.osd.common.constants.Constants; -import it.cilea.osd.common.model.BaseObject; - -import java.util.ResourceBundle; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.Errors; -import org.springframework.validation.FieldError; -import org.springframework.validation.Validator; - -public abstract class BaseValidator implements Validator -{ - private static Log log = LogFactory.getLog(BaseValidator.class); - - private Class clazz; - - public boolean supports(Class clazz) - { - return BaseObject.class.isAssignableFrom(clazz); - } - - /** - * Get the FieldError validation message from the underlying MessageSource - * for the given fieldName. - * - * @param errors - * The validation errors. - * @param fieldName - * The fieldName to retrieve the error message from. - * @return The validation message or an empty String. - */ - protected String getValidationMessage(Errors errors, String fieldName) - { - String message = ""; - FieldError fieldError = errors.getFieldError(fieldName); - if (fieldError != null) - { - String errore = fieldError.getCode(); - // FIXME localize it - ResourceBundle msgs = ResourceBundle - .getBundle(Constants.BUNDLE_KEY); - message = msgs.getString(errore); - } - return message; - } - - protected String getValidationMessage(String errors) - { - String message = ""; - if (errors != null && errors.length() != 0) - { - // FIXME localize it - ResourceBundle msgs = ResourceBundle - .getBundle(Constants.BUNDLE_KEY); - message = msgs.getString(errors); - } - return message; - } - - public Class getClazz() - { - return clazz; - } - - public void setClazz(Class clazz) - { - this.clazz = clazz; - } -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.validation; + +import it.cilea.osd.common.constants.Constants; +import it.cilea.osd.common.model.BaseObject; + +import java.util.ResourceBundle; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.validation.Errors; +import org.springframework.validation.FieldError; +import org.springframework.validation.Validator; + +public abstract class BaseValidator implements Validator +{ + private static Log log = LogFactory.getLog(BaseValidator.class); + + private Class clazz; + + public boolean supports(Class clazz) + { + return BaseObject.class.isAssignableFrom(clazz); + } + + /** + * Get the FieldError validation message from the underlying MessageSource + * for the given fieldName. + * + * @param errors + * The validation errors. + * @param fieldName + * The fieldName to retrieve the error message from. + * @return The validation message or an empty String. + */ + protected String getValidationMessage(Errors errors, String fieldName) + { + String message = ""; + FieldError fieldError = errors.getFieldError(fieldName); + if (fieldError != null) + { + String errore = fieldError.getCode(); + // FIXME localize it + ResourceBundle msgs = ResourceBundle + .getBundle(Constants.BUNDLE_KEY); + message = msgs.getString(errore); + } + return message; + } + + protected String getValidationMessage(String errors) + { + String message = ""; + if (errors != null && errors.length() != 0) + { + // FIXME localize it + ResourceBundle msgs = ResourceBundle + .getBundle(Constants.BUNDLE_KEY); + message = msgs.getString(errors); + } + return message; + } + + public Class getClazz() + { + return clazz; + } + + public void setClazz(Class clazz) + { + this.clazz = clazz; + } +} diff --git a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/webflow/BaseFormAction.java b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/webflow/BaseFormAction.java index 9f6246b..9cf6317 100644 --- a/commons-cilea-webapi/src/main/java/it/cilea/osd/common/webflow/BaseFormAction.java +++ b/commons-cilea-webapi/src/main/java/it/cilea/osd/common/webflow/BaseFormAction.java @@ -1,162 +1,162 @@ -/** - * Cilea Commons Framework - * - * Copyright (c) 2008, CILEA and third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by CILEA. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License v3 or any later version, as published - * by the Free Software Foundation, Inc. . - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package it.cilea.osd.common.webflow; - -import it.cilea.osd.common.constants.Constants; -import it.cilea.osd.common.model.Identifiable; -import it.cilea.osd.common.service.IPersistenceService; - - -import java.beans.PropertyEditor; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.PropertyEditorRegistry; -import org.springframework.context.MessageSource; -import org.springframework.webflow.action.FormAction; -import org.springframework.webflow.context.servlet.ServletExternalContext; -import org.springframework.webflow.core.collection.MutableAttributeMap; -import org.springframework.webflow.execution.Event; -import org.springframework.webflow.execution.RequestContext; - -public class BaseFormAction extends FormAction { - - protected IA applicationService; - - protected Log log = LogFactory.getLog(BaseFormAction.class); - - private String formObjectIDName; - - private Map customPropertyEditors; - - protected MessageSource messageSource = null; - - @Override - /** - * Register the custom property editors as defined in the - * customPropertyEditors map - */ - protected void registerPropertyEditors(PropertyEditorRegistry registry) { - super.registerPropertyEditors(registry); - if (customPropertyEditors != null) { - for (Class propertyClass : customPropertyEditors.keySet()) { - log.debug("Register customEditor "+ customPropertyEditors.get(propertyClass).getClass() + " for the "+propertyClass); - registry.registerCustomEditor(propertyClass, customPropertyEditors - .get(propertyClass)); - } - } - } - - @Override - /** - * Restituisce l'oggetto prelevandolo dallo Scope definito dal FormObjectScope se esistente. - * Altrimenti cerca di ottenerlo dal db utilizzando, nello stesso Scope, il valore contenuto - * nella variabile il cui nome e' definito dall'attributo FormObjectIDName (valorizzato di default - * a FormObjectName_id). - * In caso di insuccesso si comporta di come la FormAction standard di webflow. - * - */ - protected Object createFormObject(RequestContext context) throws Exception { - if (getFormObjectClass() == null) - { - log.debug("FormObjectClass Undefined! call the super createFormObject"); - return super.createFormObject(context); - } - MutableAttributeMap formScope = getFormObjectScope().getScope(context); - Object formObject = formScope.get(getFormObjectName()); - //FIXME: verificare la correttezza di questo check! il createFormObject non dovrebbe sempre restituire una nuova istanza - if (formObject != null) - { - log.debug("get the object from the scope " + getFormObjectScope().getLabel() ); - return formObject; - } - else - { - log.debug("form object null"); - if (formObjectIDName == null) formObjectIDName = getFormObjectName()+"_id"; - log.debug("Object "+getFormObjectName()+" not found in the scope "+getFormObjectScope().getLabel()); - Integer formObjectID = formScope.getInteger(formObjectIDName, null); - if (formObjectID != null) - { - log.debug("Retrieving the object "+ getFormObjectClass() + " from the DB - ID: "+formObjectID); - return applicationService.get(getFormObjectClass(), formObjectID); - } - else - { - log.debug("Creating a new instance of "+ getFormObjectClass()); - return super.createFormObject(context); - } - } - } - - public void setApplicationService(IA applicationService) { - this.applicationService = applicationService; - } - - public void setFormObjectIDName(String formObjectIDName) { - this.formObjectIDName = formObjectIDName; - } - - public void setCustomPropertyEditors( - Map customPropertyEditors) { - this.customPropertyEditors = customPropertyEditors; - } - - public Event refresh(RequestContext context) throws Exception - { - log.debug("Refreshing the object in the flow"); - Object objectRefresh = applicationService.refresh((Identifiable) getFormObject(context), getFormObjectClass()); - getFormObjectScope().getScope(context).put(getFormObjectName(), objectRefresh); - return success(); - } - - public void saveMessage(RequestContext context, String msg) { - ServletExternalContext servletContext = (ServletExternalContext) context - .getExternalContext(); - HttpServletRequest request = servletContext.getRequest(); - List messages = (List) request.getSession().getAttribute( - Constants.MESSAGES_KEY); - - if (messages == null) { - messages = new ArrayList(); - } - - messages.add(msg); - request.getSession().setAttribute(Constants.MESSAGES_KEY, messages); - } - - public String getText(String msgCode, Object[] args) { - return msgCode; - } - - public void setMessageSource(MessageSource messageSource) { - this.messageSource = messageSource; - } -} +/** + * Cilea Commons Framework + * + * Copyright (c) 2008, CILEA and third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by CILEA. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License v3 or any later version, as published + * by the Free Software Foundation, Inc. . + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package it.cilea.osd.common.webflow; + +import it.cilea.osd.common.constants.Constants; +import it.cilea.osd.common.model.Identifiable; +import it.cilea.osd.common.service.IPersistenceService; + + +import java.beans.PropertyEditor; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.PropertyEditorRegistry; +import org.springframework.context.MessageSource; +import org.springframework.webflow.action.FormAction; +import org.springframework.webflow.context.servlet.ServletExternalContext; +import org.springframework.webflow.core.collection.MutableAttributeMap; +import org.springframework.webflow.execution.Event; +import org.springframework.webflow.execution.RequestContext; + +public class BaseFormAction extends FormAction { + + protected IA applicationService; + + protected Log log = LogFactory.getLog(BaseFormAction.class); + + private String formObjectIDName; + + private Map customPropertyEditors; + + protected MessageSource messageSource = null; + + @Override + /** + * Register the custom property editors as defined in the + * customPropertyEditors map + */ + protected void registerPropertyEditors(PropertyEditorRegistry registry) { + super.registerPropertyEditors(registry); + if (customPropertyEditors != null) { + for (Class propertyClass : customPropertyEditors.keySet()) { + log.debug("Register customEditor "+ customPropertyEditors.get(propertyClass).getClass() + " for the "+propertyClass); + registry.registerCustomEditor(propertyClass, customPropertyEditors + .get(propertyClass)); + } + } + } + + @Override + /** + * Restituisce l'oggetto prelevandolo dallo Scope definito dal FormObjectScope se esistente. + * Altrimenti cerca di ottenerlo dal db utilizzando, nello stesso Scope, il valore contenuto + * nella variabile il cui nome e' definito dall'attributo FormObjectIDName (valorizzato di default + * a FormObjectName_id). + * In caso di insuccesso si comporta di come la FormAction standard di webflow. + * + */ + protected Object createFormObject(RequestContext context) throws Exception { + if (getFormObjectClass() == null) + { + log.debug("FormObjectClass Undefined! call the super createFormObject"); + return super.createFormObject(context); + } + MutableAttributeMap formScope = getFormObjectScope().getScope(context); + Object formObject = formScope.get(getFormObjectName()); + //FIXME: verificare la correttezza di questo check! il createFormObject non dovrebbe sempre restituire una nuova istanza + if (formObject != null) + { + log.debug("get the object from the scope " + getFormObjectScope().getLabel() ); + return formObject; + } + else + { + log.debug("form object null"); + if (formObjectIDName == null) formObjectIDName = getFormObjectName()+"_id"; + log.debug("Object "+getFormObjectName()+" not found in the scope "+getFormObjectScope().getLabel()); + Integer formObjectID = formScope.getInteger(formObjectIDName, null); + if (formObjectID != null) + { + log.debug("Retrieving the object "+ getFormObjectClass() + " from the DB - ID: "+formObjectID); + return applicationService.get(getFormObjectClass(), formObjectID); + } + else + { + log.debug("Creating a new instance of "+ getFormObjectClass()); + return super.createFormObject(context); + } + } + } + + public void setApplicationService(IA applicationService) { + this.applicationService = applicationService; + } + + public void setFormObjectIDName(String formObjectIDName) { + this.formObjectIDName = formObjectIDName; + } + + public void setCustomPropertyEditors( + Map customPropertyEditors) { + this.customPropertyEditors = customPropertyEditors; + } + + public Event refresh(RequestContext context) throws Exception + { + log.debug("Refreshing the object in the flow"); + Object objectRefresh = applicationService.refresh((Identifiable) getFormObject(context), getFormObjectClass()); + getFormObjectScope().getScope(context).put(getFormObjectName(), objectRefresh); + return success(); + } + + public void saveMessage(RequestContext context, String msg) { + ServletExternalContext servletContext = (ServletExternalContext) context + .getExternalContext(); + HttpServletRequest request = servletContext.getRequest(); + List messages = (List) request.getSession().getAttribute( + Constants.MESSAGES_KEY); + + if (messages == null) { + messages = new ArrayList(); + } + + messages.add(msg); + request.getSession().setAttribute(Constants.MESSAGES_KEY, messages); + } + + public String getText(String msgCode, Object[] args) { + return msgCode; + } + + public void setMessageSource(MessageSource messageSource) { + this.messageSource = messageSource; + } +} diff --git a/pom.xml b/pom.xml index aaef821..4c96ba5 100644 --- a/pom.xml +++ b/pom.xml @@ -1,208 +1,216 @@ - - 4.0.0 - it.cilea - commons-cilea - 2.2-SNAPSHOT - pom - - - UTF-8 - - 4.1.8.Final - 3.1.1.RELEASE - - - - scm:git:https://github.com/Cineca/CCommons.git - scm:git:https://github.com/Cineca/CCommons.git - https://github.com/Cineca/CCommons.git - 2.0 - - - - - - - maven-compiler-plugin - - 1.6 - 1.6 - - - - org.apache.maven.plugins - maven-release-plugin - 2.4.1 - - - release - clean deploy - - @{project.version} - - true - - - - - - - - - release - - false - - - commons-cilea-webapi - commons-cilea-api - - - - - - commons-cilea-webapi - commons-cilea-api - - - - - repo - CILEA Maven Repository - https://github.com/Cineca/mvn-repo/raw/master/releases - - - snapshot-repo - CILEA Maven Repository - https://github.com/Cineca/mvn-repo/raw/master/snapshots - - - - - - - commons-collections - commons-collections - 3.2 - - - - org.hibernate - hibernate-entitymanager - ${org.hibernate.version} - - - - org.hibernate - hibernate-ehcache - 4.0.1.Final - - - - org.hibernate - hibernate-core - 4.1.8.Final - - - - org.hibernate.common - hibernate-commons-annotations - 4.0.1.Final - - - - commons-logging - commons-logging - 1.1.1 - - - - commons-lang - commons-lang - 2.2 - - - - spring-core - org.springframework - ${org.spring.version} - - - - org.springframework - spring-orm - ${org.spring.version} - - - - spring-beans - org.springframework - ${org.spring.version} - - - - spring-aop - org.springframework - ${org.spring.version} - - - - spring-context - org.springframework - ${org.spring.version} - - - - spring-tx - org.springframework - ${org.spring.version} - - - - spring-jdbc - org.springframework - ${org.spring.version} - - - - javax.servlet - servlet-api - 2.3 - provided - - - - displaytag - displaytag - 1.2 - - - com.lowagie - itext - - - commons-collections - commons-collections - - - org.slf4j - slf4j-log4j12 - - - org.slf4j - jcl104-over-slf4j - - - - - - org.slf4j - slf4j-api - 1.6.1 - - - - + + 4.0.0 + it.cilea + commons-cilea + 2.6-SNAPSHOT + pom + + + UTF-8 + + 4.2.21.Final + 4.2.21.Final + 4.2.21.Final + 4.0.2.Final + 1.0.1.Final + 3.2.16.RELEASE + + + + scm:git:https://github.com/4Science/CCommons.git + scm:git:https://github.com/4Science/CCommons.git + https://github.com/4Science/CCommons.git + 2.0 + + + + + + + maven-compiler-plugin + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-release-plugin + 2.5.2 + + + release + clean deploy + + @{project.version} + + true + + + + + + + + + release + + false + + + commons-cilea-webapi + commons-cilea-api + + + + + + commons-cilea-webapi + commons-cilea-api + + + + + 4science-nexus + 4Science Public Releases + https://nexus.4science.it/repository/maven-releases/ + + + 4science-snapshot + 4Science Public Snapshot + https://nexus.4science.it/repository/maven-snapshots/ + + + website + https://github.com/4Science/JDynA/wiki + + + + + + + commons-collections + commons-collections + 3.2 + + + + org.hibernate + hibernate-entitymanager + ${org.hibernate.version} + + + + org.hibernate + hibernate-ehcache + ${org.hibernate.ehcache.version} + + + + org.hibernate + hibernate-core + ${org.hibernate.version} + + + + org.hibernate.common + hibernate-commons-annotations + ${org.hibernate.annotations.version} + + + + commons-logging + commons-logging + 1.1.1 + + + + commons-lang + commons-lang + 2.2 + + + + spring-core + org.springframework + ${org.spring.version} + + + + org.springframework + spring-orm + ${org.spring.version} + + + + spring-beans + org.springframework + ${org.spring.version} + + + + spring-aop + org.springframework + ${org.spring.version} + + + + spring-context + org.springframework + ${org.spring.version} + + + + spring-tx + org.springframework + ${org.spring.version} + + + + spring-jdbc + org.springframework + ${org.spring.version} + + + + javax.servlet + servlet-api + 2.3 + provided + + + + displaytag + displaytag + 1.2 + + + com.lowagie + itext + + + commons-collections + commons-collections + + + org.slf4j + slf4j-log4j12 + + + org.slf4j + jcl104-over-slf4j + + + + + + org.slf4j + slf4j-api + 1.6.1 + + + + \ No newline at end of file