Project

General

Profile

Download (4.36 KB) Statistics
| Branch: | Revision:

git_sitools_idoc / sitools-idoc / hesiod / javaExt / src / fr / ias / sitools / vo / tap / TableAccessProtocolLibrary.java @ 779bac69

1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package fr.ias.sitools.vo.tap;
7

    
8
import fr.ias.sitools.vo.representation.VOTableRepresentation;
9
import fr.cnes.sitools.dataset.DataSetApplication;
10
import fr.cnes.sitools.plugins.resources.model.ResourceModel;
11
import java.util.Map;
12
import java.util.logging.Level;
13
import org.restlet.Context;
14
import org.restlet.Request;
15

    
16
/**
17
 *
18
 * @author marc
19
 */
20
public class TableAccessProtocolLibrary {
21

    
22
    public enum langSupported {
23

    
24
        ADQL
25
    };
26

    
27
    public enum formatResultsSupported {
28

    
29
        VOTABLE
30
    };
31

    
32
    // Pour la requete
33
    public static final String FORMAT = "FORMAT";
34
    public static final String QUERY = "QUERY";
35
    public static final String LANG = "LANG";
36
    public static final String PHASE = "PHASE";
37
    public static final String REQUEST = "REQUEST";
38
    // String pour décomposer la requete ADQL
39
    public static final String SELECT = "SELECT";
40
    public static final String FROM = "FROM";
41
    public static final String WHERE = "WHERE";
42
    public static final String SELECT_ALL = "*";
43
    public static final String BLANCK = " ";
44

    
45
    private transient DataSetApplication datasetApp;
46
    private transient ResourceModel resourceModel;
47
    private transient Request request;
48
    private transient Context context;
49

    
50
    /**
51
     *
52
     */
53
    public static final String DICTIONARY = "PARAM_Dictionary";
54
    //Pour les Metadata
55
    /**
56
     *
57
     */
58
    public static final String DESCRIPTION = "Description";
59
    /**
60
     *
61
     */
62
    public static final String INSTRUMENT = "Instrument";
63
    /**
64
     *
65
     */
66
    public static final String SERVICE_NAME = "Service Name";
67
    /**
68
     *
69
     */
70
    public static final String MAX_RECORDS = "Max records";
71

    
72
    public TableAccessProtocolLibrary(final DataSetApplication datasetApp, final ResourceModel resourceModel, final Request request, final Context context) {
73
        this.datasetApp = datasetApp;
74
        this.resourceModel = resourceModel;
75
        this.request = request;
76
        this.context = context;
77
    }
78

    
79
    /**
80
     * Fill data Model that will be used in the template.
81
     *
82
     * @return data model for the template
83
     */
84
    private Map fillDataModel() {
85
        // init
86
        Map dataModel = null;
87
        Map<String, Object> map = this.request.getAttributes();
88
        /*
89
         String entityAsText = this.request.getEntityAsText(); 
90
         String query1 = this.request.getResourceRef().getQuery();
91
         String queryDecoded = this.request.getResourceRef().getQuery(true);
92
         String queryNotDecoded = this.request.getResourceRef().getQuery(false);
93
         */
94
        String tapRequestType = this.request.getAttributes().get("tapRequestType").toString();
95
        // Handling input parameters
96
        final DataModelInterface inputParameters = new TableAccessProtocolInputParameters(datasetApp, request, this.context, this.resourceModel);
97
        if (tapRequestType.equalsIgnoreCase("sync")) {
98
            this.context.getLogger().log(Level.INFO, "JE SUIS DANS LE SYNC !!!");
99
            // data model response
100
            if (inputParameters.getDataModel().containsKey("infos")) {
101
                dataModel = inputParameters.getDataModel();
102
            } else {
103
                final TableAccessProtocolDataModelInterface response = new TableAccessProtocolResponse((TableAccessProtocolInputParameters) inputParameters, resourceModel);
104
                dataModel = response.getDataModel();
105
            }
106
        } else if (tapRequestType.equalsIgnoreCase("async")) {
107
            this.context.getLogger().log(Level.INFO, "JE SUIS DANS LE ASYNC !!!");
108
            TableAccessProtocolAsynchronousResponse asyncTask = new TableAccessProtocolAsynchronousResponse((TableAccessProtocolInputParameters) inputParameters);
109
            asyncTask.run();
110
            this.context.getLogger().log(Level.INFO, "Apres le run de la tache async !!!");
111
            
112
        } else {
113
            this.context.getLogger().log(Level.INFO, "JE SUIS DANS NI SYNC NI ASYNC !!!");
114
        }
115

    
116
        return dataModel;
117
    }
118

    
119
    /**
120
     * VOTable response.
121
     *
122
     * @return VOTable response
123
     */
124
    public final VOTableRepresentation getResponse() {
125
        final Map dataModel = fillDataModel();
126
        return new VOTableRepresentation(dataModel, "votable.ftl");
127
    }
128

    
129
}