Skip to content

Commit

Permalink
Merge pull request #453 from socialappslab/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
cdparra authored Apr 30, 2017
2 parents 2c56da3 + bf1d9df commit 0c6694e
Show file tree
Hide file tree
Showing 34 changed files with 2,367 additions and 201 deletions.
44 changes: 3 additions & 41 deletions app/controllers/Assemblies.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,47 +442,9 @@ public static Result updateAssembly(@ApiParam(name = "id", value = "Assembly ID"
Assembly newAssembly = null;
TransferResponseStatus responseBody = new TransferResponseStatus();
try {
newAssembly = newAssemblyForm.get();
newAssembly.setAssemblyId(id);
Assembly oldAssembly = Assembly.findById(id);
newAssembly.setForumPosts(oldAssembly.getForumPosts());
newAssembly.setFollowedAssemblies(oldAssembly.getFollowedAssemblies());
newAssembly.setFollowingAssemblies(oldAssembly.getFollowingAssemblies());
List<Theme> themes = newAssembly.getThemes();
List<Theme> themesLoaded = new ArrayList<Theme>();
for (Theme theme: themes) {
Theme t = Theme.read(theme.getThemeId());
themesLoaded.add(t);
}
newAssembly.setThemes(themesLoaded);
List<Config> configs = newAssembly.getConfigs();
List<Config> configsLoaded = new ArrayList<Config>();
for (Config conf: configs) {
Config c = Config.read(conf.getUuid());
if (c==null) {
conf.setConfigTarget(ConfigTargets.ASSEMBLY);
conf.setTargetUuid(newAssembly.getUuid());
Config.create(conf);
}
configsLoaded.add(conf);
}
newAssembly.setConfigs(configsLoaded);
List<Campaign> campaigns = newAssembly.getCampaigns();
List<Campaign> campaignsLoaded = new ArrayList<Campaign>();
for (Campaign camp: campaigns) {
Campaign c = Campaign.read(camp.getCampaignId());
campaignsLoaded.add(c);
}
newAssembly.setCampaigns(campaignsLoaded);
List<WorkingGroup> wg = newAssembly.getWorkingGroups();
List<WorkingGroup> wgLoaded = new ArrayList<WorkingGroup>();
for (WorkingGroup wgroup: wg
) {
WorkingGroup workingGroup = WorkingGroup.read(wgroup.getGroupId());
wgLoaded.add(workingGroup);
}
newAssembly.setWorkingGroups(wgLoaded);

Assembly updatedAssembly = newAssemblyForm.get();
newAssembly = Assembly.readAndUpdate(updatedAssembly,id);

AssemblyProfile profile = newAssembly.getProfile();
AssemblyProfile profileDB = AssemblyProfile.findByAssembly(newAssembly.getUuid());
profile.setAssemblyProfileId(profileDB.getAssemblyProfileId());
Expand Down
149 changes: 129 additions & 20 deletions app/controllers/Campaigns.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import delegates.CampaignDelegate;
import delegates.NotificationsDelegate;
import delegates.ResourcesDelegate;
import enums.ContributionTypes;
import enums.NotificationEventName;
import enums.ResourceSpaceTypes;
import enums.ResourceTypes;
import enums.*;
import exceptions.ConfigurationException;
import http.Headers;
import io.swagger.annotations.*;
Expand All @@ -44,8 +41,13 @@
import utils.GlobalData;
import utils.LogActions;

import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.sql.Timestamp;
import java.text.DateFormat;
Expand Down Expand Up @@ -216,22 +218,84 @@ public static Result updateCampaign(
responseBody.setStatusMessage(Messages.get(
GlobalData.CAMPAIGN_CREATE_MSG_ERROR,
newCampaignForm.errorsAsJson()));
Logger.info("Error pdating campaign");
Logger.info("Error updating campaign");
Logger.debug("=> " + newCampaignForm.errorsAsJson());
return badRequest(Json.toJson(responseBody));
} else {
Campaign updatedCampaign = newCampaignForm.get();
updatedCampaign.setCampaignId(campaignId);
updatedCampaign.update();
Logger.info("Updating campaign");
Logger.debug("=> " + newCampaignForm.toString());
Assembly rs = Assembly.read(aid);
Campaign c = Campaign.read(updatedCampaign.getCampaignId());
Promise.promise(() -> {
return NotificationsDelegate.signalNotification(ResourceSpaceTypes.ASSEMBLY, NotificationEventName.UPDATED_CAMPAIGN, rs, c);
});
try {
Campaign campaignOld = Campaign.read(campaignId);
Campaign updatedCampaign = newCampaignForm.get();
List<Component> componentLoaded = updatedCampaign.getTransientComponents();
campaignOld.setCampaignId(campaignId);
campaignOld.setGoal(updatedCampaign.getGoal());
campaignOld.setTitle(updatedCampaign.getTitle());
campaignOld.setShortname(updatedCampaign.getShortname());
campaignOld.setUrl(updatedCampaign.getUrl());
campaignOld.setListed(updatedCampaign.getListed());
List<Component> componentList = new ArrayList<Component>();
for (Component component:componentLoaded
) {
Component componentOld = Component.read(component.getComponentId());
componentOld.setTitle(component.getTitle());
componentOld.setDescription(component.getDescription());
componentOld.setEndDate(component.getEndDate());
componentOld.setStartDate(component.getStartDate());
componentOld.setKey(component.getKey());
componentOld.setPosition(component.getPosition());
componentOld.setTimeline(component.getTimeline());
componentOld.update();
componentOld.refresh();
componentList.add(componentOld);
}
List<CampaignTimelineEdge> timelineEdges = new ArrayList<>();
int edges =0;
for (Component component:componentList
) {
CampaignTimelineEdge edge = new CampaignTimelineEdge();
edge.setCampaign(campaignOld);
if (edges == 0) {
edge.setFromComponent(component);
edge.setStart(true);
timelineEdges.add(edge);
edges++;
} else {
if (edges < componentList.size() - 1) {
edge.setFromComponent(component);
timelineEdges.add(edge);
}
CampaignTimelineEdge prevEdge = timelineEdges.get(edges - 1);
prevEdge.setToComponent(component);
edges++;
}
}
for (CampaignTimelineEdge edge:campaignOld.getTimelineEdges()
) {
edge.delete();
}
List<CampaignTimelineEdge> timelineEdgesLoaded = new ArrayList<>();
for (CampaignTimelineEdge edge:timelineEdges
) {
edge.save();
edge.refresh();
timelineEdgesLoaded.add(edge);
}
campaignOld.setComponents(componentList);
campaignOld.setTimelineEdges(timelineEdgesLoaded);
campaignOld.update();
campaignOld.refresh();
Logger.info("Updating campaign");
Logger.debug("=> " + newCampaignForm.toString());
ResourceSpace rs = Assembly.read(aid).getResources();

Promise.promise(() -> {
return NotificationsDelegate.signalNotification(ResourceSpaceTypes.ASSEMBLY, NotificationEventName.UPDATED_CAMPAIGN, rs, campaignOld);
});

return ok(Json.toJson(updatedCampaign));
return ok(Json.toJson(campaignOld));
} catch (Exception e) {
e.printStackTrace();
return badRequest(Json.toJson("Error updating fields"));
}
}
}

Expand Down Expand Up @@ -865,7 +929,7 @@ public static Result listCampaignComponents(
Campaign campaign = Campaign.read(campaignId);
List<Component> components;
if (all != null) {
components = campaign.getComponents();
components = campaign.getComponentsByTimeline();
} else {
components = campaign.getPagedComponents(page, pageSize);
}
Expand Down Expand Up @@ -897,7 +961,7 @@ public static Result listPublicCampaignComponents(
Campaign campaign = Campaign.readByUUID(campaignUUID);
List<Component> components;
if (all != null) {
components = campaign.getComponents();
components = campaign.getComponentsByTimeline();
} else {
components = campaign.getPagedComponents(page, pageSize);
}
Expand Down Expand Up @@ -1206,6 +1270,7 @@ public String contentType() {
@ApiResponses(value = {@ApiResponse(code = 404, message = "No resource space found", response = TransferResponseStatus.class)})
@ApiImplicitParams({
@ApiImplicitParam(name = "SESSION_KEY", value = "User's session authentication key", dataType = "String", paramType = "header")})
@SubjectPresent
public static Result listSpaceResources(@ApiParam(name = "sid", value = "ResourceSpace ID") Long sid) {
ResourceSpace resourceSpace = ResourceSpace.read(sid);
List<Resource> resources;
Expand All @@ -1219,6 +1284,30 @@ public static Result listSpaceResources(@ApiParam(name = "sid", value = "Resourc

}

/**
* GET /api/space/:sid/resources/:rid
*
* @param sid
* @param rid
* @return
*/
@ApiOperation(httpMethod = "GET", response = Resource.class, value = "Resource in a resource space")
@ApiResponses(value = {@ApiResponse(code = 404, message = "No resource space found", response = TransferResponseStatus.class)})
@ApiImplicitParams({
@ApiImplicitParam(name = "SESSION_KEY", value = "User's session authentication key", dataType = "String", paramType = "header")})
@SubjectPresent
public static Result listSpaceResourcesById(@ApiParam(name = "sid", value = "ResourceSpace ID") Long sid,
@ApiParam(name = "rid", value = "Resource ID") Long rid) {
ResourceSpace resourceSpace = ResourceSpace.findByResource(sid,rid);
if (resourceSpace == null) {
return notFound(Json
.toJson(new TransferResponseStatus("No resource space found with id "+sid)));
} else {
Resource resource = Resource.read(rid);
return ok(Json.toJson(resource));
}
}

/**
* GET /api/space/:uuid/resources
* Returns the Resources associated to the resource space
Expand All @@ -1236,9 +1325,29 @@ public static Result listSpaceResourcesbyUuid(@ApiParam(name = "uuid", value = "
.toJson(new TransferResponseStatus("No resource space found with uuid "+uuid)));
} else {
resources = resourceSpace.getResources();
}
return ok(Json.toJson(resources));
String result;
try {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
result = mapper.writerWithView(Views.Public.class)
.writeValueAsString(resources);
} catch (Exception e) {
e.printStackTrace();
return notFound(Json.toJson(new TransferResponseStatus(ResponseStatus.NODATA, "No resources with this space uuid")));
}
Content ret = new Content() {
@Override
public String body() {
return result;
}

@Override
public String contentType() {
return "application/json";
}
};
return ok(ret);
}
}

/**
Expand Down
65 changes: 53 additions & 12 deletions app/controllers/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.feth.play.module.pa.PlayAuthenticate;
import enums.ResourceSpaceTypes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
Expand All @@ -30,6 +31,7 @@

import java.util.*;

@Api(value = "10 configuration: configuration management", description = "Configurations management")
@With(Headers.class)
public class Configs extends Controller {

Expand Down Expand Up @@ -156,9 +158,9 @@ public static Result createConfig(Long aid) {
@ApiOperation(httpMethod = "GET", response = HashMap.class, responseContainer = "List", produces = "application/json",
value = "Get configs in a Resource Space")
@ApiResponses(value = {@ApiResponse(code = 404, message = "No resource space found", response = TransferResponseStatus.class)})
// @ApiImplicitParams({
// @ApiImplicitParam(name = "SESSION_KEY", value = "User's session authentication key", dataType = "String", paramType = "header")})
// @SubjectPresent
@ApiImplicitParams({
@ApiImplicitParam(name = "SESSION_KEY", value = "User's session authentication key", dataType = "String", paramType = "header")})
@SubjectPresent
public static Result findSpaceConfigs(Long sid) {
ResourceSpace resourceSpace = ResourceSpace.read(sid);
List<Config> configs = resourceSpace.getConfigs();
Expand All @@ -172,6 +174,30 @@ public static Result findSpaceConfigs(Long sid) {
return ok(Json.toJson(map));
}

/**
* GET /api/space/:sid/config/:uuid
*
* @param sid
* @param uuid
* @return
*/
@ApiOperation(httpMethod = "GET", response = Config.class, produces = "application/json",
value = "Get config by id in a Resource Space")
@ApiResponses(value = {@ApiResponse(code = 404, message = "No resource space found", response = TransferResponseStatus.class)})
@ApiImplicitParams({
@ApiImplicitParam(name = "SESSION_KEY", value = "User's session authentication key", dataType = "String", paramType = "header")})
@SubjectPresent
public static Result findSpaceConfigById(Long sid, UUID uuid) {
ResourceSpace resourceSpace = ResourceSpace.findByConfig(sid, uuid);
if (resourceSpace == null) {
return notFound(Json
.toJson(new TransferResponseStatus("No config found with uuid "+uuid+ " in space with id "+sid)));
} else {
Config resourceSpaceConfig = Config.read(uuid);
return ok(Json.toJson(resourceSpaceConfig));
}
}

/**
* GET /api/space/:uuid/config/public
*
Expand Down Expand Up @@ -208,9 +234,9 @@ public static Result findSpaceConfigsPublic(UUID uuid) {
@ApiResponses(value = {@ApiResponse(code = 404, message = "No resource space found", response = TransferResponseStatus.class)})
@ApiImplicitParams({
@ApiImplicitParam(name = "sid", value = "Resource Space id", dataType = "Long", paramType = "path"),
@ApiImplicitParam(name = "config_map", value = "configuration key value json map", dataType = "String", paramType = "body", required = true)})
// @ApiImplicitParam(name = "SESSION_KEY", value = "User's session authentication key", dataType = "String", paramType = "header")})
// @SubjectPresent
@ApiImplicitParam(name = "config_map", value = "configuration key value json map", dataType = "String", paramType = "body", required = true),
@ApiImplicitParam(name = "SESSION_KEY", value = "User's session authentication key", dataType = "String", paramType = "header")})
@SubjectPresent
public static Result updateSpaceConfig(Long sid) {
JsonNode requestBody = request().body().asJson();
ObjectMapper mapper = new ObjectMapper();
Expand All @@ -233,18 +259,33 @@ public static Result updateSpaceConfig(Long sid) {
for(String key : updatedConfig.getConfigs().keySet()) {
Object value = updatedConfig.getConfigs().get(key);
List<Config> updateConfigs = new ArrayList<Config>();
ConfigTargets configTargets = null;
UUID uuid = null;
if (ResourceSpaceTypes.ASSEMBLY.equals(resourceSpace.getType())) {
updateConfigs = Config.findByTypeAndKey(resourceSpace.getAssemblyResources().getUuid(),ConfigTargets.ASSEMBLY,key);
configTargets = ConfigTargets.ASSEMBLY;
uuid = resourceSpace.getAssemblyResources()==null?null:resourceSpace.getAssemblyResources().getUuid();
} else if (ResourceSpaceTypes.CAMPAIGN.equals(resourceSpace.getType())) {
updateConfigs = Config.findByTypeAndKey(resourceSpace.getCampaign().getUuid(),ConfigTargets.CAMPAIGN,key);
configTargets = ConfigTargets.CAMPAIGN;
uuid = resourceSpace.getCampaign()==null?null:resourceSpace.getCampaign().getUuid();
} else if (ResourceSpaceTypes.COMPONENT.equals(resourceSpace.getType())) {
updateConfigs = Config.findByTypeAndKey(resourceSpace.getComponent().getUuid(),ConfigTargets.COMPONENT,key);
configTargets = ConfigTargets.COMPONENT;
uuid = resourceSpace.getComponent()==null?null:resourceSpace.getComponent().getUuid();
} else if (ResourceSpaceTypes.CONTRIBUTION.equals(resourceSpace.getType())) {
updateConfigs = Config.findByTypeAndKey(resourceSpace.getContribution().getUuid(),ConfigTargets.CONTRIBUTION,key);
configTargets = ConfigTargets.CONTRIBUTION;
uuid = resourceSpace.getContribution()==null?null:resourceSpace.getContribution().getUuid();
} else if (ResourceSpaceTypes.WORKING_GROUP.equals(resourceSpace.getType())) {
updateConfigs = Config.findByTypeAndKey(resourceSpace.getWorkingGroupResources().getUuid(),ConfigTargets.WORKING_GROUP,key);
configTargets = ConfigTargets.WORKING_GROUP;
uuid = resourceSpace.getWorkingGroupResources()==null?null:resourceSpace.getWorkingGroupResources().getUuid();
}
if(configTargets==null || uuid ==null){
responseBody = new TransferResponseStatus();
responseBody.setStatusMessage(Messages.get(
GlobalData.CONFIG_CREATE_MSG_ERROR, "\nEntity of type "+resourceSpace.getType()+" does not exists"));
return badRequest(Json.toJson(responseBody));
}
if (updateConfigs.size()==0) {

updateConfigs = Config.findByTypeAndKey(uuid,configTargets,key);
if (updateConfigs ==null || updateConfigs.size()==0) {
responseBody = new TransferResponseStatus();
responseBody.setStatusMessage(Messages.get(
GlobalData.CONFIG_CREATE_MSG_ERROR, "\nConfiguration Key '" + key + "' does not exists"));
Expand Down
Loading

0 comments on commit 0c6694e

Please sign in to comment.