Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cdparra committed May 7, 2018
2 parents 9c25558 + e10a1a0 commit 73c8eab
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 41 deletions.
13 changes: 9 additions & 4 deletions app/controllers/Contributions.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.poi.xwpf.usermodel.XWPFRun;
import play.Logger;
import play.Play;
import play.api.mvc.Session;
import play.data.Form;
import play.i18n.Messages;
import play.libs.F;
Expand Down Expand Up @@ -486,7 +485,7 @@ public static Result findResourceSpaceContributionById(

Contribution contribution = Contribution.read(cid);
if(flat.equals("true")) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm a z");
SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-DD HH:mm:ss");
Map<String, Object> aRet = new HashMap<>();
aRet.put("title",contribution.getTitle());
aRet.put("text", contribution.getText());
Expand Down Expand Up @@ -1180,10 +1179,11 @@ public static Result getContributionsChangeHistory(
public static Result putContributionByPeerDocId(
@ApiParam(name = "pid", value = "PeerDoc ID") String peerDocId,
@ApiParam(name = "title", value = "New Title") String title,
@ApiParam(name = "description", value = "New Description") String description,
@ApiParam(name = "lastUpdate", value = "Last activity") String lastUpdate) throws Exception {
try {
Contribution contribution = Contribution.getByPeerDocId(peerDocId);
if(title.isEmpty() && lastUpdate.isEmpty()) {
if(title.isEmpty() && lastUpdate.isEmpty() && description.isEmpty()) {
TransferResponseStatus responseBody = new TransferResponseStatus();
responseBody.setStatusMessage("Nothing to update");
return badRequest(Json.toJson(responseBody));
Expand All @@ -1192,6 +1192,10 @@ public static Result putContributionByPeerDocId(
if (!title.isEmpty()) {
contribution.setTitle(title);
}
if (!description.isEmpty()) {
contribution.setText(description);
}

if(!lastUpdate.isEmpty()) {
lastUpdate = java.net.URLDecoder.decode(lastUpdate, "UTF-8");
DateFormat format = new SimpleDateFormat("YYYY-MM-DD HH:mm:ss", Locale.ENGLISH);
Expand Down Expand Up @@ -2145,7 +2149,8 @@ public static Result updateContributionsPopularity(
* @param contributionId
* @return
*/
@ApiOperation(httpMethod = "PUT", response = Contribution.class, produces = "application/json", value = "Update contribution in Assembly")
@ApiOperation(httpMethod = "PUT", response = Contribution.class, produces = "application/json",
value = "Update contribution in Assembly", notes = "The lastUpdate date must be in YYYY-MM-DD HH:mm:ss format")
@ApiResponses(value = {@ApiResponse(code = BAD_REQUEST, message = "Contribution form has errors", response = TransferResponseStatus.class)})
@ApiImplicitParams({
@ApiImplicitParam(name = "Contribution object", value = "Body of Contribution in JSON", required = true, dataType = "models.Contribution", paramType = "body"),
Expand Down
95 changes: 59 additions & 36 deletions app/controllers/Spaces.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,25 @@
package controllers;


import static play.data.Form.form;

import be.objectify.deadbolt.java.actions.Dynamic;
import be.objectify.deadbolt.java.actions.SubjectPresent;
import com.avaje.ebean.Ebean;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.feth.play.module.pa.PlayAuthenticate;
import delegates.NotificationsDelegate;
import enums.*;
import http.Headers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;

import io.swagger.annotations.*;
import models.*;
import models.misc.ThemeStats;
import models.misc.Views;
import models.transfer.BallotTransfer;
import models.transfer.ThemeListTransfer;
import models.transfer.TransferResponseStatus;

import org.apache.commons.io.FileUtils;

import play.Logger;
import play.data.Form;
import play.i18n.Messages;
Expand All @@ -47,20 +31,18 @@
import play.mvc.With;
import play.twirl.api.Content;
import security.SecurityModelConstants;
import service.PlayAuthenticateLocal;
import utils.GlobalData;
import utils.LogActions;
import be.objectify.deadbolt.java.actions.Dynamic;
import be.objectify.deadbolt.java.actions.SubjectPresent;

import com.avaje.ebean.Ebean;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.feth.play.module.pa.PlayAuthenticate;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;

import delegates.NotificationsDelegate;
import static play.data.Form.form;

@Api(value = "09 space: resource space management", description = "Resource space management")
@With(Headers.class)
Expand Down Expand Up @@ -2935,4 +2917,45 @@ public static Result addSpaceResourcesbyUuid(@ApiParam(name = "uuid", value = "R
}
}
}

@ApiOperation(produces="application/json", value="Simple search of uuid by object id", httpMethod="GET")
public static Result getUUIDByIdAndType(
@ApiParam(name = "type", value = "Object type",
allowableValues = "assembly,campaign,contribution,group,resource") String type,
@ApiParam(name = "id", value = "Object id") Long id) {

UUID aRet = null;
AppCivistBaseModel object;
switch (type) {
case "assembly":
object = Assembly.findById(id);
aRet = object == null ? null: ((Assembly) object).getUuid();
break;
case "campaign":
object = Campaign.find.byId(id);
aRet = object == null ? null: ((Campaign) object).getUuid();
break;
case "contribution":
object = Contribution.find.byId(id);
aRet = object == null ? null: ((Contribution) object).getUuid();
break;
case "group":
object = WorkingGroup.find.byId(id);
aRet = object == null ? null: ((WorkingGroup) object).getUuid();
break;
case "resource":
object = Resource.find.byId(id);
aRet = object == null ? null: ((Resource) object).getUuid();
break;
}

if(aRet != null) {
Map<String, UUID> objectAret = new HashMap<>();
objectAret.put("uuid", aRet);
return ok(Json.toJson(objectAret));
} else {
return notFound(Json
.toJson(new TransferResponseStatus("No object found with id "+id)));
}
}
}
3 changes: 2 additions & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ GET /api/assembly/:aid/campaign/:cid/contribution
GET /api/assembly/:aid/group/:gid/contribution controllers.Contributions.findAssemblyGroupContributions(aid: Long, gid: Long, space?="forum", type?="")
GET /api/assembly/:aid/contribution/:cid controllers.Contributions.findContribution(aid: Long, cid: Long)
GET /api/assembly/:aid/contribution/:cid/history controllers.Contributions.getContributionsChangeHistory(aid: Long, cid: Long)
PUT /api/contribution/:pdi controllers.Contributions.putContributionByPeerDocId(pdi: String, title?="", lastActivity?="")
PUT /api/contribution/:pdi controllers.Contributions.putContributionByPeerDocId(pdi: String, title?="", description?="",lastActivity?="")
POST /api/contribution/clean/history controllers.Contributions.deleteUnchangedContributionHistories()
POST /api/contribution/clean/feedback controllers.Contributions.cleanUnarchivedContributionFeedbacks()
POST /api/contribution/history controllers.Contributions.createHistories()
Expand Down Expand Up @@ -470,3 +470,4 @@ GET /api/public/assembly/:aid/group/:gid

# Update Language
POST /api/contribution/language controllers.Contributions.updateAllContributionLanguages()
GET /api/uuid controllers.Spaces.getUUIDByIdAndType(type: String, id : Long)

0 comments on commit 73c8eab

Please sign in to comment.