Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add traits endpoint #42

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@
<version>1.0.0</version>
</dependency>

<dependency>
<groupId>com.strandls.biodiv</groupId>
<artifactId>esmodule-client</artifactId>
<version>1.0.0</version>
</dependency>

<dependency>
<groupId>com.strandls.biodiv</groupId>
<artifactId>activity-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
package com.strandls.traits.controller;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
Expand All @@ -26,6 +28,7 @@
import com.strandls.traits.pojo.Facts;
import com.strandls.traits.pojo.FactsCreateData;
import com.strandls.traits.pojo.FactsUpdateData;
import com.strandls.traits.pojo.Traits;
import com.strandls.traits.pojo.TraitsValue;
import com.strandls.traits.pojo.TraitsValuePair;
import com.strandls.traits.services.TraitsServices;
Expand Down Expand Up @@ -73,6 +76,52 @@ public Response getAllTraits() {
}
}

@POST
@Path(ApiConstants.TRAIT + ApiConstants.CREATE)
@Produces(MediaType.APPLICATION_JSON)

@ApiOperation(value = "Fetch all the Traits", notes = "Returns all the IBP traits", response = TraitsValuePair.class, responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "unable to fetch all the traits", response = String.class) })

public Response createTrait(@QueryParam("dataType") String dataType, @QueryParam("description") String description,
@QueryParam("name") String name, @QueryParam("traitTypes") String traitTypes,
@QueryParam("units") String units, @QueryParam("speciesField") String speciesField,
@QueryParam("source") String source, @QueryParam("showInObservation") Boolean showInObservation,
@QueryParam("isParticipatory") Boolean isParticipatory, @QueryParam("values") String values,
@QueryParam("taxonIds") String taxonIds, @QueryParam("icon") String icon, @QueryParam("min") String min,
@QueryParam("max") String max) {
try {
String result = services.createTraits(dataType, description, Long.parseLong(speciesField), source, name,
traitTypes, units, showInObservation, isParticipatory, values, taxonIds, icon, min, max);
return Response.status(Status.OK).entity(result).build();
} catch (Exception e) {
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
}
}

@POST
@Path(ApiConstants.TRAIT + ApiConstants.UPDATE)
@Produces(MediaType.APPLICATION_JSON)

@ApiOperation(value = "Fetch all the Traits", notes = "Returns all the IBP traits", response = TraitsValuePair.class, responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "unable to fetch all the traits", response = String.class) })

public Response updateTrait(@QueryParam("description") String description, @QueryParam("id") Long id,
@QueryParam("name") String name, @QueryParam("traitTypes") String traitTypes,
@QueryParam("showInObservation") Boolean showInObservation,
@QueryParam("isParticipatory") Boolean isParticipatory, @QueryParam("source") String source,
@ApiParam(name = "traitValues") Map<String, List<Map<String, Object>>> traitValues) {
try {
String result = services.updateTraits(description, id, name, traitTypes, showInObservation, isParticipatory,
source, traitValues.get("traitValues"));
return Response.status(Status.OK).entity(result).build();
} catch (Exception e) {
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
}
}

@GET
@Path("/{objectType}/{objectId}")
@Consumes(MediaType.TEXT_PLAIN)
Expand Down Expand Up @@ -157,6 +206,25 @@ public Response getTraitList(@PathParam("speciesGroupId") String speciesGroupId)

}

@GET
@Path(ApiConstants.TRAIT + "/{traitId}")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)

@ApiOperation(value = "Find facts by taxonId", notes = "Returns list of facts for a particular TaxonId", response = Facts.class, responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "traits not found for TaxonId", response = String.class) })

public Response getTraitBytraitId(@PathParam("traitId") String trtId) {
try {
Long traitId = Long.parseLong(trtId);
Map<String, Object> result = services.fetchByTraitId(traitId);
return Response.status(Status.OK).entity(result).build();
} catch (Exception e) {
return Response.status(Status.BAD_REQUEST).build();
}
}

@GET
@Path(ApiConstants.TAXON + "/{taxonId}")
@Consumes(MediaType.TEXT_PLAIN)
Expand Down Expand Up @@ -210,13 +278,33 @@ public Response getTraitsValue(@PathParam("traitId") String traitId) {
}
}

@PUT
@Path(ApiConstants.UPDATE + "/{objectType}/{objectId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)

@ApiOperation(value = "Adds new Traits", notes = "Returns the list of allTraitValue Pair", response = FactValuePair.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Unable to edit the Traits", response = String.class) })

public Response addNewTraits(@Context HttpServletRequest request, @PathParam("objectType") String objectType,
@PathParam("objectId") String objectId, @ApiParam(name = "factsAddData") Map<String, List> factsAddData,
@QueryParam("userId") String userId, @QueryParam("taxonId") String taxonId) {
try {
Long objId = Long.parseLong(objectId);
String result = services.addNewTraits(request, objectType, objId, factsAddData, userId, taxonId);
return Response.status(Status.OK).entity(result).build();
} catch (Exception e) {
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
}
}

@PUT
@Path(ApiConstants.UPDATE + "/{objectType}/{objectId}/{traitId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)

@ValidateUser

@ApiOperation(value = "Updates the Traits with Values", notes = "Returns the list of allTraitValue Pair", response = FactValuePair.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Unable to edit the Traits", response = String.class) })

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/strandls/traits/pojo/Traits.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package com.strandls.traits.pojo;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -24,6 +26,8 @@ public class Traits implements Serializable {
*/
private static final long serialVersionUID = -7750012729432714454L;
private Long id;
private Date createdOn;
private Date lastRevised;
private String dataType;
private String description;
private Long fieldId;
Expand All @@ -35,6 +39,7 @@ public class Traits implements Serializable {
private Boolean isParticipatory;
private Boolean isDeleted;
private String source;
private String icon;

@Id
@GeneratedValue
Expand All @@ -47,6 +52,24 @@ public void setId(Long id) {
this.id = id;
}

@Column(name = "created_on")
public Date getCreatedOn() {
return createdOn;
}

public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}

@Column(name = "last_revised")
public Date getLastRevised() {
return lastRevised;
}

public void setLastRevised(Date lastRevised) {
this.lastRevised = lastRevised;
}

@Column(name = "data_types")
public String getDataType() {
return dataType;
Expand Down Expand Up @@ -128,6 +151,15 @@ public void setSource(String source) {
this.source = source;
}

@Column(name = "icon")
public String getIcon() {
return icon;
}

public void setIcon(String icon) {
this.icon = icon;
}

@Column(name = "units")
public String getUnits() {
return units;
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/strandls/traits/pojo/TraitsValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public class TraitsValue implements Serializable {
private String value;
private String icon;
private Long traitInstanceId;
private String description;
private String source;
private Boolean isDeleted;
private Long displayOrder;

@Id
@GeneratedValue
Expand All @@ -50,6 +53,33 @@ public void setValue(String value) {
this.value = value;
}

@Column(name = "display_order", columnDefinition = "BIGINT")
public Long getDisplayOrder() {
return displayOrder;
}

public void setDisplayOrder(Long displayOrder) {
this.displayOrder = displayOrder;
}

@Column(name = "description")
public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

@Column(name = "source")
public String getSource() {
return source;
}

public void setSource(String source) {
this.source = source;
}

@Column(name = "icon")
public String getIcon() {
return icon;
Expand Down
Loading
Loading