Commit 1b1dfa8c authored by Matija Obreza's avatar Matija Obreza

REST /me/teams with TeamSerializer

parent 9fc25ed4
......@@ -35,9 +35,12 @@ import javax.persistence.UniqueConstraint;
import org.genesys2.server.model.AclAwareModel;
import org.genesys2.server.model.VersionedAuditedModel;
import org.genesys2.server.servlet.controller.rest.serialization.TeamSerializer;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Store;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* A team is a group of users, allowed to manage data in the system. Implements
* the {@link AclAwareModel} so that ACL entries are managed.
......@@ -46,6 +49,7 @@ import org.hibernate.search.annotations.Store;
*/
@Entity()
@Table(name = "team", uniqueConstraints = { @UniqueConstraint(name = "team_UC_name", columnNames = { "name" }) })
@JsonSerialize(using = TeamSerializer.class)
public class Team extends VersionedAuditedModel implements AclAwareModel {
private static final long serialVersionUID = -6992621329254944604L;
......
......@@ -65,6 +65,12 @@ public class UserController extends RestController {
return OAuth2Cleanup.clean(user);
}
@RequestMapping(value = "/me/teams", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
Object listTeams() {
return teamService.listMyTeams();
}
@RequestMapping(value = "/me/teams", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
Object createTeam(@RequestBody TeamJson teamJson) {
......@@ -78,6 +84,7 @@ public class UserController extends RestController {
return OAuth2Cleanup.clean(teamService.addTeam(teamJson.name));
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping(value = "/user/{uuid}/locked", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
boolean changeLock(@PathVariable("uuid") String uuid, @RequestBody boolean locked) {
......@@ -85,6 +92,7 @@ public class UserController extends RestController {
return true;
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping(value = "/user/{uuid}/enabled", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
boolean changeEnabled(@PathVariable("uuid") String uuid, @RequestBody boolean enabled) {
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest.serialization;
import java.io.IOException;
import org.genesys2.server.model.impl.Team;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
public class TeamSerializer extends JsonSerializer<Team> {
@Override
public void serialize(Team team, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException {
if (team == null) {
jgen.writeNull();
} else {
jgen.writeStartObject();
jgen.writeObjectField("uuid", team.getUuid());
jgen.writeObjectField("name", team.getName());
jgen.writeEndObject();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment