Changeset 5549 for ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java
- Timestamp:
- 08/11/14 16:07:55 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java
r4550 r5549 14 14 import clarin.cmdi.componentregistry.ComponentRegistry; 15 15 import clarin.cmdi.componentregistry.ComponentRegistryException; 16 import clarin.cmdi.componentregistry. DeleteFailedException;16 import clarin.cmdi.componentregistry.ItemNotFoundException; 17 17 import clarin.cmdi.componentregistry.MDMarshaller; 18 import clarin.cmdi.componentregistry.UserUnauthorizedException; 18 19 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 19 import clarin.cmdi.componentregistry.components.CMDComponentType;20 20 import clarin.cmdi.componentregistry.components.CMDComponentSpec.Header; 21 21 import clarin.cmdi.componentregistry.model.BaseDescription; 22 import clarin.cmdi.componentregistry.model.ComponentDescription;23 22 import clarin.cmdi.componentregistry.model.ProfileDescription; 24 23 … … 33 32 protected abstract MDMarshaller getMarshaller(); 34 33 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 63 35 64 36 /** … … 70 42 @Override 71 43 public List<ProfileDescription> getProfileDescriptionsForMetadaEditor() throws ComponentRegistryException { 72 44 // TODO: Below can also be done by accepting and passing a parameter in the ProfileDescriptionDaoImpl, should have better performance 73 45 74 46 // Get all profile descriptions … … 77 49 ArrayList<ProfileDescription> descriptions = new ArrayList<ProfileDescription>(); 78 50 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) { 82 58 } 59 83 60 } 84 61 // Return filtered list … … 102 79 } 103 80 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 122 84 123 85 protected void writeXsd(CMDComponentSpec expandedSpec, OutputStream outputStream) { … … 135 97 } 136 98 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 - throw143 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 -> throw154 throw new DeleteFailedException("Component is still in use by one or more other components. Request component usage for details.");155 }156 }157 }158 99 }
Note: See TracChangeset
for help on using the changeset viewer.