Package eu.planets_project.ifr.core.wee.api.ReportingLog

Examples of eu.planets_project.ifr.core.wee.api.ReportingLog.Message


                title = null;
                log.info("Processing file #" + (count + 1));
                try {
                    // Identify
                    String[] types = runIdentification(dgo, wfResult);
                    log.info(new Message("Identification", new Parameter("File", dgo.getTitle()), new Parameter(
                            "Result", Arrays.asList(types).toString())));

                    // Extract metadata - will otherwise get lost between steps!
                    List<Metadata> mList = dgo.getMetadata();

                    if ((mList != null) && (mList.size() > 0)) {
                        metadata = mList.get(0).getContent();
                    }

                    if (metadata == null) {
                        log.warn("No metadata contained in DigitalObject!");
                        log.info("Add title: " + dgo.getTitle());
                        title = dgo.getTitle();
                        if(title.contains("."))
                        {
                          title = title.substring(0, title.lastIndexOf("."));
                        }
                        URI myMigrateToURI =
                              this.getServiceCallConfigs(this.migrate).getPropertyAsURI(SER_PARAM_MIGRATE_TO);
                        String newExtension =
                              FormatRegistryFactory.getFormatRegistry().getFirstExtension(myMigrateToURI);
                        title = title + "." + newExtension;
                    } else {
                        log.info("Extracted metadata: " + metadata);
                    }
                   
                    // Migrate
                    try {
                        FormatRegistry fr = FormatRegistryFactory.getFormatRegistry();
                        String ext = fr.getFirstExtension(new URI(types[0]));
                        log.info("Getting extension: " + ext);
                        if (ext != null) {
                            dgo = runMigrateService(dgo, fr.createExtensionUri(ext), wfResult);
                            dgo = new DigitalObject.Builder(dgo.getContent())
                                .title(title)
                                .build();
                            objects.add(dgo);
                            log.info(new Message("Migration", new Parameter("Input", ext), new Parameter("Result", dgo
                                    .getTitle())));
                        }
                    } catch (URISyntaxException e) {
                        throw new RuntimeException(e);
                    }
View Full Code Here


        wfResultItem.addLogInfo("for endpoint: " + wri.getServiceEndpoint());
      }

      String initialFileName = dgoA.getPermanentUri().toString().substring(
          dgoA.getPermanentUri().toString().lastIndexOf(URI_SEPARATOR) + 1 );
              wfResultItem.addLogInfo(new Message("Characterisation", new Parameter("File", initialFileName), new Parameter(
                    "Result", "Properties")));
              wfResultItem.addLogInfo(new Message("Identification", new Parameter("File", initialFileName), new Parameter(
                    "Result", Arrays.asList(types).toString())));

            // Extract metadata - will otherwise get lost between steps!
            String metadata = "";
            List<Metadata> mList = dgoA.getMetadata();
            if ((mList != null) && (mList.size() > 0)) {
                metadata = mList.get(0).getContent();
            }

            if (metadata == null) {
              wfResultItem.addLogInfo("No metadata contained in DigitalObject!");
            } else {
              wfResultItem.addLogInfo("Extracted metadata: " + metadata);
            }           

      // Migration service
          wfResultItem.addLogInfo("STEP 3: Starting migration");
      URI dgoBRef = runMigration(migrate, dgoA.getPermanentUri(), true);
      wfResultItem.addLogInfo("Completed migration. URI: " + dgoBRef);
     
      String migrationEndpoint = "";
      for (WorkflowResultItem wri : getWFResult().getWorkflowResultItems()) {
        wfResultItem.addLogInfo("for Migration parameter: " + Arrays.asList(wri.getServiceParameters()).toString());
        wfResultItem.addLogInfo("for endpoint: " + wri.getServiceEndpoint());
        if (wri.getServiceParameters().size() > 0
            && Arrays.asList(wri.getServiceParameters()).toString().contains("migration")) {
          wfResultItem.addLogInfo(new Message("Migration", new Parameter("Input", Arrays.asList(types).toString())
          , new Parameter("Result", Arrays.asList(wri.getServiceParameters()).toString())));
          migrationEndpoint = wri.getServiceEndpoint();
        }
      }

      // Evaluate migrated file data
      String migratedFileName = "";
      String migratedFileSize = "";
     
      if (dgoBRef != null) {
        try {
            DataRegistry dataRegistry = DataRegistryFactory.getDataRegistry();
          URI baseUri = new PDURI(dgoBRef.normalize()).formDataRegistryRootURI();
          wfResultItem.addLogInfo("base URI " + baseUri);
     
          DigitalObject obj = dataRegistry.getDigitalObjectManager(baseUri).retrieve(dgoBRef);   
          wfResultItem.addLogInfo("obj: " + obj.toString());

          InputStream contentStream = obj.getContent().getInputStream();             
              BufferedReader br = new BufferedReader(new InputStreamReader(contentStream));
              StringBuilder sb = new StringBuilder();
              String line = null;
   
              while ((line = br.readLine()) != null) {
                sb.append(line + "\n");
              }
   
              br.close();
            migratedFileName = dgoA.getPermanentUri().toString().substring(
                dgoA.getPermanentUri().toString().lastIndexOf(URI_SEPARATOR) + 1 );
            migratedFileSize = Integer.toString(sb.toString().length());
        } catch (Exception e) {
          wfResultItem.addLogInfo("migration error: " + e.getMessage());
        }
      }
     
      // Insert in JCR repository
            wfResultItem.addLogInfo("STEP 4: Insert in JCR repository. initial digital object: " + dgoA.toString());
            // Manage the Digital Object Data Registry:
            wfResultItem.addLogInfo("Initialize JCR repository instance.");
            JcrDigitalObjectManagerImpl dodm =
               (JcrDigitalObjectManagerImpl) JcrDigitalObjectManagerImpl.getInstance();
            DigitalObject dgoB = dodm.store(PERMANENT_URI_PATH, dgoA, true);
           wfResultItem.addLogInfo("Completed storing in JCR repository: " + dgoB.toString());
          
          wfResultItem.addLogInfo(new Message("JCRinsert", new Parameter("Digital Object", dgoB.getTitle()), new Parameter(
                    "Result", dgoB.getPermanentUri().toString())));

           // Enrich digital object with format information from identification service
           if (types != null) {
             wfResultItem.addLogInfo("Identified formats count: " + types.length);
        for (int i=0; i<types.length; i++) {
          wfResultItem.addLogInfo("type[" + i + "]: " + types[i]);
        }     

        if (types[0] != null) {
            List<Property> pList = new ArrayList<Property>();
            Property pIdentificationContent = new Property.Builder(URI.create("Identify"))
                  .name("content by reference")
                  .value(types[0].toString())
                  .description("This is a format for initial document identified by identification service")
                  .unit("URI")
                  .type("digital object format")
                  .build();
            pList.add(pIdentificationContent);
            Event eIdentifyFormat = new Event(
                IDENTIFICATION_EVENT, System.currentTimeMillis() + "", new Double(DURATION),
                new Agent("http://testbed-dev.planets-project.ait.ac.at:80/pserv-pc-droid/Droid?wsdl"
                    , identify.NAME, identify.QNAME.toString()),
                pList);
          dgoB = addEvent(dgoB, eIdentifyFormat, URI.create(types[0]));
         
          List<Property> pMigrationList = new ArrayList<Property>();
          Property pMigrationContent = new Property.Builder(URI.create("Migrate"))
                .name("content by reference")
                .value(types[0].toString())
                .description("This is a migration event")
                .unit("URI")
                .type("digital object format")
                .build();
          pMigrationList.add(pMigrationContent);
            Event eMigration = new Event(
                MIGRATION_EVENT, System.currentTimeMillis() + "", new Double(DURATION),
                new Agent(migrationEndpoint, migrate.NAME, migrate.QNAME.toString()),
                pMigrationList);
          dgoB = addEvent(dgoB, eMigration, null);
         
               // add create SIP event
          List<Property> pSipList = new ArrayList<Property>();
          Property pSipContent = new Property.Builder(URI.create("CreateSIP"))
                .name("SIP message")
                .value(types[0].toString())
                .description("This is a SIP message creation")
                .unit("file")
                .type("ZIP format")
                .build();
          pSipList.add(pSipContent);
          Event eSip = new Event(
              SIP_CREATION_EVENT, System.currentTimeMillis() + "", new Double(DURATION),
              new Agent("ZIP file", "The SIP message creation", "ZIP"),
              pSipList);
          dgoB = addEvent(dgoB, eSip, null);         
             }
           }
          
      // Update digital object in JCR repository
            wfResultItem.addLogInfo("STEP 5: Update digital object in JCR repository. initial digital object: " +
                dgoB.toString());
           dgoB = dodm.updateDigitalObject(dgoB, false);
           wfResultItem.addLogInfo("Completed update in JCR repository. result digital object: " + dgoB.toString());
           
            // Create SIP message (ZIP archive) and send it back to the initial repository
            wfResultItem.addLogInfo(
                "STEP 6: Send enriched digital object back to the initial repository as SIP. Create ZIP archive.");           
        List<String> filenames = new ArrayList<String>();
      String parentDir = "OriginalEpublication";
      String strHeaderDirectory = "";
      String strContentDirectory = parentDir + "/content";
      createDirectories(strHeaderDirectory);
      createDirectories(strContentDirectory);
           wfResultItem.addLogInfo("before resHeader");
           String resHeader = createMetadataXml(strHeaderDirectory, types[0]
                                                , migratedFileName, migratedFileSize);
           if (resHeader != null) {
               wfResultItem.addLogInfo("resHeader != null: " + resHeader);
             filenames.add(resHeader);
           }
           wfResultItem.addLogInfo("after resHeader");
          
           // add file to SIP content
      try {
        String resContent = addFileToZipContent(strContentDirectory, dgoB.getContent().getInputStream());
             wfResultItem.addLogInfo("add file to SIP content");
             if (resContent != null) {
               filenames.add(resContent);
             }
      } catch (Exception e) {
        wfResultItem.addLogInfo("read file content error: " + e.getMessage());
      }
          
           wfResultItem.addLogInfo("before create SIP archive");
      String sipFileName = createZipArchive(filenames);
           wfResultItem.addLogInfo("After create SIP archive sipFileName: " + sipFileName);
      String zipFileRes = sipFileName.substring(sipFileName.lastIndexOf(URI_SEPARATOR) + 1);
           wfResultItem.addLogInfo("After create SIP archive zipFileRes: " + zipFileRes);
     
      wfResultItem.addLogInfo("host auth: "  + this.getHostAuthority());
        URI zipOutFolder = new URI("http",this.getHostAuthority(),"/wee-gen/id-"+this.getWorkflowReportingLogger().getResultsId(),null,null);
        URL zipFileURL = new URL(zipOutFolder+"/" + zipFileRes);
      wfResultItem.addLogInfo("zipFileURL: "  + zipFileURL);

          wfResultItem.addLogInfo(new Message("SIP", new Parameter("Files", Arrays.asList(filenames).toString()), new Parameter(
                    "Result", zipFileURL.toString())));
      List<URL> uris = new ArrayList<URL>();
      uris.add(zipFileURL);
      wfResultItem.addLogInfo(this.link(uris));
