Package eu.planets_project.tb.impl.model.measure

Examples of eu.planets_project.tb.impl.model.measure.MeasurementImpl


     * @param dobUri
     * @param value
     */
    public static void createMeasurement(MeasurementEventImpl mev, Property p, String dobUri, String value ) {
        // Make
        MeasurementImpl m = new MeasurementImpl(mev);
        // Create a property from the manual one:
        m.setProperty( new Property.Builder(p).build() );
        //m.setUserEquivalence(this.newManEqu);
        m.setEquivalence( Equivalence.UNKNOWN );
        m.setValue(value);
        MeasurementTarget target = new MeasurementTarget();
        target.setType(TargetType.DIGITAL_OBJECT);
        target.getDigitalObjects().add(0, dobUri);
        /*
        target.setDigitalObjectProperty( 0,
                    new Property.Builder( p ).value(value).build()
                );
        */
        m.setTarget(target);
        // And add it, and persist:
        mev.addMeasurement(m);
    }
View Full Code Here


     * and converts it into the Testbed's Property model element: MeasurementImpl
     * @param p eu.planets_project.services.datatypes.Property
     * @return
     */
    public static MeasurementImpl createMeasurementFromOntologyProperty(OntologyProperty p) throws Exception{
       MeasurementImpl m = new MeasurementImpl();
       if( p == null ) throw new Exception("invalid OntologyProperty: null");
       String propURI = p.getURI();
       // Invent a uri if required - shouldn't be the case:
       if( propURI == null ) {
           propURI = TecRegMockup.URI_ONTOLOGY_PROP_ROOT + p.getName();
       }
       URI pURI;
       try {
           pURI = new URI(propURI);
       } catch (URISyntaxException e) {
           log.debug(e);
           return m;
       }
    // Copy into measurement property:
      m.setProperty( OntoPropertyUtil.createPropertyFromOntoProperty(pURI, p) );
       
        return m;
    }
View Full Code Here

        }
       
        // Patch the descriptions in with the results:
        List<MeasurementImpl> mobs = new ArrayList<MeasurementImpl>();
        for( MeasurementImpl mr : mrl ) {
            MeasurementImpl new_m = null;
           
            // Look for matches:
            if( observables.keySet().contains( this.getStage() )) {
                for( MeasurementImpl m : observables.get( this.getStage() ) ) {
                    //log.info("Comparing '"+m.getIdentifier() +"' to '"+mr.getIdentifier()+"', "+m.getName());
                    if( m.getIdentifier() != null && mr.getIdentifier() != null &&
                            m.getIdentifier().toString().equals( mr.getIdentifier() ) ) {
                        new_m = m.clone();
                        new_m.setValue( mr.getValue() );
                    }
                }
            }
           
            // If that doesn't work, generate manually:
            if( new_m == null && mr.getIdentifier() != null ) {
                new_m = new MeasurementImpl(null,mr);
            }
           
            // Add to the results:
            if( new_m != null ) {
                //log.info("Adding observable: "+new_m.toString());
View Full Code Here

        // Find all the PRONOM IDs for this format URI:
        for( URI puid : this.getPronomURIAliases(formatURI) ) {
            List<Property> measurableProperties = dp.listProperties(puid);
            if( measurableProperties != null ) {
                for( Property p : measurableProperties ) {
                    MeasurementImpl m = this.createMeasurementFromProperty(p);
                    if( ! meas.containsKey( m.getIdentifier() ) ) {
                        meas.put(m.getIdentifierUri(), m);
                    }
                }
            }
        }
View Full Code Here

     * and converts it into the Testbed's Property model element: MeasurementImpl
     * @param p eu.planets_project.services.datatypes.Property
     * @return
     */
    private MeasurementImpl createMeasurementFromProperty( Property p ) {
        MeasurementImpl m = new MeasurementImpl();
       
        if( p == null ) return m;
       
        URI propURI = p.getUri();
        // Invent a uri if required:
        if( propURI == null ) {
            try {
                propURI = new URI( TecRegMockup.URI_XCDL_PROP_ROOT + p.getName());
            } catch (URISyntaxException e) {
                e.printStackTrace();
                return m;
            }
            // Rebuild the property:
            p = new Property.Builder(propURI).name(p.getName()).description(p.getDescription())
            .type(p.getType()).unit(p.getUnit()).value(p.getValue()).build();
        }
       
        // Copy in:
        m.setProperty(p);
        m.getTarget().setType(MeasurementTarget.TargetType.DIGITAL_OBJECT);
        m.setValue(p.getValue());
       
        return m;
    }
View Full Code Here

            throw new Exception ("Service Invocation Failed! : " + e.getMessage() );
        }
        msAfter = System.currentTimeMillis();
       
        // Compute the run time.
        stage_m.add( new MeasurementImpl(TecRegMockup.PROP_SERVICE_TIME, ""+((msAfter-msBefore)/1000.0)) );
        // Add the object size:
        stage_m.add( new MeasurementImpl(TecRegMockup.PROP_DO_SIZE, ""+IdentifyWorkflow.getContentSize(dob) ) );

        // Now record
        if( success && migrated.getDigitalObject() != null ) {

            stage_m.add( new MeasurementImpl( TecRegMockup.PROP_SERVICE_EXECUTION_SUCEEDED, "true"));

            // Take the digital object, put it in a temp file, and give it a sensible name, using the new format extension.
            File doTmp = File.createTempFile("migrateResult", ".tmp");
            doTmp.deleteOnExit();
            DigitalObjectUtils.toFile(migrated.getDigitalObject(), doTmp);
            DigitalObject.Builder newdob = new DigitalObject.Builder(migrated.getDigitalObject());
            newdob.content( Content.byReference(doTmp) );
            // FIXME The above need to be a full recursive storage operation!
           
            if( to != null ) {
                //Format f = new Format(to);
              Set<String> extensionsTo = ServiceBrowser.fr.getExtensions(to);
                String title = dob.getTitle();
                if(extensionsTo.iterator().hasNext()){
                  title += "."+extensionsTo.iterator().next();
                }
                title = title.substring( title.lastIndexOf("/") + 1);
                newdob.title( title );
            }
            wr.setResult(newdob.build());
            wr.setResultType(WorkflowResult.RESULT_DIGITAL_OBJECT);
            wr.logReport(migrated.getReport());
            log.info("Migration succeeded.");
            return;
        }
       
        // Only get to here if there was not a valid result.
       
        // Build in a 'service failed' property, i.e. the call worked, but no result.
        stage_m.add( new MeasurementImpl( TecRegMockup.PROP_SERVICE_EXECUTION_SUCEEDED, "false"));

        // ADD a report, so the full set is known.
        wr.logReport(migrated.getReport());
       
        // FIXME Should now throw an Exception, as the WF cannot proceed?
View Full Code Here

                }
            }
        }
       
        // Compute the run time.
        stage_m.add(new MeasurementImpl(TecRegMockup.PROP_SERVICE_TIME, ""+((msAfter-msBefore)/1000.0)) );
        // Add the object size:
        stage_m.add( new MeasurementImpl(TecRegMockup.PROP_DO_SIZE, ""+IdentifyWorkflow.getContentSize(dob) ) );

        // Record results:
        if( success ) {
            stage_m.add( new MeasurementImpl( TecRegMockup.PROP_SERVICE_EXECUTION_SUCEEDED, "true"));
            if( result != null && result.getProperties() != null ) {
                log.info("Got "+result.getProperties().size()+" properties");
                for( Property p : result.getProperties() ) {
                    log.info("Recording measurement: "+p.getUri()+":"+p.getName()+" = "+p.getValue());
                    stage_m.add(new MeasurementImpl( p.getUri(), p.getValue() ));
                }
            }
            return;
        }

        // FAILED:
        stage_m.add( new MeasurementImpl( TecRegMockup.PROP_SERVICE_EXECUTION_SUCEEDED, "false"));

    }
