diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/BasicPropertyAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/BasicPropertyAdaptor.java new file mode 100644 index 0000000000000000000000000000000000000000..66bb8014adf12d56676ba987d2a46f8d7ee09dd8 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/BasicPropertyAdaptor.java @@ -0,0 +1,57 @@ +/* + * 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.dynamic; + +import ch.systemsx.cisd.openbis.generic.shared.dto.EntityPropertyPE; + +/** + * Simple {@link IEntityPropertyAdaptor} implementation + * + * @author Piotr Buczek + */ +public class BasicPropertyAdaptor implements IEntityPropertyAdaptor +{ + + private final String code; + + private final String value; + + private final EntityPropertyPE propertyPE; + + public BasicPropertyAdaptor(String code, String value, EntityPropertyPE propertyPE) + { + this.code = code; + this.value = value; + this.propertyPE = propertyPE; + } + + public String getPropertyTypeCode() + { + return code; + } + + public String getValueAsString() + { + return value; + } + + public EntityPropertyPE getPropertyPE() + { + return propertyPE; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/DynamicPropertyCalculator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/DynamicPropertyCalculator.java new file mode 100644 index 0000000000000000000000000000000000000000..2a2b3001d934f679cf0922b83d45c07b4fe41595 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/DynamicPropertyCalculator.java @@ -0,0 +1,25 @@ +/* + * 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.dynamic; + +/** + * @author Piotr Buczek + */ +public class DynamicPropertyCalculator +{ + // TODO +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/IEntityAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/IEntityAdaptor.java new file mode 100644 index 0000000000000000000000000000000000000000..16dc7e074857eda5b345227564c885b928fa2c8a --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/IEntityAdaptor.java @@ -0,0 +1,41 @@ +/* + * 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.dynamic; + +import java.util.Collection; + +/** + * Interface implemented by all entity adaptors + * + * @author Piotr Buczek + */ +// TODO 2010-10-15, Piotr Buczek: what naming convention should be used for DTOs used in Jython +public interface IEntityAdaptor +{ + /** Returns the code. */ + public String getCode(); + + /** Returns the property by code of the property type. */ + public IEntityPropertyAdaptor getPropertyByCode(String propertyTypeCode); + + /** Returns the property value by code of the property type. */ + public String getPropertyValueByCode(String propertyTypeCode); + + /** Returns collection of properties of the entity */ + public Collection<IEntityPropertyAdaptor> getProperties(); + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/IEntityPropertyAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/IEntityPropertyAdaptor.java new file mode 100644 index 0000000000000000000000000000000000000000..7f597d19641b3ead92da9c98c55c48ebad536584 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/IEntityPropertyAdaptor.java @@ -0,0 +1,32 @@ +/* + * 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.dynamic; + +/** + * Interface implemented by all entity properties + * + * @author Piotr Buczek + */ +public interface IEntityPropertyAdaptor +{ + /** Returns the code of property type. */ + public String getPropertyTypeCode(); + + /** Returns the property value as string. */ + public String getValueAsString(); + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/SampleAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/SampleAdaptor.java new file mode 100644 index 0000000000000000000000000000000000000000..c992780ee15b2d06fff8963fb6ca00041bf3555b --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/dynamic/SampleAdaptor.java @@ -0,0 +1,89 @@ +/* + * 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.dynamic; + +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 +{ + private final Map<String, IEntityPropertyAdaptor> propertiesByCode = + new HashMap<String, IEntityPropertyAdaptor>(); + + private final String code; + + private final SamplePE samplePE; + + SampleAdaptor(SamplePE 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() + { + 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(); + } + +}