Merge branch 'hotfix/5.45.1'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / dataimport / e4 / GbifResponseImportView.java
1 /**
2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.view.dataimport.e4;
10
11 import java.io.IOException;
12 import java.net.URISyntaxException;
13 import java.util.Collection;
14
15 import org.apache.http.client.ClientProtocolException;
16
17 import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
18 import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
19
20 /**
21 * @author pplitzner
22 * @date Sep 5, 2014
23 *
24 */
25 public class GbifResponseImportView extends DataImportView<GbifResponse> {
26
27
28 public static final String ID = "eu.etaxonomy.taxeditor.view.dataimport.e4.GbifResponseImportView";
29
30 @Override
31 protected String getTextForTableItem(GbifResponse item) {
32
33 String text = "";
34 String unitId = "";
35 if(item.getDataSetProtocol()!=null){
36 text += "["+item.getDataSetProtocol()+"] ";
37 }
38 if (item.getDerivedUnitFacade().getAccessionNumber() != null) {
39 unitId = item.getDerivedUnitFacade().getAccessionNumber();
40 }else if (item.getDerivedUnitFacade().getBarcode() != null) {
41 unitId = item.getDerivedUnitFacade().getBarcode();
42 }else {
43 unitId = item.getDerivedUnitFacade().getCatalogNumber();
44 }
45 if(item.getScientificName() != null){
46
47 text = item.getScientificName().getTitleCache();
48 }
49 //if (text != null){
50 String collectionCode = item.getDerivedUnitFacade().getCollection() != null ? " - " + item.getDerivedUnitFacade().getCollection().getCode(): "";
51 String kindOfUnit = item.getDerivedUnitFacade().getDerivedUnitKindOfUnit() != null ? " - " + item.getDerivedUnitFacade().getDerivedUnitKindOfUnit().toString():"";
52
53 return text + collectionCode + unitId + kindOfUnit;
54 //}
55
56 // String text = "";
57 // if(item.getDataSetProtocol()!=null){
58 // text += "["+item.getDataSetProtocol()+"] ";
59 // }
60 // text += item.getDerivedUnitFacade().innerDerivedUnit().generateTitle();
61 // return text;
62 }
63
64 /* (non-Javadoc)
65 * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#query()
66 */
67 @Override
68 public void query() {
69 String errorMessage = "Could not execute query " + query;
70 try{
71 Collection<GbifResponse> results = new GbifQueryServiceWrapper().query(query);
72 setResults(results);
73 } catch (ClientProtocolException e) {
74 logger.error(errorMessage, e);
75 } catch (IOException e) {
76 logger.error(errorMessage, e);
77 } catch (URISyntaxException e) {
78 // TODO Auto-generated catch block
79 e.printStackTrace();
80 }
81 }
82 }