From e6905a46bf8f99a9de486548cd4914204d6e402b Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Fri, 15 Oct 2010 14:59:16 +0000 Subject: [PATCH] [LMS-1818] AbstractEntityAdaptor and other adaptors SVN: 18325 --- .../property/AbstractEntityAdaptor.java | 85 +++++++++++++++++++ .../property/BasicPropertyAdaptor.java | 2 +- .../property/ExperimentAdaptor.java | 42 +++++++++ .../property/ExternalDataAdaptor.java | 42 +++++++++ .../calculator/property/MaterialAdaptor.java | 42 +++++++++ .../calculator/property/SampleAdaptor.java | 53 +----------- 6 files changed, 215 insertions(+), 51 deletions(-) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/AbstractEntityAdaptor.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/ExperimentAdaptor.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/ExternalDataAdaptor.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/MaterialAdaptor.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/AbstractEntityAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/AbstractEntityAdaptor.java new file mode 100644 index 00000000000..d13dcd0e749 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/AbstractEntityAdaptor.java @@ -0,0 +1,85 @@ +/* + * 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.web.server.calculator.property; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import ch.systemsx.cisd.openbis.generic.shared.dto.EntityPropertyPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.IEntityPropertiesHolder; + +/** + * Abstract {@link IEntityAdaptor} implementation. + * + * @author Piotr Buczek + */ +public class AbstractEntityAdaptor implements IEntityAdaptor +{ + protected final Map<String, IEntityPropertyAdaptor> propertiesByCode = + new HashMap<String, IEntityPropertyAdaptor>(); + + private final String code; + + public AbstractEntityAdaptor(String code) + { + this.code = code; + } + + protected void initProperties(IEntityPropertiesHolder propertiesHolder) + { + for (EntityPropertyPE property : propertiesHolder.getProperties()) + { + final String propertyTypeCode = + property.getEntityTypePropertyType().getPropertyType().getCode(); + final String value; + if (property.getMaterialValue() != null) + { + value = property.getMaterialValue().getCode(); + } else if (property.getVocabularyTerm() != null) + { + value = property.getVocabularyTerm().getCode(); + } else + { + value = property.getValue(); + } + propertiesByCode.put(propertyTypeCode, new BasicPropertyAdaptor(propertyTypeCode, + value, property)); + } + } + + public String getCode() + { + return code; + } + + public IEntityPropertyAdaptor getPropertyByCode(String propertyTypeCode) + { + return propertiesByCode.get(propertyTypeCode); + } + + public String getPropertyValueByCode(String propertyTypeCode) + { + return propertiesByCode.get(propertyTypeCode).getValueAsString(); + } + + public Collection<IEntityPropertyAdaptor> getProperties() + { + return propertiesByCode.values(); + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/BasicPropertyAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/BasicPropertyAdaptor.java index f55503ee6ba..05f10713819 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/BasicPropertyAdaptor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/BasicPropertyAdaptor.java @@ -23,7 +23,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.EntityPropertyPE; * * @author Piotr Buczek */ -public class BasicPropertyAdaptor implements IEntityPropertyAdaptor +class BasicPropertyAdaptor implements IEntityPropertyAdaptor { private final String code; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/ExperimentAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/ExperimentAdaptor.java new file mode 100644 index 00000000000..2e39019591e --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/ExperimentAdaptor.java @@ -0,0 +1,42 @@ +/* + * 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.web.server.calculator.property; + +import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; + +/** + * {@link IEntityAdaptor} implementation for {@link ExperimentPE}. + * + * @author Piotr Buczek + */ +public class ExperimentAdaptor extends AbstractEntityAdaptor +{ + private final ExperimentPE experimentPE; + + public ExperimentAdaptor(ExperimentPE experimentPE) + { + super(experimentPE.getCode()); + initProperties(experimentPE); + this.experimentPE = experimentPE; + } + + public ExperimentPE getExperimentPE() + { + return experimentPE; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/ExternalDataAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/ExternalDataAdaptor.java new file mode 100644 index 00000000000..136315769d6 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/ExternalDataAdaptor.java @@ -0,0 +1,42 @@ +/* + * 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.web.server.calculator.property; + +import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE; + +/** + * {@link IEntityAdaptor} implementation for {@link ExternalDataPE}. + * + * @author Piotr Buczek + */ +public class ExternalDataAdaptor extends AbstractEntityAdaptor +{ + private final ExternalDataPE externalDataPE; + + public ExternalDataAdaptor(ExternalDataPE externalDataPE) + { + super(externalDataPE.getCode()); + initProperties(externalDataPE); + this.externalDataPE = externalDataPE; + } + + public ExternalDataPE getExternalDataPE() + { + return externalDataPE; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/MaterialAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/MaterialAdaptor.java new file mode 100644 index 00000000000..2bc0ea95a27 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/MaterialAdaptor.java @@ -0,0 +1,42 @@ +/* + * 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.web.server.calculator.property; + +import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; + +/** + * {@link IEntityAdaptor} implementation for {@link MaterialPE}. + * + * @author Piotr Buczek + */ +public class MaterialAdaptor extends AbstractEntityAdaptor +{ + private final MaterialPE MaterialPE; + + public MaterialAdaptor(MaterialPE MaterialPE) + { + super(MaterialPE.getCode()); + initProperties(MaterialPE); + this.MaterialPE = MaterialPE; + } + + public MaterialPE getMaterialPE() + { + return MaterialPE; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/SampleAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/SampleAdaptor.java index 1a8e04bcfc3..e98da322ac3 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/SampleAdaptor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/property/SampleAdaptor.java @@ -16,49 +16,22 @@ package ch.systemsx.cisd.openbis.generic.client.web.server.calculator.property; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; -import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePropertyPE; /** * {@link IEntityAdaptor} implementation for {@link SamplePE}. * * @author Piotr Buczek */ -public class SampleAdaptor implements IEntityAdaptor +public class SampleAdaptor extends AbstractEntityAdaptor { - private final Map<String, IEntityPropertyAdaptor> propertiesByCode = - new HashMap<String, IEntityPropertyAdaptor>(); - - private final String code; - private final SamplePE samplePE; public SampleAdaptor(SamplePE samplePE) { + super(samplePE.getCode()); + initProperties(samplePE); this.samplePE = samplePE; - this.code = samplePE.getCode(); - for (SamplePropertyPE property : samplePE.getProperties()) - { - final String propertyTypeCode = - property.getEntityTypePropertyType().getPropertyType().getCode(); - final String value; - if (property.getMaterialValue() != null) - { - value = property.getMaterialValue().getCode(); - } else if (property.getVocabularyTerm() != null) - { - value = property.getVocabularyTerm().getCode(); - } else - { - value = property.getValue(); - } - propertiesByCode.put(propertyTypeCode, new BasicPropertyAdaptor(propertyTypeCode, - value, property)); - } } public SamplePE getSamplePE() @@ -66,24 +39,4 @@ public class SampleAdaptor implements IEntityAdaptor return samplePE; } - public String getCode() - { - return code; - } - - public IEntityPropertyAdaptor getPropertyByCode(String propertyTypeCode) - { - return propertiesByCode.get(propertyTypeCode); - } - - public String getPropertyValueByCode(String propertyTypeCode) - { - return propertiesByCode.get(propertyTypeCode).getValueAsString(); - } - - public Collection<IEntityPropertyAdaptor> getProperties() - { - return propertiesByCode.values(); - } - } -- GitLab