From 7f275b18b8c8cfc8d1e1d4124bf0853f3fd5b3da Mon Sep 17 00:00:00 2001 From: pkupczyk <pkupczyk> Date: Fri, 19 Oct 2012 13:41:13 +0000 Subject: [PATCH] Fix a bug where an entity registration page couldn't be entered because of a failing HTML escaped managed properties script (script was taken from HTML escaped EntityType object that was sent from the GWT client) SVN: 27246 --- .../web/client/ICommonClientService.java | 2 +- .../web/client/ICommonClientServiceAsync.java | 4 +- .../ui/widget/EntityRegistrationPanel.java | 3 +- .../web/server/CommonClientService.java | 5 +- .../openbis/generic/server/CommonServer.java | 10 ++- .../generic/server/CommonServerLogger.java | 4 +- .../translator/EntityTypeTranslator.java | 71 +++++++++++++++++++ 7 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/EntityTypeTranslator.java 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 657e0270b1a..a966d924ac0 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 @@ -249,7 +249,7 @@ public interface ICommonClientService extends IClientService public List<SampleType> listSampleTypes() throws UserFailureException; public Map<String, List<IManagedInputWidgetDescription>> listManagedInputWidgetDescriptions( - EntityType entityType) throws UserFailureException; + EntityKind entityKind, String entityTypeCode) throws UserFailureException; /** * Returns a list of samples matching given criteria. 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 66dd2159a12..6a6f409f265 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 @@ -199,8 +199,8 @@ public interface ICommonClientServiceAsync extends IClientServiceAsync /** @see ICommonClientService#listSampleTypes() */ public void listSampleTypes(AsyncCallback<List<SampleType>> asyncCallback); - /** @see ICommonClientService#listManagedInputWidgetDescriptions(EntityType) */ - public void listManagedInputWidgetDescriptions(EntityType entityType, + /** @see ICommonClientService#listManagedInputWidgetDescriptions(EntityKind, String) */ + public void listManagedInputWidgetDescriptions(EntityKind entityKind, String entityTypeCode, AsyncCallback<Map<String, List<IManagedInputWidgetDescription>>> asyncCallback); /** @see ICommonClientService#listFileTypes() */ diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/EntityRegistrationPanel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/EntityRegistrationPanel.java index 57b295c8ccb..aa5ebb8601a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/EntityRegistrationPanel.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/EntityRegistrationPanel.java @@ -143,7 +143,8 @@ abstract public class EntityRegistrationPanel<T extends ModelData, S extends Dro private void showAndUpdateRegistrationForm(final T entityTypeModel, final EntityType entityType) { viewContext.getService().listManagedInputWidgetDescriptions( - entityType, + entityKind, + entityType.getCode(), new AbstractAsyncCallback<Map<String, List<IManagedInputWidgetDescription>>>( viewContext) { 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 36be9fd0f58..82af3c7a731 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 @@ -397,10 +397,11 @@ public final class CommonClientService extends AbstractClientService implements @Override public Map<String, List<IManagedInputWidgetDescription>> listManagedInputWidgetDescriptions( - EntityType entityType) + EntityKind entityKind, String entityTypeCode) { final String sessionToken = getSessionToken(); - return commonServer.listManagedInputWidgetDescriptions(sessionToken, entityType); + return commonServer.listManagedInputWidgetDescriptions(sessionToken, entityKind, + entityTypeCode); } @Override 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 7111ca7b595..1dfe6db5dc0 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 @@ -303,6 +303,7 @@ import ch.systemsx.cisd.openbis.generic.shared.translator.DataStoreTranslator; import ch.systemsx.cisd.openbis.generic.shared.translator.DataTypeTranslator; import ch.systemsx.cisd.openbis.generic.shared.translator.DtoConverters; import ch.systemsx.cisd.openbis.generic.shared.translator.EntityHistoryTranslator; +import ch.systemsx.cisd.openbis.generic.shared.translator.EntityTypeTranslator; import ch.systemsx.cisd.openbis.generic.shared.translator.ExperimentTranslator; import ch.systemsx.cisd.openbis.generic.shared.translator.ExperimentTranslator.LoadableFields; import ch.systemsx.cisd.openbis.generic.shared.translator.ExternalDataManagementSystemTranslator; @@ -613,12 +614,19 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt @Override @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) public Map<String, List<IManagedInputWidgetDescription>> listManagedInputWidgetDescriptions( - String sessionToken, EntityType entityType) + String sessionToken, EntityKind entityKind, String entityTypeCode) { checkSession(sessionToken); + EntityTypePE entityTypePE = + getDAOFactory().getEntityTypeDAO(DtoConverters.convertEntityKind(entityKind)) + .tryToFindEntityTypeByCode(entityTypeCode); + + EntityType entityType = EntityTypeTranslator.translate(entityTypePE); + List<? extends EntityTypePropertyType<?>> assignedPropertyTypes = entityType.getAssignedPropertyTypes(); + return listManagedInputWidgetDescriptions(assignedPropertyTypes); } 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 107b5545801..8d574679183 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 @@ -261,10 +261,10 @@ final class CommonServerLogger extends AbstractServerLogger implements ICommonSe @Override public Map<String, List<IManagedInputWidgetDescription>> listManagedInputWidgetDescriptions( - String sessionToken, EntityType entityType) + String sessionToken, EntityKind entityKind, String entityTypeCode) { logAccess(sessionToken, "list_managed_input_widget_descriptions", "TYPE(%s)", - entityType.getCode()); + entityTypeCode); return null; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/EntityTypeTranslator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/EntityTypeTranslator.java new file mode 100644 index 00000000000..187dbe31800 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/EntityTypeTranslator.java @@ -0,0 +1,71 @@ +/* + * Copyright 2012 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.translator; + +import java.util.HashMap; +import java.util.Map; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetTypePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentTypePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialTypePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePE; +import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils; + +/** + * @author pkupczyk + */ +public class EntityTypeTranslator +{ + + public static EntityType translate(EntityTypePE entityTypePE) + { + if (entityTypePE == null) + { + return null; + } + + Map<PropertyTypePE, PropertyType> cache = new HashMap<PropertyTypePE, PropertyType>(); + + switch (entityTypePE.getEntityKind()) + { + case EXPERIMENT: + ExperimentTypePE experimentTypePE = (ExperimentTypePE) entityTypePE; + HibernateUtils.initialize(experimentTypePE.getExperimentTypePropertyTypes()); + return ExperimentTypeTranslator.translate(experimentTypePE, cache); + case SAMPLE: + SampleTypePE sampleTypePE = (SampleTypePE) entityTypePE; + HibernateUtils.initialize(sampleTypePE.getSampleTypePropertyTypes()); + return SampleTypeTranslator.translate(sampleTypePE, cache); + case DATA_SET: + DataSetTypePE dataSetTypePE = (DataSetTypePE) entityTypePE; + HibernateUtils.initialize(dataSetTypePE.getDataSetTypePropertyTypes()); + return DataSetTypeTranslator.translate(dataSetTypePE, cache); + case MATERIAL: + MaterialTypePE materialTypePE = (MaterialTypePE) entityTypePE; + HibernateUtils.initialize(materialTypePE.getMaterialTypePropertyTypes()); + return MaterialTypeTranslator.translate(materialTypePE, cache); + default: + throw new IllegalArgumentException("Unsupported entity kind: " + + entityTypePE.getEntityKind()); + } + + } +} -- GitLab