diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/AttachmentDownloadLocatorResolver.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/AttachmentDownloadLocatorResolver.java index 64fbc78c14b2c8b4865678d71338f34ff4af66d0..70718188ad047cf6c3abaf0f2922c2afbd715868 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/AttachmentDownloadLocatorResolver.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/AttachmentDownloadLocatorResolver.java @@ -9,7 +9,9 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.IAttachmentHolder; import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolder; import ch.systemsx.cisd.openbis.generic.shared.basic.PermlinkUtilities; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AttachmentHolderKind; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.BasicProjectIdentifier; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; /** * ViewLocatorHandler used for downloading attachment. We use permIds to identify attachment holder @@ -33,21 +35,28 @@ public class AttachmentDownloadLocatorResolver extends AbstractViewLocatorResolv checkRequiredParameter(entityKindValueOrNull, ViewLocator.ENTITY_PARAMETER); AttachmentHolderKind attachmentHolderKind = getAttachmentHolderKind(entityKindValueOrNull); - EntityKind entityKind = getEntityKind(locator); - // valid only for samples and experiments - String permIdValueOrNull = - locator.getParameters().get(PermlinkUtilities.PERM_ID_PARAMETER_KEY); String fileNameOrNull = locator.getParameters().get(PermlinkUtilities.FILE_NAME_KEY); String versionOrNull = locator.getParameters().get(PermlinkUtilities.VERSION_KEY); - checkRequiredParameter(permIdValueOrNull, PermlinkUtilities.PERM_ID_PARAMETER_KEY); checkRequiredParameter(fileNameOrNull, PermlinkUtilities.FILE_NAME_KEY); checkRequiredParameter(versionOrNull, PermlinkUtilities.VERSION_KEY); try { int version = Integer.parseInt(versionOrNull); - downloadAttachment(entityKind, attachmentHolderKind, permIdValueOrNull, fileNameOrNull, - version); + if (attachmentHolderKind == AttachmentHolderKind.PROJECT) + { + BasicProjectIdentifier projectIdentifier = + ProjectLocatorResolver.extractProjectIdentifier(locator); + downloadProjectAttachment(projectIdentifier, fileNameOrNull, version); + } else + { + String permIdValueOrNull = + locator.getParameters().get(PermlinkUtilities.PERM_ID_PARAMETER_KEY); + checkRequiredParameter(permIdValueOrNull, PermlinkUtilities.PERM_ID_PARAMETER_KEY); + EntityKind entityKind = getEntityKind(locator); + downloadAttachment(entityKind, attachmentHolderKind, permIdValueOrNull, + fileNameOrNull, version); + } } catch (NumberFormatException e) { throw new UserFailureException("URL parameter '" + PermlinkUtilities.VERSION_KEY @@ -66,17 +75,18 @@ public class AttachmentDownloadLocatorResolver extends AbstractViewLocatorResolv version)); } + private void downloadProjectAttachment(BasicProjectIdentifier identifier, + final String fileName, final int version) throws UserFailureException + { + viewContext.getService().getProjectInfo(identifier, + new ProjectAttachmentDownloadCallback(viewContext, fileName, version)); + } + private AttachmentHolderKind getAttachmentHolderKind(String entityKind) { try { - AttachmentHolderKind holderKind = AttachmentHolderKind.valueOf(entityKind); - if (holderKind == AttachmentHolderKind.PROJECT) - { - throw new UserFailureException( - "Download of attachments is not supported for projects."); - } - return holderKind; + return AttachmentHolderKind.valueOf(entityKind); } catch (IllegalArgumentException exception) { throw new UserFailureException("Invalid '" + ViewLocator.ENTITY_PARAMETER @@ -84,7 +94,8 @@ public class AttachmentDownloadLocatorResolver extends AbstractViewLocatorResolv } } - public class AttachmentDownloadCallback extends AbstractAsyncCallback<IEntityInformationHolder> + private static class AttachmentDownloadCallback extends + AbstractAsyncCallback<IEntityInformationHolder> { private final AttachmentHolderKind attachmentHolderKind; @@ -133,4 +144,25 @@ public class AttachmentDownloadLocatorResolver extends AbstractViewLocatorResolv } + private static class ProjectAttachmentDownloadCallback extends AbstractAsyncCallback<Project> + { + private final String fileName; + + private final int version; + + private ProjectAttachmentDownloadCallback(final IViewContext<?> viewContext, + final String fileName, final int version) + { + super(viewContext); + this.fileName = fileName; + this.version = version; + } + + @Override + protected final void process(final Project result) + { + AttachmentDownloadHelper.download(fileName, version, result); + } + } + } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/ProjectLocatorResolver.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/ProjectLocatorResolver.java index deae3b1c64deaf3f0dc9ef83d3c4da731835f673..f22ba4999ebfdb27d8eeef82e04e022e209c92ef 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/ProjectLocatorResolver.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/locator/ProjectLocatorResolver.java @@ -44,7 +44,7 @@ public class ProjectLocatorResolver extends AbstractViewLocatorResolver openInitialProjectViewer(extractProjectIdentifier(locator)); } - protected BasicProjectIdentifier extractProjectIdentifier(ViewLocator locator) + static BasicProjectIdentifier extractProjectIdentifier(ViewLocator locator) { String codeValueOrNull = locator.getParameters().get(CODE_PARAMETER_KEY); String spaceValueOrNull = locator.getParameters().get(SPACE_PARAMETER_KEY); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/attachment/AttachmentBrowser.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/attachment/AttachmentBrowser.java index 6707bee922219b4f3f6fce0ae0426e5785d6fd82..e08deb42425b4d4253701f0180b55dec9e3adfa6 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/attachment/AttachmentBrowser.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/attachment/AttachmentBrowser.java @@ -150,11 +150,8 @@ public class AttachmentBrowser extends AbstractSimpleBrowserGrid<AttachmentVersi protected ColumnDefsAndConfigs<AttachmentVersions> createColumnsDefinition() { ColumnDefsAndConfigs<AttachmentVersions> schema = super.createColumnsDefinition(); - if (attachmentHolder.getAttachmentHolderKind() != AttachmentHolderKind.PROJECT) - { - schema.setGridCellRendererFor(AttachmentColDefKind.PERMLINK.id(), LinkRenderer - .createExternalLinkRenderer(viewContext.getMessage(Dict.PERMLINK))); - } + schema.setGridCellRendererFor(AttachmentColDefKind.PERMLINK.id(), LinkRenderer + .createExternalLinkRenderer(viewContext.getMessage(Dict.PERMLINK))); return schema; } 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 098d83e1f622eb2bde3edee1f2a33b714f047b5d..38cc88bf9ae38cc035e457124164211cb6b8018a 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 @@ -1205,7 +1205,7 @@ public final class CommonServer extends AbstractCommonServer<ICommonServer> impl IProjectBO projectBO = businessObjectFactory.createProjectBO(session); projectBO.loadDataByTechId(projectId); return AttachmentTranslator.translate(listHolderAttachments(session, projectBO - .getProject()), null); + .getProject()), session.getBaseIndexURL()); } catch (final DataAccessException ex) { throw createUserFailureException(ex); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/PermlinkUtilities.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/PermlinkUtilities.java index 57707ae9cf8e108e6fe42f1c6bee4a9b4f4405fd..725afac1ba6f24380b66ce95d829c29f5539cdf2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/PermlinkUtilities.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/PermlinkUtilities.java @@ -16,6 +16,7 @@ package ch.systemsx.cisd.openbis.generic.shared.basic; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.locator.ProjectLocatorResolver; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AttachmentHolderKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; @@ -50,19 +51,38 @@ public class PermlinkUtilities public static final String VERSION_KEY = "version"; - public final static String createAttachmentPermlinkURL(final String baseIndexURL, - final String fileName, final int version, final AttachmentHolderKind entityKind, - final String permId) + private final static URLMethodWithParameters createAttachmentParameters( + final String baseIndexURL, final String fileName, final int version) { URLMethodWithParameters ulrWithParameters = new URLMethodWithParameters(baseIndexURL); ulrWithParameters.addParameter(BasicConstant.VIEW_MODE_KEY, BasicConstant.VIEW_MODE_SIMPLE); ulrWithParameters.startHistoryToken(); ulrWithParameters.addParameter(BasicConstant.LOCATOR_ACTION_PARAMETER, DOWNLOAD_ATTACHMENT_ACTION); - ulrWithParameters.addParameter(ENTITY_KIND_PARAMETER_KEY, entityKind.name()); - ulrWithParameters.addParameter(PERM_ID_PARAMETER_KEY, permId); ulrWithParameters.addParameter(FILE_NAME_KEY, fileName); ulrWithParameters.addParameter(VERSION_KEY, version); + return ulrWithParameters; + } + + public final static String createAttachmentPermlinkURL(final String baseIndexURL, + final String fileName, final int version, final AttachmentHolderKind entityKind, + final String permId) + { + URLMethodWithParameters ulrWithParameters = + createAttachmentParameters(baseIndexURL, fileName, version); + ulrWithParameters.addParameter(ENTITY_KIND_PARAMETER_KEY, entityKind.name()); + ulrWithParameters.addParameter(PERM_ID_PARAMETER_KEY, permId); + return ulrWithParameters.toString(); + } + + public final static String createProjectAttachmentPermlinkURL(final String baseIndexURL, + final String fileName, final int version, final String projectCode, final String space) + { + URLMethodWithParameters ulrWithParameters = + createAttachmentParameters(baseIndexURL, fileName, version); + ulrWithParameters.addParameter(ENTITY_KIND_PARAMETER_KEY, AttachmentHolderKind.PROJECT); + ulrWithParameters.addParameter(ProjectLocatorResolver.CODE_PARAMETER_KEY, projectCode); + ulrWithParameters.addParameter(ProjectLocatorResolver.SPACE_PARAMETER_KEY, space); return ulrWithParameters.toString(); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/AttachmentTranslator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/AttachmentTranslator.java index 957da57de6603fb08acff0a0bb0527df09ce5ad4..3b140bb7b0d800e032a1c9b4aa3f60e32653fcc6 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/AttachmentTranslator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/AttachmentTranslator.java @@ -24,11 +24,13 @@ import org.apache.commons.lang.StringEscapeUtils; import ch.systemsx.cisd.openbis.generic.shared.basic.PermlinkUtilities; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Attachment; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AttachmentHolderKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AttachmentWithContent; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment; import ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentContentPE; import ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentHolderPE; import ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE; /** * A {@link Attachment} <---> {@link AttachmentPE} translator. @@ -51,13 +53,7 @@ public final class AttachmentTranslator return null; } final Attachment result = new Attachment(); - final AttachmentHolderPE holder = attachment.getParent(); - if (baseIndexURL != null) - { - result.setPermlink(PermlinkUtilities.createAttachmentPermlinkURL(baseIndexURL, - attachment.getFileName(), attachment.getVersion(), holder - .getAttachmentHolderKind(), holder.getPermId())); - } + result.setPermlink(createPermlink(attachment, baseIndexURL)); result.setFileName(StringEscapeUtils.escapeHtml(attachment.getFileName())); result.setTitle(StringEscapeUtils.escapeHtml(attachment.getTitle())); result.setDescription(StringEscapeUtils.escapeHtml(attachment.getDescription())); @@ -67,6 +63,23 @@ public final class AttachmentTranslator return result; } + private static String createPermlink(AttachmentPE attachment, String baseIndexURL) + { + final AttachmentHolderPE holder = attachment.getParent(); + final String fileName = attachment.getFileName(); + final int version = attachment.getVersion(); + if (holder.getAttachmentHolderKind() == AttachmentHolderKind.PROJECT) + { + ProjectPE project = (ProjectPE) holder; + return PermlinkUtilities.createProjectAttachmentPermlinkURL(baseIndexURL, fileName, version, + project.getCode(), project.getGroup().getCode()); + } else + { + return PermlinkUtilities.createAttachmentPermlinkURL(baseIndexURL, fileName, version, + holder.getAttachmentHolderKind(), holder.getPermId()); + } + } + public final static AttachmentWithContent translateWithContent(final AttachmentPE attachment) { if (attachment == null) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/ProjectTranslator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/ProjectTranslator.java index 3d03bf6c93e108b02e9c8af87c5b3bc2fe527626..7fd6e7305b0f66d56ac393f545e48fb3ae1b127b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/ProjectTranslator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/ProjectTranslator.java @@ -69,14 +69,8 @@ public final class ProjectTranslator result.setRegistrationDate(project.getRegistrationDate()); result.setIdentifier(StringEscapeUtils.escapeHtml(IdentifierHelper.createProjectIdentifier( project).toString())); - List<Attachment> attachments; - if (project.attachmentsInitialized() == false) - { - attachments = DtoConverters.createUnmodifiableEmptyList(); - } else - { - attachments = AttachmentTranslator.translate(project.getAttachments(), null); - } + // we don't use attachments collection directly from project + List<Attachment> attachments = DtoConverters.createUnmodifiableEmptyList(); result.setAttachments(attachments); return result; }