Changeset 1631 for ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java
- Timestamp:
- 11/28/11 15:46:02 (13 years ago)
- Location:
- ComponentRegistry/branches/jeaferversion
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/branches/jeaferversion/ComponentRegistry
- Property svn:ignore
-
old new 7 7 profiles.xml 8 8 nb-configuration.xml 9 nbactions-Run without tests.xml
-
- Property svn:ignore
-
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java
r1604 r1631 20 20 import clarin.cmdi.componentregistry.components.CMDComponentSpec.Header; 21 21 import clarin.cmdi.componentregistry.model.AbstractDescription; 22 import clarin.cmdi.componentregistry.model.CommentMapping.Comment; 22 23 import clarin.cmdi.componentregistry.model.ComponentDescription; 23 24 import clarin.cmdi.componentregistry.model.ProfileDescription; … … 33 34 @Override 34 35 public List<ComponentDescription> getUsageInComponents(String componentId) throws ComponentRegistryException { 35 36 37 38 39 40 41 42 43 36 List<ComponentDescription> result = new ArrayList<ComponentDescription>(); 37 List<ComponentDescription> descs = getComponentDescriptions(); 38 for (ComponentDescription desc : descs) { 39 CMDComponentSpec spec = getMDComponent(desc.getId()); 40 if (spec != null && findComponentId(componentId, spec.getCMDComponent())) { 41 result.add(desc); 42 } 43 } 44 return result; 44 45 } 45 46 46 47 @Override 47 48 public List<ProfileDescription> getUsageInProfiles(String componentId) throws ComponentRegistryException { 48 49 50 51 52 53 54 55 49 List<ProfileDescription> result = new ArrayList<ProfileDescription>(); 50 for (ProfileDescription profileDescription : getProfileDescriptions()) { 51 CMDComponentSpec profile = getMDProfile(profileDescription.getId()); 52 if (profile != null && findComponentId(componentId, profile.getCMDComponent())) { 53 result.add(profileDescription); 54 } 55 } 56 return result; 56 57 } 58 59 // public List<Comment> getUsageInComments(String componentId) throws ComponentRegistryException { 60 // List<Comment> result = new ArrayList<Comment>(); 61 // for (Comment comment : getComments()) { 62 // CMDComponentSpec myComment = getMDComment(comment.getId()); 63 // if (myComment != null && findComponentId(componentId, myComment.getCMDComponent())) { 64 // result.add(comment); 65 // System.out.println("get unsage in comments : " + myComment + "\n"); 66 // } 67 // } 68 // 69 // return result; 70 // } 57 71 58 72 /** … … 63 77 @Override 64 78 public List<ProfileDescription> getProfileDescriptionsForMetadaEditor() throws ComponentRegistryException { 65 79 // TODO: Below can also be done by accepting and passing a parameter in the ProfileDescriptionDao, should have better performance 66 80 67 68 69 70 71 72 73 74 75 76 77 81 // Get all profile descriptions 82 List<ProfileDescription> descriptionsCollection = getProfileDescriptions(); 83 // Filter out ones that do should not be shown for metadata editor 84 ArrayList<ProfileDescription> descriptions = new ArrayList<ProfileDescription>(descriptionsCollection.size()); 85 for (ProfileDescription profile : descriptionsCollection) { 86 if (((ProfileDescription) profile).isShowInEditor()) { 87 descriptions.add((ProfileDescription) profile); 88 } 89 } 90 // Return filtered list 91 return descriptions; 78 92 } 79 93 80 94 /* HELPER METHODS */ 81 95 protected static String stripRegistryId(String id) { 82 96 return StringUtils.removeStart(id, ComponentRegistry.REGISTRY_ID); 83 97 } 84 98 85 99 protected static void enrichSpecHeader(CMDComponentSpec spec, AbstractDescription description) { 86 87 88 89 90 91 92 93 100 Header header = spec.getHeader(); 101 header.setID(description.getId()); 102 if (StringUtils.isEmpty(header.getName())) { 103 header.setName(description.getName()); 104 } 105 if (StringUtils.isEmpty(header.getDescription())) { 106 header.setDescription(description.getDescription()); 107 } 94 108 } 95 109 96 110 protected static boolean findComponentId(String componentId, List<CMDComponentType> componentReferences) { 97 98 99 100 101 102 103 104 111 for (CMDComponentType cmdComponent : componentReferences) { 112 if (componentId.equals(cmdComponent.getComponentId())) { 113 return true; 114 } else if (findComponentId(componentId, cmdComponent.getCMDComponent())) { 115 return true; 116 } 117 } 118 return false; 105 119 } 106 120 107 121 protected static void writeXsd(CMDComponentSpec expandedSpec, OutputStream outputStream) { 108 122 MDMarshaller.generateXsd(expandedSpec, outputStream); 109 123 } 110 124 111 125 protected static void writeXml(CMDComponentSpec spec, OutputStream outputStream) { 112 113 114 115 116 117 118 126 try { 127 MDMarshaller.marshal(spec, outputStream); 128 } catch (UnsupportedEncodingException e) { 129 LOG.error("Error in encoding: ", e); 130 } catch (JAXBException e) { 131 LOG.error("Cannot marshall spec: " + spec, e); 132 } 119 133 } 120 134 121 135 protected void checkStillUsed(String componentId) throws DeleteFailedException, ComponentRegistryException { 122 123 124 125 126 136 List<ProfileDescription> profiles = getUsageInProfiles(componentId); 137 List<ComponentDescription> components = getUsageInComponents(componentId); 138 if (!profiles.isEmpty() || !components.isEmpty()) { 139 throw new DeleteFailedException(createStillInUseMessage(profiles, components)); 140 } 127 141 } 128 142 129 143 private String createStillInUseMessage(List<ProfileDescription> profiles, List<ComponentDescription> components) { 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 144 StringBuilder result = new StringBuilder(); 145 if (!profiles.isEmpty()) { 146 result.append("Still used by the following profiles: \n"); 147 for (ProfileDescription profileDescription : profiles) { 148 result.append(" - ").append(profileDescription.getName()).append("\n"); 149 } 150 } 151 if (!components.isEmpty()) { 152 result.append("Still used by the following components: \n"); 153 for (ComponentDescription componentDescription : components) { 154 result.append(" - ").append(componentDescription.getName()).append("\n"); 155 } 156 } 157 result.append("Try to change above mentioned references first."); 158 return result.toString(); 145 159 } 146 160 }
Note: See TracChangeset
for help on using the changeset viewer.