source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java @ 5549

Last change on this file since 5549 was 5549, checked in by olhsha@mpi.nl, 10 years ago

Added group service. Tested via the tomcat on loclahots (test URI and postman), old unit tests are adjusted and work well. Todo: retest on localhost tomcat, look at run-time exceptions, add new unit tests, adjust front-end

File size: 3.4 KB
Line 
1package clarin.cmdi.componentregistry.impl;
2
3import java.io.OutputStream;
4import java.io.UnsupportedEncodingException;
5import java.util.ArrayList;
6import java.util.List;
7
8import javax.xml.bind.JAXBException;
9
10import org.apache.commons.lang.StringUtils;
11import org.slf4j.Logger;
12import org.slf4j.LoggerFactory;
13
14import clarin.cmdi.componentregistry.ComponentRegistry;
15import clarin.cmdi.componentregistry.ComponentRegistryException;
16import clarin.cmdi.componentregistry.ItemNotFoundException;
17import clarin.cmdi.componentregistry.MDMarshaller;
18import clarin.cmdi.componentregistry.UserUnauthorizedException;
19import clarin.cmdi.componentregistry.components.CMDComponentSpec;
20import clarin.cmdi.componentregistry.components.CMDComponentSpec.Header;
21import clarin.cmdi.componentregistry.model.BaseDescription;
22import clarin.cmdi.componentregistry.model.ProfileDescription;
23
24/**
25 *
26 * @author Twan Goosen <twan.goosen@mpi.nl>
27 */
28public abstract class ComponentRegistryImplBase implements ComponentRegistry {
29
30    private final static Logger LOG = LoggerFactory.getLogger(ComponentRegistryImplBase.class);
31
32    protected abstract MDMarshaller getMarshaller();
33
34   
35
36    /**
37     *
38     * @return List of profile descriptions ordered by name ascending, only the
39     * ones marked for showing in metadata editor
40     * @throws ComponentRegistryException
41     */
42    @Override
43    public List<ProfileDescription> getProfileDescriptionsForMetadaEditor() throws ComponentRegistryException {
44        // TODO: Below can also be done by accepting and passing a parameter in the ProfileDescriptionDaoImpl, should have better performance
45
46        // Get all profile descriptions
47        List<String> descriptionsCollectionIds = getAllNonDeletedProfileIds();
48        // Filter out ones that do should not be shown for metadata editor
49        ArrayList<ProfileDescription> descriptions = new ArrayList<ProfileDescription>();
50        for (String id : descriptionsCollectionIds) {
51            try {
52                ProfileDescription profile = getProfileDescriptionAccessControlled(id);
53                if (profile.isShowInEditor()) {
54                    descriptions.add(profile);
55                }
56            } catch (UserUnauthorizedException e) {
57            } catch (ItemNotFoundException e) {
58            }
59
60        }
61        // Return filtered list
62        return descriptions;
63    }
64
65    /* HELPER METHODS */
66    protected static String stripRegistryId(String id) {
67        return StringUtils.removeStart(id, ComponentRegistry.REGISTRY_ID);
68    }
69
70    protected static void enrichSpecHeader(CMDComponentSpec spec, BaseDescription description) {
71        Header header = spec.getHeader();
72        header.setID(description.getId());
73        if (StringUtils.isEmpty(header.getName())) {
74            header.setName(description.getName());
75        }
76        if (StringUtils.isEmpty(header.getDescription())) {
77            header.setDescription(description.getDescription());
78        }
79    }
80
81   
82   
83   
84
85    protected void writeXsd(CMDComponentSpec expandedSpec, OutputStream outputStream) {
86        getMarshaller().generateXsd(expandedSpec, outputStream);
87    }
88
89    protected void writeXml(CMDComponentSpec spec, OutputStream outputStream) {
90        try {
91            getMarshaller().marshal(spec, outputStream);
92        } catch (UnsupportedEncodingException e) {
93            LOG.error("Error in encoding: ", e);
94        } catch (JAXBException e) {
95            LOG.error("Cannot marshall spec: " + spec, e);
96        }
97    }
98
99}
Note: See TracBrowser for help on using the repository browser.