import org.apache.log4j.Logger;\r
import org.springframework.transaction.TransactionStatus;\r
\r
+import eu.etaxonomy.cdm.api.application.CdmApplicationController;\r
import eu.etaxonomy.cdm.api.service.ITermService;\r
import eu.etaxonomy.cdm.api.service.IVocabularyService;\r
import eu.etaxonomy.cdm.api.service.pager.Pager;\r
public class AdaptaterCdmXper implements ICdmAdapter{\r
private static final Logger logger = Logger.getLogger(AdaptaterCdmXper.class);\r
\r
- TransactionStatus tx = Xper.getCdmApplicationController().startTransaction();\r
+ TransactionStatus tx;\r
+\r
+ private CdmApplicationController cdmApplicationController;\r
\r
- public AdaptaterCdmXper() {\r
- \r
+ public AdaptaterCdmXper(CdmApplicationController appCtr) {\r
+ setCdmApplicationController(appCtr);\r
}\r
\r
+\r
+ public void setCdmApplicationController(CdmApplicationController appCtr) {\r
+ this.cdmApplicationController = appCtr;\r
+ tx = cdmApplicationController.startTransaction();\r
+ }\r
+\r
+\r
+ public CdmApplicationController getCdmApplicationController() {\r
+ return cdmApplicationController;\r
+ }\r
+\r
\r
public void load(){\r
loadFeatures();\r
// UUID featureTreeUUID = UUID.fromString("43ab1efd-fa15-419a-8cd6-05477e4b37bc");\r
List<String> featureTreeInit = Arrays.asList(new String[]{"root.children.feature.representations"});\r
\r
- TransactionStatus tx = Xper.getCdmApplicationController().startTransaction();\r
- FeatureTree featureTree = Xper.getCdmApplicationController().getFeatureTreeService().load(featureTreeUUID, featureTreeInit);\r
+ TransactionStatus tx = cdmApplicationController.startTransaction();\r
+ FeatureTree featureTree =cdmApplicationController.getFeatureTreeService().load(featureTreeUUID, featureTreeInit);\r
if (featureTree != null) {\r
loadFeatureNode(featureTree.getRoot(), -1);\r
}else{\r
logger.warn("Feature tree " + featureTreeUUID.toString() + " not found");\r
}\r
- Xper.getCdmApplicationController().commitTransaction(tx);\r
+ cdmApplicationController.commitTransaction(tx);\r
}\r
\r
/**\r
\r
// Load all the taxa and 1 description\r
public void loadTaxaAndDescription() {\r
- TransactionStatus tx = Xper.getCdmApplicationController().startTransaction();\r
- List<TaxonBase> taxonList = Xper.getCdmApplicationController().getTaxonService().list(Taxon.class , null, null, null, null);\r
+ TransactionStatus tx = cdmApplicationController.startTransaction();\r
+ List<TaxonBase> taxonList = cdmApplicationController.getTaxonService().list(Taxon.class , null, null, null, null);\r
for(TaxonBase taxonBase : taxonList){\r
if (Utils.currentBase != null) {\r
Individual individual = new Individual(taxonBase.getName().toString());\r
Utils.currentBase.addIndividual(individual);\r
}\r
}\r
- Xper.getCdmApplicationController().commitTransaction(tx);\r
+ cdmApplicationController.commitTransaction(tx);\r
}\r
\r
// Load the first taxonDescription\r
public void loadDescription(Individual individual, TaxonBase taxonBase) {\r
\r
- Pager<TaxonDescription> taxonDescriptionPager = Xper.getCdmApplicationController().getDescriptionService().getTaxonDescriptions((Taxon)taxonBase, null, null, null, 0, Arrays.asList(new String[]{"elements.states", "elements.feature"} ));\r
+ Pager<TaxonDescription> taxonDescriptionPager = cdmApplicationController.getDescriptionService().getTaxonDescriptions((Taxon)taxonBase, null, null, null, 0, Arrays.asList(new String[]{"elements.states", "elements.feature"} ));\r
List<TaxonDescription> taxonDescriptionList = taxonDescriptionPager.getRecords();\r
TaxonDescription taxonDescription = taxonDescriptionList.get(0);\r
Set<DescriptionElementBase> DescriptionElementBaseList = taxonDescription.getElements();\r
// Create a workingSet if not exist\r
public void createWorkingSet(){\r
\r
- if(Xper.getCdmApplicationController().getWorkingSetService().list(WorkingSet.class, null, null, null, null).size() <= 0){\r
+ if(cdmApplicationController.getWorkingSetService().list(WorkingSet.class, null, null, null, null).size() <= 0){\r
WorkingSet ws = WorkingSet.NewInstance();\r
\r
UUID featureTreeUUID = UUID.fromString("47eda782-89c7-4c69-9295-e4052ebe16c6");\r
List<String> featureTreeInit = Arrays.asList(new String[]{"root.children.feature.representations"});\r
\r
- FeatureTree featureTree = Xper.getCdmApplicationController().getFeatureTreeService().load(featureTreeUUID, featureTreeInit);\r
+ FeatureTree featureTree = cdmApplicationController.getFeatureTreeService().load(featureTreeUUID, featureTreeInit);\r
ws.setDescriptiveSystem(featureTree);\r
\r
- List<TaxonBase> taxonList = Xper.getCdmApplicationController().getTaxonService().list(Taxon.class , null, null, null, null);\r
+ List<TaxonBase> taxonList = cdmApplicationController.getTaxonService().list(Taxon.class , null, null, null, null);\r
for(TaxonBase taxonBase : taxonList){\r
- Pager<TaxonDescription> taxonDescriptionPager = Xper.getCdmApplicationController().getDescriptionService().getTaxonDescriptions((Taxon)taxonBase, null, null, null, 0, Arrays.asList(new String[]{"elements.states", "elements.feature"} ));\r
+ Pager<TaxonDescription> taxonDescriptionPager = cdmApplicationController.getDescriptionService().getTaxonDescriptions((Taxon)taxonBase, null, null, null, 0, Arrays.asList(new String[]{"elements.states", "elements.feature"} ));\r
List<TaxonDescription> taxonDescriptionList = taxonDescriptionPager.getRecords();\r
TaxonDescription taxonDescription = taxonDescriptionList.get(0);\r
ws.addDescription(taxonDescription);\r
System.out.println(taxonDescription.getUuid());\r
}\r
\r
- Xper.getCdmApplicationController().getWorkingSetService().save(ws);\r
+ cdmApplicationController.getWorkingSetService().save(ws);\r
}\r
}\r
\r
* @param vars\r
*/\r
private void saveFeatures(List<Variable> vars) {\r
- tx = Xper.getCdmApplicationController().startTransaction();\r
+ tx = cdmApplicationController.startTransaction();\r
for (Variable variable : vars){\r
Feature feature = getFeature(variable);\r
if (Utils.numType.equals(variable.getType())){\r
logger.warn("variable type undefined");\r
}\r
}\r
- Xper.getCdmApplicationController().commitTransaction(tx);\r
+ cdmApplicationController.commitTransaction(tx);\r
}\r
\r
\r
*/\r
private Feature getFeature(Variable variable) {\r
UUID uuid = variable.getUuid();\r
- ITermService termService = Xper.getCdmApplicationController().getTermService();\r
+ ITermService termService = cdmApplicationController.getTermService();\r
DefinedTermBase<?> term = termService.find(uuid);\r
Feature feature = CdmBase.deproxy(term, Feature.class);\r
return feature;\r
}\r
\r
private void saveCategoricalFeature(Variable variable, Feature feature) {\r
- ITermService termService = Xper.getCdmApplicationController().getTermService();\r
- IVocabularyService vocService = Xper.getCdmApplicationController().getVocabularyService();\r
+ ITermService termService = cdmApplicationController.getTermService();\r
+ IVocabularyService vocService = cdmApplicationController.getVocabularyService();\r
if (feature == null){\r
saveNewFeature(variable, termService, vocService);\r
}else{\r
\r
\r
private void saveNumericalFeature(Variable variable, Feature feature) {\r
- ITermService termService = Xper.getCdmApplicationController().getTermService();\r
- IVocabularyService vocService = Xper.getCdmApplicationController().getVocabularyService();\r
+ ITermService termService = cdmApplicationController.getTermService();\r
+ IVocabularyService vocService = cdmApplicationController.getVocabularyService();\r
String variableUnit = variable.getUnit();\r
Set<MeasurementUnit> units = feature.getRecommendedMeasurementUnits();\r
//preliminary\r
return null;\r
}\r
\r
+\r
+\r
+\r
+\r
}\r
\r
public class TestAdapterCdmXper {\r
\r
+ AdaptaterCdmXper adapterCdmXper;\r
\r
- \r
- public TestAdapterCdmXper(){\r
- \r
+ /**\r
+ * \r
+ */\r
+ private void startApplications() {\r
DbSchemaValidation dbSchemaValidation = DbSchemaValidation.VALIDATE;\r
ICdmDataSource datasource = CdmDestinations.cdm_test_local_xper();\r
-\r
- final CdmApplicationController appCtr = CdmApplicationController.NewInstance(datasource, dbSchemaValidation);\r
+ System.out.println("cdm start");\r
+ CdmApplicationController appCtr = CdmApplicationController.NewInstance(datasource, dbSchemaValidation);\r
+ System.out.println("cdm started :::");\r
\r
+ adapterCdmXper = new AdaptaterCdmXper(appCtr);\r
\r
Thread t = new Thread() {\r
public void run() {\r
- new Xper(appCtr);\r
+ new Xper(adapterCdmXper);\r
}\r
};\r
+ System.out.println("xper2 start");\r
t.start();\r
+ while(!Utils.xperReady){\r
+ //TODO wait\r
+ }\r
+ System.out.println("xper2 started :::");\r
}\r
\r
- public static void xperloadDataFromCdm(){\r
+ public void xperloadDataFromCdm(){\r
+ System.out.println("start load data");\r
+ // display a loading gif\r
+ Utils.displayLoadingGif(true);\r
+ \r
+ \r
// create a new empty base and load data from CDM\r
- if(Xper.getCdmApplicationController() != null){\r
+ if(Utils.cdmAdapter != null){\r
// create a new base\r
Xper.getMainframe().newBase("baseTest");\r
// specify that the current base is not new (needed to be able to add images)\r
Utils.isNewBase = false;\r
- // use the current directory as working directory for Xper2\r
- XPDisplay.getControler().getBase().setPathName(System.getProperty("user.dir") + Utils.sep);\r
- // create a _thumbnail directory to store thumbnails\r
- new File(System.getProperty("user.dir") + Utils.sep + "images" + Utils.sep + "_thumbnails").mkdirs();\r
// delete the variable create by default and update the frame\r
XPDisplay.getControler().getBase().deleteVariable(XPDisplay.getControler().getBase().getVariableAt(0));\r
XPDisplay.displayNbVariable();\r
XPDisplay.getControler().displayJifVarTree();\r
\r
- AdaptaterCdmXper adapterCdmXper = new AdaptaterCdmXper();\r
- Utils.cdmAdapter = adapterCdmXper;\r
- \r
if (Utils.currentBase != null) {\r
// adaptaterCdmXper.createWorkingSet();\r
adapterCdmXper.load();\r
XPDisplay.getControler().displayJifVarTree();\r
}\r
}\r
+ // undisplay a loading gif\r
+ Utils.displayLoadingGif(false);\r
+ System.out.println("data loaded :::");\r
}\r
\r
/**\r
- * @param args\r
+ * \r
*/\r
- public static void main(String[] args) {\r
- System.out.println("cdm start");\r
- new TestAdapterCdmXper();\r
- System.out.println("cdm started :::");\r
- \r
- while(!Utils.xperReady){\r
- //TODO wait\r
- }\r
- System.out.println("start load data");\r
- // display a loading gif\r
- Utils.displayLoadingGif(true);\r
- // load the data from CDM\r
- \r
- xperloadDataFromCdm();\r
- // undisplay a loading gif\r
- Utils.displayLoadingGif(false);\r
- System.out.println("stop load data");\r
+ private void createThumbnailDirectory() {\r
+ // create a _thumbnail directory to store thumbnails\r
+ new File(System.getProperty("user.dir") + Utils.sep + "images" + Utils.sep + "_thumbnails").mkdirs();\r
+ }\r
+ \r
+ /**\r
+ * \r
+ */\r
+ private void generateThumbnails() {\r
System.out.println("start generate thumbnails");\r
// generate all thumbnails (a loading gif is automatically displayed\r
Utils.generateThumbnailsFromURLImage(XPDisplay.getControler().getBase().getAllResources());\r
System.out.println("stop generate thumbnails");\r
+ }\r
+ \r
+\r
+ private void startPartialCdm() {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+ /**\r
+ * @param args\r
+ */\r
+ public static void main(String[] args) {\r
+ System.out.println("start test");\r
+ //start CDM and Xper\r
+ TestAdapterCdmXper testAdapter = new TestAdapterCdmXper();\r
+ testAdapter.startApplications();\r
+ testAdapter.createThumbnailDirectory();\r
+ if (args.length >= 1 && "-p".equals(args[0]) ){\r
+ testAdapter.startPartialCdm();\r
+ }else{\r
+ // load the data from CDM\r
+ testAdapter.xperloadDataFromCdm();\r
+ // use the current directory as working directory for Xper2\r
+ XPDisplay.getControler().getBase().setPathName(System.getProperty("user.dir") + Utils.sep);\r
+ \r
+ testAdapter.generateThumbnails();\r
+ }\r
+\r
+\r
\r
}\r
\r
+\r
+\r
+\r
}\r