|
| 1 | +/******************************************************************************* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2011 - 2015 OpenWorm. |
| 5 | + * http://openworm.org |
| 6 | + * |
| 7 | + * All rights reserved. This program and the accompanying materials |
| 8 | + * are made available under the terms of the MIT License |
| 9 | + * which accompanies this distribution, and is available at |
| 10 | + * http://opensource.org/licenses/MIT |
| 11 | + * |
| 12 | + * Contributors: |
| 13 | + * OpenWorm - http://openworm.org/people.html |
| 14 | + * |
| 15 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 16 | + * of this software and associated documentation files (the "Software"), to deal |
| 17 | + * in the Software without restriction, including without limitation the rights |
| 18 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 19 | + * copies of the Software, and to permit persons to whom the Software is |
| 20 | + * furnished to do so, subject to the following conditions: |
| 21 | + * |
| 22 | + * The above copyright notice and this permission notice shall be included in |
| 23 | + * all copies or substantial portions of the Software. |
| 24 | + * |
| 25 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 26 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 27 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 28 | + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 29 | + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 30 | + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 31 | + * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 32 | + *******************************************************************************/ |
| 33 | +package org.geppetto.datasources; |
| 34 | + |
| 35 | +import java.util.ArrayList; |
| 36 | +import java.util.List; |
| 37 | + |
| 38 | +import org.geppetto.core.datasources.IDataSourceService; |
| 39 | +import org.geppetto.core.datasources.QueryChecker; |
| 40 | +import org.geppetto.core.model.GeppettoModelAccess; |
| 41 | +import org.geppetto.core.services.AService; |
| 42 | +import org.geppetto.model.DataSource; |
| 43 | +import org.geppetto.model.Query; |
| 44 | +import org.geppetto.model.variables.Variable; |
| 45 | + |
| 46 | +/** |
| 47 | + * @author matteocantarelli |
| 48 | + * |
| 49 | + */ |
| 50 | +public abstract class ADataSourceService extends AService implements IDataSourceService |
| 51 | +{ |
| 52 | + |
| 53 | + public enum ConnectionType |
| 54 | + { |
| 55 | + GET, POST |
| 56 | + } |
| 57 | + |
| 58 | + private DataSource configuration; |
| 59 | + |
| 60 | + private String dataSourceTemplate; |
| 61 | + |
| 62 | + private GeppettoModelAccess geppettoModelAccess; |
| 63 | + |
| 64 | + public ADataSourceService(String dataSourceTemplate) |
| 65 | + { |
| 66 | + this.dataSourceTemplate = dataSourceTemplate; |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public void initialize(DataSource configuration, GeppettoModelAccess geppettoModelAccess) |
| 71 | + { |
| 72 | + this.configuration = configuration; |
| 73 | + this.geppettoModelAccess = geppettoModelAccess; |
| 74 | + } |
| 75 | + |
| 76 | + protected GeppettoModelAccess getGeppettoModelAccess() |
| 77 | + { |
| 78 | + return geppettoModelAccess; |
| 79 | + } |
| 80 | + |
| 81 | + protected String getTemplate() |
| 82 | + { |
| 83 | + return dataSourceTemplate; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @return the configuration for this DataSourceService |
| 88 | + */ |
| 89 | + protected DataSource getConfiguration() |
| 90 | + { |
| 91 | + return configuration; |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * @param url |
| 96 | + * @param queryString |
| 97 | + * @return |
| 98 | + */ |
| 99 | + protected String getQueryURL(String url, String queryString) |
| 100 | + { |
| 101 | + String queryURL = null; |
| 102 | + // TODO Do we need a template? Plain concatenation? |
| 103 | + return queryURL; |
| 104 | + } |
| 105 | + |
| 106 | + /* |
| 107 | + * (non-Javadoc) |
| 108 | + * |
| 109 | + * @see org.geppetto.core.model.QueryProvider#getAvailableQueries(org.geppetto.model.variables.Variable) |
| 110 | + */ |
| 111 | + @Override |
| 112 | + public List<Query> getAvailableQueries(Variable variable) |
| 113 | + { |
| 114 | + List<Query> availableQueries = new ArrayList<Query>(); |
| 115 | + for(Query query : configuration.getQueries()) |
| 116 | + { |
| 117 | + if(QueryChecker.check(query, variable)) |
| 118 | + { |
| 119 | + availableQueries.add(query); |
| 120 | + } |
| 121 | + } |
| 122 | + return availableQueries; |
| 123 | + } |
| 124 | + |
| 125 | + /* |
| 126 | + * (non-Javadoc) |
| 127 | + * |
| 128 | + * @see org.geppetto.core.services.IService#registerGeppettoService() |
| 129 | + */ |
| 130 | + @Override |
| 131 | + public void registerGeppettoService() throws Exception |
| 132 | + { |
| 133 | + // Nothing to do here |
| 134 | + } |
| 135 | + |
| 136 | +} |
0 commit comments