WebLab 1.2/How To Update

From WebLab Wiki
Revision as of 11:32, 2 July 2014 by Ymombrun (talk | contribs) (ResourceCollection is obsolete)
Jump to navigationJump to search

Migrating FAQ from previous WebLab versions to version 1.2


After each modification, save the file (CTRL-s) and if eclipse doesn't mean to understand your modification, just do a PROJECT->CLEAN to force JIT compilation of the current file.

Remember, under eclipse, to delete obsolete imports (in red) and renew them with C-S-o keyboard sequence: if things goes wrong, your pom.xml is probably not good, so modify it and do a “mvn clean eclipse:clean eclipse:eclipse” in the console then press F5 while in eclipse to refresh project definitions/references.

Migrating from WebLab 1.1.1 to WebLab 1.2

Change all pom.xml

Almost all pom.xml must be changed. After a pom changing, apply “General Advices”.

You can take some pom.xml examples from any component of WebLab on OW2.

URI and Namespace changes

Hereafter are some examples (old, then new):

http://weblab-project.org/core/model/text
http://weblab.ow2.org/core/1.2/model/text#
http://weblab-project.org/core/model/user
http://weblab.ow2.org/core/1.2/model/user#
http://weblab-project.org/core/model/ontology/processing/
http://weblab.ow2.org/core/1.2/model/ontology/processing#
http://weblab-project.org/core/ontology/retrieval/
http://weblab.ow2.org/core/1.2/ontology/retrieval#
http://weblab-project.org/services/chaincrawling/types
http://weblab.ow2.org/services/chaincrawling/types
http://weblab-project.org/services
http://weblab.ow2.org/services
http://weblab-project.org/core/model/
http://weblab.ow2.org/core/1.2/model#
org.weblab_project.core
org.ow2.weblab.core
http://weblab-project.org
http://weblab.ow2.org/

Interfaces changes

Replace :

org.weblab_project.services.analyser.Analyser

By :

org.ow2.weblab.services.analyser.Analyser


List of the good interfaces :

org.ow2.weblab.core.services.Analyser
org.ow2.weblab.core.services.Indexer
org.ow2.weblab.core.services.Searcher
org.ow2.weblab.core.services.ResourceContainer

Packages changes

Example of some often used newer imports are:


import org.ow2.weblab.content.binary.BinaryFolderContentManager;
import org.ow2.weblab.core.extended.exception.WebLabCheckedException;
import org.ow2.weblab.core.extended.exception.WebLabUncheckedException;
import org.ow2.weblab.core.extended.factory.AnnotationFactory;
import org.ow2.weblab.core.extended.jaxb.XMLStringCleaner;
import org.ow2.weblab.core.extended.ontologies.DCTerms;
import org.ow2.weblab.core.extended.ontologies.DublinCore;
import org.ow2.weblab.core.extended.ontologies.RDFS;
import org.ow2.weblab.core.extended.properties.PropertiesLoader;
import org.ow2.weblab.core.extended.util.ResourceUtil;
import org.ow2.weblab.core.helper.PoKHelperExtended;
import org.ow2.weblab.core.helper.RDFHelperFactory;
import org.ow2.weblab.core.helper.ResourceHelper;
import org.ow2.weblab.core.model.Annotation;
import org.ow2.weblab.core.model.MediaUnit;
import org.ow2.weblab.core.model.Resource;
import org.ow2.weblab.core.model.Text;

Marshalling changes

WebLabMarshaler->WebLabMarshaller and regenerates imports as usual.


Exception management changes

XXXException->UnexpectedException

Example:

protected static Resource checkArgs(final ProcessArgs args) throws UnexpectedException {
   return throw new UnexpectedException("Invalid null parameter.", "E1");
}

Content Manager changes

groupId of content-manager is <groupId>org.ow2.weblab.components</groupId> and not <groupId>org.ow2.weblab</groupId>

Configuration file is contentManager.properties and no longer content.properties for the content-manager.


ResourceCollection is obsolete

Replace:

ResourceCollection

By:

ComposedResource


 rs.getResource().add(be.getResource(id).getResourceStored());

GetResourceArgs is obsolete

Replace:

GetResourceArgs

By:

LoadResourceArgs


import org.weblab_project.services.resourcecontainer.types.SaveResourceArgs;

import org.ow2.weblab.services.resourcecontainer.types.SaveResourceReturn;


Return-Status-Logger service is obsolete

return-status-logger: this service is deleted.

