diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientService.java index 0aa5b6b82cc64e19e6ec7a98dc26dac08384546b..5570a321c9c64682d6f351b4a5f681f69fb4ae0f 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientService.java @@ -188,4 +188,9 @@ public interface ICommonClientService extends IClientService */ public void registerPropertyType(final PropertyType propertyType) throws UserFailureException; + /** + * Registers given {@link Vocabulary}. + */ + public void registerVocabulary(final Vocabulary vocabulary) throws UserFailureException; + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientServiceAsync.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientServiceAsync.java index d257d3d45a6ce566d0544e1c539f36bb36190478..afe92266de5e446af53e6bf83263383466eeb2f1 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientServiceAsync.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientServiceAsync.java @@ -152,5 +152,9 @@ public interface ICommonClientServiceAsync extends IClientServiceAsync /** @see ICommonClientService#registerPropertyType(PropertyType) */ public void registerPropertyType(final PropertyType propertyType, - AsyncCallback<Void> asyncCallback); + final AsyncCallback<Void> asyncCallback); + + /** @see ICommonClientService#registerVocabulary(Vocabulary) */ + public void registerVocabulary(final Vocabulary vocabulary, + final AsyncCallback<Void> asyncCallback); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/CategoriesBuilder.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/CategoriesBuilder.java index 0c3195aa4cdee04130847c86aabc32da9d305d7b..479c73d4c5efedd988d032873422544cca937ad1 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/CategoriesBuilder.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/CategoriesBuilder.java @@ -175,7 +175,7 @@ public class CategoriesBuilder final List<MenuElement> elements = new ArrayList<MenuElement>(); elements.add(new MenuElement(MENU_ELEMENTS.LIST, "List", provider.getDummyComponent())); elements.add(new MenuElement(MENU_ELEMENTS.REGISTER, "Register", provider - .getDummyComponent())); + .getVocabularyRegistration())); return new MenuCategory(CATEGORIES.VOCABULARIES, "Vocabularies", elements); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java index 90282add1b58bace68709b896835e5a418e4517b..7f9d460fdc2a94866da3eb5909ae5f65d4d31ee4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java @@ -28,6 +28,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.propert import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.sample.SampleBatchRegistrationPanel; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.sample.SampleBrowser; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.sample.SampleRegistrationPanel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary.VocabularyRegistrationForm; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.EntityKind; /** @@ -66,6 +67,8 @@ final class ComponentProvider private PropertyTypeAssignmentForm propertyTypeSampleTypeAssignmentForm; + private VocabularyRegistrationForm vocabularyRegistrationForm; + ComponentProvider(final CommonViewContext viewContext) { sampleBrowser = new SampleBrowser(viewContext); @@ -83,6 +86,7 @@ final class ComponentProvider new PropertyTypeAssignmentForm(viewContext, EntityKind.EXPERIMENT); propertyTypeSampleTypeAssignmentForm = new PropertyTypeAssignmentForm(viewContext, EntityKind.SAMPLE); + vocabularyRegistrationForm = new VocabularyRegistrationForm(viewContext); } public final ITabItem getSampleBrowser() @@ -120,6 +124,11 @@ final class ComponentProvider return new DefaultTabItem("Sample batch registration", sampleBatchRegistration); } + public final ITabItem getVocabularyRegistration() + { + return new DefaultTabItem("Vocabulary registration", vocabularyRegistrationForm); + } + public ITabItem getExperimentBrowser() { return new DefaultTabItem("Experiment browser", experimentBrowser, experimentBrowser); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistration.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistration.java index c0c15cb6e595d779f3faefdefc8f3a219c8d3eb0..1e5c4e8972eb7e2feaeaa43608a61e399ec25454 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistration.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistration.java @@ -32,6 +32,8 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.Voca import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.AbstractRegistrationForm; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.CodeField; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.VarcharField; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary.VocabularyRegistrationFieldSet; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary.VocabularySelectionWidget; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DataType; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DataTypeCode; @@ -45,7 +47,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; */ public final class PropertyTypeRegistration extends AbstractRegistrationForm { - private static final String PREFIX = "property-type-registration"; + private static final String PREFIX = "property-type-registration_"; public static final String ID_PREFIX = GenericConstants.ID_PREFIX + PREFIX; @@ -198,7 +200,7 @@ public final class PropertyTypeRegistration extends AbstractRegistrationForm } } - private final class PropertyTypeRegistrationCallback extends AbstractAsyncCallback<Void> + public final class PropertyTypeRegistrationCallback extends AbstractAsyncCallback<Void> { private final PropertyType propertyType; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidgetForPropertyTypeRegistration.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidgetForPropertyTypeRegistration.java index 2d7798e5bed7adcb82fe1868522f37a5e4f6cfb3..547de781e9cec7961b236dd04a8b0e3163c43577 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidgetForPropertyTypeRegistration.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidgetForPropertyTypeRegistration.java @@ -9,6 +9,8 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAs import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.ModelDataPropertyNames; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.VocabularyModel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary.VocabularyRegistrationFieldSet; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary.VocabularySelectionWidget; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; /** diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularyRegistrationFieldSet.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyRegistrationFieldSet.java similarity index 93% rename from openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularyRegistrationFieldSet.java rename to openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyRegistrationFieldSet.java index 5749480fe2b9fb9cb808ccc1511a8e1cd90bde4a..7b9f03f9079f03a5934f73d1b9baff7412afffe9 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularyRegistrationFieldSet.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyRegistrationFieldSet.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type; +package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary; import java.util.ArrayList; import java.util.List; @@ -52,8 +52,9 @@ public final class VocabularyRegistrationFieldSet extends FieldSet private final int fieldWith; - VocabularyRegistrationFieldSet(final IViewContext<ICommonClientServiceAsync> viewContext, - final int labelWidth, final int fieldWidth) + public VocabularyRegistrationFieldSet( + final IViewContext<ICommonClientServiceAsync> viewContext, final int labelWidth, + final int fieldWidth) { this.viewContext = viewContext; this.labelWidth = labelWidth; @@ -98,11 +99,11 @@ public final class VocabularyRegistrationFieldSet extends FieldSet return textArea; } - final Vocabulary createVocabulary() + public final Vocabulary createVocabulary() { final Vocabulary vocabulary = new Vocabulary(); - vocabulary - .setCode(PropertyType.USER_NAMESPACE_CODE_PREPEND + vocabularyCodeField.getValue()); + vocabulary.setCode(PropertyType.USER_NAMESPACE_CODE_PREPEND + + vocabularyCodeField.getValue()); vocabulary.setDescription(StringUtils.trimToNull(vocabularyDescriptionField.getValue())); final List<VocabularyTerm> vocabularyTerms = new ArrayList<VocabularyTerm>(); for (final String termCode : VocabularyTermValidator.getTerms(vocabularyTermsField diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyRegistrationForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyRegistrationForm.java new file mode 100644 index 0000000000000000000000000000000000000000..bc27d1bf3f553e130a5db04d657dc2dfe1bf7495 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyRegistrationForm.java @@ -0,0 +1,100 @@ +/* + * Copyright 2008 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.web.client.application.ui.vocabulary; + +import com.extjs.gxt.ui.client.widget.LayoutContainer; + +import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.GenericConstants; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.InfoBoxCallbackListener; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.AbstractRegistrationForm; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; + +/** + * A {@link LayoutContainer} extension for registering a new vocabulary. + * + * @author Christian Ribeaud + */ +public final class VocabularyRegistrationForm extends AbstractRegistrationForm +{ + private static final String PREFIX = "vocabulary-registration_"; + + public static final String ID_PREFIX = GenericConstants.ID_PREFIX + PREFIX; + + private final IViewContext<ICommonClientServiceAsync> viewContext; + + private VocabularyRegistrationFieldSet vocabularyRegistrationFieldSet; + + public VocabularyRegistrationForm(final IViewContext<ICommonClientServiceAsync> viewContext) + { + super(viewContext, ID_PREFIX); + this.viewContext = viewContext; + addFields(); + } + + private final void addFields() + { + formPanel.add(vocabularyRegistrationFieldSet = + new VocabularyRegistrationFieldSet(viewContext, labelWidth, fieldWitdh - 40)); + } + + // + // AbstractRegistrationForm + // + + @Override + protected final void submitValidForm() + { + final Vocabulary vocabulary = vocabularyRegistrationFieldSet.createVocabulary(); + viewContext.getService().registerVocabulary(vocabulary, + new VocabularyRegistrationCallback(viewContext, vocabulary)); + } + + // + // Helper classes + // + + public final class VocabularyRegistrationCallback extends AbstractAsyncCallback<Void> + { + private final Vocabulary vocabulary; + + VocabularyRegistrationCallback(final IViewContext<?> viewContext, + final Vocabulary vocabulary) + { + super(viewContext, new InfoBoxCallbackListener<Void>(infoBox)); + this.vocabulary = vocabulary; + } + + private final String createMessage() + { + return "Vocabulary <b>" + vocabulary.getCode() + "</b> successfully registered."; + } + + // + // AbstractAsyncCallback + // + + @Override + protected final void process(final Void result) + { + infoBox.displayInfo(createMessage()); + formPanel.reset(); + } + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularySelectionWidget.java similarity index 99% rename from openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidget.java rename to openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularySelectionWidget.java index 4c6666580522476000d27d49b673af54a0062db7..1ba026386032909723ee7862027e0b3d17a5de51 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularySelectionWidget.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type; +package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary; import java.util.List; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularyTermValidator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermValidator.java similarity index 98% rename from openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularyTermValidator.java rename to openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermValidator.java index 18501451cdb75962572d77ef8e6482cc568c60a5..df599fd817a3216a288bfd1311992d8c6cd2565a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularyTermValidator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermValidator.java @@ -1,4 +1,4 @@ -package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type; +package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary; import java.util.ArrayList; import java.util.List; @@ -18,7 +18,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.Strin */ final class VocabularyTermValidator implements Validator<String, TextArea> { - private final IMessageProvider messageProvider; VocabularyTermValidator(final IMessageProvider messageProvider) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java index 5b5d3a78496291df4be89fdbd320d6ae42a7a462..cfe7caf095d2f7053469c740a89be4bd893674fa 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java @@ -558,8 +558,8 @@ public final class CommonClientService extends AbstractClientService implements } } - public String assignPropertyType(EntityKind entityKind, String propertyTypeCode, - String entityTypeCode, boolean isMandatory, String defaultValue) + public String assignPropertyType(final EntityKind entityKind, final String propertyTypeCode, + final String entityTypeCode, final boolean isMandatory, final String defaultValue) throws ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException { try @@ -588,4 +588,17 @@ public final class CommonClientService extends AbstractClientService implements } } + public final void registerVocabulary(final Vocabulary vocabulary) + throws ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException + { + assert vocabulary != null : "Unspecified vocabulary."; + try + { + final String sessionToken = getSessionToken(); + commonServer.registerVocabulary(sessionToken, vocabulary); + } catch (final UserFailureException e) + { + throw UserFailureExceptionTranslator.translate(e); + } + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonBusinessObjectFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonBusinessObjectFactory.java index 54fba1e5289758333da79a9c685c0dba44126586..7282c074aee053da78e63c31e29367bd66d53720 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonBusinessObjectFactory.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonBusinessObjectFactory.java @@ -31,11 +31,13 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.IPropertyTypeTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.IRoleAssignmentTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleBO; import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleTable; +import ch.systemsx.cisd.openbis.generic.server.business.bo.IVocabularyBO; import ch.systemsx.cisd.openbis.generic.server.business.bo.PropertyTypeBO; import ch.systemsx.cisd.openbis.generic.server.business.bo.PropertyTypeTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.RoleAssignmentTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.SampleBO; import ch.systemsx.cisd.openbis.generic.server.business.bo.SampleTable; +import ch.systemsx.cisd.openbis.generic.server.business.bo.VocabularyBO; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.shared.dto.Session; @@ -96,9 +98,14 @@ public final class CommonBusinessObjectFactory extends AbstractBusinessObjectFac return new PropertyTypeTable(getDaoFactory(), session); } - public final IPropertyTypeBO createPropertyTypeBO(final Session session) + public final IPropertyTypeBO createPropertyTypeBO(final Session session) { return new PropertyTypeBO(getDaoFactory(), session); } + public final IVocabularyBO createVocabularyBO(Session session) + { + return new VocabularyBO(getDaoFactory(), session); + } + } 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 4f6f0ae106b0fb56662f3e7520070a614e0cdfef..9e1bc7aa634c83d88267921011c022f686217052 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 @@ -28,6 +28,7 @@ import ch.systemsx.cisd.authentication.Principal; import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.PropertyType; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; import ch.systemsx.cisd.openbis.generic.server.business.bo.ICommonBusinessObjectFactory; import ch.systemsx.cisd.openbis.generic.server.business.bo.IExperimentTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.IExternalDataTable; @@ -36,6 +37,7 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.IPropertyTypeBO; import ch.systemsx.cisd.openbis.generic.server.business.bo.IPropertyTypeTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.IRoleAssignmentTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleTable; +import ch.systemsx.cisd.openbis.generic.server.business.bo.IVocabularyBO; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IRoleAssignmentDAO; import ch.systemsx.cisd.openbis.generic.server.util.GroupIdentifierHelper; @@ -393,8 +395,9 @@ public final class CommonServer extends AbstractServer<ICommonServer> implements return vocabularies; } - public String assignPropertyType(String sessionToken, EntityKind entityKind, - String propertyTypeCode, String entityTypeCode, boolean isMandatory, String defaultValue) + public String assignPropertyType(final String sessionToken, final EntityKind entityKind, + final String propertyTypeCode, final String entityTypeCode, final boolean isMandatory, + final String defaultValue) { assert sessionToken != null : "Unspecified session token"; @@ -415,4 +418,14 @@ public final class CommonServer extends AbstractServer<ICommonServer> implements propertyTypeBO.save(); } + public final void registerVocabulary(final String sessionToken, final Vocabulary vocabulary) + { + assert sessionToken != null : "Unspecified session token"; + assert vocabulary != null : "Unspecified vocabulary"; + + final Session session = getSessionManager().getSession(sessionToken); + final IVocabularyBO propertyTypeBO = businessObjectFactory.createVocabularyBO(session); + propertyTypeBO.define(vocabulary); + propertyTypeBO.save(); + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServerLogger.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServerLogger.java index 5a9abd73890c49775340b3f51fb96b04edfb5923..1b1ddada95c39ae88cbb0ae76e251fb69878c760 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServerLogger.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServerLogger.java @@ -22,6 +22,7 @@ import java.util.List; import ch.systemsx.cisd.authentication.ISessionManager; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.NewSample; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.PropertyType; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; import ch.systemsx.cisd.openbis.generic.shared.ICommonServer; import ch.systemsx.cisd.openbis.generic.shared.dto.DataTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; @@ -219,16 +220,17 @@ final class CommonServerLogger extends AbstractServerLogger implements ICommonSe return null; } - public final List<VocabularyPE> listVocabularies(String sessionToken) + public final List<VocabularyPE> listVocabularies(final String sessionToken) { logAccess(sessionToken, "list_vocabularies"); return null; } - public String assignPropertyType(String sessionToken, EntityKind entityKind, - String propertyTypeCode, String entityTypeCode, boolean isMandatory, String defaultValue) + public String assignPropertyType(final String sessionToken, final EntityKind entityKind, + final String propertyTypeCode, final String entityTypeCode, final boolean isMandatory, + final String defaultValue) { - String entityTypeFormat = entityKind.name() + "_TYPE(%S)"; + final String entityTypeFormat = entityKind.name() + "_TYPE(%S)"; logTracking(sessionToken, "assign_property_type", " PROPERTY_TYPE(%S) " + entityTypeFormat + " MANDATORY(%S) DEFAULT(%S)", propertyTypeCode, entityTypeCode, isMandatory, defaultValue); @@ -241,4 +243,9 @@ final class CommonServerLogger extends AbstractServerLogger implements ICommonSe logTracking(sessionToken, "register_property_type", "PROPERTY_TYPE(%s)", propertyType .getCode()); } + + public final void registerVocabulary(final String sessionToken, final Vocabulary vocabulary) + { + logTracking(sessionToken, "register_vocabulary", "VOCABULARY(%s)", vocabulary.getCode()); + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ICommonBusinessObjectFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ICommonBusinessObjectFactory.java index f6a0297719747da0494b2ef781bde205eaaaccf0..c75ed37085234ed0a4e6b858eaed2b24a2ca770a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ICommonBusinessObjectFactory.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ICommonBusinessObjectFactory.java @@ -56,9 +56,13 @@ public interface ICommonBusinessObjectFactory */ public IPropertyTypeTable createPropertyTypeTable(final Session session); - /** * Creates a {@link IPropertyTypeBO} <i>Business Object</i>. */ public IPropertyTypeBO createPropertyTypeBO(final Session session); + + /** + * Creates a {@link IVocabularyBO} <i>Business Object</i>. + */ + public IVocabularyBO createVocabularyBO(final Session session); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IPropertyTypeBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IPropertyTypeBO.java index aea7f1adc634bce505b73b888d5d31d0481fbfb2..8d67ca19c572289e348a48b00cb5795eac7cc9c0 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IPropertyTypeBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IPropertyTypeBO.java @@ -21,7 +21,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE; /** - * Business object of a project. Holds an instance of {@link PropertyTypePE}. + * Business object of a property type. Holds an instance of {@link PropertyTypePE}. * * @author Christian Ribeaud */ diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IVocabularyBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IVocabularyBO.java new file mode 100644 index 0000000000000000000000000000000000000000..85c38254ad3357c324dc01c5123709f95ab199a0 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IVocabularyBO.java @@ -0,0 +1,46 @@ +/* + * Copyright 2008 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.business.bo; + +import ch.systemsx.cisd.common.exceptions.UserFailureException; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; +import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE; + +/** + * Business object of a vocabulary. Holds an instance of {@link VocabularyPE}. + * + * @author Christian Ribeaud + */ +public interface IVocabularyBO extends IBusinessObject +{ + /** + * Defines a new vocabulary. + * <p> + * After invocation of this method {@link IBusinessObject#save()} should be invoked to store the + * new vocabulary in the <i>Data Access Layer</i>. + * </p> + * + * @throws UserFailureException if given <var>vocabulary</var> does already exist. + */ + public void define(final Vocabulary vocabulary) throws UserFailureException; + + /** + * Returns the loaded {@link VocabularyPE}. + */ + public VocabularyPE getVocabulary(); + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBO.java index 00a1a126b085334e49133c90d32f33846dc1d1a4..c04f94d23c898178849e626d23219ba07b9b26cd 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBO.java @@ -32,8 +32,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityDataType; * * @author Christian Ribeaud */ -public final class PropertyTypeBO extends AbstractVocabularyBusinessObject implements - IPropertyTypeBO +public final class PropertyTypeBO extends VocabularyBO implements IPropertyTypeBO { private PropertyTypePE propertyTypePE; @@ -74,12 +73,15 @@ public final class PropertyTypeBO extends AbstractVocabularyBusinessObject imple propertyType.getVocabulary().getCode()); if (vocabularyPE == null) { - vocabularyPE = createVocabulary(propertyType.getVocabulary()); + define(propertyType.getVocabulary()); + super.save(); + vocabularyPE = getVocabulary(); } propertyTypePE.setVocabulary(vocabularyPE); } } + @Override public final void save() throws UserFailureException { assert propertyTypePE != null : "Property type not defined."; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractVocabularyBusinessObject.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBO.java similarity index 73% rename from openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractVocabularyBusinessObject.java rename to openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBO.java index 54767cd5ba6e15c7e0644499021ae9713982e764..7648e8cdb486381c1bf601e82092ec7c1c20a105 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractVocabularyBusinessObject.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBO.java @@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo; import org.springframework.dao.DataAccessException; +import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.VocabularyTerm; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; @@ -26,21 +27,26 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE; import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyTermPE; /** - * An <i>abtract</i> {@link AbstractBusinessObject} extension which creates a {@link VocabularyPE} - * in the database out of a given {@link Vocabulary}. + * The only productive implementation of {@link IVocabularyBO}. * * @author Christian Ribeaud */ -abstract class AbstractVocabularyBusinessObject extends AbstractBusinessObject +public class VocabularyBO extends AbstractBusinessObject implements IVocabularyBO { - AbstractVocabularyBusinessObject(IDAOFactory daoFactory, Session session) + private VocabularyPE vocabularyPE; + + public VocabularyBO(final IDAOFactory daoFactory, final Session session) { super(daoFactory, session); } - final VocabularyPE createVocabulary(final Vocabulary vocabulary) + // + // AbstractVocabularyBusinessObject + // + + public final void define(final Vocabulary vocabulary) throws UserFailureException { - final VocabularyPE vocabularyPE = new VocabularyPE(); + vocabularyPE = new VocabularyPE(); vocabularyPE.setCode(vocabulary.getCode()); vocabularyPE.setDescription(vocabulary.getDescription()); vocabularyPE.setDatabaseInstance(getHomeDatabaseInstance()); @@ -52,6 +58,11 @@ abstract class AbstractVocabularyBusinessObject extends AbstractBusinessObject vocabularyTermPE.setRegistrator(findRegistrator()); vocabularyPE.addTerm(vocabularyTermPE); } + } + + public void save() throws UserFailureException + { + assert vocabularyPE != null : "Unspecified vocabulary"; try { getVocabularyDAO().createVocabulary(vocabularyPE); @@ -59,7 +70,11 @@ abstract class AbstractVocabularyBusinessObject extends AbstractBusinessObject { throwException(e, String.format("Vocabulary '%s'.", vocabularyPE.getCode())); } - return vocabularyPE; } + public final VocabularyPE getVocabulary() + { + assert vocabularyPE != null : "Unspecified vocabulary"; + return vocabularyPE; + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/ICommonServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/ICommonServer.java index 76ab713c8dd937b21f7c5179e349b5dfcfc649a3..918bbce67f81f18b4ca0eea1a71f2f1ccefb6b23 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/ICommonServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/ICommonServer.java @@ -21,6 +21,7 @@ import java.util.List; import org.springframework.transaction.annotation.Transactional; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.PropertyType; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Vocabulary; import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.AuthorizationGuard; import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.ReturnValueFilter; import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RoleSet; @@ -242,7 +243,14 @@ public interface ICommonServer extends IServer */ @Transactional @RolesAllowed(RoleSet.INSTANCE_ADMIN) - public String assignPropertyType(String sessionToken, EntityKind entityKind, - String propertyTypeCode, String entityTypeCode, boolean isMandatory, String defaultValue); + public String assignPropertyType(final String sessionToken, final EntityKind entityKind, + final String propertyTypeCode, final String entityTypeCode, final boolean isMandatory, + final String defaultValue); + /** + * Registers given {@link Vocabulary}. + */ + @Transactional + @RolesAllowed(RoleSet.INSTANCE_ADMIN) + public void registerVocabulary(final String sessionToken, final Vocabulary vocabulary); }