Ignore:
Timestamp:
08/11/14 16:07:55 (10 years ago)
Author:
olhsha@mpi.nl
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/AdminRegistry.java

    r4098 r5549  
    1414import clarin.cmdi.componentregistry.ComponentRegistryException;
    1515import clarin.cmdi.componentregistry.ComponentRegistryFactory;
    16 import clarin.cmdi.componentregistry.ComponentStatus;
    1716import clarin.cmdi.componentregistry.DeleteFailedException;
     17import clarin.cmdi.componentregistry.ItemNotFoundException;
    1818import clarin.cmdi.componentregistry.MDMarshaller;
    19 import clarin.cmdi.componentregistry.OwnerUser;
     19import clarin.cmdi.componentregistry.UserCredentials;
    2020import clarin.cmdi.componentregistry.UserUnauthorizedException;
    2121import clarin.cmdi.componentregistry.components.CMDComponentSpec;
     
    5454
    5555    public void submitFile(CMDItemInfo info, Principal userPrincipal)
    56             throws SubmitFailedException {
     56            throws SubmitFailedException, UserUnauthorizedException {
     57        if (userPrincipal == null) {
     58            LOG.info("Null user principal, nothings is submitted.");
     59            return;
     60        }
     61       
    5762        try {
    5863            BaseDescription originalDescription = info.getDataNode()
     
    7277                    IOUtils.toInputStream(info.getContent(), "UTF-8"), null);
    7378            checkId(originalDescription.getId(), description.getId());
    74 
    75             int result = getRegistry(userPrincipal, originalDescription, info)
    76                     .update(description, spec, userPrincipal,
    77                             info.isForceUpdate());
     79            ComponentRegistry cr = this.getRegistry(new UserCredentials(userPrincipal));
     80            int result = cr.update(description, spec, info.isForceUpdate());
    7881            if (result < 0) {
    7982                throw new SubmitFailedException(
     
    8386            throw new SubmitFailedException(e);
    8487        } catch (IOException e) {
     88            throw new SubmitFailedException(e);
     89        } catch (ItemNotFoundException e) {
    8590            throw new SubmitFailedException(e);
    8691        }
     
    109114        BaseDescription desc = info.getDataNode().getDescription();
    110115        try {
    111             deleteFromRegistry(userPrincipal, desc, info);
     116            this.deleteFromRegistry(userPrincipal, desc, info);
    112117            LOG.info("Deleted item: " + id);
    113118        } catch (IOException e) {
     
    119124        } catch (ComponentRegistryException e) {
    120125            throw new SubmitFailedException(e);
     126        } catch (ItemNotFoundException e) {
     127            throw new SubmitFailedException(e);
    121128        }
    122129
     
    125132    private void deleteFromRegistry(Principal userPrincipal,
    126133            BaseDescription desc, CMDItemInfo info) throws IOException,
    127             UserUnauthorizedException, ComponentRegistryException {
    128         ComponentRegistry registry = getRegistry(userPrincipal, desc, info);
     134            UserUnauthorizedException, ComponentRegistryException, ItemNotFoundException {
     135       
     136        if (userPrincipal == null) {
     137           LOG.info("Bnull user principal, nothing is deleted");
     138           return;
     139        }
     140       
     141        ComponentRegistry registry = this.getRegistry(new UserCredentials(userPrincipal));
    129142        LOG.info("Deleting item: " + desc);
    130143        if (desc.isProfile()) {
    131             registry.deleteMDProfile(desc.getId(), userPrincipal);
     144            registry.deleteMDProfile(desc.getId());
    132145        } else {
    133             registry.deleteMDComponent(desc.getId(), userPrincipal,
    134                     info.isForceUpdate());
     146            registry.deleteMDComponent(desc.getId(), info.isForceUpdate());
    135147        }
    136148    }
    137149
    138     private ComponentRegistry getRegistry(Principal userPrincipal,
    139             BaseDescription desc, CMDItemInfo info) {
    140         ComponentRegistry registry = componentRegistryFactory
    141                 .getPublicRegistry();
    142         // TODO: More generic check
    143         if (info.getStatus() == ComponentStatus.PRIVATE /*
    144                                                          * || info.getStatus()
    145                                                          * == ComponentStatus.
    146                                                          * DEVELOPMENT
    147                                                          */) {
    148             registry = componentRegistryFactory.getOtherUserComponentRegistry(
    149                     userPrincipal, info.getStatus(),
    150                     new OwnerUser(Integer.parseInt(desc.getUserId())));
    151         }
    152         return registry;
    153     }
     150    private ComponentRegistry getRegistry(UserCredentials credentials) throws UserUnauthorizedException{
     151        return componentRegistryFactory.getBaseRegistry(credentials);
     152        }
     153   
    154154}
Note: See TracChangeset for help on using the changeset viewer.