View Full Code Here

                // Identify
              wfResultItem.addLogInfo("starting identify object: ");
                String[] types = runIdentification(dgo, wfResultItem);
              wfResultItem.addLogInfo("completed identify object format: " +
                  new Message("Identification", new Parameter("File", dgo.getTitle()), new Parameter(
                        "Result", Arrays.asList(types).toString())));

                // Extract metadata - will otherwise get lost between steps!
                List<Metadata> mList = dgo.getMetadata();

                if ((mList != null) && (mList.size() > 0)) {
                    metadata = mList.get(0).getContent();
                }

                if (metadata == null) {
                  wfResultItem.addLogInfo("No metadata contained in DigitalObject!");
                  wfResultItem.addLogInfo("Add title: " + dgo.getTitle());
                    title = dgo.getTitle();
          if(title.contains("."))
          {
            title = title.substring(0, title.lastIndexOf("."));
          }
              URI myMigrateToURI =
                    this.getServiceCallConfigs(this.migrate).getPropertyAsURI(SER_PARAM_MIGRATE_TO);
                    String newExtension =
                          FormatRegistryFactory.getFormatRegistry().getFirstExtension(myMigrateToURI);
                      title = title + "." + newExtension;
                } else {
                  wfResultItem.addLogInfo("Extracted metadata: " + metadata);
                }
               
                // Migrate
                try {
                    FormatRegistry fr = FormatRegistryFactory.getFormatRegistry();
                    String ext = fr.getFirstExtension(new URI(types[0]));
                    wfResultItem.addLogInfo("Getting extension: " + ext);
                    if (ext != null) {
                        URI uridgo = runMigration(migrate, dgo.getPermanentUri());
                        dgo = new DigitalObject.Builder(dgo.getContent())
                            .title(title)
                            .build();
                        objects.add(dgo);
                        wfResultItem.addLogInfo("Migration result uri: " + uridgo + ", result: " +
                            new Message("Migration", new Parameter("Input", ext), new Parameter("Result", dgo
                                .getTitle())));
                    }
                } catch (URISyntaxException e) {
                    throw new RuntimeException(e);
                }
View Full Code Here

                        log.info("Getting extension: " + ext);
                        if (ext != null) {
                            DigitalObject dgoOut = runMigrateService(dgo, fr.createExtensionUri(ext), wfResult);
                           
                            objects.add(dgoOut);
                            log.info(new Message("Migration", new Parameter("Input", ext), new Parameter("Result", dgo
                                    .getTitle())));
                        }
                    } catch (URISyntaxException e) {
                        throw new RuntimeException(e);
                    }
View Full Code Here

TOP

Related Classes of eu.planets_project.ifr.core.wee.api.ReportingLog.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.