Consequence: modify the BPEL chain to suppress call to this service.


UsageContext is obsolete

args.getUsageContext().getUri() => does not work as getUsageContext() returns a String


Le groupId de rdf-helper-jena-structure passe de

<groupId>org.weblab-project.core</groupId>

à

<groupId>org.weblab-project.core.helpers</groupId>


Replace: (we no longer specifie properties to load)

props = PropertiesLoader.loadProperties(SERVICE_CONFIG_FILE, toLoad);

By:

props = PropertiesLoader.loadProperties(SERVICE_CONFIG_FILE);


BinaryFolderContentManager is deleted

Use content-manager instead.


LowLevelDescriptor.setKey no longer exists

Replace:

LowLevelDescriptor.setKey

By:

LowLevelDescriptor.setData


Feature class deleted

Just suppress the associated code !


Class BinaryMediaUnit deleted

Replace :

BinaryMediaUnit

By:

Either: Image, Audio, Video


LinearSegment creation modified

Replace:

final LinearSegment res3 = ResourceFactory.createResource("Test", "res3", LinearSegment.class);

By:

final LinearSegment res3 = SegmentFactory.createAndLinkLinearSegment(arg0, arg1, arg2)


LinearSegment getting modified

List<LinearSegment> linearSegmentList = ResourceUtil.getSelectedSubResources(toBeIndexed, LinearSegment.class);

No equivalent method is existing for now, do a loop to get all MediaUnits then all LinearSegments of these MediaUnits.

Anyway, you can use the following method as a replacement:

      /**

       * ================================================================================

       * ====================  getSegmentsFromResource ==================================

       * ================================================================================

       *

       * Get all classes (exemple: LinearSegment) from a Resource.

       * Since this method is recursive, example of calls can be found in the method itself :)

       *

       * @param myres: Resource to recursively search in

       * @param resClass: class to search for. This class must extend Segment class

       * @return

       */

      private <T extends Segment> List<T> getSegmentsFromResource(

                  Resource myres, Class<T> searchedClass) {

            ArrayList<T> arr = new ArrayList<T>();

            if (myres instanceof MediaUnit) {

                  MediaUnit subMU = (MediaUnit) myres;

                  for (Segment seg : subMU.getSegment()) {

                        if (searchedClass.isInstance(seg)) {

                             arr.add(searchedClass.cast(seg));

                        }

                  }

            } else if (myres instanceof Document) {

                  for (MediaUnit subMU : ((Document) myres).getMediaUnit()) {

                        for (Segment seg : subMU.getSegment()) {

                             if (searchedClass.isInstance(seg)) {

                                   arr.add(searchedClass.cast(seg));

                             }

                        }

                  }

            } else if (myres instanceof ComposedResource) {

                  for (Resource subres : ((ComposedResource) myres)

                             .getResource()) {

                        arr.addAll(getSegmentsFromResource(subres, searchedClass));

                  }

            } else if (myres instanceof Resource) {

                  List<Resource> listres = ResourceUtil.getSubResources(myres);

                  for (Resource subres : listres) {

                        arr.addAll(getSegmentsFromResource(subres, searchedClass));

                  }

            } else {

                  log.error("getSegmentsFromResource(): Class type not managed: "

                             + myres.getClass().getName());

            }

            return arr;

      }


ComposedUnit obsolete

ComposedUnit is deleted, and is role is now done by MediaUnit.

All sub-elements of ComposedUnit goes one level upper in the the XML tree.


Code replacement example1

Replace:

List<Text> mediaUnits = ComposedUnitUtil.getSelectedSubMediaUnits(

(ComposedUnit) maMediaUnitres, Text.class);

By:


List<Text> mediaUnits = new ArrayList<Text>();

for (MediaUnit subMU: ((Document)maMediaUnit).getMediaUnit()) {

if (subMU instanceof Text) {

mediaUnits.add((Text) subMU);

}

}

Code replacement example2

Replace:

if (ComposedUnitUtil.getSelectedSubMediaUnits(cu, Text.class).size() == 0)

By:

if (ResourceUtil.getSelectedSubResources(cu, Text.class).size() == 0)


RDF HELPER changes

RDFSelector

  • RDFSelector->AdvancedSelector
  • getSelector()->getSelector(true)

WTripleMap

  • WTripleMap wtm->Statements wtm
  • wtm.get(uriRel).get(xxx)->wtm.get(uriRel).getValue(xxx)

rdf-helper.properties

Put the following line in rdf-helper.properties:

