Skip to content
This repository has been archived by the owner on Jul 17, 2018. It is now read-only.

Commit

Permalink
[#1] metadata-template-service-impl implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rskarbez committed Feb 24, 2017
1 parent 5d4083c commit e316900
Show file tree
Hide file tree
Showing 10 changed files with 586 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ protected void configure(HttpSecurity http) throws Exception {
.authenticationEntryPoint(irodsBasicAuthEntryPoint).and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(connectionCloseFilter,
SecurityContextPersistenceFilter.class);
http.addFilterBefore(connectionCloseFilter, SecurityContextPersistenceFilter.class);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
@Path("/ping")


@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaResteasyServerCodegen", date = "2017-02-23T16:25:45.614-05:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaResteasyServerCodegen", date = "2017-02-23T17:08:15.207-05:00")
public class PingApi {
private final PingApiService delegate = PingApiServiceFactory.getPingApi();

@GET


@Produces({ "application/json", "application/xml" })
public Response server( @QueryParam("midTierOnly") Boolean midTierOnly,@Context SecurityContext securityContext)
public Response ping( @QueryParam("midTierOnly") Boolean midTierOnly,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.server(midTierOnly,securityContext);
return delegate.ping(midTierOnly,securityContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;

@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaResteasyServerCodegen", date = "2017-02-23T16:25:45.614-05:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaResteasyServerCodegen", date = "2017-02-23T17:08:15.207-05:00")
public abstract class PingApiService {
public abstract Response server(Boolean midTierOnly,SecurityContext securityContext)
public abstract Response ping(Boolean midTierOnly,SecurityContext securityContext)
throws NotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
import java.util.List;

import org.irods.jargon.rest.metadatatemplate.NotFoundException;
import org.irods.jargon.rest.security.IrodsAuthentication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -27,50 +31,65 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;

@Component
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaResteasyServerCodegen", date = "2017-02-22T16:39:27.094-05:00")
public class BuildFormApiServiceImpl extends BuildFormApiService {

private final Logger log = LoggerFactory.getLogger(this.getClass());


@Autowired
private IRODSAccessObjectFactory irodsAccessObjectFactory;

@Override
public Response buildForm(MetadataTemplateRequest body,
SecurityContext securityContext) throws NotFoundException {

JargonMetadataResolver resolver = null;
MetadataTemplate template = null;
String uuidString = null;

if (securityContext == null) {
// throw new IllegalArgumentException("null securityContext");
return Response.status(405).entity("null securityContext").build();
}

log.info("authentication:{}", SecurityContextHolder.getContext()
.getAuthentication());
IrodsAuthentication irodsAuthentication = (IrodsAuthentication) SecurityContextHolder
.getContext().getAuthentication();

Form form = new Form();

try {
resolver = new JargonMetadataResolver(irodsAccount,
resolver = new JargonMetadataResolver(
irodsAuthentication.getIrodsAccount(),
irodsAccessObjectFactory);
} catch (JargonException e) {
log.error(
"JargonException: JargonMetadataResolver could not be created",
e);
}

if (resolver == null) {
log.error("Unable to instantiate JargonMetadataResolver");

return Response
.status(500)
.entity("Internal server error - Unable to instantiate JargonMetadataResolver")
.build();
}

try {
if (!body.getUuid().isEmpty()) {
// Prefer UUID if provided
template = resolver.findTemplateByUUID(body.getUuid());
} else if (!body.getFqName().isEmpty()) {
// Prefer FQ name if no UUID provided
template = resolver.findTemplateByFqName(body.getFqName());
} else if (!body.getName().isEmpty() && !body.getActiveDir().isEmpty()) {
template = resolver.findTemplateByName(body.getName(), body.getActiveDir());
} else if (!body.getName().isEmpty()
&& !body.getActiveDir().isEmpty()) {
template = resolver.findTemplateByName(body.getName(),
body.getActiveDir());
} else {
return Response
.status(400)
Expand All @@ -80,13 +99,10 @@ public Response buildForm(MetadataTemplateRequest body,
} catch (FileNotFoundException e) {
log.error("Metadata template file not found");

return Response
.status(404)
.entity("File not found")
.build();
return Response.status(404).entity("File not found").build();
} catch (MetadataTemplateParsingException e) {
log.error("Error parsing metadata template file JSON");

return Response
.status(500)
.entity("Internal server error - Error parsing metadata template file JSON")
Expand All @@ -106,7 +122,7 @@ public Response buildForm(MetadataTemplateRequest body,
.entity("Internal server error - IOException when trying to load metadata template file")
.build();
}

form.setName(template.getName());
form.setDescription(template.getDescription());
form.setUniqueId(uuidString);
Expand Down Expand Up @@ -218,17 +234,15 @@ public Response buildForm(MetadataTemplateRequest body,
}
} // TODO else if (other type of MetadataTemplate)

return Response
.status(200)
.entity(form)
.build();
return Response.status(200).entity(form).build();
}

public IRODSAccessObjectFactory getIrodsAccessObjectFactory() {
return irodsAccessObjectFactory;
}

public void setIrodsObjectFactory(IRODSAccessObjectFactory irodsAccessObjectFactory) {

public void setIrodsObjectFactory(
IRODSAccessObjectFactory irodsAccessObjectFactory) {
this.irodsAccessObjectFactory = irodsAccessObjectFactory;
}
}
Loading

0 comments on commit e316900

Please sign in to comment.