Commit d11a0a1d0292c3434b6216a3874b8af9b1700741

Authored by Nathanael Jourdane
1 parent 5f904693
Exists in master

Create package ervice with its controller and model.

src/main/java/eu/omp/irap/vespa/epntapclient/lib/Queries.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java
... ... @@ -14,13 +14,13 @@
14 14 * <http://www.gnu.org/licenses/>.
15 15 */
16 16  
17   -package eu.omp.irap.vespa.epntapclient.lib;
  17 +package eu.omp.irap.vespa.epntapclient.service;
18 18  
19 19 import java.util.ArrayList;
20 20 import java.util.List;
21 21 import java.util.Map;
22 22  
23   -import eu.omp.irap.vespa.epntapclient.votable.utils.Strings.StringJoiner;
  23 +import eu.omp.irap.vespa.epntapclient.votable.utils.StringJoiner;
24 24  
25 25 /**
26 26 * Defines the queries and the query patterns usually used in the application.
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/service/Service.java 0 → 100644
... ... @@ -0,0 +1,153 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.service;
  18 +
  19 +/**
  20 + * @author N. Jourdane
  21 + */
  22 +public class ServiceModel {
  23 +
  24 + private String ivoid;
  25 +
  26 + private String resTitle;
  27 +
  28 + private String shortName;
  29 +
  30 + private String type;
  31 +
  32 + private String description;
  33 +
  34 + private String creator;
  35 +
  36 + private String contentLevel;
  37 +
  38 + private String referenceURL;
  39 +
  40 + private String created;
  41 +
  42 + private String updated;
  43 +
  44 +
  45 + public enum ServiceType {
  46 +
  47 + OBSCORE("obscore"), EPNCORE("epncore");
  48 +
  49 + private String type = "";
  50 +
  51 +
  52 + ServiceType(String type) {
  53 + this.type = type;
  54 + }
  55 +
  56 + @Override
  57 + public String toString() {
  58 + return type;
  59 + }
  60 + }
  61 +
  62 +
  63 + private ServiceModel() {
  64 + }
  65 +
  66 + ServiceModel(String ivoid) {
  67 + this.ivoid = ivoid;
  68 + }
  69 +
  70 + public boolean isValid() {
  71 + boolean isValid = ivoid != null && resTitle != null && shortName != null;
  72 + isValid = isValid && type != null && description != null && creator != null;
  73 + isValid = isValid && contentLevel != null && referenceURL != null && created != null;
  74 + return isValid && updated != null;
  75 + }
  76 +
  77 + public String getIvoid() {
  78 + return ivoid;
  79 + }
  80 +
  81 + public String getResTitle() {
  82 + return resTitle;
  83 + }
  84 +
  85 + public String getShortName() {
  86 + return shortName;
  87 + }
  88 +
  89 + public String getType() {
  90 + return type;
  91 + }
  92 +
  93 + public String getDescription() {
  94 + return description;
  95 + }
  96 +
  97 + public String getCreator() {
  98 + return creator;
  99 + }
  100 +
  101 + public String getContentLevel() {
  102 + return contentLevel;
  103 + }
  104 +
  105 + public String getReferenceURL() {
  106 + return referenceURL;
  107 + }
  108 +
  109 + public String getCreated() {
  110 + return created;
  111 + }
  112 +
  113 + public String getUpdated() {
  114 + return updated;
  115 + }
  116 +
  117 + public void setTitle(String resTitle) {
  118 + this.resTitle = resTitle;
  119 + }
  120 +
  121 + public void setShortName(String shortName) {
  122 + this.shortName = shortName;
  123 + }
  124 +
  125 + public void setType(String type) {
  126 + this.type = type;
  127 + }
  128 +
  129 + public void setDescription(String description) {
  130 + this.description = description;
  131 + }
  132 +
  133 + public void setCreator(String creator) {
  134 + this.creator = creator;
  135 + }
  136 +
  137 + public void setContentLevel(String contentLevel) {
  138 + this.contentLevel = contentLevel;
  139 + }
  140 +
  141 + public void setReferenceURL(String referenceURL) {
  142 + this.referenceURL = referenceURL;
  143 + }
  144 +
  145 + public void setCreated(String created) {
  146 + this.created = created;
  147 + }
  148 +
  149 + public void setUpdated(String updated) {
  150 + this.updated = updated;
  151 + }
  152 +
  153 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java 0 → 100644
... ... @@ -0,0 +1,97 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.service;
  18 +
  19 +import java.text.SimpleDateFormat;
  20 +import java.util.ArrayList;
  21 +import java.util.List;
  22 +import java.util.logging.Logger;
  23 +
  24 +import javax.xml.datatype.XMLGregorianCalendar;
  25 +
  26 +import eu.omp.irap.vespa.epntapclient.voresource.model.ContentLevel;
  27 +import eu.omp.irap.vespa.epntapclient.voresource.model.Creator;
  28 +import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
  29 +import eu.omp.irap.vespa.epntapclient.voresource.model.Type;
  30 +import eu.omp.irap.vespa.epntapclient.votable.data.VOTableData;
  31 +import eu.omp.irap.vespa.epntapclient.votable.utils.StringJoiner;
  32 +
  33 +/**
  34 + * @author N. Jourdane
  35 + */
  36 +public class ServiceCtrl {
  37 +
  38 + /** The logger for the class ServiceCtrl. */
  39 + private static final Logger logger = Logger.getLogger(ServiceCtrl.class.getName());
  40 +
  41 + public static final String DATE_FORMAT = "yyyy/MM/dd HH:mm:ss";
  42 +
  43 +
  44 + public final ServiceModel getServiceFromResource(ServiceModel.ServiceType serviceType,
  45 + Resource resource) {
  46 + ServiceModel service = new ServiceModel(resource.getIdentifier());
  47 + service.setTitle(resource.getTitle());
  48 + service.setShortName(resource.getShortName());
  49 + StringJoiner types = new StringJoiner(", ");
  50 + for (Type type : resource.getContent().getType()) {
  51 + types.add(type.toString());
  52 + }
  53 + service.setType(types.toString());
  54 + service.setDescription(resource.getContent().getDescription());
  55 + StringJoiner creators = new StringJoiner(", ");
  56 + for (Creator creator : resource.getCuration().getCreator()) {
  57 + creators.add(creator.getName().getValue());
  58 + }
  59 + service.setCreator(creators.toString());
  60 + StringJoiner contentLevels = new StringJoiner(", ");
  61 + for (ContentLevel contentLevel : resource.getContent().getContentLevel()) {
  62 + contentLevels.add(contentLevel.value());
  63 + }
  64 +
  65 + service.setContentLevel(contentLevels.toString());
  66 + service.setReferenceURL(resource.getContent().getReferenceURL());
  67 + service.setCreated(ServiceCtrl.XMLDateToString(resource.getCreated()));
  68 + service.setUpdated(ServiceCtrl.XMLDateToString(resource.getUpdated()));
  69 + return service;
  70 + }
  71 +
  72 + private static String XMLDateToString(XMLGregorianCalendar date) {
  73 + SimpleDateFormat sdf = new SimpleDateFormat(ServiceCtrl.DATE_FORMAT);
  74 + return sdf.format(date.toGregorianCalendar().getTime());
  75 + }
  76 +
  77 + public final List<ServiceModel> getServiceFromVOTableData(ServiceModel.ServiceType serviceType,
  78 + VOTableData data) {
  79 + List<ServiceModel> services = new ArrayList<>();
  80 + for (int i = 0; i < data.getNbRows(); i++) {
  81 + ServiceModel service = new ServiceModel((String) data.getCell(i, "ivoid"));
  82 + service.setTitle((String) data.getCell(i, "res_title"));
  83 + service.setShortName((String) data.getCell(i, "short_name"));
  84 + service.setType((String) data.getCell(i, "content_type"));
  85 + service.setDescription((String) data.getCell(i, "res_description"));
  86 + service.setCreator((String) data.getCell(i, "creator_seq"));
  87 + service.setContentLevel((String) data.getCell(i, "content_level"));
  88 + service.setReferenceURL((String) data.getCell(i, "reference_url"));
  89 + service.setCreated((String) data.getCell(i, "created"));
  90 + service.setUpdated((String) data.getCell(i, "updated"));
  91 + // TODO: Convert date format
  92 + services.add(service);
  93 + }
  94 +
  95 + return services;
  96 + }
  97 +}
... ...