source: VirtualCollectionRegistry/tags/VirtualCollectionRegistry-0.4.0-alpha2/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/service/impl/VirtualCollectionPrePublicationValidator.java @ 5557

Last change on this file since 5557 was 5557, checked in by Twan Goosen, 10 years ago

tag for VCR alpha 2

File size: 3.8 KB
Line 
1/*
2 * Copyright (C) 2014 CLARIN
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17package eu.clarin.cmdi.virtualcollectionregistry.service.impl;
18
19import eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistryUsageException;
20import eu.clarin.cmdi.virtualcollectionregistry.model.Resource;
21import eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollection;
22import eu.clarin.cmdi.virtualcollectionregistry.service.VirtualCollectionValidator;
23import java.util.ArrayList;
24import java.util.List;
25import org.apache.wicket.util.string.Strings;
26import org.springframework.beans.factory.annotation.Qualifier;
27import org.springframework.stereotype.Service;
28
29/**
30 * A virtual collection validator performing "soft" validation that should occur
31 * before publication. Validated collections are <em>assumed</em> to be valid
32 * according to the 'minimal' validator applied on creation and update of the
33 * collection.
34 *
35 * @author twagoo
36 */
37@Service(value = "publication-soft")
38@Qualifier("publication-soft")
39public class VirtualCollectionPrePublicationValidator implements VirtualCollectionValidator {
40
41    @Override
42    public void validate(VirtualCollection vc) throws VirtualCollectionRegistryUsageException {
43        final List<String> warnings = new ArrayList<>();
44
45        switch (vc.getType()) {
46            case EXTENSIONAL:
47                validateResources(vc, warnings);
48                break;
49            case INTENSIONAL:
50                validateGeneratedBy(vc, warnings);
51                break;
52        }
53
54        if (Strings.isEmpty(vc.getDescription())) {
55            warnings.add("The collection has no description");
56        }
57
58        if (vc.getPurpose() == null) {
59            warnings.add("The purpose has not been specified");
60        }
61
62        if (vc.getPurpose() == VirtualCollection.Purpose.FUTURE_USE) {
63            warnings.add("The reproducibility of the collection has been marked 'future use'");
64        }
65
66        if (vc.getReproducibility() == null) {
67            warnings.add("The degree of reproducibility has not been specified");
68        }
69
70        if (vc.getCreators().isEmpty()) {
71            warnings.add("No creators have been specified for the collection");
72        }
73
74        if (!warnings.isEmpty()) {
75            throw new VirtualCollectionRegistryUsageException("Collection is not fit for publication", warnings);
76        }
77    }
78
79    private void validateResources(VirtualCollection vc, List<String> warnings) {
80        int nonPidCount = 0;
81        for (Resource resource : vc.getResources()) {
82            if (!ReferenceValidator.isPid(resource.getRef())) {
83                nonPidCount++;
84            }
85        }
86        if (nonPidCount == 0) {
87            return;
88        }
89
90        if (nonPidCount == 1) {
91            warnings.add(String.format("One resource is not referenced through a persistent identifier", nonPidCount));
92        } else {
93            warnings.add(String.format("%d resources are not referenced through a persistent identifier", nonPidCount));
94        }
95    }
96
97    private void validateGeneratedBy(VirtualCollection vc, List<String> warnings) {
98        final String queryUri = vc.getGeneratedBy().getURI();
99        if (!ReferenceValidator.isPid(queryUri)) {
100            warnings.add("The query URI is not a persistent identifer");
101        }
102    }
103
104}
Note: See TracBrowser for help on using the repository browser.