diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/api/v1/QueryApiFacade.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/api/v1/QueryApiFacade.java new file mode 100644 index 0000000000000000000000000000000000000000..c246d32d28b36ebdbe7f5441e8aae599ebe13dee --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/api/v1/QueryApiFacade.java @@ -0,0 +1,64 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.query.client.api.v1; + +import java.util.List; + +import ch.systemsx.cisd.common.spring.HttpInvokerUtils; +import ch.systemsx.cisd.openbis.plugin.query.server.api.v1.ResourceNames; +import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.IQueryApiServer; +import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.dto.QueryDescription; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class QueryApiFacade +{ + private static final int SERVER_TIMEOUT_MIN = 5; + + public static QueryApiFacade create(String serverURL, String userID, String password) + { + IQueryApiServer service = HttpInvokerUtils.createServiceStub(IQueryApiServer.class, serverURL + ResourceNames.QUERY_PLUGIN_SERVER_URL, SERVER_TIMEOUT_MIN); + String sessionToken = service.tryToAuthenticateAtQueryServer(userID, password); + if (sessionToken == null) + { + throw new IllegalArgumentException("User " + userID + "couldn't be authenticated"); + } + return new QueryApiFacade(service, sessionToken); + } + + private final IQueryApiServer service; + private final String sessionToken; + + QueryApiFacade(IQueryApiServer service, String sessionToken) + { + this.service = service; + this.sessionToken = sessionToken; + } + + public void logout() + { + service.logout(sessionToken); + } + + public List<QueryDescription> listQueries() + { + return service.listQueries(sessionToken); + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/api/v1/QueryApiTest.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/api/v1/QueryApiTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d111a5d5a84ff336592045810a28f692a76b8ef4 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/api/v1/QueryApiTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.query.client.api.v1; + +import java.util.List; + +import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.dto.QueryDescription; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class QueryApiTest +{ + public static void main(String[] args) + { + if (args.length != 3) + { + System.err.println("Usage: <openbis-server-url> <user> <password>"); + return; + } + + String serverURL = args[0]; + String userID = args[1]; + String password = args[2]; + + QueryApiFacade facade = QueryApiFacade.create(serverURL, userID, password); + + List<QueryDescription> queries = facade.listQueries(); + for (QueryDescription queryDescription : queries) + { + System.out.println(queryDescription.getName()+": "+queryDescription.getParameters()); + } + + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/api/v1/QueryApiLogger.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/api/v1/QueryApiLogger.java new file mode 100644 index 0000000000000000000000000000000000000000..cb34fabbcaf11949fbce02dc33be1c5befa44f8c --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/api/v1/QueryApiLogger.java @@ -0,0 +1,59 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.query.server.api.v1; + +import java.util.List; +import java.util.Map; + +import ch.systemsx.cisd.authentication.ISessionManager; +import ch.systemsx.cisd.common.spring.IInvocationLoggerContext; +import ch.systemsx.cisd.openbis.generic.server.AbstractServerLogger; +import ch.systemsx.cisd.openbis.generic.shared.dto.Session; +import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.IQueryApiServer; +import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.dto.QueryDescription; +import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.dto.QueryTableModel; + +/** + * + * + * @author Franz-Josef Elmer + */ +class QueryApiLogger extends AbstractServerLogger implements IQueryApiServer +{ + + QueryApiLogger(ISessionManager<Session> sessionManager, IInvocationLoggerContext context) + { + super(sessionManager, context); + } + + public QueryTableModel executeQuery(long queryID, Map<String, String> parameterBindings) + { + return null; + } + + public List<QueryDescription> listQueries(String sessionToken) + { + logAccess(sessionToken, "list_queries"); + return null; + } + + public String tryToAuthenticateAtQueryServer(String userID, String userPassword) + { + return null; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/api/v1/QueryApiServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/api/v1/QueryApiServer.java new file mode 100644 index 0000000000000000000000000000000000000000..49da8e315193865b77b79f105de3810abf4b22c4 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/api/v1/QueryApiServer.java @@ -0,0 +1,80 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.query.server.api.v1; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Component; + +import ch.systemsx.cisd.common.spring.IInvocationLoggerContext; +import ch.systemsx.cisd.openbis.generic.server.AbstractServer; +import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO; +import ch.systemsx.cisd.openbis.plugin.query.shared.IQueryServer; +import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.IQueryApiServer; +import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.dto.QueryDescription; +import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.dto.QueryTableModel; +import ch.systemsx.cisd.openbis.plugin.query.shared.basic.dto.QueryExpression; + +/** + * + * + * @author Franz-Josef Elmer + */ +@Component(ResourceNames.QUERY_PLUGIN_SERVER) +public class QueryApiServer extends AbstractServer<IQueryApiServer> implements IQueryApiServer +{ + @Resource(name = ch.systemsx.cisd.openbis.plugin.query.shared.ResourceNames.QUERY_PLUGIN_SERVER) + private IQueryServer queryServer; + + public IQueryApiServer createLogger(IInvocationLoggerContext context) + { + return new QueryApiLogger(sessionManager, context); + } + + public String tryToAuthenticateAtQueryServer(String userID, String userPassword) + { + SessionContextDTO session = tryToAuthenticate(userID, userPassword); + return session == null ? null : session.getSessionToken(); + } + + public List<QueryDescription> listQueries(String sessionToken) + { + List<QueryDescription> result = new ArrayList<QueryDescription>(); + List<QueryExpression> queries = queryServer.listQueries(sessionToken); + for (QueryExpression queryExpression : queries) + { + QueryDescription queryDescription = new QueryDescription(); + queryDescription.setId(queryExpression.getId()); + queryDescription.setName(queryExpression.getName()); + queryDescription.setDescription(queryExpression.getDescription()); + queryDescription.setParameters(queryExpression.getParameters()); + result.add(queryDescription); + } + return result; + } + + public QueryTableModel executeQuery(long queryID, Map<String, String> parameterBindings) + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/api/v1/QueryServiceServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/api/v1/QueryServiceServer.java new file mode 100644 index 0000000000000000000000000000000000000000..97e16d43a288b8d45336c3e547f537cbb8f0aefb --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/api/v1/QueryServiceServer.java @@ -0,0 +1,47 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.query.server.api.v1; + +import javax.annotation.Resource; + +import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.IQueryApiServer; + +/** + * + * + * @author Franz-Josef Elmer + */ +@Controller +@RequestMapping( + { ResourceNames.QUERY_PLUGIN_SERVER_URL, "/openbis" + ResourceNames.QUERY_PLUGIN_SERVER_URL }) +public class QueryServiceServer extends HttpInvokerServiceExporter +{ + @Resource(name = ResourceNames.QUERY_PLUGIN_SERVER) + private IQueryApiServer server; + + @Override + public void afterPropertiesSet() + { + setServiceInterface(IQueryApiServer.class); + setService(server); + super.afterPropertiesSet(); + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/api/v1/ResourceNames.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/api/v1/ResourceNames.java new file mode 100644 index 0000000000000000000000000000000000000000..91052e1adc16a898861b176a1fea198a5d3767e3 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/api/v1/ResourceNames.java @@ -0,0 +1,30 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.query.server.api.v1; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class ResourceNames +{ + public final static String QUERY_PLUGIN_SERVER = "query-api-server-v1"; + + public final static String QUERY_PLUGIN_SERVER_URL = "/rmi-query-v1"; + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/shared/api/v1/IQueryApiServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/shared/api/v1/IQueryApiServer.java new file mode 100644 index 0000000000000000000000000000000000000000..729268f3ecd11e8e6f193c82007b8d3f62b9dbc3 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/shared/api/v1/IQueryApiServer.java @@ -0,0 +1,60 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.query.shared.api.v1; + +import java.util.List; +import java.util.Map; + +import org.springframework.transaction.annotation.Transactional; + +import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.dto.QueryDescription; +import ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.dto.QueryTableModel; + +/** + * Public API interface to query server (version 1). + * + * @author Franz-Josef Elmer + */ +// DO NOT CHANGE THE INTERFACE CONTRACT IN A NON-BACKWARD COMPATIBLE WAY! +public interface IQueryApiServer +{ + /** + * Tries to authenticate specified user with specified password. Returns session token if + * succeeded otherwise <code>null</code> is returned. + */ + @Transactional // this is not a readOnly transaction - it can create new users + public String tryToAuthenticateAtQueryServer(String userID, String userPassword); + + /** + * Logout the session with the specified session token. + */ + @Transactional(readOnly = true) + public void logout(String sessionToken); + + /** + * Lists all queries available for the user of the specified session. + */ + @Transactional(readOnly = true) + public List<QueryDescription> listQueries(String sessionToken); + + /** + * Executes specified query using specified parameter bindings. + */ + @Transactional(readOnly = true) + public QueryTableModel executeQuery(long queryID, Map<String, String> parameterBindings); + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/shared/api/v1/dto/QueryDescription.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/shared/api/v1/dto/QueryDescription.java new file mode 100644 index 0000000000000000000000000000000000000000..16761123916f015ddde347053e64c651697c2175 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/shared/api/v1/dto/QueryDescription.java @@ -0,0 +1,93 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.dto; + +import java.io.Serializable; +import java.util.List; + +/** + * Description of a query. Contains everything needed on client side to show to the user what + * queries are available, to specify parameter bindings, and to identify a query uniquely. + * + * @author Franz-Josef Elmer + */ +public class QueryDescription implements Serializable +{ + private static final long serialVersionUID = 1L; + + private long id; + + private String name; + + private String description; + + private List<String> parameters; + + /** + * Returns the ID of the query. Will be used to identify the query to be executed. + */ + public long getId() + { + return id; + } + + public void setId(long id) + { + this.id = id; + } + + /** + * Returns the name of the query. + */ + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + /** + * Returns an optional description or empty string if undefined. + */ + public String getDescription() + { + return description == null ? "" : description; + } + + public void setDescription(String description) + { + this.description = description; + } + + /** + * Returns the list of parameters to which values should be bound when executing the query. + * + * @return an empty list if there are no parameters. + */ + public List<String> getParameters() + { + return parameters; + } + + public void setParameters(List<String> parameters) + { + this.parameters = parameters; + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/shared/api/v1/dto/QueryTableModel.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/shared/api/v1/dto/QueryTableModel.java new file mode 100644 index 0000000000000000000000000000000000000000..794617541d855e4f3d5eb229b26fa0ccfacaf539 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/shared/api/v1/dto/QueryTableModel.java @@ -0,0 +1,30 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.query.shared.api.v1.dto; + +import java.io.Serializable; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class QueryTableModel implements Serializable +{ + private static final long serialVersionUID = 1L; + +}