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/ComponentRegistryImplBase.java

    r4550 r5549  
    1414import clarin.cmdi.componentregistry.ComponentRegistry;
    1515import clarin.cmdi.componentregistry.ComponentRegistryException;
    16 import clarin.cmdi.componentregistry.DeleteFailedException;
     16import clarin.cmdi.componentregistry.ItemNotFoundException;
    1717import clarin.cmdi.componentregistry.MDMarshaller;
     18import clarin.cmdi.componentregistry.UserUnauthorizedException;
    1819import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    19 import clarin.cmdi.componentregistry.components.CMDComponentType;
    2020import clarin.cmdi.componentregistry.components.CMDComponentSpec.Header;
    2121import clarin.cmdi.componentregistry.model.BaseDescription;
    22 import clarin.cmdi.componentregistry.model.ComponentDescription;
    2322import clarin.cmdi.componentregistry.model.ProfileDescription;
    2423
     
    3332    protected abstract MDMarshaller getMarshaller();
    3433
    35     @Override
    36     public List<ComponentDescription> getUsageInComponents(String componentId) throws ComponentRegistryException {
    37         LOG.debug("Checking usage of component {} in components", componentId);
    38         List<ComponentDescription> result = new ArrayList<ComponentDescription>();
    39         List<String> ids = getAllNonDeletedComponentIds();
    40         for (String id : ids) {
    41             CMDComponentSpec spec = getMDComponent(id);
    42             if (spec != null && hasComponentId(componentId, spec.getCMDComponent())) {
    43                 LOG.debug("Component {} used in component {}", componentId, spec.getHeader().getID());
    44                 result.add(getComponentDescription(id));
    45             }
    46         }
    47         return result;
    48     }
    49 
    50     @Override
    51     public List<ProfileDescription> getUsageInProfiles(String componentId) throws ComponentRegistryException {
    52         LOG.debug("Checking usage of component {} in profiles", componentId);
    53         List<ProfileDescription> result = new ArrayList<ProfileDescription>();
    54         for (String id : getAllNonDeletedProfileIds()) {
    55             CMDComponentSpec profile = getMDProfile(id);
    56             if (profile != null && hasComponentId(componentId, profile.getCMDComponent())) {
    57                 LOG.debug("Component {} used in profile {}", componentId, profile.getHeader().getID());
    58                 result.add(getProfileDescription(id));
    59             }
    60         }
    61         return result;
    62     }
     34   
    6335
    6436    /**
     
    7042    @Override
    7143    public List<ProfileDescription> getProfileDescriptionsForMetadaEditor() throws ComponentRegistryException {
    72         // TODO: Below can also be done by accepting and passing a parameter in the ProfileDescriptionDaoImpl, should have better performance
     44        // TODO: Below can also be done by accepting and passing a parameter in the ProfileDescriptionDaoImpl, should have better performance
    7345
    7446        // Get all profile descriptions
     
    7749        ArrayList<ProfileDescription> descriptions = new ArrayList<ProfileDescription>();
    7850        for (String id : descriptionsCollectionIds) {
    79             ProfileDescription profile = getProfileDescription(id);
    80             if (profile.isShowInEditor()) {
    81                 descriptions.add(profile);
     51            try {
     52                ProfileDescription profile = getProfileDescriptionAccessControlled(id);
     53                if (profile.isShowInEditor()) {
     54                    descriptions.add(profile);
     55                }
     56            } catch (UserUnauthorizedException e) {
     57            } catch (ItemNotFoundException e) {
    8258            }
     59
    8360        }
    8461        // Return filtered list
     
    10279    }
    10380
    104     protected static boolean findComponentId(String componentId, List<CMDComponentType> componentReferences) {
    105         for (CMDComponentType cmdComponent : componentReferences) {
    106             if (hasComponentId(componentId, cmdComponent)) {
    107                 return true;
    108             }
    109         }
    110         return false;
    111     }
    112 
    113     private static boolean hasComponentId(String componentId, CMDComponentType cmdComponent) {
    114         if (componentId.equals(cmdComponent.getComponentId())) {
    115             return true;
    116         } else if (findComponentId(componentId, cmdComponent.getCMDComponent())) {
    117             return true;
    118         } else {
    119             return false;
    120         }
    121     }
     81   
     82   
     83   
    12284
    12385    protected void writeXsd(CMDComponentSpec expandedSpec, OutputStream outputStream) {
     
    13597    }
    13698
    137     protected void checkStillUsed(String componentId) throws DeleteFailedException, ComponentRegistryException {
    138         for (String id : getAllNonDeletedProfileIds()) {
    139             CMDComponentSpec spec = getMDProfile(id);
    140             if (spec != null && hasComponentId(componentId, spec.getCMDComponent())) {
    141                 LOG.warn("Cannot delete component {}, still used in profile {} and possibly other profiles and/or components", componentId, spec.getHeader().getID());
    142                 // Profile match - throw
    143                 throw new DeleteFailedException("Component is still in use by other components or profiles. Request component usage for details.");
    144             }
    145         }
    146 
    147         LOG.debug("Component {} is not used in any profiles", componentId);
    148 
    149         for (String id : getAllNonDeletedComponentIds()) {
    150             CMDComponentSpec spec = getMDComponent(id);
    151             if (spec != null && hasComponentId(componentId, spec.getCMDComponent())) {
    152                 LOG.warn("Cannot delete component {}, still used in component {} and possibly other components", componentId, spec.getHeader().getID());
    153                 // Component match -> throw
    154                 throw new DeleteFailedException("Component is still in use by one or more other components. Request component usage for details.");
    155             }
    156         }
    157     }
    15899}
Note: See TracChangeset for help on using the changeset viewer.