Changeset 372


Ignore:
Timestamp:
04/21/10 16:36:41 (14 years ago)
Author:
patdui
Message:
  • some fixes
Location:
ComponentRegistry/trunk/ComponentRegistry/src/main
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/bin/registryFiller.sh

    r128 r372  
    22
    33LIB=../share
    4 CLASSPATH=.:./log4j.properties:
     4CLASSPATH=.:./log4j.properties:./registry.properties
    55JAVA=java
    66
  • ComponentRegistry/trunk/ComponentRegistry/src/main/bin/registryMigration.sh

    r131 r372  
    22
    33LIB=../share
    4 CLASSPATH=.:./log4j.properties:
     4CLASSPATH=.:./log4j.properties::./registry.properties
    55JAVA=java
    66
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/tools/RegistryFiller.java

    r207 r372  
    44import java.io.ByteArrayOutputStream;
    55import java.io.File;
    6 import java.io.FileInputStream;
    76import java.io.IOException;
    87import java.net.HttpURLConnection;
    98import java.net.URI;
     9import java.net.URL;
    1010import java.util.ArrayList;
    1111import java.util.Arrays;
     
    3636
    3737/**
    38  * Disclaimer: This class is only usable to automate the initialisation of an ComponentRegistry. It fill the registry with
     38 * Disclaimer: This class is only usable to automate the initialisation of an ComponentRegistry. It fills the registry with
    3939 * 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
    4040 * interface for "proper" adding of profiles/components.
     
    6969
    7070    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());
    7273        String url = properties.getProperty(urlPropName);
    7374        URI uri = UriBuilder.fromUri(url).build();
     
    8283     * Uses a heuristic to resolve components which are linked together through fileName. It will try to find the component with a name
    8384     * 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
    8686     * @throws IOException when properties cannot be loaded
    8787     *
     
    8989    public static void main(String[] args) throws IOException {
    9090        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) {
    9292            printUsage();
    9393        }
    9494        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];
    9997        int nrOfFailed = 0;
    100         for (int i = 4; i < args.length; i++) {
     98        for (int i = 2; i < args.length; i++) {
    10199            File file = new File(args[i]);
    102100            LOG.info("Adding " + (i - 3) + "/" + (args.length - 4) + ": " + file.getName());
    103101            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);
    106105                } else {
    107                     filler.addComponent(file, FilenameUtils.getBaseName(file.getName()), creatorName, description, group);
     106                    filler.addComponent(file, FilenameUtils.getBaseName(file.getName()), description, group);
    108107                }
    109108            } catch (Exception e) {
     
    121120
    122121    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)>");
    124123        System.out.println("It also needs a filled in registry.properties");
    125124        System.exit(0);
    126125    }
    127126
    128     public void addProfile(File file, String name, String creatorName, String description, String group) {
    129         profiles.add(new RegObject(file, name, creatorName, description, group));
    130     }
    131 
    132     public void addComponent(File file, String name, String creatorName, String description, 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));
    134133    }
    135134
     
    174173            MDMarshaller.marshal(comp, out);
    175174            ByteArrayInputStream input = new ByteArrayInputStream(out.toByteArray());
    176             helper.registerProfile(input, regObject.getCreatorName(), regObject.getDescription(), regObject.getName());
     175            helper.registerProfile(input, regObject.getDescription(), regObject.getName());
    177176        }
    178177        if (!unresolvedComponents.isEmpty()) {
     
    275274            MDMarshaller.marshal(comp, out);
    276275            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());
    279277        }
    280278        resolvedComponents = new HashMap<RegObject, CMDComponentSpec>();
     
    306304        private final File file;
    307305        private final String name;
    308         private final String creatorName;
    309306        private final String description;
    310307        private final String group;
    311308
    312         public RegObject(File file, String name, String creatorName, String description, String group) {
     309        public RegObject(File file, String name, String description, String group) {
    313310            this.file = file;
    314311            this.name = name;
    315             this.creatorName = creatorName;
    316312            this.description = description;
    317313            this.group = group;
     
    324320        public String getName() {
    325321            return name;
    326         }
    327 
    328         public String getCreatorName() {
    329             return creatorName;
    330322        }
    331323
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/tools/RegistryMigration.java

    r207 r372  
    5151        for (ComponentDescription desc : descriptions) {
    5252            File file = registry.getComponentFile(desc.getId());
    53             filler.addComponent(file, desc.getName(), desc.getCreatorName(), desc.getDescription(), desc.getGroupName());
     53            filler.addComponent(file, desc.getName(), desc.getDescription(), desc.getGroupName());
    5454        }
    5555    }
     
    5959        for (ProfileDescription desc : descriptions) {
    6060            File file = registry.getProfileFile(desc.getId());
    61             filler.addProfile(file, desc.getName(), desc.getCreatorName(), desc.getDescription(), "");
     61            filler.addProfile(file, desc.getName(), desc.getDescription(), "");
    6262        }
    6363    }
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/tools/RegistryToolHelper.java

    r207 r372  
    3535    }
    3636
    37     public void registerComponent(InputStream input, String creatorName, String description, 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);
    3939        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);
    4142        handleResult(response);
    4243    }
    4344
    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);
    4749        handleResult(response);
    4850    }
    49    
     51
    5052    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)));
    5254    }
    5355
    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 {
    5657        FormDataMultiPart form = new FormDataMultiPart();
    5758        form.field(ComponentRegistryRestService.DATA_FORM_FIELD, input, MediaType.APPLICATION_OCTET_STREAM_TYPE);
Note: See TracChangeset for help on using the changeset viewer.