Package eu.planets_project.services.migrate

Examples of eu.planets_project.services.migrate.MigrateResult


     * @param message
     * @return
     */
    private MigrateResult returnWithErrorMessage(String message, Exception e ) {
        if( e == null ) {
            return new MigrateResult(null, ServiceUtils.createErrorReport(message));
        } else {
            return new MigrateResult(null, ServiceUtils.createExceptionErrorReport(message, e));
        }
    }
View Full Code Here


      //retrieve the actual digital object
      DigitalObject digoToMigrate = dataRegistry.retrieve(digOToMigrateRef);
     
      // now call the migration
      MigrateResult migrateResult = migrationService.migrate(
          digoToMigrate, migrateFromURI, migrateToURI, parameterList);

      // document
      wfResultItem.setEndTime(System.currentTimeMillis());
      ServiceReport report = migrateResult.getReport();
      // report service status and type
      wfResultItem.setServiceReport(report);
      if (report.getType() == Type.ERROR) {
        String s = "Service execution failed: " + report.getMessage();
        wfResultItem.addLogInfo(s);
        throw new Exception(s);
      }

      DigitalObject migOutput = migrateResult.getDigitalObject();

      // add Migration Event to DigitalObject
      Event migrEvent = buildMigrationOutputEvent(digoToMigrate,
          parameterList, wfResultItem.getStartTime(), wfResultItem
              .getDuration(),serDescr,endpoint);
View Full Code Here

  private void testMigrate(URI inputFormat, URI outputFormat, List<Parameter> parameters) {
    String htmlVersion = getHtmlVersion(inputFormat);
    Assert.assertNotNull("HTML version is null!", htmlVersion);
    DigitalObject digObj = createDigitalObject(inputFormat);
   
    MigrateResult mr = JTIDY.migrate(digObj, inputFormat, outputFormat, parameters);

    ServiceReport sr = mr.getReport();
   
    if(sr.getType() == Type.ERROR) {
      System.err.println("FAILED: " + sr);
    }
    else {
      System.out.println("SUCCESS! Got Report: " + sr);
       
      DigitalObject doOut = mr.getDigitalObject();

      assertTrue("Resulting digital object is null.", doOut != null);
     
      File result = DigitalObjectUtils.toFile(doOut);
     
View Full Code Here

        }

        /*
         * Now call the migration service
         */
        MigrateResult migrateResult = this.migrate1.migrate(digO, migrateFromURI, migrateToURI, parameterList);
        ServiceReport report = migrateResult.getReport();

        if(report.getType() == Type.ERROR){
            String s = "Service execution failed: " + report.getMessage();
            log.debug(s);
            throw new Exception(s);
        }

        return migrateResult.getDigitalObject();
    }
View Full Code Here

                             + toolProcessRunner.getProcessOutputAsString()
                             + "\nStandard error output: "
                             + toolProcessRunner.getProcessErrorAsString();
            serviceReport = new ServiceReport(Type.ERROR,
                                              Status.TOOL_ERROR, message);
            return new MigrateResult(null, serviceReport);
        }


        //cleanup
        if (migrationPath.useTempSourceFile()){
            migrationPath.getTempSourceFile().getFile().delete();
        }
        for (TempFile tempFile : migrationPath.getTempFileDeclarations()) {
            tempFile.getFile().delete();
        }


        //READING THE OUTPUT
        //TODO return a reference to the outputfile
        DigitalObject.Builder builder;


        if (migrationPath.useTempDestinationFile()){
            //we should read a temp file afterwards
            File outputfile = migrationPath.getTempOutputFile().getFile();
            if (returnByReference){
                builder = new DigitalObject.Builder(Content.byReference(outputfile));
            } else {
                builder = new DigitalObject.Builder(Content.byValue(outputfile));
                outputfile.delete();
            }


            String message = "Successfully migrated object with title '"
                             + sourceObject.getTitle() + "' from format URI: "
                             + sourceFormat + " to " + destinationFormat
                             + " Standard output: "
                             + toolProcessRunner.getProcessOutputAsString()
                             + "\nStandard error output: "
                             + toolProcessRunner.getProcessErrorAsString();
            serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS,
                                              message);

        } else {

            if (returnByReference){
                //we should read the output
                builder = new DigitalObject.Builder(Content.byReference(toolProcessRunner.getProcessOutput()));
            } else{
                builder = new DigitalObject.Builder(Content.byValue(toolProcessRunner.getProcessOutput()));
            }
            String message = "Successfully migrated object with title '"
                             + sourceObject.getTitle() + "' from format URI: "
                             + sourceFormat + " to " + destinationFormat
                             + " Standard error output: "
                             + toolProcessRunner.getProcessErrorAsString();
            serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS,
                                              message);


        }


        //TODO cleanup the dir
        DigitalObject destinationObject = builder
                .format(destinationFormat)
                .build();

        return new MigrateResult(destinationObject, serviceReport);

    }
