Package eu.planets_project.pp.plato.services

Examples of eu.planets_project.pp.plato.services.PlatoServiceException


                result.getMigratedObject().setFullname(filename);
            }
            lastResult = result;
            return true;
        } catch (NumberFormatException e) {
            throw new PlatoServiceException("Migration failed, CRiB returned an invalid result.", e);
        } catch (RemoteException e) {
            throw new PlatoServiceException("Migration failed, could not access CRiB.", e);
        } catch (ServiceException e) {
            throw new PlatoServiceException("Migration failed, could not access CRiB.", e);
        } catch (EJBException e) {
            throw new PlatoServiceException("Migration failed, could not access CRiB.", e);
        }
    }
View Full Code Here


        try {
            lastInfo = "";

            if (sourceFormat.getName() == null || "".equals(sourceFormat.getName())
             || sourceFormat.getVersion() == null || "".equals(sourceFormat.getVersion())) {
                throw new PlatoServiceException("The sample object's format is missing name or version information," +
                                "both of which are needed for querying this registry. " +
                                "Please provide name and version or try one of the other registries, which work on PUIDS of formats.");
            }
             
            ArrayList<String> shortnames = new ArrayList<String>();

            /*
             * CRiB uses "<name>, version <version nr>", both from PRONOM, as ID 
             */
            String cribID = Utils.makeCRiBId(sourceFormat);
            /*
             * First get the available target formats
             */
           
            String [] targetFormats = serviceRegistryService.getSupportedTargetFormats(cribID);
            ArrayList<PreservationActionDefinition> preservationActions = new ArrayList<PreservationActionDefinition>();
            for (int i = targetFormats.length-1; i >= 0; i--) {
                String targetFormat = targetFormats[i];
                /*
                 * Then get all the possible migration paths for each target format
                 * - each migration path corresponds to one service  
                 */
                PreservationActionDefinition action;
               
                MigrationPath[] paths = serviceRegistryService.getMigrationPaths(cribID, targetFormat);
                for (int j = 0; j < paths.length; j++) {
                    MigrationPath path = paths[j];
                    action = new PreservationActionDefinition();
                   
                    action.setShortname(getShortnameFromPath(path, shortnames));
                    String urls[] = path.getAccessPoints();
                    LinkedList<Parameter> params = new LinkedList<Parameter>();
                    for (int k = 0; k < urls.length; k++) {
                        Parameter param = new Parameter();
                        param.setName(""+k);
                        param.setValue(urls[k]);
                        params.add(param);
                    }
                    action.setParams(params);
                    action.setTargetFormat(targetFormats[i]);
                    if (urls.length > 0)
                        action.setUrl(urls[0].substring(0, urls[0].lastIndexOf("/")));
                    /*
                     * extract information about the conversions from urls
                     */
                    StringBuilder b = new StringBuilder();
                    b.append(getSourceFormatFromPath(urls[0]));
                    for(int uIdx = 0; uIdx < urls.length; uIdx++) {
                        b.append(">");
                        b.append(getTargetFormatFromPath(urls[uIdx]));
                    }
                    action.setInfo(b.toString());
                    /*
                     * mark this as a CRiB action
                     */
                    action.setActionIdentifier("CRiB");
                    /*
                     * no gif, bmp, text - conversions: they are of minor interest for dp
                     */
/*                String info = action.getInfo().toUpperCase();
                    if (!(info.contains("GIF") ||
                        info.contains("TEXT") ||
                        info.contains("BMP") ||
                        info.contains("PDF") ||
                        info.indexOf("JPG",4) > -1 ))
*/                   
                    preservationActions.add(action);
                }
            }
            if (preservationActions.size() == 0)
                lastInfo = "This registry does not contain a service that handles objects of type " + sourceFormat.getLongName();
            return preservationActions;
        } catch (UDDIException e) {
            throw new PlatoServiceException("Access to registry failed.", e);
        } catch (TransportException e) {
            throw new PlatoServiceException("Access to registry failed.", e);
        } catch (RemoteException e) {
            throw new PlatoServiceException("Access to registry failed.", e);
        }
    }
