diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServiceProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServiceProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..6250fd10c345299c8b6d2d4773c11c15111490af --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServiceProvider.java @@ -0,0 +1,56 @@ +/* + * Copyright 2009 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.server; + +import org.springframework.beans.factory.BeanFactory; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import ch.systemsx.cisd.openbis.generic.server.business.bo.ICommonBusinessObjectFactory; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; +import ch.systemsx.cisd.openbis.generic.shared.ICommonServer; + +/** + * Provider of common openBIS server services. + * + * @author Piotr Buczek + */ +public class CommonServiceProvider +{ + public static final BeanFactory APPLICATION_CONTEXT = + new ClassPathXmlApplicationContext(new String[] + { "applicationContext.xml" }, true); + + public static ICommonServer getCommonServer() + { + return (ICommonServer) APPLICATION_CONTEXT.getBean("common-server"); + } + + public static IDAOFactory getDAOFactory() + { + return (IDAOFactory) APPLICATION_CONTEXT.getBean("dao-factory"); + } + + public static ICommonBusinessObjectFactory getBusinessObjectFactory() + { + return (ICommonBusinessObjectFactory) APPLICATION_CONTEXT + .getBean("common-business-object-factory"); + } + + private CommonServiceProvider() + { + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/DemoMaintenanceTask.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/DemoMaintenanceTask.java new file mode 100644 index 0000000000000000000000000000000000000000..9a86061531366c670459bb04b5f5161ad6bffca8 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/DemoMaintenanceTask.java @@ -0,0 +1,68 @@ +/* + * 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.server.task; + +import java.util.List; +import java.util.Properties; + +import org.apache.log4j.Logger; + +import ch.systemsx.cisd.common.logging.LogCategory; +import ch.systemsx.cisd.common.logging.LogFactory; +import ch.systemsx.cisd.common.maintenance.IMaintenanceTask; +import ch.systemsx.cisd.openbis.generic.server.CommonServiceProvider; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IProjectDAO; +import ch.systemsx.cisd.openbis.generic.shared.ICommonServer; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; +import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO; + +/** + * Demo {@link IMaintenanceTask}. + * + * @author Piotr Buczek + */ +public class DemoMaintenanceTask implements IMaintenanceTask +{ + private static final Logger operationLog = + LogFactory.getLogger(LogCategory.OPERATION, DemoMaintenanceTask.class); + + public void execute() + { + IProjectDAO projectDAO = CommonServiceProvider.getDAOFactory().getProjectDAO(); + List<ProjectPE> projects = projectDAO.listProjects(); + operationLog.info(projects.size() + " project(s) found"); + ICommonServer server = CommonServiceProvider.getCommonServer(); + SessionContextDTO contextOrNull = server.tryToAuthenticate("test", "x"); + if (contextOrNull != null) + { + final String sessionToken = contextOrNull.getSessionToken(); + List<Person> persons = server.listPersons(sessionToken); + operationLog.info(persons.size() + " person(s) found"); + } else + { + operationLog.error("authentication failed"); + } + operationLog.info("task executed"); + } + + public void setUp(String pluginName, Properties properties) + { + operationLog.info("Plugin " + pluginName + " initialized with properties:\n" + properties); + } + +} diff --git a/openbis/source/java/service.properties b/openbis/source/java/service.properties index 8d843243f032dc641616863e076c05efa242422b..9c60b009559f2b97becc9930f97dfabef84d6b25 100644 --- a/openbis/source/java/service.properties +++ b/openbis/source/java/service.properties @@ -107,4 +107,25 @@ query-databases = 1 1.database-driver = org.postgresql.Driver 1.database-url = jdbc:postgresql://localhost/openbis_${database.kind} #1.database-username = -#1.database-password = \ No newline at end of file +#1.database-password = + +# --------------------------------------------------------------------------- +# maintenance plugins configuration +# --------------------------------------------------------------------------- + +# Comma separated names of maintenance plugins. +# Each plugin should have configuration properties prefixed with its name. +# Mandatory properties for each <plugin> include: +# <plugin>.class - Fully qualified plugin class name +# <plugin>.interval - The time between plugin executions (in seconds) +# Optional properties for each <plugin> include: +# <plugin>.start - Time of the first execution (HH:mm) +# <plugin>.execute-only-once - If true the task will be executed exactly once, +# interval will be ignored. By default set to false. +#maintenance-plugins = demo + +demo.class = ch.systemsx.cisd.openbis.generic.server.task.DemoMaintenanceTask +demo.interval = 60 +#demo.execute-only-once = true +demo.property_1 = some value +demo.property_2 = some value 2 \ No newline at end of file