Changeset 4550
- Timestamp:
- 02/25/14 09:35:47 (10 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/CMDComponentSpecExpander.java
r2561 r4550 44 44 CMDComponentSpec spec = getUncachedComponent(componentId); 45 45 if (spec != null) { 46 CMDComponentType nested = getComponentTypeOfAComponent(spec);46 CMDComponentType nested = spec.getCMDComponent(); 47 47 expandNestedComponent(nested.getCMDComponent(), newPath); 48 48 overwriteAttributes(cmdComponentType, nested); … … 63 63 cmdComponents.clear(); 64 64 cmdComponents.addAll(expanded); 65 }66 67 private CMDComponentType getComponentTypeOfAComponent(CMDComponentSpec result) {68 List<CMDComponentType> cmdComponents = result.getCMDComponent();69 if (cmdComponents.size() != 1) {70 LOG.error("Internal error: CMDComponentSpec which is not a profile can only have one "71 + "CMDComponentType (which is the description of the component itself).");72 }73 CMDComponentType cmdComponentType = cmdComponents.get(0);74 return cmdComponentType;75 65 } 76 66 … … 95 85 // Use uncached components and profiles, because we expand and thus change them this change should not be in the cache. 96 86 CMDComponentSpec result = getUncachedComponent(componentId);//registry.getUncachedComponent(componentId); 97 CMDComponentType cmdComponentType = getComponentTypeOfAComponent(result);87 CMDComponentType cmdComponentType = result.getCMDComponent(); 98 88 expandNestedComponent(cmdComponentType.getCMDComponent(), componentId); 99 89 return result; … … 103 93 // Use uncached components and profiles, because we expand and thus change them this change should not be in the cache. 104 94 CMDComponentSpec result = getUncachedProfile(profileId);//registry.getUncachedProfile(profileId); 105 List<CMDComponentType> cmdComponents= result.getCMDComponent();106 expandNestedComponent( cmdComponents, profileId);95 CMDComponentType cmdComponent = result.getCMDComponent(); 96 expandNestedComponent(Collections.singletonList(cmdComponent), profileId); 107 97 return result; 108 98 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/StatisticsPage.java
r1419 r4550 21 21 import clarin.cmdi.componentregistry.model.ComponentDescription; 22 22 import clarin.cmdi.componentregistry.model.ProfileDescription; 23 import java.util.Collection; 24 import java.util.Collections; 23 25 24 26 /** … … 69 71 CMDComponentSpec profile = CMDComponentSpecExpanderDbImpl.expandProfile(pd.getId(), (ComponentRegistryDbImpl) registry); 70 72 Statistics stats = new Statistics(); 71 componentCounter(profile .getCMDComponent(), stats);73 componentCounter(profile, stats); 72 74 item.add(new Label("nrcomp", "" + stats.componentnumber)); 73 75 item.add(new Label("nrprofelem", "" + stats.elementcounter)); … … 82 84 CMDComponentSpec compspec = CMDComponentSpecExpanderDbImpl.expandComponent(cd.getId(), (ComponentRegistryDbImpl) registry); 83 85 Statistics stats = new Statistics(); 84 componentCounter(compspec .getCMDComponent(), stats);86 componentCounter(compspec, stats); 85 87 item.add(new Label("nrcomp", "" + stats.componentnumber)); 86 88 item.add(new Label("nrelem", "" + stats.elementcounter)); … … 88 90 } 89 91 90 private void componentCounter(List<CMDComponentType> components, Statistics stats) { 92 private void componentCounter(CMDComponentSpec components, Statistics stats) { 93 componentCounter(Collections.singleton(components.getCMDComponent()), stats); 94 } 95 96 private void componentCounter(Collection<CMDComponentType> components, Statistics stats) { 91 97 if (components != null) { 92 98 for (CMDComponentType component : components) { -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java
r4098 r4550 28 28 */ 29 29 public abstract class ComponentRegistryImplBase implements ComponentRegistry { 30 30 31 31 private final static Logger LOG = LoggerFactory.getLogger(ComponentRegistryImplBase.class); 32 32 33 33 protected abstract MDMarshaller getMarshaller(); 34 34 35 35 @Override 36 36 public List<ComponentDescription> getUsageInComponents(String componentId) throws ComponentRegistryException { 37 38 39 40 for (String id:ids) {41 42 if (spec != null && findComponentId(componentId, spec.getCMDComponent())) {43 44 45 46 47 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 48 } 49 49 50 50 @Override 51 51 public List<ProfileDescription> getUsageInProfiles(String componentId) throws ComponentRegistryException { 52 53 54 55 56 if (profile != null && findComponentId(componentId, profile.getCMDComponent())) {57 58 59 60 61 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 62 } 63 63 64 64 /** 65 65 * 66 * @return List of profile descriptions ordered by name ascending, only the ones marked for showing in metadata editor 66 * @return List of profile descriptions ordered by name ascending, only the 67 * ones marked for showing in metadata editor 67 68 * @throws ComponentRegistryException 68 69 */ … … 71 72 // TODO: Below can also be done by accepting and passing a parameter in the ProfileDescriptionDaoImpl, should have better performance 72 73 73 74 75 76 77 for (String id:descriptionsCollectionIds) {78 79 80 81 82 83 84 74 // Get all profile descriptions 75 List<String> descriptionsCollectionIds = getAllNonDeletedProfileIds(); 76 // Filter out ones that do should not be shown for metadata editor 77 ArrayList<ProfileDescription> descriptions = new ArrayList<ProfileDescription>(); 78 for (String id : descriptionsCollectionIds) { 79 ProfileDescription profile = getProfileDescription(id); 80 if (profile.isShowInEditor()) { 81 descriptions.add(profile); 82 } 83 } 84 // Return filtered list 85 return descriptions; 85 86 } 86 87 87 88 /* HELPER METHODS */ 88 89 protected static String stripRegistryId(String id) { 89 90 return StringUtils.removeStart(id, ComponentRegistry.REGISTRY_ID); 90 91 } 91 92 92 93 protected static void enrichSpecHeader(CMDComponentSpec spec, BaseDescription description) { 93 94 95 96 97 98 99 100 94 Header header = spec.getHeader(); 95 header.setID(description.getId()); 96 if (StringUtils.isEmpty(header.getName())) { 97 header.setName(description.getName()); 98 } 99 if (StringUtils.isEmpty(header.getDescription())) { 100 header.setDescription(description.getDescription()); 101 } 101 102 } 102 103 103 104 protected static boolean findComponentId(String componentId, List<CMDComponentType> componentReferences) { 104 for (CMDComponentType cmdComponent : componentReferences) { 105 if (componentId.equals(cmdComponent.getComponentId())) { 106 return true; 107 } else if (findComponentId(componentId, cmdComponent.getCMDComponent())) { 108 return true; 109 } 110 } 111 return false; 105 for (CMDComponentType cmdComponent : componentReferences) { 106 if (hasComponentId(componentId, cmdComponent)) { 107 return true; 108 } 109 } 110 return false; 112 111 } 113 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 } 122 114 123 protected void writeXsd(CMDComponentSpec expandedSpec, OutputStream outputStream) { 115 124 getMarshaller().generateXsd(expandedSpec, outputStream); 116 125 } 117 126 118 127 protected void writeXml(CMDComponentSpec spec, OutputStream outputStream) { 119 120 121 122 123 124 125 128 try { 129 getMarshaller().marshal(spec, outputStream); 130 } catch (UnsupportedEncodingException e) { 131 LOG.error("Error in encoding: ", e); 132 } catch (JAXBException e) { 133 LOG.error("Cannot marshall spec: " + spec, e); 134 } 126 135 } 127 136 128 137 protected void checkStillUsed(String componentId) throws DeleteFailedException, ComponentRegistryException { 129 130 131 if (spec != null && findComponentId(componentId, spec.getCMDComponent())) {132 133 134 135 136 137 138 139 140 141 142 if (spec != null && findComponentId(componentId, spec.getCMDComponent())) {143 144 145 146 147 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 } 148 157 } 149 158 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r4135 r4550 38 38 import java.util.ArrayList; 39 39 import java.util.Arrays; 40 import java.util.Collections; 40 41 import java.util.Date; 41 42 import java.util.List; … … 1176 1177 // removing filename from spec before it gets extended. 1177 1178 // recursion over all the components 1178 setFileNamesFromListToNull( spec.getCMDComponent());1179 setFileNamesFromListToNull(Collections.singletonList(spec.getCMDComponent())); 1179 1180 1180 1181 try { … … 1236 1237 // ComponentRegistryException 1237 1238 registry.getExpander().expandNestedComponent( 1238 specCopy.getCMDComponent(), desc.getId());1239 Collections.singletonList(specCopy.getCMDComponent()), desc.getId()); 1239 1240 } catch (JAXBException ex) { 1240 1241 throw new ComponentRegistryException( -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/MDValidator.java
r4098 r4550 29 29 30 30 public class MDValidator implements Validator { 31 31 32 32 private final static Logger LOG = LoggerFactory.getLogger(MDValidator.class); 33 33 static final String MISMATCH_ERROR = "Cannot register component as a profile or vica versa."; … … 57 57 * @param desc 58 58 * @param registry (registry you currently used) 59 * @param userRegistry can be null, We get user registry as well so we can give nice error messages if needed. Can be the same as 59 * @param userRegistry can be null, We get user registry as well so we can 60 * give nice error messages if needed. Can be the same as 60 61 * @param registry 61 62 */ 62 63 public MDValidator(InputStream input, BaseDescription description, ComponentRegistry registry, ComponentRegistry userRegistry, ComponentRegistry publicRegistry, MDMarshaller marshaller) { 63 64 65 66 67 68 69 } 70 64 this.input = input; 65 this.description = description; 66 this.registry = registry; 67 this.userRegistry = userRegistry; 68 this.publicRegistry = publicRegistry; 69 this.marshaller = marshaller; 70 } 71 71 72 @Override 72 73 public List<String> getErrorMessages() { 73 74 } 75 74 return errorMessages; 75 } 76 76 77 @Override 77 78 public boolean validate() { 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 validateComponents(spec.getCMDComponent());115 116 117 118 119 120 } 121 79 try { 80 clarin.cmdi.schema.cmd.Validator validator = new clarin.cmdi.schema.cmd.Validator(new URL(Configuration.getInstance().getGeneralComponentSchema())); 81 validator.setResourceResolver(new ComponentRegistryResourceResolver()); 82 // We may need to reuse the input stream, so save it to a byte array first 83 originalSpecBytes = getBytesFromInputStream(); 84 StreamSource source = new StreamSource(new ByteArrayInputStream(originalSpecBytes)); 85 if (!validator.validateProfile(source)) { 86 final List<Message> validatorMessages = validator.getMessages(); 87 if (validatorMessages.size() > 0) { 88 for (Message message : validatorMessages) { 89 errorMessages.add(PARSE_ERROR + message.getText()); 90 } 91 } else { 92 errorMessages.add(PARSE_ERROR + UNKNOWN_VALIDATION_ERROR); 93 } 94 } else { 95 spec = unmarshalSpec(originalSpecBytes); 96 if (spec.isIsProfile() != description.isProfile()) { 97 errorMessages.add(MISMATCH_ERROR); 98 } 99 } 100 } catch (MalformedURLException e) { 101 errorMessages.add(SCHEMA_ERROR + e.getMessage()); 102 LOG.error(SCHEMA_ERROR, e); 103 } catch (JAXBException e) { 104 errorMessages.add(PARSE_ERROR + e.getMessage()); 105 LOG.error(PARSE_ERROR, e); 106 } catch (ValidatorException e) { 107 errorMessages.add(PARSE_ERROR + e.getMessage()); 108 LOG.error(PARSE_ERROR, e); 109 } catch (IOException e) { 110 errorMessages.add(IO_ERROR + e.getMessage()); 111 LOG.error(IO_ERROR, e); 112 } 113 if (errorMessages.isEmpty()) { 114 try { 115 validateComponents(spec); 116 } catch (ComponentRegistryException e) { 117 errorMessages.add(COMPONENT_REGISTRY_EXCEPTION_ERROR + e); 118 } 119 } 120 return errorMessages.isEmpty(); 121 } 122 122 123 private byte[] getBytesFromInputStream() throws IOException { 123 int len; 124 byte[] b = new byte[4096]; 125 final ByteArrayOutputStream bOS = new ByteArrayOutputStream(); 126 127 while ((len = input.read(b)) > 0) { 128 bOS.write(b, 0, len); 129 } 130 131 return bOS.toByteArray(); 132 } 133 124 int len; 125 byte[] b = new byte[4096]; 126 final ByteArrayOutputStream bOS = new ByteArrayOutputStream(); 127 128 while ((len = input.read(b)) > 0) { 129 bOS.write(b, 0, len); 130 } 131 132 return bOS.toByteArray(); 133 } 134 135 private void validateComponents(CMDComponentSpec componentSpec) throws ComponentRegistryException { 136 validateComponents(Collections.singletonList(componentSpec.getCMDComponent())); 137 } 138 134 139 private void validateComponents(List<CMDComponentType> cmdComponents) throws ComponentRegistryException { 135 136 137 138 139 } 140 140 for (CMDComponentType cmdComponentType : cmdComponents) { 141 validateDescribedComponents(cmdComponentType); 142 validateComponents(cmdComponentType.getCMDComponent());//Recursion 143 } 144 } 145 141 146 private void validateDescribedComponents(CMDComponentType cmdComponentType) throws ComponentRegistryException { 142 143 } 144 147 checkPublicComponents(cmdComponentType); 148 } 149 145 150 private void checkPublicComponents(CMDComponentType cmdComponentType) throws ComponentRegistryException { 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 } 173 151 if (isDefinedInSeparateFile(cmdComponentType)) { 152 String id = cmdComponentType.getComponentId(); 153 CMDComponentSpec registeredComponent; 154 if (registry.isPublic()) { // public registry requires only published components 155 registeredComponent = registry.getMDComponent(id); 156 if (registeredComponent == null) { 157 String error = cmdComponentType.getComponentId(); 158 if (userRegistry != null) { 159 ComponentDescription desc = userRegistry.getComponentDescription(id); 160 if (desc != null) { 161 error = desc.getName() + " (" + cmdComponentType.getComponentId() + ")"; 162 } 163 } 164 errorMessages.add(COMPONENT_NOT_PUBLICLY_REGISTERED_ERROR + error); 165 } 166 } else { //User registry, can link to components from public registry and the user's registry 167 registeredComponent = registry.getMDComponent(id); 168 if (registeredComponent == null) { 169 registeredComponent = publicRegistry.getMDComponent(id); 170 if (registeredComponent == null) { 171 errorMessages.add(COMPONENT_NOT_REGISTERED_ERROR + cmdComponentType.getComponentId()); 172 } 173 } 174 175 } 176 } 177 } 178 174 179 private boolean isDefinedInSeparateFile(CMDComponentType cmdComponentType) { 175 180 return cmdComponentType.getName() == null; 176 181 } 177 182 … … 179 184 * Do not call before having called {@link #validate() }! 180 185 * 181 * @return the spec unmarshalled during {@link #validate() }. If this has not been called, returns null. 186 * @return the spec unmarshalled during {@link #validate() }. If this has 187 * not been called, returns null. 182 188 */ 183 189 public CMDComponentSpec getCMDComponentSpec() { 184 190 return spec; 185 191 } 186 192 187 193 /** 188 * Creates a fresh (re-unmarshalled) copy of the specification this instance has validated. If you are not going to alter this copy, 189 * you can re-use and share the copy used during validation by getting it from {@link #getCMDComponentSpec() }. 194 * Creates a fresh (re-unmarshalled) copy of the specification this instance 195 * has validated. If you are not going to alter this copy, you can re-use 196 * and share the copy used during validation by getting it from {@link #getCMDComponentSpec() 197 * }. 190 198 * <em>Do not call before having called {@link #validate() }!</em> 191 199 * 192 * @return a freshly unmarshalled copy of the spec based on the bytes collected from the input stream passed to {@link #validate() }. 193 * If this has not been called, returns null. 194 * @throws JAXBException exception occurred while marshalling from the input bytes 200 * @return a freshly unmarshalled copy of the spec based on the bytes 201 * collected from the input stream passed to {@link #validate() }. If this 202 * has not been called, returns null. 203 * @throws JAXBException exception occurred while marshalling from the input 204 * bytes 195 205 * @see #validate() 196 206 * @see #getCMDComponentSpec() 197 207 */ 198 208 public CMDComponentSpec getCopyOfCMDComponentSpec() throws JAXBException { 199 200 201 } 202 209 // Re-unmarshall original bytes 210 return unmarshalSpec(originalSpecBytes); 211 } 212 203 213 private CMDComponentSpec unmarshalSpec(byte[] inputBytes) throws JAXBException { 204 214 return marshaller.unmarshal(CMDComponentSpec.class, new ByteArrayInputStream(inputBytes), null); 205 215 } 206 216 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/CMDComponentSetFilenamesToNullTestRunner.java
r3449 r4550 11 11 import java.io.IOException; 12 12 import java.io.InputStreamReader; 13 import java.util.Collections; 13 14 import java.util.List; 14 15 import javax.xml.bind.JAXBException; … … 16 17 17 18 /** 18 * non-automated developers. test, with and input (a valid 19 * component/prifile xml file and a path to it) and the output (the file20 * where all filenames are set to null, in the same directory as the21 * input file)22 * @author olhsha 19 * non-automated developers. test, with and input (a valid component/prifile xml 20 * file and a path to it) and the output (the file where all filenames are set 21 * to null, in the same directory as the input file) 22 * 23 * @author olhsha 23 24 * @author George.Georgovassilis@mpi.nl 24 25 */ … … 26 27 27 28 /** 28 * 29 * 29 30 * @author olhsha 30 31 */ 31 32 /** 32 33 * makes a new component (with filled-in filename) 33 * 34 * @param filename 35 * is assigned to the filed "filename" of the new component 36 * @param childcomponents 37 * is assigned to the list of child components of the new 38 * component 34 * 35 * @param filename is assigned to the filed "filename" of the new component 36 * @param childcomponents is assigned to the list of child components of the 37 * new component 39 38 * @return the reference to the new component 40 39 */ 41 40 protected CMDComponentType makeTestComponent(String filename, 42 43 44 45 46 47 48 49 50 51 52 53 41 List<CMDComponentType> childcomponents) { 42 43 CMDComponentType component = new CMDComponentType(); 44 component.setFilename(filename); 45 List<CMDComponentType> kids = component.getCMDComponent(); 46 assertFalse(kids == null); 47 assertEquals(kids.size(), 0); 48 if (childcomponents != null) { 49 kids.addAll(childcomponents); 50 } 51 ; 52 return component; 54 53 } 55 54 … … 58 57 */ 59 58 private void checkNullnessOfFilenamesInComponent(CMDComponentType component) { 60 61 59 assertEquals(component.getFilename(), null); 60 checkNullnessOfFilenamesInListOfComponents(component.getCMDComponent()); 62 61 } 63 62 … … 66 65 */ 67 66 private void checkNullnessOfFilenamesInListOfComponents( 68 69 70 71 67 List<CMDComponentType> listofcomponents) { 68 for (CMDComponentType currentcomponent : listofcomponents) { 69 checkNullnessOfFilenamesInComponent(currentcomponent); 70 } 72 71 } 73 72 … … 77 76 */ 78 77 private boolean checkNonNullnessOfFilenamesInComponent( 79 80 81 82 83 84 85 86 87 88 78 CMDComponentType component) { 79 80 String filename = component.getFilename(); 81 System.out.println(filename); 82 boolean check = (filename == null); 83 if (check) { 84 return false; 85 } 86 return checkNonNullnessOfFilenamesInListOfComponents(component 87 .getCMDComponent()); 89 88 } 90 89 … … 94 93 */ 95 94 private boolean checkNonNullnessOfFilenamesInListOfComponents( 96 97 98 99 100 101 102 103 104 95 List<CMDComponentType> listofcomponents) { 96 boolean check; 97 for (CMDComponentType currentcomponent : listofcomponents) { 98 check = checkNonNullnessOfFilenamesInComponent(currentcomponent); 99 if (!check) { 100 return false; 101 } 102 } 103 return true; 105 104 } 106 105 … … 109 108 */ 110 109 private void addDummyFilenamesToComponent(CMDComponentType component) { 111 112 113 114 115 116 110 if (component != null) { 111 component.setFilename("Dummy"); 112 List<CMDComponentType> listofcomponents = component 113 .getCMDComponent(); 114 addDummyFilenamesToListOfComponents(listofcomponents); 115 } 117 116 } 118 117 … … 121 120 */ 122 121 private void addDummyFilenamesToListOfComponents( 123 124 125 126 122 List<CMDComponentType> listofcomponents) { 123 for (CMDComponentType currentcomponent : listofcomponents) { 124 addDummyFilenamesToComponent(currentcomponent); 125 } 127 126 } 128 127 … … 131 130 */ 132 131 private CMDComponentSpec makeTestFromFile(String filename) 133 134 135 136 137 138 List<CMDComponentType> listofcomponents = compspec.getCMDComponent();139 140 141 132 throws IOException, JAXBException { 133 FileInputStream is = new FileInputStream(filename); 134 String profilestring = RegistryTestHelper.getStringFromStream(is); 135 CMDComponentSpec compspec = RegistryTestHelper 136 .getComponentFromString(profilestring); // calling unmarchaller 137 List<CMDComponentType> listofcomponents = Collections.singletonList(compspec.getCMDComponent()); 138 addDummyFilenamesToListOfComponents(listofcomponents); 139 assertTrue(checkNonNullnessOfFilenamesInListOfComponents(listofcomponents)); 140 return compspec; 142 141 } 143 142 … … 147 146 */ 148 147 private void writeDummiedXML(String filenamein, String filenameout) 149 150 151 152 148 throws IOException, JAXBException { 149 CMDComponentSpec compspec = makeTestFromFile(filenamein); 150 String os = RegistryTestHelper.getXml(compspec); 151 RegistryTestHelper.writeStringToFile(os, filenameout); 153 152 } 154 153 … … 157 156 */ 158 157 private void setFileNamesToNullInFile(String dirName, String fileNameInit, 159 160 161 162 163 164 165 166 167 168 169 170 List<CMDComponentType> listofcomponents = compspec.getCMDComponent();171 172 173 174 175 176 177 158 String fileNameDummied, String fileNameUnDummied) 159 throws IOException, JAXBException { 160 161 String path = RegistryTestHelper.openTestDir(dirName); 162 writeDummiedXML(path + fileNameInit, path + fileNameDummied); 163 164 FileInputStream is = new FileInputStream(path + fileNameDummied); 165 String dummiedcontent = RegistryTestHelper.getStringFromStream(is); 166 CMDComponentSpec compspec = RegistryTestHelper 167 .getComponentFromString(dummiedcontent); // calling unmarchaller 168 169 List<CMDComponentType> listofcomponents = Collections.singletonList(compspec.getCMDComponent()); 170 171 IComponentRegistryRestService testrestservice = new ComponentRegistryRestService(); 172 testrestservice.setFileNamesFromListToNull(listofcomponents); 173 checkNullnessOfFilenamesInListOfComponents(listofcomponents); 174 175 String os = RegistryTestHelper.getXml(compspec); 176 RegistryTestHelper.writeStringToFile(os, path + fileNameUnDummied); 178 177 } 179 178 … … 184 183 */ 185 184 public static void main(String args[]) throws java.io.IOException, 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 185 JAXBException { 186 187 BufferedReader buffer = new BufferedReader(new InputStreamReader( 188 System.in)); 189 190 System.out.println(""); 191 System.out 192 .print("Sub-directory (of target/) name? (up to 32 symbols): "); 193 String dirName = buffer.readLine(); 194 System.out.println(""); 195 System.out 196 .println("(Watch out: this is a temorary directory, which is removed after any new clean+build)"); 197 System.out.println(dirName); 198 199 System.out.println(""); 200 System.out.println("Check if your file is in this temorary directory"); 201 System.out.print("and input the file name (up to 32 symbols): "); 202 String fileName = buffer.readLine(); 203 System.out.println(fileName); 204 205 System.out.println("Bedankt, ff wachten .. "); 206 207 String fileNameDummied = "Dummied" + fileName; 208 String fileNameUnDummied = "Nulled" + fileName; 209 210 CMDComponentSetFilenamesToNullTestRunner helper = new CMDComponentSetFilenamesToNullTestRunner(); 211 212 helper.setFileNamesToNullInFile(dirName, fileName, fileNameDummied, 213 fileNameUnDummied); 214 215 System.out.println("Now look up the directory target/" + dirName); 217 216 } 218 217 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
r4131 r4550 161 161 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); 162 162 assertNotNull(component); 163 assertEquals("Access", component.getCMDComponent().get (0).getName());163 assertEquals("Access", component.getCMDComponent().getName()); 164 164 component = getResource().path("/registry/components/" + id2) 165 165 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 166 166 assertNotNull(component); 167 assertEquals("Access", component.getCMDComponent().get (0).getName());167 assertEquals("Access", component.getCMDComponent().getName()); 168 168 169 169 assertEquals(id2, component.getHeader().getID()); … … 536 536 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); 537 537 assertNotNull(profile); 538 assertEquals("Actor", profile.getCMDComponent().get (0).getName());538 assertEquals("Actor", profile.getCMDComponent().getName()); 539 539 profile = getResource().path("/registry/profiles/" + id2) 540 540 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 541 541 assertNotNull(profile); 542 assertEquals("Actor", profile.getCMDComponent().get (0).getName());542 assertEquals("Actor", profile.getCMDComponent().getName()); 543 543 544 544 assertEquals(id2, profile.getHeader().getID()); … … 796 796 assertEquals("Published", profileDescription.getDescription()); 797 797 CMDComponentSpec spec = getPublicSpec(profileDescription); 798 assertEquals("publishedName", spec.getCMDComponent().get (0).getName());798 assertEquals("publishedName", spec.getCMDComponent().getName()); 799 799 } 800 800 … … 845 845 assertEquals("Published", componentDescription.getDescription()); 846 846 CMDComponentSpec spec = getPublicSpec(componentDescription); 847 assertEquals("publishedName", spec.getCMDComponent().get (0).getName());847 assertEquals("publishedName", spec.getCMDComponent().getName()); 848 848 } 849 849 … … 1185 1185 CMDComponentSpec spec = getUserComponent(desc); 1186 1186 assertNotNull(spec); 1187 assertEquals("Access", spec.getCMDComponent().get (0).getName());1187 assertEquals("Access", spec.getCMDComponent().getName()); 1188 1188 components = getUserComponents(); 1189 1189 assertEquals(1, components.size()); … … 1214 1214 spec = getUserComponent(desc); 1215 1215 assertNotNull(spec); 1216 assertEquals("TESTNAME", spec.getCMDComponent().get (0).getName());1216 assertEquals("TESTNAME", spec.getCMDComponent().getName()); 1217 1217 components = getUserComponents(); 1218 1218 assertEquals(1, components.size()); … … 1247 1247 CMDComponentSpec spec = getUserProfile(desc); 1248 1248 assertNotNull(spec); 1249 assertEquals("Actor", spec.getCMDComponent().get (0).getName());1249 assertEquals("Actor", spec.getCMDComponent().getName()); 1250 1250 profiles = getUserProfiles(); 1251 1251 assertEquals(1, profiles.size()); … … 1276 1276 spec = getUserProfile(desc); 1277 1277 assertNotNull(spec); 1278 assertEquals("TESTNAME", spec.getCMDComponent().get (0).getName());1278 assertEquals("TESTNAME", spec.getCMDComponent().getName()); 1279 1279 profiles = getUserProfiles(); 1280 1280 assertEquals(1, profiles.size()); -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/MDValidatorTest.java
r4098 r4550 294 294 // Spec content should match XML 295 295 assertTrue(cmdComponentSpec.isIsProfile()); 296 assertEquals("Actor", cmdComponentSpec.getCMDComponent().get(0) 297 .getName()); 296 assertEquals("Actor", cmdComponentSpec.getCMDComponent().getName()); 298 297 299 298 // Spec copy should be a freshly unmarshalled copy … … 303 302 // Content should still match XML 304 303 assertTrue(specCopy.isIsProfile()); 305 assertEquals("Actor", specCopy.getCMDComponent().get (0).getName());304 assertEquals("Actor", specCopy.getCMDComponent().getName()); 306 305 } 307 306
Note: See TracChangeset
for help on using the changeset viewer.