View Full Code Here

                result.getMigratedObject().getFormatInfo().assignValues(targetFormat);
            }
            lastResult = result;
            return true;
        } catch (NumberFormatException e) {
            throw new PlatoServiceException("Migration failed, CRiB returned an invalid result.", e);
        } catch (RemoteException e) {
            throw new PlatoServiceException("Migration failed, could not access CRiB.", e);
        } catch (EJBException e) {
            throw new PlatoServiceException("Migration failed, could not access CRiB.", e);
        }       
    }
View Full Code Here

        try {
            lastInfo = "";

            if (sourceFormat.getName() == null || "".equals(sourceFormat.getName())
             || sourceFormat.getVersion() == null || "".equals(sourceFormat.getVersion())) {
               throw new PlatoServiceException("The sample object's format is missing name or version information," +
                                "both of which are needed for querying this registry. " +
                                "Please provide name and version or try one of the other registries, which work on PUIDS of formats.");
            }
           
            ArrayList<String> shortnames = new ArrayList<String>();

            /*
             * CRiB uses "<name>, version <version nr>", both from PRONOM, as ID 
             */
            String cribID = Utils.makeCRiBId(sourceFormat);
            /*
             * First get the available target formats
             */
            String [] targetFormats = serviceRegistryService.findall_targetFormats(cribID);
            ArrayList<PreservationActionDefinition> preservationActions = new ArrayList<PreservationActionDefinition>();
            for (int i = targetFormats.length-1; i >= 0; i--) {
                String targetFormat = targetFormats[i];
                /*
                 * Then get all the possible migration paths for each target format
                 * - each migration path corresponds to one service  
                 */
                PreservationActionDefinition action;
               
                MigrationPath[] paths = serviceRegistryService.findall_migrationPaths(cribID, targetFormat);
                for (int j = 0; j < paths.length; j++) {
                    MigrationPath path = paths[j];
                    action = new PreservationActionDefinition();
                   
                    action.setShortname(getShortnameFromPath(path, shortnames));
                    String urls[] = path.getAccessPoints();
                    LinkedList<Parameter> params = new LinkedList<Parameter>();
                    for (int k = 0; k < urls.length; k++) {
                        Parameter param = new Parameter();
                        param.setName("crib::location"+k);
                        param.setValue(urls[k]);
                        params.add(param);
                    }
                    action.setParams(params);
                    action.setTargetFormat(targetFormats[i]);
                    if (urls.length > 0)
                        action.setUrl(urls[0].substring(0, urls[0].lastIndexOf("/")));
                    /*
                     * extract information about the conversions from urls
                     */
                    StringBuilder b = new StringBuilder();
                    b.append(getSourceFormatFromPath(urls[0]));
                    for(int uIdx = 0; uIdx < urls.length; uIdx++) {
                        b.append(">");
                        b.append(getTargetFormatFromPath(urls[uIdx]));
                    }
                    action.setInfo(b.toString());
                    /*
                     * mark this as a CRiB action
                     */
                    action.setActionIdentifier("CRiB-local");
                    /*
                     * no gif, bmp, text - conversions: they are of minor interest for dp
                     */
/*                String info = action.getInfo().toUpperCase();
                    if (!(info.contains("GIF") ||
                        info.contains("TEXT") ||
                        info.contains("BMP") ||
                        info.contains("PDF") ||
                        info.indexOf("JPG",4) > -1 ))
*/                   
                       preservationActions.add(action);
                }
            }
            if (preservationActions.size() == 0)
                lastInfo = "This registry does not contain a service that handles objects of type " + sourceFormat.getLongName();
            return preservationActions;
        } catch (UDDIException e) {
            throw new PlatoServiceException("Access to registry failed.", e);
        } catch (TransportException e) {
            throw new PlatoServiceException("Access to registry failed.", e);
        } catch (RemoteException e) {
            throw new PlatoServiceException("Access to registry failed.", e);
        }
    }
View Full Code Here

       
        Service service = null;
        try {
            service = Service.create(wsdlLocation, CreateView.QNAME);
        } catch(WebServiceException e) {
            throw new PlatoServiceException("Error creating web service.", e);
        }

        //
        // we have to create a temp file to later on pass it to the the Planets GRATE viewer.
        // for some reasons, when i pass it on by value, it doesn't work. GRATE always complains