pokhelper=org.ow2.weblab.core.helper.impl.JenaPoKHelper

pokhelperextended=org.ow2.weblab.core.helper.impl.JenaPoKHelperExtended

resourcehelper=org.ow2.weblab.core.helper.impl.JenaResourceHelper

resourcehelperextended=org.ow2.weblab.core.helper.impl.JenaResourceHelperExtended

bean-helper.properties:

Put the following line in bean-helper.properties:

beanhelper=org.ow2.weblab.core.helper.impl.BeanHelperImpl


Code migration example3

Replace:

WTripleMap mapUris = rdfSelector.searchFor(resource, WebLab.IS_LINKED_TO);

for (String uri : mapUris.keySet()) {

if (mapUris.get(uri).containsKey(WebLab.IS_LINKED_TO)) {

String uriResource = (String) mapUris.get(uri).get(WebLab.IS_LINKED_TO);

By:

Statements mapUris = rdfSelector.searchFor(resource, WebLab.IS_LINKED_TO);

List<String> listValues = mapUris.getTypedValues(null, WebLab.IS_LINKED_TO, String.class);

for (String uriResource: listValues) {

Code migration example4

Replace:

Statements newMapUris = rdfSelector.searchFor(retrieved, WebLab.HAS_ORIGINAL_FILE_NAME, DublinCore.TITLE_PROPERTY_NAME, DublinCore.FORMAT_PROPERTY_NAME);

if (newMapUris.get(uriResource).containsKey(DublinCore.TITLE_PROPERTY_NAME)) {

Object labelO = newMapUris.get(uriResource).get(DublinCore.TITLE_PROPERTY_NAME);

if (labelO != null) {

if (labelO instanceof List<?>) {

bre.setLabel((String)((List<?>) labelO).get(0));

} else {

bre.setLabel((String) labelO);

}

}

By:

List<String> listValues = newMapUris.getTypedValues(null, DublinCore.TITLE_PROPERTY_NAME, String.class);

if (listValues.size() > 0) bre.setLabel(listValues.get(0));


folder-source-reader service no longer available

folder-source-reader service must be replaced by the equivalent service: folder-crawler (1.5)


xml-normaliser, tika-normaliser

They use contentManager, configured by contentManager.properties

Migrating from WebLab 1.0 to WebLab 1.1

1) Deprecated AnnotationHelper ah = RDFHelperFactory.getAnnotationHelper(anno);

PoKHelper pok = RDFHelperFactory.getPoKHelper(anno);

Annotation is now "linked" with a Document while POK (PieceOfKnowledge) are self sufficient.


If you develop portlChange Annotation with PieceOfKnowledge in your portlet.xml


2) Unresolved import: import org.weblab_project.core.model.query.SemanticQuery;

=>replace with StringQuery


3) Unresolved import: import com.sun.xml.ws.server.UnsupportedMediaException;

Change it with: import com.sun.xml.internal.ws.server.UnsupportedMediaException;

(due to java 1.6. migration)


4) SemanticQuery doesn't exist: SemanticQuery query = ResourceFactory.createResource("weblab://netviz" + start, String.valueOf(start),SemanticQuery.class);

Replace SemanticQuery with StringQuery


5) Method undefined:query.setSparql(request);

Replace with query.setRequest(request);


6) Method undefined: searchReturn.getResults();

getResults used to return a ResourceCollection.

Replace with searchReturn.getResultSet().getPok();

In the calling function, replace ResourceCollection with PieceOfKnowledge (if outside of a document's context)


7) Cannot be resolved: List<WTriple> list = rdfSelector.findInResource(r, null, WebLab.IS_PRODUCED_FROM, null);

=> IS_LINKED_TO (but in some cases it is another constant IS_XXX)


8) Unresolved import:import org.weblab_project.core.logging.WebLabLogFactory;

=>delete the import line, change WebLabLogFactory with LogFactory et regenerate imports (CTR+SHIFT+o under eclipse).


9) WARN org.weblab_project.core.properties.PropertiesLoader - Cannot load property 'pokhelperextended' from file 'rdf-helper.properties'.

Update your rdf-helper.properties, fill it with the lines:

pokhelper=org.weblab_project.core.helper.impl.JenaPoKHelper

pokhelperextended=org.weblab_project.core.helper.impl.JenaPoKHelperExtended

resourcehelper=org.weblab_project.core.helper.impl.JenaResourceHelper

resourcehelperextended=org.weblab_project.core.helper.impl.JenaResourceHelperExtended