View Full Code Here

        // yes yes, this probably ought to be a bunch of methods
        Properties p = new Properties();
        try {
            p.loadFromXML(new FileInputStream(new File("commands.xml")));
        } catch (InvalidPropertiesFormatException e) {
            return new MigrateResult(null, ServiceUtils
                    .createExceptionErrorReport("Could not load commands.xml",
                            e));
        } catch (FileNotFoundException e) {
            return new MigrateResult(null, ServiceUtils
                    .createExceptionErrorReport("Could not load commands.xml",
                            e));
        } catch (IOException e) {
            return new MigrateResult(null, ServiceUtils
                    .createExceptionErrorReport("Could not load commands.xml",
                            e));
        }
        MultiProperties mp = MultiProperties.load(p);
        Map<String, String> params = new HashMap<String, String>();
        for (Parameter param : parameters) {
            params.put(param.getName(), param.getValue());
        }
        Map<String, String> toolParams = mp.get(params.get("tool-name"));
        try {
            File inputFile = DigitalObjectUtils.toFile(dob);

            File outputFile = File.createTempFile("generic-output", "tmp");
            FileUtils.deleteQuietly(outputFile);

            String commandString = toolParams.get("path") + File.separator
                    + toolParams.get("command");
            String argsString = toolParams.get("arguments");
            argsString = argsString.replace("$IN", inputFile.getAbsolutePath());
            argsString = argsString.replace("$OUT", outputFile
                    .getAbsolutePath());

            List<String> strings = new ArrayList<String>();
            strings.add(commandString);
            for (String s : argsString.split(" ")) {
                strings.add(s);
            }

            ProcessRunner pr = new ProcessRunner(strings);
            pr.run();

            FileUtils.deleteQuietly(inputFile);
            FileUtils.deleteQuietly(outputFile);

            boolean toolError = pr.getReturnCode() == -1;
            ServiceReport log;
            if (toolError) {
                log = new ServiceReport(Type.ERROR, Status.TOOL_ERROR, pr
                        .getProcessErrorAsString());
            } else {
                log = new ServiceReport(Type.INFO, Status.SUCCESS, pr
                        .getProcessOutputAsString());
            }
            /*
             * log.properties = new ArrayList<Property>(); log.properties.add(
             * new Property( URI.create("planets:uri"), "name", "value") );
             */
            return new MigrateResult(readDestination(outputFile), log);
        } catch (IOException e) {
            return new MigrateResult(null, ServiceUtils
                    .createExceptionErrorReport(
                            "Could not execute command using tool "
                                    + params.get("tool-name"), e));
        }
    }
View Full Code Here

      .getProcessErrorAsString());

  final ServiceReport serviceReport = new ServiceReport(messageType,
    messageStatus, reportMessage);

  return new MigrateResult(resultObject, serviceReport);
    }
View Full Code Here

TOP

Related Classes of eu.planets_project.services.migrate.MigrateResult

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.