From 311fa3b6370dcded75af67e268697ed94e575901 Mon Sep 17 00:00:00 2001 From: Jens Reimann Date: Wed, 27 May 2015 09:49:46 +0200 Subject: [PATCH] process child artifact attach operation inside lock manager, #97 --- .../pm/storage/service/jpa/ArtifactImpl.java | 2 +- .../service/jpa/StorageServiceImpl.java | 27 ++++++++++--------- .../pm/storage/service/StorageService.java | 2 -- .../web/artifact/ArtifactController.java | 9 ++++++- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/ArtifactImpl.java b/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/ArtifactImpl.java index 74d4cf89..84e283b3 100644 --- a/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/ArtifactImpl.java +++ b/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/ArtifactImpl.java @@ -46,7 +46,7 @@ public List getValidationMessages () @Override public Artifact attachArtifact ( final String name, final InputStream stream, final Map providedMetaData ) { - return this.channel.getService ().createAttachedArtifact ( this.id, name, stream, providedMetaData ); + return this.channel.getService ().createAttachedArtifact ( this.channel.getId (), this.id, name, stream, providedMetaData ); } @Override diff --git a/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/StorageServiceImpl.java b/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/StorageServiceImpl.java index 7a40e18d..88d20dfb 100644 --- a/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/StorageServiceImpl.java +++ b/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/StorageServiceImpl.java @@ -218,6 +218,20 @@ private Artifact internalCreateArtifact ( final String channelId, final String n } ); } + public Artifact createAttachedArtifact ( final String channelId, final String parentArtifactId, final String name, final InputStream stream, final Map providedMetaData ) + { + return this.lockManager.modifyCall ( channelId, () -> { + return doWithHandler ( ( hi ) -> { + final ArtifactEntity artifact = hi.createAttachedArtifact ( parentArtifactId, name, stream, providedMetaData ); + if ( artifact == null ) + { + return null; + } + return convert ( convert ( artifact.getChannel () ), artifact, null ); + } ); + } ); + } + protected ChannelEntity getCheckedChannel ( final EntityManager em, final String channelId ) { final ChannelEntity channel = em.find ( ChannelEntity.class, channelId ); @@ -703,19 +717,6 @@ public void generateArtifact ( final String id ) doWithHandlerVoid ( hi -> hi.generateArtifact ( id ) ); } - @Override - public Artifact createAttachedArtifact ( final String parentArtifactId, final String name, final InputStream stream, final Map providedMetaData ) - { - return doWithHandler ( ( hi ) -> { - final ArtifactEntity artifact = hi.createAttachedArtifact ( parentArtifactId, name, stream, providedMetaData ); - if ( artifact == null ) - { - return null; - } - return convert ( convert ( artifact.getChannel () ), artifact, null ); - } ); - } - public Collection getAllDeployKeys ( final String channelId ) { return doWithTransaction ( ( em ) -> { diff --git a/de.dentrassi.pm.storage.service/src/de/dentrassi/pm/storage/service/StorageService.java b/de.dentrassi.pm.storage.service/src/de/dentrassi/pm/storage/service/StorageService.java index d0f90338..4c8f2fa7 100644 --- a/de.dentrassi.pm.storage.service/src/de/dentrassi/pm/storage/service/StorageService.java +++ b/de.dentrassi.pm.storage.service/src/de/dentrassi/pm/storage/service/StorageService.java @@ -87,8 +87,6 @@ public default Channel createChannel () public Artifact createGeneratorArtifact ( String channelId, String name, String generatorId, InputStream stream, Map providedMetaData ); - public Artifact createAttachedArtifact ( String parentArtifactId, String name, InputStream stream, Map providedMetaData ); - public Collection listChannels (); /** diff --git a/de.dentrassi.pm.storage.web/src/de/dentrassi/pm/storage/web/artifact/ArtifactController.java b/de.dentrassi.pm.storage.web/src/de/dentrassi/pm/storage/web/artifact/ArtifactController.java index f5f5086c..9d91b6f1 100644 --- a/de.dentrassi.pm.storage.web/src/de/dentrassi/pm/storage/web/artifact/ArtifactController.java +++ b/de.dentrassi.pm.storage.web/src/de/dentrassi/pm/storage/web/artifact/ArtifactController.java @@ -146,6 +146,13 @@ public ModelAndView attach ( @PathVariable ( "artifactId" ) final String artifac public ModelAndView attachPost ( @PathVariable ( "artifactId" ) final String artifactId, @RequestParameter ( required = false, value = "name" ) String name, final @RequestParameter ( "file" ) Part file) { + final Artifact parentArtifact = this.service.getArtifact ( artifactId ); + + if ( parentArtifact == null ) + { + return CommonController.createNotFound ( "artifact", artifactId ); + } + Artifact artifact; try { @@ -154,7 +161,7 @@ public ModelAndView attachPost ( @PathVariable ( "artifactId" ) final String art name = file.getSubmittedFileName (); } - artifact = this.service.createAttachedArtifact ( artifactId, name, file.getInputStream (), null ); + artifact = parentArtifact.attachArtifact ( name, file.getInputStream (), null ); } catch ( final IOException e ) {