298b1f4b66ce0638bc638b0b83471446c81db1ea
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / dataimport / SpecimenImportView.java
1 // $Id$
2 /**
3 * Copyright (C) 2014 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.editor.view.dataimport;
11
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.net.URI;
15 import java.util.ArrayList;
16 import java.util.Collection;
17
18 import org.apache.http.client.ClientProtocolException;
19 import org.eclipse.core.runtime.jobs.Job;
20
21 import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
22 import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
23 import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
24 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
25 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
26 import eu.etaxonomy.taxeditor.editor.view.dataimport.transientServices.TransientCdmRepository;
27 import eu.etaxonomy.taxeditor.store.CdmStore;
28
29 /**
30 * @author pplitzner
31 * @date Sep 3, 2014
32 *
33 */
34 public class SpecimenImportView extends DataImportView<SpecimenOrObservationBase<?>> {
35
36 public static final String ID = "eu.etaxonomy.taxeditor.editor.view.dataimport.SpecimenImportView"; //$NON-NLS-1$
37
38 private URI endPoint;
39
40 public SpecimenImportView() {
41 }
42
43 /**
44 * @param endPoint
45 */
46 public void setEndpoint(URI endPoint) {
47 this.endPoint = endPoint;
48 }
49
50 /* (non-Javadoc)
51 * @see eu.etaxonomy.taxeditor.editor.view.dataimport.DataImportView#getTextForTableItem(java.lang.Object)
52 */
53 @Override
54 protected String getTextForTableItem(SpecimenOrObservationBase<?> item) {
55 return item.getTitleCache();
56 }
57
58 /* (non-Javadoc)
59 * @see eu.etaxonomy.taxeditor.editor.view.dataimport.DataImportView#query()
60 */
61 @Override
62 public void query() {
63 String errorMessage = "Could not execute query " + query;
64
65 Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
66 try {
67 //FIXME move ABCD import to cdmlib -> this will also get rid of the transient services
68 InputStream resultStream;
69 resultStream = new BioCaseQueryServiceWrapper().query(query, endPoint);
70 Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(null, null);
71 TransientCdmRepository repo =
72 new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
73 configurator.setCdmAppController(repo);
74 configurator.setAddMediaAsMediaSpecimen(true);
75 if(CdmStore.getCurrentSessionManager().isRemoting()) {
76 Job job = CdmStore.getImportManager().createIOServiceJob(configurator, resultStream, SOURCE_TYPE.INPUTSTREAM);
77 CdmStore.getImportManager().run(job);
78 } else {
79 configurator.setSource(resultStream);
80 CdmDefaultImport<Abcd206ImportConfigurator> importer = new CdmDefaultImport<Abcd206ImportConfigurator>();
81 importer.invoke(configurator);
82 }
83 results = repo.getUnits();
84 setResults(results);
85 } catch (ClientProtocolException e) {
86 logger.error(errorMessage, e);
87 } catch (IOException e) {
88 logger.error(errorMessage, e);
89 }
90
91 setResults(results);
92
93 }
94
95 }