Changeset 372
- Timestamp:
- 04/21/10 16:36:41 (14 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src/main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/bin/registryFiller.sh
r128 r372 2 2 3 3 LIB=../share 4 CLASSPATH=.:./log4j.properties: 4 CLASSPATH=.:./log4j.properties:./registry.properties 5 5 JAVA=java 6 6 -
ComponentRegistry/trunk/ComponentRegistry/src/main/bin/registryMigration.sh
r131 r372 2 2 3 3 LIB=../share 4 CLASSPATH=.:./log4j.properties: 4 CLASSPATH=.:./log4j.properties::./registry.properties 5 5 JAVA=java 6 6 -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/tools/RegistryFiller.java
r207 r372 4 4 import java.io.ByteArrayOutputStream; 5 5 import java.io.File; 6 import java.io.FileInputStream;7 6 import java.io.IOException; 8 7 import java.net.HttpURLConnection; 9 8 import java.net.URI; 9 import java.net.URL; 10 10 import java.util.ArrayList; 11 11 import java.util.Arrays; … … 36 36 37 37 /** 38 * Disclaimer: This class is only usable to automate the initialisation of an ComponentRegistry. It fill the registry with38 * Disclaimer: This class is only usable to automate the initialisation of an ComponentRegistry. It fills the registry with 39 39 * components/profiles from the file system, it is not meant to be used as a quick help setting up a Clarin Registry. Use the registry web 40 40 * interface for "proper" adding of profiles/components. … … 69 69 70 70 public RegistryFiller(String urlPropName) throws IOException { 71 properties.load(new FileInputStream("/registry.properties")); 71 URL urlResource = ClassLoader.getSystemResource("registry.properties"); 72 properties.load(urlResource.openStream()); 72 73 String url = properties.getProperty(urlPropName); 73 74 URI uri = UriBuilder.fromUri(url).build(); … … 82 83 * Uses a heuristic to resolve components which are linked together through fileName. It will try to find the component with a name 83 84 * equal to the filename (without extension) and set the registered id correct. 84 * @param args RegistryFiller "P.Duin" "Test files" imdi -c 85 * /Users/patdui/Workspace/Clarin/metadata/toolkit/components/imdi/component*.xml 85 * @param args RegistryFiller "Test files" imdi /Users/patdui/Workspace/Clarin/metadata/toolkit/components/imdi/component*.xml 86 86 * @throws IOException when properties cannot be loaded 87 87 * … … 89 89 public static void main(String[] args) throws IOException { 90 90 LOG.info("RegistryFiller started with arguments: " + Arrays.toString(args)); 91 if (args.length == 0 || args.length < 5) {91 if (args.length == 0 || args.length < 3) { 92 92 printUsage(); 93 93 } 94 94 RegistryFiller filler = new RegistryFiller(FILLER_URL_PROP); 95 String creatorName = args[0]; 96 String description = args[1]; 97 String group = args[2]; 98 boolean registerProfiles = "-p".equals(args[3]); //Otherwise -c 95 String description = args[0]; 96 String group = args[1]; 99 97 int nrOfFailed = 0; 100 for (int i = 4; i < args.length; i++) {98 for (int i = 2; i < args.length; i++) { 101 99 File file = new File(args[i]); 102 100 LOG.info("Adding " + (i - 3) + "/" + (args.length - 4) + ": " + file.getName()); 103 101 try { 104 if (registerProfiles) { 105 filler.addProfile(file, FilenameUtils.getBaseName(file.getName()), creatorName, description, group); 102 CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, file); 103 if (spec.isIsProfile()) { 104 filler.addProfile(file, FilenameUtils.getBaseName(file.getName()), description, group); 106 105 } else { 107 filler.addComponent(file, FilenameUtils.getBaseName(file.getName()), creatorName,description, group);106 filler.addComponent(file, FilenameUtils.getBaseName(file.getName()), description, group); 108 107 } 109 108 } catch (Exception e) { … … 121 120 122 121 private static void printUsage() { 123 System.out.println("usage: <creatorName> <description> <groupType> <-c|-p (components or profiles)> <xml file(s)>");122 System.out.println("usage: <description> <groupType> <xml file(s)>"); 124 123 System.out.println("It also needs a filled in registry.properties"); 125 124 System.exit(0); 126 125 } 127 126 128 public void addProfile(File file, String name, String creatorName, Stringdescription, String group) {129 profiles.add(new RegObject(file, name, creatorName,description, group));130 } 131 132 public void addComponent(File file, String name, String creatorName, Stringdescription, String group) {133 components.add(new RegObject(file, name, creatorName,description, group));127 public void addProfile(File file, String name, String description, String group) { 128 profiles.add(new RegObject(file, name, description, group)); 129 } 130 131 public void addComponent(File file, String name, String description, String group) { 132 components.add(new RegObject(file, name, description, group)); 134 133 } 135 134 … … 174 173 MDMarshaller.marshal(comp, out); 175 174 ByteArrayInputStream input = new ByteArrayInputStream(out.toByteArray()); 176 helper.registerProfile(input, regObject.get CreatorName(), regObject.getDescription(), regObject.getName());175 helper.registerProfile(input, regObject.getDescription(), regObject.getName()); 177 176 } 178 177 if (!unresolvedComponents.isEmpty()) { … … 275 274 MDMarshaller.marshal(comp, out); 276 275 ByteArrayInputStream input = new ByteArrayInputStream(out.toByteArray()); 277 helper.registerComponent(input, regObject.getCreatorName(), regObject.getDescription(), regObject.getGroup(), regObject 278 .getName()); 276 helper.registerComponent(input, regObject.getDescription(), regObject.getGroup(), regObject.getName()); 279 277 } 280 278 resolvedComponents = new HashMap<RegObject, CMDComponentSpec>(); … … 306 304 private final File file; 307 305 private final String name; 308 private final String creatorName;309 306 private final String description; 310 307 private final String group; 311 308 312 public RegObject(File file, String name, String creatorName, Stringdescription, String group) {309 public RegObject(File file, String name, String description, String group) { 313 310 this.file = file; 314 311 this.name = name; 315 this.creatorName = creatorName;316 312 this.description = description; 317 313 this.group = group; … … 324 320 public String getName() { 325 321 return name; 326 }327 328 public String getCreatorName() {329 return creatorName;330 322 } 331 323 -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/tools/RegistryMigration.java
r207 r372 51 51 for (ComponentDescription desc : descriptions) { 52 52 File file = registry.getComponentFile(desc.getId()); 53 filler.addComponent(file, desc.getName(), desc.get CreatorName(), desc.getDescription(), desc.getGroupName());53 filler.addComponent(file, desc.getName(), desc.getDescription(), desc.getGroupName()); 54 54 } 55 55 } … … 59 59 for (ProfileDescription desc : descriptions) { 60 60 File file = registry.getProfileFile(desc.getId()); 61 filler.addProfile(file, desc.getName(), desc.get CreatorName(), desc.getDescription(), "");61 filler.addProfile(file, desc.getName(), desc.getDescription(), ""); 62 62 } 63 63 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/tools/RegistryToolHelper.java
r207 r372 35 35 } 36 36 37 public void registerComponent(InputStream input, String creatorName, Stringdescription, String group, String name) throws IOException {38 FormDataMultiPart form = createForm(input, creatorName,description, name);37 public void registerComponent(InputStream input, String description, String group, String name) throws IOException { 38 FormDataMultiPart form = createForm(input, description, name); 39 39 form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, group); 40 RegisterResponse response = getAuthenticatedResource("/components").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 40 RegisterResponse response = getAuthenticatedResource("/components").type(MediaType.MULTIPART_FORM_DATA).post( 41 RegisterResponse.class, form); 41 42 handleResult(response); 42 43 } 43 44 44 public void registerProfile(InputStream input, String creatorName, String description, String name) throws IOException { 45 FormDataMultiPart form = createForm(input, creatorName, description, name); 46 RegisterResponse response = getAuthenticatedResource("/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 45 public void registerProfile(InputStream input, String description, String name) throws IOException { 46 FormDataMultiPart form = createForm(input, description, name); 47 RegisterResponse response = getAuthenticatedResource("/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 48 form); 47 49 handleResult(response); 48 50 } 49 51 50 52 private Builder getAuthenticatedResource(String path) { 51 return service.path(path).header(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(userName +":"+password)));53 return service.path(path).header(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(userName + ":" + password))); 52 54 } 53 55 54 55 private FormDataMultiPart createForm(InputStream input, String creatorName, String description, String name) throws IOException { 56 private FormDataMultiPart createForm(InputStream input, String description, String name) throws IOException { 56 57 FormDataMultiPart form = new FormDataMultiPart(); 57 58 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, input, MediaType.APPLICATION_OCTET_STREAM_TYPE);
Note: See TracChangeset
for help on using the changeset viewer.