diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/AdminConsole.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/AdminConsole.java index f246da2d96343e46bdf7f41f7de9a8aaf9d5a7c3..d2dc9a1b80ce45231db7c083c69030a149c7a266 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/AdminConsole.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/AdminConsole.java @@ -128,6 +128,7 @@ public class AdminConsole private static Map<String, ICommand> createCommands() { HashMap<String, ICommand> map = new HashMap<String, ICommand>(); + map.put("register-property-type", new RegisterPropertyType()); map.put("register-type", new RegisterType()); map.put("assign-to", new Assignment()); map.put("set", new Set()); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/Lexer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/Lexer.java new file mode 100644 index 0000000000000000000000000000000000000000..890b5f76fdef947f9755f8ab4cfe2c6829383ded --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/Lexer.java @@ -0,0 +1,119 @@ +/* + * 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.generic.client.console; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Franz-Josef Elmer + */ +class Lexer +{ + private static class ParsingContext + { + private final List<String> tokens = new ArrayList<String>(); + private final StringBuilder builder = new StringBuilder(); + + public void addCharacter(char character) + { + builder.append(character); + } + + public void finishToken() + { + tokens.add(builder.toString()); + builder.setLength(0); + } + + public List<String> getTokens() + { + if (builder.length() > 0) + { + finishToken(); + } + return tokens; + } + } + + private enum State + { + BETWEEN_TOKENS() + { + @Override + public State next(char character, ParsingContext context) + { + if (Character.isWhitespace(character)) + { + return this; + } + if (character == '\"') + { + return IN_QUOTED_TOKEN; + } + context.addCharacter(character); + return IN_TOKEN; + } + }, + IN_TOKEN() + { + @Override + public State next(char character, ParsingContext context) + { + if (Character.isWhitespace(character)) + { + context.finishToken(); + return BETWEEN_TOKENS; + } + if (character == '\"') + { + context.finishToken(); + return IN_QUOTED_TOKEN; + } + context.addCharacter(character); + return this; + } + }, + IN_QUOTED_TOKEN() + { + @Override + public State next(char character, ParsingContext context) + { + if (character == '\"') + { + context.finishToken(); + return BETWEEN_TOKENS; + } + context.addCharacter(character); + return this; + } + }; + + abstract State next(char character, ParsingContext context); + } + + static List<String> extractTokens(String string) + { + ParsingContext context = new ParsingContext(); + State state = State.BETWEEN_TOKENS; + for (int i = 0, n = string.length(); i < n; i++) + { + state = state.next(string.charAt(i), context); + } + return context.getTokens(); + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/RegisterPropertyType.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/RegisterPropertyType.java new file mode 100644 index 0000000000000000000000000000000000000000..a04ccb7486a7e03ba9f68ff42d8e8cd45dce03ec --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/RegisterPropertyType.java @@ -0,0 +1,54 @@ +/* + * 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.generic.client.console; + +import ch.systemsx.cisd.openbis.generic.shared.ICommonServer; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class RegisterPropertyType implements ICommand +{ + + private static final String WITH_DATA_TYPE = " with data type "; + private static final String LABEL = ", label = "; + + public void execute(ICommonServer server, String sessionToken, ScriptContext context, + String argument) + { + PropertyType propertyType = new PropertyType(); + int indexOfWithDataType = argument.indexOf(WITH_DATA_TYPE); + if (indexOfWithDataType < 0) + { + throw new IllegalArgumentException("'with data type' misspelled"); + } + propertyType.setCode(argument.substring(0, indexOfWithDataType)); + +// propertyType.setLabel(label); +// propertyType.setDescription(description); +// DataTypeCode dataType = DataTypeCode.valueOf(dataTypeCode); +// propertyType.setDataType(new DataType(dataType)); + server.registerPropertyType(sessionToken, propertyType); + + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java index afeae4e4c4536b412dc10808694e561789d3addb..cfba67300d866531936db9a2ec3fb4f9b4c64579 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java @@ -1627,8 +1627,9 @@ public final class CommonServer extends AbstractCommonServer<ICommonServer> impl Session session = getSession(sessionToken); IExternalDataTable externalDataTable = businessObjectFactory.createExternalDataTable(session); + Map<String, String> parameterBindings = new HashMap<String, String>(); externalDataTable.processDatasets(serviceDescription.getKey(), serviceDescription - .getDatastoreCode(), datasetCodes); + .getDatastoreCode(), datasetCodes, parameterBindings); } public void registerAuthorizationGroup(String sessionToken, diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExternalDataTable.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExternalDataTable.java index 7601abf7debea713aa94abeec0c83eb635767bb0..f1bfe077f04f0184b727e3e37177db6fed1922f1 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExternalDataTable.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExternalDataTable.java @@ -36,6 +36,7 @@ import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.generic.server.business.IDataStoreServiceFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IExternalDataDAO; +import ch.systemsx.cisd.openbis.generic.shared.Constants; import ch.systemsx.cisd.openbis.generic.shared.IDataStoreService; import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; @@ -394,7 +395,7 @@ public final class ExternalDataTable extends AbstractExternalDataBusinessObject } public void processDatasets(String datastoreServiceKey, String datastoreCode, - List<String> datasetCodes) + List<String> datasetCodes, Map<String, String> parameterBindings) { DataStorePE dataStore = findDataStore(datastoreCode); IDataStoreService service = tryGetDataStoreService(dataStore); @@ -404,7 +405,8 @@ public final class ExternalDataTable extends AbstractExternalDataBusinessObject } List<DatasetDescription> locations = loadAvailableDatasetDescriptions(datasetCodes); String sessionToken = dataStore.getSessionToken(); - service.processDatasets(sessionToken, datastoreServiceKey, locations, + parameterBindings.put(Constants.USER_PARAMETER, session.tryGetPerson().getUserId()); + service.processDatasets(sessionToken, datastoreServiceKey, locations, parameterBindings, tryGetLoggedUserEmail()); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IExternalDataTable.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IExternalDataTable.java index 936be1bc1ac167d39870b11e827ddbbba87dbfa9..a8838d8cebff3076b1991cc39acde6ff9976e178 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IExternalDataTable.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IExternalDataTable.java @@ -17,6 +17,7 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo; import java.util.List; +import java.util.Map; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel; @@ -105,8 +106,12 @@ public interface IExternalDataTable TableModel createReportFromDatasets(String datastoreServiceKey, String datastoreCode, List<String> datasetCodes); - /** Schedules processing of specified datasets using the specified datastore service. */ - void processDatasets(String datastoreServiceKey, String datastoreCode, List<String> datasetCodes); + /** + * Schedules processing of specified datasets with specified parameter bindings using the + * specified datastore service. + */ + void processDatasets(String datastoreServiceKey, String datastoreCode, + List<String> datasetCodes, Map<String, String> parameterBindings); /** * Loads data sets that belong to chosen data store. diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/Constants.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/Constants.java new file mode 100644 index 0000000000000000000000000000000000000000..71a41b1a9aa21ee8afc27668affb0206435366b6 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/Constants.java @@ -0,0 +1,27 @@ +/* + * 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.generic.shared; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class Constants +{ + public static final String USER_PARAMETER = "user"; +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/IDataStoreService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/IDataStoreService.java index 2d10c28338e15766a7ee27354b79fd198361fd4e..fe5aa6cf4bf021b374eaeb2d74b54f74ac116180 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/IDataStoreService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/IDataStoreService.java @@ -17,6 +17,7 @@ package ch.systemsx.cisd.openbis.generic.shared; import java.util.List; +import java.util.Map; import ch.systemsx.cisd.common.exceptions.InvalidAuthenticationException; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; @@ -79,14 +80,15 @@ public interface IDataStoreService List<DatasetDescription> datasets); /** - * Schedules the processing task with the specified id for provided datasets. + * Schedules the processing task with the specified id for provided datasets and specified + * parameter bindings. * * @param userEmailOrNull Email of user who initiated processing and will get a message after * the processing is finished. It may be null if the user doesn't have email and no * message will be send in such case. */ public void processDatasets(String sessionToken, String serviceKey, - List<DatasetDescription> datasets, String userEmailOrNull); + List<DatasetDescription> datasets, Map<String, String> parameterBindings, String userEmailOrNull); /** * Schedules archiving of provided datasets. diff --git a/openbis/source/java/service.properties b/openbis/source/java/service.properties index 21eccb97a98c74ae111f9cda544381d48aa6cd08..cc50459a3b947d80c28f49483acd2319ac1979fd 100644 --- a/openbis/source/java/service.properties +++ b/openbis/source/java/service.properties @@ -74,10 +74,15 @@ onlinehelp.generic.page-template = https://wiki-bsse.ethz.ch/pages/createpage.ac #onlinehelp.specific.root-url = https://wiki-bsse.ethz.ch/display/CISDDoc/OnlineHelp #onlinehelp.specific.page-template = https://wiki-bsse.ethz.ch/pages/createpage.action?spaceKey=CISDDoc&title=${title}&linkCreation=true&fromPageId=40633829 -query-database.label = openBIS meta data -query-database.databaseEngineCode = ${database.engine} -query-database.basicDatabaseName = openbis -query-database.databaseKind = ${database.kind} +#query-database.label = openBIS meta data +#query-database.databaseEngineCode = ${database.engine} +#query-database.basicDatabaseName = openbis +#query-database.databaseKind = ${database.kind} +query-database.label = Example Data +query-database.databaseEngineCode = postgresql +query-database.basicDatabaseName = example +query-database.databaseKind = dev + # Comma-separated list of host names and IP addresses of clients on which an INSTANCE_ADMIN # user is allowed to change identity accepted-remote-hosts-for-identity-change = localhost diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/console/LexerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/console/LexerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..65e7b5e14b9f5343907ed296c286b2646d0461f5 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/console/LexerTest.java @@ -0,0 +1,49 @@ +/* + * 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.generic.client.console; + +import org.testng.AssertJUnit; +import org.testng.annotations.Test; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class LexerTest extends AssertJUnit +{ + @Test + public void test() + { + check("[]", ""); + check("[]", " "); + check("[]", " \t "); + check("[alpha]", "alpha"); + check("[alpha]", " alpha"); + check("[alpha]", "\talpha\t"); + check("[alpha]", " alpha\t "); + check("[a, b, hello world]", "a b \"hello world\""); + check("[a, b, hello \t world ]", " a\tb \"hello \t world \" "); + check("[a, b, hello 'world']", "a b\"hello 'world'\""); + check("[a, b]", "\"a\"\"b\""); + } + + private void check(String expectedTokens, String input) + { + assertEquals(expectedTokens, Lexer.extractTokens(input).toString()); + } +}