View Full Code Here

                }
            }
        }
       
        // Compute the run time.
        stage_m.add(new MeasurementImpl(TecRegMockup.PROP_SERVICE_TIME, ""+((msAfter-msBefore)/1000.0)) );
        // Add the object size:
        stage_m.add( new MeasurementImpl(TecRegMockup.PROP_DO_SIZE, ""+IdentifyWorkflow.getContentSize(dob) ) );
       
        // Record results:
        if( success ) {
            try {
                stage_m.add( new MeasurementImpl( TecRegMockup.PROP_SERVICE_EXECUTION_SUCEEDED, "true"));
                log.info("Start with Measurements #"+stage_m.size());
                IdentifyWorkflow.collectIdentifyResults(stage_m, result, dob);
                log.info("Afterwards, Measurements #"+stage_m.size());
            return;
            } catch ( Exception e ) {
                log.error("Failed to record identification results: "+e);
            }
        }

        // FAILED:
        stage_m.add( new MeasurementImpl( TecRegMockup.PROP_SERVICE_EXECUTION_SUCEEDED, "false"));

    }
View Full Code Here

       
        // Record the endpoint of the service used for this stage.  FIXME Can this be done more automatically, from above?
        idStage.setEndpoint(identifierEndpoint);
       
        List<MeasurementImpl> recs = idStage.getMeasurements();
        recs.add(new MeasurementImpl(TecRegMockup.PROP_SERVICE_TIME, ""+((msAfter-msBefore)/1000.0) ));
       
        // Now record
        try {
            if( success && identify.getTypes() != null && identify.getTypes().size() > 0 ) {
                recs.add( new MeasurementImpl( TecRegMockup.PROP_SERVICE_EXECUTION_SUCEEDED, "true"));
                collectIdentifyResults(recs, identify, dob);
                wr.logReport(identify.getReport());
                return wr;
            }
        } catch( Exception e ) {
            exceptionReport += "<p>Failed with exception: "+e+"</p>";
        }

        // Build in a 'service failed' property.
        recs.add( new MeasurementImpl( TecRegMockup.PROP_SERVICE_EXECUTION_SUCEEDED, "false"));

        // Create a ServiceReport from the exception.
        // TODO can we distinguish tool and install error here?
        ServiceReport sr = new ServiceReport(Type.ERROR, Status.TOOL_ERROR,
                "No info");
View Full Code Here

    public static void collectIdentifyResults( List<MeasurementImpl> recs, IdentifyResult ident, DigitalObject dob ) {
        if( ident == null ) return;
        if( ident.getTypes() != null ) {
            for( URI format_uri : ident.getTypes() ) {
                if( format_uri != null ) {
                    recs.add( new MeasurementImpl( TecRegMockup.PROP_DO_FORMAT, format_uri.toString()));
        }
            }
        }
        if( ident.getMethod() != null ) {
            recs.add( new MeasurementImpl( TecRegMockup.PROP_SERVICE_IDENTIFY_METHOD, ident.getMethod().name() ));
        }
        // Store the size:
        recs.add( new MeasurementImpl(TecRegMockup.PROP_DO_SIZE, ""+getContentSize(dob) ) );
        return;
    }
View Full Code Here

TOP

Related Classes of eu.planets_project.tb.impl.model.measure.MeasurementImpl

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.