Project

General

Profile

Revision 87ffda36

ID87ffda365bd5992de5c74073feb59283b9b5f6c9
Parent ff3035c8
Child d499114c

Added by Andreas Müller over 2 years ago

ref #3560 unpublished exception handling for TaxonController.doGetAcceptedFor

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/TaxonController.java
40 40
import eu.etaxonomy.cdm.api.service.config.IncludedTaxonConfiguration;
41 41
import eu.etaxonomy.cdm.api.service.dto.IncludedTaxaDTO;
42 42
import eu.etaxonomy.cdm.api.service.pager.Pager;
43
import eu.etaxonomy.cdm.exception.UnpublishedException;
43 44
import eu.etaxonomy.cdm.model.common.MarkerType;
44 45
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
45 46
import eu.etaxonomy.cdm.model.description.TaxonDescription;
......
145 146
            logger.info("doGetAcceptedFor() " + requestPathAndQuery(request));
146 147
        }
147 148

  
148
        Taxon result = null;
149 149
        try {
150
            result = service.findAcceptedTaxonFor(uuid, classification_uuid, getInitializationStrategy());
150
            boolean includeUnpublished = NO_UNPUBLISHED;
151
            Taxon result = service.findAcceptedTaxonFor(uuid, classification_uuid, includeUnpublished, getInitializationStrategy());
152
            result = checkExistsAndAccess(result, includeUnpublished, response);
153

  
154
            return result;
151 155
        } catch (EntityNotFoundException e){
152 156
            HttpStatusMessage.UUID_NOT_FOUND.send(response);
157
        } catch (UnpublishedException e) {
158
            HttpStatusMessage.ACCESS_DENIED.send(response);
153 159
        }
160
        return null;
154 161

  
155
        return result;
156 162
    }
157 163

  
158 164
    @RequestMapping(value = "classifications", method = RequestMethod.GET)
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITaxonService.java
30 30
import eu.etaxonomy.cdm.api.service.search.LuceneParseException;
31 31
import eu.etaxonomy.cdm.api.service.search.SearchResult;
32 32
import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;
33
import eu.etaxonomy.cdm.exception.UnpublishedException;
33 34
import eu.etaxonomy.cdm.model.common.DefinedTerm;
34 35
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
35 36
import eu.etaxonomy.cdm.model.common.Language;
......
881 882
     */
882 883
    public List<Synonym>  createAllInferredSynonyms(Taxon taxon, Classification tree, boolean doWithMisappliedNames);
883 884

  
884
    public Taxon findAcceptedTaxonFor(UUID synonymUuid, UUID classificationUuid, List<String> propertyPaths);
885
    public Taxon findAcceptedTaxonFor(UUID synonymUuid, UUID classificationUuid, boolean includeUnpublished,
886
            List<String> propertyPaths) throws UnpublishedException;
885 887

  
886 888
    public List<TaxonBase> findTaxaByName(MatchingTaxonConfigurator config);
887 889

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ServiceBase.java
26 26

  
27 27
import eu.etaxonomy.cdm.api.service.pager.Pager;
28 28
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
29
import eu.etaxonomy.cdm.exception.UnpublishedException;
29 30
import eu.etaxonomy.cdm.model.common.CdmBase;
31
import eu.etaxonomy.cdm.model.common.IPublishable;
30 32
import eu.etaxonomy.cdm.persistence.dao.common.ICdmEntityDao;
31 33
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.DaoBase;
32 34
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
......
299 301
    }
300 302

  
301 303

  
304
    /**
305
     * Throws an exception if the publishable entity should not be published.
306
     * @param publishable the publishable entity
307
     * @param includeUnpublished should publish be checked
308
     * @param message the error message to include
309
     * @throws UnpublishedException thrown if entity is not public and unpublished should not be included
310
     */
311
    protected void checkPublished(IPublishable publishable, boolean includeUnpublished, String message) throws UnpublishedException {
312
        if (!(includeUnpublished || !publishable.isPublish())){
313
            throw new UnpublishedException("Access denied. "+  message);
314
        }
315
    }
316

  
317

  
302 318

  
303 319
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
63 63
import eu.etaxonomy.cdm.api.service.search.SearchResultBuilder;
64 64
import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;
65 65
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
66
import eu.etaxonomy.cdm.exception.UnpublishedException;
66 67
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
67 68
import eu.etaxonomy.cdm.hibernate.search.AcceptedTaxonBridge;
68 69
import eu.etaxonomy.cdm.hibernate.search.DefinedTermBaseClassBridge;
......
500 501
    }
501 502

  
502 503
    @Override
503
    public Taxon findAcceptedTaxonFor(UUID synonymUuid, UUID classificationUuid, List<String> propertyPaths){
504
    public Taxon findAcceptedTaxonFor(UUID synonymUuid, UUID classificationUuid,
505
            boolean includeUnpublished, List<String> propertyPaths) throws UnpublishedException{
504 506

  
505 507
        Taxon result = null;
506 508
        Long count = 0l;
......
509 511

  
510 512
        try {
511 513
            synonym = (Synonym) dao.load(synonymUuid);
514
            checkPublished(synonym, includeUnpublished, "Synoym is unpublished.");
512 515
        } catch (ClassCastException e){
513 516
            throw new EntityNotFoundException("The TaxonBase entity referenced by " + synonymUuid + " is not a Synonmy");
514 517
        } catch (NullPointerException e){
......
530 533
        count = dao.countAcceptedTaxonFor(synonym, classificationFilter) ;
531 534
        if(count > 0){
532 535
            result = dao.acceptedTaxonFor(synonym, classificationFilter, propertyPaths);
536
            checkPublished(result, includeUnpublished, "Accepted taxon unpublished");
533 537
        }
534 538

  
535 539
        return result;
536 540
    }
537 541

  
538

  
539 542
    @Override
540 543
    public Set<Taxon> listRelatedTaxa(Taxon taxon, Set<TaxonRelationshipEdge> includeRelationships, Integer maxDepth,
541 544
            boolean includeUnpublished, Integer limit, Integer start, List<String> propertyPaths) {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)