From 131e6c2f6b36dc2476a8d5fa4852bfc1c70321f4 Mon Sep 17 00:00:00 2001 From: ribeaudc <ribeaudc> Date: Tue, 18 Nov 2008 08:08:47 +0000 Subject: [PATCH] [LMS-634] remove: - 'AbstractAttachmentPE' and 'FileAttachmentPE'. fix: - Partly (or fully) openBIS System Tests. SVN: 9002 --- .../application/framework/MainTabPanel.java | 11 +- .../shared/dto/AbstractAttachmentPE.java | 169 ----------------- .../generic/shared/dto/AttachmentPE.java | 170 ++++++++++++++++-- .../generic/shared/dto/Experiment.java | 12 +- .../generic/shared/dto/ExperimentPE.java | 2 +- .../generic/shared/dto/FileAttachmentPE.java | 63 ------- openbis/source/java/hibernateContext.xml | 1 - .../application/ui/amc/CreateGroup.java | 2 +- .../application/ui/amc/CreatePerson.java | 2 +- .../client/application/ui/amc/CreateRole.java | 2 +- 10 files changed, 176 insertions(+), 258 deletions(-) delete mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AbstractAttachmentPE.java delete mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/FileAttachmentPE.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/MainTabPanel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/MainTabPanel.java index 7ba19ffc8e4..dd967da9e92 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/MainTabPanel.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/MainTabPanel.java @@ -38,13 +38,13 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewConte */ public class MainTabPanel extends TabPanel { - private static final String PREFIX = "main-tab-panel_"; + private static final String PREFIX = GenericConstants.ID_PREFIX + "main-tab-panel_"; public static final String TAB_SUFFIX = "_tab"; private final IViewContext<IGenericClientServiceAsync> viewContext; - public static final String ID = GenericConstants.ID_PREFIX + PREFIX; + public static final String ID = PREFIX.substring(0, PREFIX.length() - 1); MainTabPanel(final IViewContext<IGenericClientServiceAsync> viewContext) { @@ -52,14 +52,13 @@ public class MainTabPanel extends TabPanel setLayout(new FitLayout()); setTabScroll(true); add(createWelcomePanel()); - // Remove last '_'. - setId(ID.substring(0, ID.length() - 1)); + setId(ID); } private final MainTabItem createWelcomePanel() { final LayoutContainer layoutContainer = new LayoutContainer(new CenterLayout()); - layoutContainer.setId(ID + "welcome"); + layoutContainer.setId(PREFIX + "welcome"); layoutContainer.addText(createWelcomeText()); final MainTabItem intro = new MainTabItem(new DefaultTabItem(" ", layoutContainer)); intro.setClosable(false); @@ -123,7 +122,7 @@ public class MainTabPanel extends TabPanel public MainTabItem(final ITabItem tabItem) { this.tabItem = tabItem; - setId(ID + tabItem.getId() + TAB_SUFFIX); + setId(PREFIX + tabItem.getId() + TAB_SUFFIX); setClosable(true); setLayout(new FitLayout()); setText(tabItem.getTitle()); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AbstractAttachmentPE.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AbstractAttachmentPE.java deleted file mode 100644 index 57d3ab9e561..00000000000 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AbstractAttachmentPE.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2007 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.dto; - -import java.io.Serializable; - -import javax.persistence.Column; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.MappedSuperclass; -import javax.persistence.SequenceGenerator; - -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.hibernate.validator.Length; -import org.hibernate.validator.NotNull; - -import ch.systemsx.cisd.common.utilities.ModifiedShortPrefixToStringStyle; -import ch.systemsx.cisd.openbis.generic.shared.GenericSharedConstants; -import ch.systemsx.cisd.openbis.generic.shared.util.EqualsHashUtils; - -/** - * Superclass to store attachment. Does not contain attachment content. - * - * @author Christian Ribeaud - * @author Tomasz Pylak - */ -@MappedSuperclass -public class AbstractAttachmentPE extends HibernateAbstractRegistrationHolder implements - Serializable, Comparable<AbstractAttachmentPE> -{ - private static final long serialVersionUID = GenericSharedConstants.VERSION; - - private String fileName; - - private int version; - - transient private Long id; - - /** - * Parent (e.g. an experiment) to which this attachment belongs. - */ - private ExperimentPE parent; - - /** - * Returns the file name of the property or <code>null</code>. - */ - @Column(name = ColumnNames.FILE_NAME_COLUMN) - @NotNull(message = ValidationMessages.FILE_NAME_NOT_NULL_MESSAGE) - @Length(max = 100, message = ValidationMessages.FILE_NAME_LENGTH_MESSAGE) - public String getFileName() - { - return fileName; - } - - public void setFileName(final String fileName) - { - this.fileName = fileName; - } - - @Column(name = ColumnNames.VERSION_COLUMN) - @NotNull(message = ValidationMessages.VERSION_NOT_NULL_MESSAGE) - public int getVersion() - { - return version; - } - - public void setVersion(final int version) - { - this.version = version; - } - - @SequenceGenerator(name = SequenceNames.EXPERIMENT_ATTACHMENT_SEQUENCE, sequenceName = SequenceNames.EXPERIMENT_ATTACHMENT_SEQUENCE, allocationSize = 1) - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SequenceNames.EXPERIMENT_ATTACHMENT_SEQUENCE) - public final Long getId() - { - return id; - } - - public final void setId(final Long id) - { - this.id = id; - } - - @ManyToOne(fetch = FetchType.LAZY) - @NotNull(message = ValidationMessages.EXPERIMENT_NOT_NULL_MESSAGE) - @JoinColumn(name = ColumnNames.EXPERIMENT_COLUMN, updatable = false) - public ExperimentPE getParent() - { - return parent; - } - - public void setParent(final ExperimentPE parent) - { - this.parent = parent; - } - - // - // Object - // - - @Override - public boolean equals(final Object obj) - { - EqualsHashUtils.assertDefined(getFileName(), "name"); - EqualsHashUtils.assertDefined(getVersion(), "version"); - if (obj == this) - { - return true; - } - if (obj instanceof AbstractAttachmentPE == false) - { - return false; - } - final AbstractAttachmentPE that = (AbstractAttachmentPE) obj; - final EqualsBuilder builder = new EqualsBuilder(); - builder.append(getFileName(), that.getFileName()); - builder.append(getVersion(), that.getVersion()); - builder.append(getParent(), that.getParent()); - return builder.isEquals(); - } - - @Override - public int hashCode() - { - final HashCodeBuilder builder = new HashCodeBuilder(); - builder.append(getFileName()); - builder.append(getVersion()); - builder.append(getParent()); - return builder.toHashCode(); - } - - @Override - public String toString() - { - return ToStringBuilder.reflectionToString(this, - ModifiedShortPrefixToStringStyle.MODIFIED_SHORT_PREFIX_STYLE); - } - - // - // Comparable - // - - public final int compareTo(final AbstractAttachmentPE o) - { - final int byFile = getFileName().compareTo(o.getFileName()); - return byFile == 0 ? Integer.valueOf(getVersion()).compareTo(o.getVersion()) : byFile; - } -} \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AttachmentPE.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AttachmentPE.java index e520a15ea26..bb36799088b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AttachmentPE.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AttachmentPE.java @@ -16,32 +16,182 @@ package ch.systemsx.cisd.openbis.generic.shared.dto; -import java.util.Collections; -import java.util.Set; +import java.io.Serializable; +import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.UniqueConstraint; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.hibernate.validator.Length; +import org.hibernate.validator.NotNull; + +import ch.systemsx.cisd.common.utilities.ModifiedShortPrefixToStringStyle; import ch.systemsx.cisd.openbis.generic.shared.GenericSharedConstants; +import ch.systemsx.cisd.openbis.generic.shared.util.EqualsHashUtils; /** - * Contains information about an attachment. Does not contain attachment content.<br> - * NOTE: this class does not add anything to the superclass. It exists only because superclasses - * cannot be mapped to tables in Hibernate. + * Contains information about an attachment together with its content. * - * @author Tomasz Pylak + * @author Bernd Rinn */ @Entity @Table(name = TableNames.EXPERIMENT_ATTACHMENTS_TABLE, uniqueConstraints = { @UniqueConstraint(columnNames = { ColumnNames.EXPERIMENT_COLUMN, ColumnNames.FILE_NAME_COLUMN, ColumnNames.VERSION_COLUMN }) }) -public class AttachmentPE extends AbstractAttachmentPE +public class AttachmentPE extends HibernateAbstractRegistrationHolder implements Serializable, + Comparable<AttachmentPE> { private static final long serialVersionUID = GenericSharedConstants.VERSION; - public static final Set<AttachmentPE> EMPTY_SET = Collections.emptySet(); - public static final AttachmentPE[] EMPTY_ARRAY = new AttachmentPE[0]; -} \ No newline at end of file + private byte[] value; + + private String fileName; + + private int version; + + transient private Long id; + + /** + * Parent (e.g. an experiment) to which this attachment belongs. + */ + private ExperimentPE parent; + + /** + * Returns the file name of the property or <code>null</code>. + */ + @Column(name = ColumnNames.FILE_NAME_COLUMN) + @NotNull(message = ValidationMessages.FILE_NAME_NOT_NULL_MESSAGE) + @Length(max = 100, message = ValidationMessages.FILE_NAME_LENGTH_MESSAGE) + public String getFileName() + { + return fileName; + } + + public void setFileName(final String fileName) + { + this.fileName = fileName; + } + + @Column(name = ColumnNames.VERSION_COLUMN) + @NotNull(message = ValidationMessages.VERSION_NOT_NULL_MESSAGE) + public int getVersion() + { + return version; + } + + public void setVersion(final int version) + { + this.version = version; + } + + @SequenceGenerator(name = SequenceNames.EXPERIMENT_ATTACHMENT_SEQUENCE, sequenceName = SequenceNames.EXPERIMENT_ATTACHMENT_SEQUENCE, allocationSize = 1) + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SequenceNames.EXPERIMENT_ATTACHMENT_SEQUENCE) + public final Long getId() + { + return id; + } + + public final void setId(final Long id) + { + this.id = id; + } + + @ManyToOne(fetch = FetchType.LAZY) + @NotNull(message = ValidationMessages.EXPERIMENT_NOT_NULL_MESSAGE) + @JoinColumn(name = ColumnNames.EXPERIMENT_COLUMN, updatable = false) + public ExperimentPE getParent() + { + return parent; + } + + public void setParent(final ExperimentPE parent) + { + this.parent = parent; + } + + /** + * Returns bytes blob stored in the attachment. + */ + @NotNull(message = ValidationMessages.ATTACHMENT_CONTENT_NOT_NULL_MESSAGE) + public byte[] getValue() + { + return value; + } + + public void setValue(final byte[] value) + { + this.value = value; + } + + // + // Object + // + + @Override + public final boolean equals(final Object obj) + { + EqualsHashUtils.assertDefined(getFileName(), "name"); + EqualsHashUtils.assertDefined(getVersion(), "version"); + if (obj == this) + { + return true; + } + if (obj instanceof AttachmentPE == false) + { + return false; + } + final AttachmentPE that = (AttachmentPE) obj; + final EqualsBuilder builder = new EqualsBuilder(); + builder.append(getFileName(), that.getFileName()); + builder.append(getVersion(), that.getVersion()); + builder.append(getParent(), that.getParent()); + return builder.isEquals(); + } + + @Override + public final int hashCode() + { + final HashCodeBuilder builder = new HashCodeBuilder(); + builder.append(getFileName()); + builder.append(getVersion()); + builder.append(getParent()); + return builder.toHashCode(); + } + + @Override + public final String toString() + { + final ToStringBuilder builder = + new ToStringBuilder(this, + ModifiedShortPrefixToStringStyle.MODIFIED_SHORT_PREFIX_STYLE); + builder.append("len(value)", value != null ? value.length : null); + builder.append("fileName", fileName); + builder.append("version", version); + return builder.toString(); + } + + // + // Comparable + // + + public final int compareTo(final AttachmentPE o) + { + final int byFile = getFileName().compareTo(o.getFileName()); + return byFile == 0 ? Integer.valueOf(getVersion()).compareTo(o.getVersion()) : byFile; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/Experiment.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/Experiment.java index 69cfc371ad9..6ddd38fb51d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/Experiment.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/Experiment.java @@ -48,7 +48,8 @@ public final class Experiment extends AbstractEntity<Experiment> private ProjectPE project; - private ProcessingInstructionDTO[] processingInstructions = ProcessingInstructionDTO.EMPTY_ARRAY; + private ProcessingInstructionDTO[] processingInstructions = + ProcessingInstructionDTO.EMPTY_ARRAY; private InvalidationPE invalidation; @@ -93,20 +94,20 @@ public final class Experiment extends AbstractEntity<Experiment> } /** - * Returns the descriptions of all {@link FileAttachmentPE}s that are stored for this + * Returns the descriptions of all {@link AttachmentPE}s that are stored for this * experiment. If there are no such properties, the array will be empty (have length 0). */ public final AttachmentPE[] getAttachments() { if (attachments == null) { - return new AttachmentPE[0]; + return AttachmentPE.EMPTY_ARRAY; } return attachments; } /** - * Sets the descriptions of all {@link FileAttachmentPE}s. + * Sets the descriptions of all {@link AttachmentPE}s. */ public final void setAttachments(final AttachmentPE[] attachments) { @@ -152,7 +153,8 @@ public final class Experiment extends AbstractEntity<Experiment> return processingInstructions; } - public final void setProcessingInstructions(final ProcessingInstructionDTO[] processingInstructions) + public final void setProcessingInstructions( + final ProcessingInstructionDTO[] processingInstructions) { this.processingInstructions = processingInstructions; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/ExperimentPE.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/ExperimentPE.java index 242a09914c9..164b28855db 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/ExperimentPE.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/ExperimentPE.java @@ -450,7 +450,7 @@ public class ExperimentPE implements IEntityPropertiesHolder<ExperimentPropertyP return builder.toString(); } - public final static void unescapeFileName(final AbstractAttachmentPE attachment) + public final static void unescapeFileName(final AttachmentPE attachment) { if (attachment != null) { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/FileAttachmentPE.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/FileAttachmentPE.java deleted file mode 100644 index bf09663e2e8..00000000000 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/FileAttachmentPE.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2007 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.dto; - -import javax.persistence.Entity; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; - -import org.hibernate.validator.NotNull; - -import ch.systemsx.cisd.openbis.generic.shared.GenericSharedConstants; - -/** - * Contains information about an attachment together with its content. - * - * @author Bernd Rinn - */ -@Entity -@Table(name = TableNames.EXPERIMENT_ATTACHMENTS_TABLE, uniqueConstraints = - { @UniqueConstraint(columnNames = - { ColumnNames.EXPERIMENT_COLUMN, ColumnNames.FILE_NAME_COLUMN, ColumnNames.VERSION_COLUMN }) }) -public class FileAttachmentPE extends AbstractAttachmentPE -{ - private static final long serialVersionUID = GenericSharedConstants.VERSION; - - private byte[] value; - - /** - * Returns bytes blob stored in the attachment. - */ - @NotNull(message = ValidationMessages.ATTACHMENT_CONTENT_NOT_NULL_MESSAGE) - public byte[] getValue() - { - return value; - } - - public void setValue(final byte[] value) - { - this.value = value; - } - - @Override - public final String toString() - { - return getClass().getSimpleName() + "{len(value)=" - + (value != null ? value.length : "<null>") + ",attachment=" + super.toString() - + "}"; - } -} diff --git a/openbis/source/java/hibernateContext.xml b/openbis/source/java/hibernateContext.xml index afefde49808..08a5221fdac 100644 --- a/openbis/source/java/hibernateContext.xml +++ b/openbis/source/java/hibernateContext.xml @@ -53,7 +53,6 @@ <value>ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPropertyPE</value> <value>ch.systemsx.cisd.openbis.generic.shared.dto.SamplePropertyPE</value> - <value>ch.systemsx.cisd.openbis.generic.shared.dto.FileAttachmentPE</value> <value>ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentPE</value> <value>ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE</value> diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/amc/CreateGroup.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/amc/CreateGroup.java index bb4cc6cfe3a..7f74e34d4d1 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/amc/CreateGroup.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/amc/CreateGroup.java @@ -42,7 +42,7 @@ public final class CreateGroup extends AbstractDefaultTestCommand public final void execute() { - GWTTestUtil.selectTabItemWithId(MainTabPanel.ID, MainTabPanel.ID + GroupsView.ID + GWTTestUtil.selectTabItemWithId(MainTabPanel.ID, MainTabPanel.ID + "_" + GroupsView.ID + MainTabPanel.TAB_SUFFIX); GWTTestUtil.clickButtonWithID(GroupsView.ADD_BUTTON_ID); GWTTestUtil.getTextFieldWithID(AddGroupDialog.CODE_FIELD_ID).setValue(groupCode); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/amc/CreatePerson.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/amc/CreatePerson.java index fc54aa2bafc..233ce6e6180 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/amc/CreatePerson.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/amc/CreatePerson.java @@ -42,7 +42,7 @@ public final class CreatePerson extends AbstractDefaultTestCommand public final void execute() { - GWTTestUtil.selectTabItemWithId(MainTabPanel.ID, MainTabPanel.ID + PersonsView.ID + GWTTestUtil.selectTabItemWithId(MainTabPanel.ID, MainTabPanel.ID + "_" + PersonsView.ID + MainTabPanel.TAB_SUFFIX); GWTTestUtil.clickButtonWithID(PersonsView.ADD_BUTTON_ID); GWTTestUtil.getTextFieldWithID(AddPersonDialog.CODE_FIELD_ID).setValue(personCode); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/amc/CreateRole.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/amc/CreateRole.java index 5ca22e831f9..55fe2533c92 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/amc/CreateRole.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/amc/CreateRole.java @@ -53,7 +53,7 @@ public final class CreateRole extends AbstractDefaultTestCommand public final void execute() { - GWTTestUtil.selectTabItemWithId(MainTabPanel.ID, MainTabPanel.ID + RolesView.ID + GWTTestUtil.selectTabItemWithId(MainTabPanel.ID, MainTabPanel.ID + "_" + RolesView.ID + MainTabPanel.TAB_SUFFIX); GWTTestUtil.clickButtonWithID(RolesView.ADD_BUTTON_ID); final RoleListBox listBox = -- GitLab