r26 - in trunk: cantharella.data/src/main/java/nc/ird/cantharella/data/model cantharella.service/src/main/java/nc/ird/cantharella/service/services cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl cantharella.service/src/main/java/nc/ird/cantharella/service/utils/normalizers
Author: acheype Date: 2012-11-16 06:13:26 +0100 (Fri, 16 Nov 2012) New Revision: 26 Url: http://forge.codelutin.com/repositories/revision/cantharella/26 Log: Add TypeDocument class in the DAO and service layers Added: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/TypeDocument.java trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/DocumentService.java trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/DocumentServiceImpl.java trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/utils/normalizers/TypeDocumentNormalizer.java Added: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/TypeDocument.java =================================================================== --- trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/TypeDocument.java (rev 0) +++ trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/TypeDocument.java 2012-11-16 05:13:26 UTC (rev 26) @@ -0,0 +1,170 @@ +/* + * Cantharella, Pharmacochemical database of natural substances - http://sourceforge.net/p/cantharella/ + * + * Copyright (C) 2009-2012 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) + * + * Cantharella is free software: you can redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Cantharella 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 General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with Cantharella. If not, see + * <http://www.gnu.org/licenses/>. + */ +package nc.ird.cantharella.data.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; + +import nc.ird.cantharella.data.model.utils.AbstractModel; + +import org.apache.commons.beanutils.BeanComparator; +import org.hibernate.validator.constraints.Length; +import org.hibernate.validator.constraints.NotEmpty; + +/** + * Model : Document type + * @author Adrien Cheype + */ +@Entity +@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "nom" }) }) +public class TypeDocument extends AbstractModel implements Cloneable, Comparable<TypeDocument> { + + /** Document type ID */ + @Id + @GeneratedValue + private Integer idTypeDocument; + + /** Document type name */ + @Length(max = LENGTH_MEDIUM_TEXT) + @NotEmpty + @Column(unique = true) + private String nom; + + /** Document type domain */ + @Length(max = LENGTH_MEDIUM_TEXT) + private String domaine; + + /** Document type description */ + @NotEmpty + @Lob + private String description; + + /** If the type document represents an image ? */ + @NotNull + private Boolean estImage; + + /** {@inheritDoc} */ + @Override + public TypeDocument clone() throws CloneNotSupportedException { + TypeDocument clone = (TypeDocument) super.clone(); + clone.idTypeDocument = idTypeDocument; + clone.nom = nom; + clone.domaine = domaine; + clone.description = description; + clone.estImage = estImage; + return clone; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return this.nom; + } + + /** {@inheritDoc} */ + @Override + public int compareTo(TypeDocument typeExtrait) { + return new BeanComparator("nom").compare(this, typeExtrait); + } + + /** + * idTypeDocument getter + * @return idTypeDocument + */ + public Integer getIdTypeDocument() { + return idTypeDocument; + } + + /** + * idTypeDocument setter + * @param idTypeDocument idTypeDocument + */ + public void setIdTypeDocument(Integer idTypeDocument) { + this.idTypeDocument = idTypeDocument; + } + + /** + * nom getter + * @return nom + */ + public String getNom() { + return nom; + } + + /** + * nom setter + * @param nom nom + */ + public void setNom(String nom) { + this.nom = nom; + } + + /** + * domaine getter + * @return domaine + */ + public String getDomaine() { + return domaine; + } + + /** + * domaine setter + * @param domaine domaine + */ + public void setDomaine(String domaine) { + this.domaine = domaine; + } + + /** + * description getter + * @return description + */ + public String getDescription() { + return description; + } + + /** + * description setter + * @param description description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * estImage getter + * @return estImage + */ + public Boolean getEstImage() { + return estImage; + } + + /** + * estImage setter + * @param estImage estImage + */ + public void setEstImage(Boolean estImage) { + this.estImage = estImage; + } + +} Property changes on: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/TypeDocument.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/DocumentService.java =================================================================== --- trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/DocumentService.java (rev 0) +++ trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/DocumentService.java 2012-11-16 05:13:26 UTC (rev 26) @@ -0,0 +1,77 @@ +/* + * Cantharella, Pharmacochemical database of natural substances - http://sourceforge.net/p/cantharella/ Copyright (C) + * 2009-2012 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) Cantharella is free + * software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Cantharella 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 General Public License for more details. You should + * have received a copy of the GNU General Public License along with Cantharella. If not, see + * <http://www.gnu.org/licenses/>. + */ +package nc.ird.cantharella.service.services; + +import java.util.List; + +import nc.ird.cantharella.data.exceptions.DataConstraintException; +import nc.ird.cantharella.data.exceptions.DataNotFoundException; +import nc.ird.cantharella.data.model.Partie; +import nc.ird.cantharella.data.model.TypeDocument; +import nc.ird.cantharella.service.utils.normalizers.TypeDocumentNormalizer; +import nc.ird.cantharella.service.utils.normalizers.UniqueFieldNormalizer; +import nc.ird.cantharella.service.utils.normalizers.utils.Normalize; + +import org.springframework.transaction.annotation.Transactional; + +/** + * Services for documents + * @author Adrien Cheype + */ +public interface DocumentService { + + /** + * List the document types available + * @return The list of document types + */ + @Transactional(readOnly = true) + List<TypeDocument> listTypeDocuments(); + + /** + * Create a document type + * @param typeDocument The document type to create + * @throws DataConstraintException If the document type already exists (unique constraints) + */ + void createTypeDocument(@Normalize(TypeDocumentNormalizer.class) TypeDocument typeDocument) + throws DataConstraintException; + + /** + * Load a document type + * @param idTypeDocument ID + * @return The corresponding document type + * @throws DataNotFoundException If not found + */ + TypeDocument loadTypeDocument(Integer idTypeDocument) throws DataNotFoundException; + + /** + * Charger a document type + * @param nom The document type name + * @return The corresponding document type + * @throws DataNotFoundException If not found + */ + TypeDocument loadTypeDocument(@Normalize(UniqueFieldNormalizer.class) String nom) throws DataNotFoundException; + + /** + * Modify a document type + * @param typeDocument The document type to modify + * @throws DataConstraintException If an unique constraint is broken with another document type + */ + void updateTypeDocument(@Normalize(TypeDocumentNormalizer.class) TypeDocument typeDocument) + throws DataConstraintException; + + /** + * Delete a document type + * @param typeDocument The document type to delete + * @throws DataConstraintException If the document type has linked data + */ + void deleteTypeDocument(TypeDocument typeDocument) throws DataConstraintException; + +} Property changes on: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/DocumentService.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/DocumentServiceImpl.java =================================================================== --- trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/DocumentServiceImpl.java (rev 0) +++ trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/DocumentServiceImpl.java 2012-11-16 05:13:26 UTC (rev 26) @@ -0,0 +1,98 @@ +/* + * Cantharella, Pharmacochemical database of natural substances - http://sourceforge.net/p/cantharella/ + * + * Copyright (C) 2009-2012 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) + * + * Cantharella is free software: you can redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Cantharella 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 General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with Cantharella. If not, see + * <http://www.gnu.org/licenses/>. + */ +package nc.ird.cantharella.service.services.impl; + +import java.util.List; + +import nc.ird.cantharella.data.dao.GenericDao; +import nc.ird.cantharella.data.exceptions.DataConstraintException; +import nc.ird.cantharella.data.exceptions.DataNotFoundException; +import nc.ird.cantharella.data.exceptions.UnexpectedException; +import nc.ird.cantharella.data.model.Partie; +import nc.ird.cantharella.data.model.TypeDocument; +import nc.ird.cantharella.service.services.DocumentService; +import nc.ird.module.utils.AssertTools; +import nc.ird.module.utils.LogTools; + +import org.apache.commons.logging.Log; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Document service implementation + * @author Adrien Cheype + */ +@Service +public final class DocumentServiceImpl implements DocumentService { + + /** Logger */ + private static final Log LOG = LogTools.getLog(); + + /** DAO */ + @Autowired + private GenericDao dao; + + /** {@inheritDoc} */ + @Override + public List<TypeDocument> listTypeDocuments() { + return dao.readList(TypeDocument.class, "nom"); + } + + /** {@inheritDoc} */ + @Override + public void createTypeDocument(TypeDocument typeDocument) throws DataConstraintException { + LOG.info("createTypeDocument: " + typeDocument.getNom()); + dao.create(typeDocument); + } + + /** {@inheritDoc} */ + @Override + public TypeDocument loadTypeDocument(Integer idTypeDocument) throws DataNotFoundException { + return dao.read(TypeDocument.class, idTypeDocument); + } + + /** {@inheritDoc} */ + @Override + public TypeDocument loadTypeDocument(String nom) throws DataNotFoundException { + return dao.read(TypeDocument.class, "nom", nom); + } + + /** {@inheritDoc} */ + @Override + public void updateTypeDocument(TypeDocument typeDocument) throws DataConstraintException { + LOG.info("updateTypeDocument: " + typeDocument.getNom()); + try { + dao.update(typeDocument); + } catch (DataNotFoundException e) { + LOG.error(e.getMessage(), e); + throw new UnexpectedException(e); + } + } + + /** {@inheritDoc} */ + @Override + public void deleteTypeDocument(TypeDocument typeDocument) throws DataConstraintException { + AssertTools.assertNotNull(typeDocument); + LOG.info("deleteTypeDocument: " + typeDocument.getNom()); + try { + dao.delete(typeDocument); + } catch (DataNotFoundException e) { + LOG.error(e.getMessage(), e); + throw new UnexpectedException(e); + } + } +} Property changes on: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/DocumentServiceImpl.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/utils/normalizers/TypeDocumentNormalizer.java =================================================================== --- trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/utils/normalizers/TypeDocumentNormalizer.java (rev 0) +++ trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/utils/normalizers/TypeDocumentNormalizer.java 2012-11-16 05:13:26 UTC (rev 26) @@ -0,0 +1,37 @@ +/* + * Cantharella, Pharmacochemical database of natural substances - http://sourceforge.net/p/cantharella/ + * + * Copyright (C) 2009-2012 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) + * + * Cantharella is free software: you can redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Cantharella 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 General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with Cantharella. If not, see + * <http://www.gnu.org/licenses/>. + */ +package nc.ird.cantharella.service.utils.normalizers; + +import nc.ird.cantharella.data.model.TypeDocument; +import nc.ird.cantharella.service.utils.normalizers.utils.Normalizer; +import nc.ird.module.utils.AssertTools; + +/** + * Document type normalizer + * @author Adrien Cheype + */ +public final class TypeDocumentNormalizer extends Normalizer<TypeDocument> { + + /** {@inheritDoc} */ + @Override + protected TypeDocument normalize(TypeDocument typeDocument) { + AssertTools.assertNotNull(typeDocument); + // Unique field + typeDocument.setNom(Normalizer.normalize(ConfigNameNormalizer.class, typeDocument.getNom())); + return typeDocument; + } +} Property changes on: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/utils/normalizers/TypeDocumentNormalizer.java ___________________________________________________________________ Added: svn:mime-type + text/plain
participants (1)
-
acheype@users.forge.codelutin.com