View Full Code Here

       
        Service service = null;
        try {
            service = Service.create(wsdlLocation, Migrate.QNAME);
        } catch(WebServiceException e) {
            throw new PlatoServiceException("Error creating web service.", e);
        }
       
        Migrate m = (Migrate) service.getPort(Migrate.class);
       
        // create digital object that contains our sample object
        DigitalObject dob = new DigitalObject.Builder( Content.byValue(sampleObject.getData().getData()) ).title("data").build();

        FormatRegistry formatRegistry = FormatRegistryFactory.getFormatRegistry();

        // create Planets URI from extension
        URI sourceFormat = formatRegistry.createExtensionUri(sampleObject.getFormatInfo().getDefaultExtension());
       
        URI targetFormat;
        try {
            targetFormat = new URI(action.getTargetFormat());
        } catch (URISyntaxException e) {
            throw new PlatoServiceException("Error in target format.", e);
        }
       
        List<Parameter> serviceParams = getParameters(action.getParamByName("settings"));
       
        if (serviceParams.size() <= 0) {
            serviceParams = null;
        }
       
        // perform migration
        MigrateResult result = m.migrate(dob, sourceFormat, targetFormat, serviceParams);

        MigrationResult migrationResult = new MigrationResult();
        migrationResult.setSuccessful((result != null) && (result.getDigitalObject() != null));

        if (migrationResult.isSuccessful()) {
            migrationResult.setReport(String.format("Service %s successfully migrated object.", wsdlLocation));
        } else {
            migrationResult.setReport(String.format("Service %s failed migrating object. " + ((result==null)? "" : result.getReport()), wsdlLocation));
            lastResult = migrationResult;
            return true;
        }

        InputStream in = result.getDigitalObject().getContent().getInputStream();
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        byte[] b = new byte[1024];

        try {
            while ((in.read(b)) != -1) {
                out.write(b);
            }
        } catch (IOException e) {
            throw new PlatoServiceException("Unable to read result data from service response.", e);
        }

        migrationResult.getMigratedObject().getData().setData(out.toByteArray());

        String fullName = sampleObject.getFullname();
View Full Code Here

            response = mPost.getResponseBodyAsString();
           
            return response+ config.getParams();

        } catch (HttpException e) {
            throw new PlatoServiceException("Could not connect to GRATE.", e);
        } catch (FileNotFoundException e) {
            throw new PlatoServiceException("Could not create temp file.", e);
        } catch (IOException e) {
            throw new PlatoServiceException("Could not connect to GRATE.", e);
        }       
       
    }
View Full Code Here

            if (! new File(FITS_HOME).exists()) {
                FITS_HOME = null;
            }
        }
        if (FITS_HOME == null) {
            throw new PlatoServiceException("FITS is not propertly configured - FITS_HOME is not defined.");
        }
    }
View Full Code Here

           
            try {
                int exitcode = cmdExecutor.runCommand(commandLine);
                if (exitcode != 0) {
                    String cmdError = cmdExecutor.getCommandError();
                    throw new PlatoServiceException("FITS characterisation for file: " + input + " failed: " + cmdError);
                }
                if (!output.exists()) {
                    throw new PlatoServiceException("FITS characterisation for file: " + input + " failed: no output was written.");
                }
               
                return new String(FileUtils.getBytesFromFile(output));
            } catch (PlatoServiceException e) {
                throw e;
            } catch (Throwable t) {
                throw new PlatoServiceException("FITS characterisation for file: " + input + " failed: " + t.getMessage(), t);           
            }
        } finally {
            output.delete();
        }
    }
View Full Code Here

        try {
            InputStream config = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile);
           
            d.parse(config);
        } catch (IOException e) {
            throw new PlatoServiceException("Could not read registry data.", e);
        } catch (SAXException e) {
            throw new PlatoServiceException("Could not read registry data.", e);
        }
     }
View Full Code Here

TOP

Related Classes of eu.planets_project.pp.plato.services.PlatoServiceException

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.