ref #6169 remoging service mock and loading ResgistrationSets by citationID
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Fri, 19 May 2017 18:00:16 +0000 (20:00 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Fri, 19 May 2017 18:00:16 +0000 (20:00 +0200)
src/main/java/eu/etaxonomy/cdm/mock/RegistrationService.java [deleted file]
src/main/java/eu/etaxonomy/cdm/service/IRegistrationWorkingSetService.java
src/main/java/eu/etaxonomy/cdm/service/RegistrationWorkingSetService.java
src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/RegistrationItem.java
src/main/java/eu/etaxonomy/cdm/vaadin/event/registration/RegistrationWorkflowEvent.java
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ListPresenter.java
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkflowPresenter.java

diff --git a/src/main/java/eu/etaxonomy/cdm/mock/RegistrationService.java b/src/main/java/eu/etaxonomy/cdm/mock/RegistrationService.java
deleted file mode 100644 (file)
index ba58a86..0000000
+++ /dev/null
@@ -1,245 +0,0 @@
-/**
-* Copyright (C) 2017 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.mock;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.apache.log4j.Logger;
-import org.joda.time.DateTime;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.TransactionStatus;
-import org.springframework.transaction.annotation.Transactional;
-
-import eu.etaxonomy.cdm.api.application.CdmRepository;
-import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.model.common.User;
-import eu.etaxonomy.cdm.model.name.Rank;
-import eu.etaxonomy.cdm.model.name.Registration;
-import eu.etaxonomy.cdm.model.name.RegistrationStatus;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
-import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
-import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
-import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
-import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationValidationException;
-
-/**
- * Mock service which creates Registration on the fly.
- * Registrations are never persisted they are only kept in memory.
- *
- * @author a.kohlbecker
- * @since Mar 10, 2017
- *
- */
-@Service("registrationServiceMock")
-@Transactional(readOnly=true)
-public class RegistrationService implements IRegistrationWorkingSetService {
-
-    private static final int SIZE = 50; // FIXME test performance with 50 !!!!!
-
-    private static final Logger logger = Logger.getLogger(RegistrationService.class);
-
-    @Autowired
-    @Qualifier("cdmRepository")
-    private CdmRepository repo;
-
-    private Map<UUID, Registration> registrationsByUUID = new HashMap<>();
-    private Map<Integer, Registration> registrationsByRegID = new HashMap<>();
-    private Map<Integer, RegistrationDTO> registrationDTOsById = new HashMap<>();
-    private Map<String, RegistrationDTO> registrationDTOsByIdentifier = new HashMap<>();
-    private Map<Integer, List<RegistrationDTO>> registrationDTOsByCitationId = new HashMap<>();
-
-    private Collection<CdmBase> cdmEntities = new HashSet<>();
-
-    int autoincrementId = 100000;
-
-    public RegistrationService() {
-    }
-
-
-    int minTypeDesignationCount = 1;
-
-    protected void init(){
-        if(isCleanSweep()){
-            autoincrementId = 100000;
-            registrationsByUUID = new HashMap<>();
-            registrationsByRegID = new HashMap<>();
-            registrationDTOsById = new HashMap<>();
-            registrationDTOsByIdentifier = new HashMap<>();
-            registrationDTOsByCitationId = new HashMap<>();
-        }
-        if(registrationsByUUID.size() == 0){
-            TransactionStatus tx = repo.startTransaction(true);
-            int pageIndex = 0;
-            while(registrationsByUUID.size() < SIZE){
-                List<TaxonNameBase> names = repo.getNameService().list(TaxonNameBase.class, 100, pageIndex++, null, null);
-                if(names.isEmpty()){
-                    break;
-                }
-                for(TaxonNameBase name : names){
-                    if(name != null && name.getRank() != null && name.getRank().isLower(Rank.SUBFAMILY()) && name.getNomenclaturalReference() != null){
-                        if(name.getTypeDesignations().size() > minTypeDesignationCount - 1) {
-
-                            // name
-                            logger.debug("creating Registration for " + name.getTitleCache());
-                            Registration reg = newMockRegistration();
-                            reg.setName(name);
-                            cdmEntities.add(name);
-
-                            // typedesignation
-                            reg.setTypeDesignations(name.getTypeDesignations());
-                            cdmEntities.addAll(name.getTypeDesignations());
-
-                            put(new RegistrationDTO(reg));
-                            logger.debug("\t\t\tdone");
-                        }
-                    }
-                }
-            }
-            repo.commitTransaction(tx);
-        }
-    }
-
-    /**
-     * @return
-     */
-    private Registration newMockRegistration() {
-        Registration reg = Registration.NewInstance();
-        reg.setId(autoincrementId);
-        reg.setSpecificIdentifier(String.valueOf(autoincrementId));
-        reg.setIdentifier("http://phycobank/" + reg.getSpecificIdentifier());
-        autoincrementId++;
-        reg.setStatus(RegistrationStatus.values()[(int) (Math.random() * RegistrationStatus.values().length)]);
-        reg.setRegistrationDate(DateTime.now());
-        return reg;
-    }
-
-    /**
-     * @return
-     */
-    private boolean isCleanSweep() {
-
-        return false;
-    }
-
-    /**
-     * @param reg
-     */
-    private void put(RegistrationDTO dto) {
-        logger.debug("putting DTO " + dto.getSummary());
-        Registration reg = dto.registration();
-        registrationsByUUID.put(dto.getUuid(), reg);
-        registrationsByRegID.put(reg.getId(), reg);
-
-        registrationDTOsById.put(reg.getId(), dto);
-        registrationDTOsByIdentifier.put(reg.getIdentifier(), dto);
-
-        if(! registrationDTOsByCitationId.containsKey(dto.getCitationID())){
-            registrationDTOsByCitationId.put(dto.getCitationID(), new ArrayList<RegistrationDTO>());
-        }
-        registrationDTOsByCitationId.get(dto.getCitationID()).add(dto);
-    }
-
-    private void mergeBack(){
-        cdmEntities.forEach(e -> repo.getNameService().getSession().merge(e));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Registration load(UUID uuid) {
-        init();
-        return registrationsByUUID.get(uuid);
-    }
-
-
-    public Collection<Registration> list(){
-        init();
-        return registrationsByUUID.values();
-    }
-
-    @Override
-    public Collection<RegistrationDTO> listDTOs() {
-        init();
-        return registrationDTOsById.values();
-    }
-
-    public Map<Integer, List<RegistrationDTO>> listDTOsByWorkingSet() {
-        init();
-        return registrationDTOsByCitationId;
-    }
-
-    /**
-     * @param  id the CDM Entity id
-     * @return
-     */
-    public Registration loadByRegistrationID(Integer id) {
-        init();
-        return registrationsByRegID.get(id);
-    }
-
-    /**
-     * @param identifier the Registration Identifier String
-     * @return
-     */
-    public RegistrationDTO loadDtoByIdentifier(String identifier) {
-        init();
-        return registrationDTOsById.get(identifier);
-    }
-
-    /**
-     * @param id the CDM Entity id
-     * @return
-     */
-    @Override
-    public RegistrationDTO loadDtoById(Integer id) {
-        init();
-        return registrationDTOsById.get(id);
-    }
-
-    /**
-     * @param  id the CDM Entity id
-     * @return
-     * @throws RegistrationValidationException
-     */
-    @Override
-    public RegistrationWorkingSet loadWorkingSetByRegistrationID(Integer id) throws RegistrationValidationException {
-        init();
-        RegistrationDTO dto = registrationDTOsById.get(id);
-
-        return new RegistrationWorkingSet(registrationDTOsByCitationId.get(dto.getCitationID()));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Collection<RegistrationDTO> listDTOs(User submitter, Collection<RegistrationStatus> includedStatus) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public RegistrationWorkingSet loadWorkingSetByReferenceID(Integer referenceID) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-}
index f4a0436ce945e0f752e6a487119a2864e9d6d824..62308a86951370f4bf70a62b6e48c47feff8181a 100644 (file)
@@ -38,12 +38,8 @@ public interface IRegistrationWorkingSetService {
      * @param  id the CDM Entity id
      * @return
      * @throws RegistrationValidationException
-     * @deprecated use other method working sets should only be addressed by the referenceID
      */
-    @Deprecated
-    public RegistrationWorkingSet loadWorkingSetByRegistrationID(Integer id) throws RegistrationValidationException;
-
-    public static final String ACTIVE_IMPL = "registrationWorkingSetService";
+    public RegistrationWorkingSet loadWorkingSetByCitationID(Integer id) throws RegistrationValidationException;
 
     /**
      * @param referenceID
index 455c736e23f78091a21cb2a8febf60ac5489d0ec..b611077beb07181ca959d426ec3ca266ea5e2210 100644 (file)
@@ -108,18 +108,11 @@ public class RegistrationWorkingSetService implements IRegistrationWorkingSetSer
         return new RegistrationWorkingSet(makeDTOs(pager.getRecords()));
     }
 
-    /**
-     * @param  id the CDM Entity id
-     * @return
-     * @throws RegistrationValidationException
-     * @deprecated use other method working sets should only be addressed by the referenceID
-     */
-    @Deprecated
     @Override
-    public RegistrationWorkingSet loadWorkingSetByRegistrationID(Integer id) throws RegistrationValidationException {
+    public RegistrationWorkingSet loadWorkingSetByCitationID(Integer id) throws RegistrationValidationException {
 
-        RegistrationDTO dto = loadDtoById(id);
-        Pager<Registration> pager = repo.getRegistrationService().page(Optional.of((Reference)dto.getCitation()), null, null, null, null);
+        Reference ref = repo.getReferenceService().find(id);
+        Pager<Registration> pager = repo.getRegistrationService().page(Optional.of(ref), null, null, null, null);
         return new RegistrationWorkingSet(makeDTOs(pager.getRecords()));
     }
 
index 17dbdadd5342308211d4e700a267070a2641832c..8a532829e86447e1d9e201f51bdbe61867615448 100644 (file)
@@ -18,6 +18,7 @@ import org.joda.time.format.ISODateTimeFormat;
 import com.vaadin.server.ExternalResource;
 import com.vaadin.server.FontAwesome;
 import com.vaadin.server.Resource;
+import com.vaadin.server.UserError;
 import com.vaadin.shared.ui.label.ContentMode;
 import com.vaadin.ui.Alignment;
 import com.vaadin.ui.Button;
@@ -163,13 +164,19 @@ public class RegistrationItem extends GridLayout {
     public void setItem(RegistrationDTO regDto, AbstractView<?> parentView){
         this.parentView = parentView;
 
-        NavigationEvent navigationEvent = new NavigationEvent(
-                RegistrationWorkflowViewBean.NAME,
-                RegistrationWorkflowViewBean.ACTION_EDIT,
-                Integer.toString(regDto.getId())
-                );
+        NavigationEvent navigationEvent = null;
+        if(regDto.getCitationID() != null) {
+            navigationEvent = new NavigationEvent(
+                    RegistrationWorkflowViewBean.NAME,
+                    RegistrationWorkflowViewBean.ACTION_EDIT,
+                    Integer.toString(regDto.getCitationID())
+                    );
+        } else {
+            setComponentError(new UserError("Citation is missing"));
+        }
 
-        updateUI(regDto.getBibliographicCitationString(), regDto.getCreated(), regDto.getDatePublished(), regDto.getMessages().size(),
+        updateUI(regDto.getBibliographicCitationString(), regDto.getCreated(), regDto.getDatePublished(),
+                regDto.getMessages().size(),
                 navigationEvent, null, regDto, regDto.getSubmitterUserName());
     }
 
index c5d2e9ec35ff7fbcbb92ad30cdc9ffb5cc32f17d..a34b4ae76b628233718890d4a735b4dae1d233d1 100644 (file)
@@ -19,11 +19,16 @@ public class RegistrationWorkflowEvent {
 
     private RegistrationType type = null;
     private Action action;
-    private Integer registrationID = null;
+    private Integer citationID = null;
 
-    public RegistrationWorkflowEvent(int registrationID){
+    /**
+     *
+     * @param citationID the id of a {@link Reference} denoting a
+     * complete registration working set.
+     */
+    public RegistrationWorkflowEvent(int citationID){
         this.action = Action.open;
-        this.registrationID = registrationID;
+        this.citationID = citationID;
     }
 
     public RegistrationWorkflowEvent(RegistrationType type){
@@ -48,8 +53,8 @@ public class RegistrationWorkflowEvent {
     /**
      * @return the registrationID
      */
-    public Integer getRegistrationID() {
-        return registrationID;
+    public Integer getCitationID() {
+        return citationID;
     }
 
     public boolean isStart() {
index 2d1c2370d438a6fd4ed72d41868ecd127392eedd..0ab2024dec6fb80d47d54af9b1aae5a597a032dd 100644 (file)
@@ -12,7 +12,6 @@ import java.util.Collection;
 import java.util.EnumSet;
 
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.context.event.EventListener;
 import org.springframework.security.core.Authentication;
 
@@ -48,7 +47,6 @@ public class ListPresenter extends AbstractPresenter<ListView> {
     private static final long serialVersionUID = 5419947244621450665L;
 
     @Autowired
-    @Qualifier(IRegistrationWorkingSetService.ACTIVE_IMPL)
     private IRegistrationWorkingSetService workingSetService;
 
     @Override
index 6559d1061709595e6a309b4e0089db832b9fc803..98f0e1bea780edc4bc7d5afb13521efe5a0e56fe 100644 (file)
@@ -14,7 +14,6 @@ import java.util.List;
 
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.context.event.EventListener;
 import org.springframework.transaction.TransactionStatus;
 
@@ -49,7 +48,6 @@ public class RegistrationWorkflowPresenter extends AbstractPresenter<Registratio
     private static final long serialVersionUID = 1L;
 
     @Autowired
-    @Qualifier(IRegistrationWorkingSetService.ACTIVE_IMPL)
     private IRegistrationWorkingSetService workingSetService;
 
     private RegistrationWorkingSet workingset;
@@ -81,8 +79,8 @@ public class RegistrationWorkflowPresenter extends AbstractPresenter<Registratio
             }
             getView().setWorkingset(workingset);
         } else {
-            Integer registrationID = event.getRegistrationID();
-            presentWorkingSetByRegID(registrationID);
+            Integer citationID = event.getCitationID();
+            presentWorkingSetByRegID(citationID);
         }
 
     }
@@ -92,9 +90,9 @@ public class RegistrationWorkflowPresenter extends AbstractPresenter<Registratio
      * @deprecated use other method working sets should only be addressed by the referenceID
      */
     @Deprecated
-    private void presentWorkingSetByRegID(Integer registrationID) {
+    private void presentWorkingSetByRegID(Integer citationID) {
         try {
-            workingset = workingSetService.loadWorkingSetByRegistrationID(registrationID);
+            workingset = workingSetService.loadWorkingSetByCitationID(citationID);
         } catch (RegistrationValidationException error) {
             getView().getWorkflow().setComponentError(new SystemError(error));
         }
@@ -178,7 +176,7 @@ public class RegistrationWorkflowPresenter extends AbstractPresenter<Registratio
     }
 
     /**
-     * 
+     *
      */
     protected void refreshView() {
         presentWorkingSet(workingset.getCitationId());