Blame view

src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java 4.03 KB
d11a0a1d   Nathanael Jourdane   Create package er...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * This file is a part of EpnTAPClient.
 * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
 * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
 * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
 *
 * This program is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
 * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
 * the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */

package eu.omp.irap.vespa.epntapclient.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import javax.xml.datatype.XMLGregorianCalendar;

import eu.omp.irap.vespa.epntapclient.voresource.model.ContentLevel;
import eu.omp.irap.vespa.epntapclient.voresource.model.Creator;
import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
import eu.omp.irap.vespa.epntapclient.voresource.model.Type;
e2264856   Nathanael Jourdane   Delete votable pa...
30
31
import eu.omp.irap.vespa.votable.data.VOTableData;
import eu.omp.irap.vespa.votable.utils.StringJoiner;
d11a0a1d   Nathanael Jourdane   Create package er...
32
33
34
35
36
37
38
39
40
41
42
43

/**
 * @author N. Jourdane
 */
public class ServiceCtrl {

	/** The logger for the class ServiceCtrl. */
	private static final Logger logger = Logger.getLogger(ServiceCtrl.class.getName());

	public static final String DATE_FORMAT = "yyyy/MM/dd HH:mm:ss";


4bcbd19f   Nathanael Jourdane   Fix imports
44
	public final Service getServiceFromResource(Service.ServiceType serviceType,
d11a0a1d   Nathanael Jourdane   Create package er...
45
			Resource resource) {
4bcbd19f   Nathanael Jourdane   Fix imports
46
		Service service = new Service(resource.getIdentifier());
d11a0a1d   Nathanael Jourdane   Create package er...
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
		service.setTitle(resource.getTitle());
		service.setShortName(resource.getShortName());
		StringJoiner types = new StringJoiner(", ");
		for (Type type : resource.getContent().getType()) {
			types.add(type.toString());
		}
		service.setType(types.toString());
		service.setDescription(resource.getContent().getDescription());
		StringJoiner creators = new StringJoiner(", ");
		for (Creator creator : resource.getCuration().getCreator()) {
			creators.add(creator.getName().getValue());
		}
		service.setCreator(creators.toString());
		StringJoiner contentLevels = new StringJoiner(", ");
		for (ContentLevel contentLevel : resource.getContent().getContentLevel()) {
			contentLevels.add(contentLevel.value());
		}

		service.setContentLevel(contentLevels.toString());
		service.setReferenceURL(resource.getContent().getReferenceURL());
		service.setCreated(ServiceCtrl.XMLDateToString(resource.getCreated()));
		service.setUpdated(ServiceCtrl.XMLDateToString(resource.getUpdated()));
		return service;
	}

	private static String XMLDateToString(XMLGregorianCalendar date) {
		SimpleDateFormat sdf = new SimpleDateFormat(ServiceCtrl.DATE_FORMAT);
		return sdf.format(date.toGregorianCalendar().getTime());
	}

4bcbd19f   Nathanael Jourdane   Fix imports
77
	public final List<Service> getServiceFromVOTableData(Service.ServiceType serviceType,
d11a0a1d   Nathanael Jourdane   Create package er...
78
			VOTableData data) {
4bcbd19f   Nathanael Jourdane   Fix imports
79
		List<Service> services = new ArrayList<>();
d11a0a1d   Nathanael Jourdane   Create package er...
80
		for (int i = 0; i < data.getNbRows(); i++) {
4bcbd19f   Nathanael Jourdane   Fix imports
81
			Service service = new Service((String) data.getCell(i, "ivoid"));
d11a0a1d   Nathanael Jourdane   Create package er...
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
			service.setTitle((String) data.getCell(i, "res_title"));
			service.setShortName((String) data.getCell(i, "short_name"));
			service.setType((String) data.getCell(i, "content_type"));
			service.setDescription((String) data.getCell(i, "res_description"));
			service.setCreator((String) data.getCell(i, "creator_seq"));
			service.setContentLevel((String) data.getCell(i, "content_level"));
			service.setReferenceURL((String) data.getCell(i, "reference_url"));
			service.setCreated((String) data.getCell(i, "created"));
			service.setUpdated((String) data.getCell(i, "updated"));
			// TODO: Convert date format
			services.add(service);
		}

		return services;
	}
}