Skip to content

Commit

Permalink
process child artifact attach operation inside lock manager, #97
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed May 27, 2015
1 parent 506317e commit 311fa3b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<ValidationMessage> getValidationMessages ()
@Override
public Artifact attachArtifact ( final String name, final InputStream stream, final Map<MetaKey, String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MetaKey, String> 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 );
Expand Down Expand Up @@ -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<MetaKey, String> 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<DeployKey> getAllDeployKeys ( final String channelId )
{
return doWithTransaction ( ( em ) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public default Channel createChannel ()

public Artifact createGeneratorArtifact ( String channelId, String name, String generatorId, InputStream stream, Map<MetaKey, String> providedMetaData );

public Artifact createAttachedArtifact ( String parentArtifactId, String name, InputStream stream, Map<MetaKey, String> providedMetaData );

public Collection<Channel> listChannels ();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 )
{
Expand Down

0 comments on commit 311fa3b

Please sign in to comment.