Commit 7bebb5b1 authored by Matija Obreza's avatar Matija Obreza

Institute networks: Code cleanup

- Removed OrganizationBlurbJson
- Renamed OrganizationDetails to NetworkDetails
- Need to use "blurb" as article slug
parent f3d46e9b
......@@ -68,7 +68,7 @@ public class NetworkController extends ApiBaseController {
}
/**
* Create or update organization
* Create or update network
*
* @return
*/
......@@ -101,16 +101,16 @@ public class NetworkController extends ApiBaseController {
* @return
*/
@GetMapping(value = "/{shortName}/details", produces = { MediaType.APPLICATION_JSON_VALUE })
public OrganizationDetails getNetworkDetails(@PathVariable("shortName") String shortName, @RequestParam(value = "language", defaultValue = "en") String language) {
public NetworkDetails getNetworkDetails(@PathVariable("shortName") String shortName, @RequestParam(value = "language", defaultValue = "en") String language) {
Organization organization = organizationService.getOrganization(shortName);
Page<FaoInstitute> members = organizationService.getOrganizationInstitutes(organization, new PageRequest(0, 50));
Article blurb = organizationService.getBlurb(organization, new Locale(language));
return OrganizationDetails.from(organization, blurb, members);
return NetworkDetails.from(organization, blurb, members);
}
/**
* Get organization blurb
* Get network blurb
*
* @return
*/
......@@ -125,13 +125,13 @@ public class NetworkController extends ApiBaseController {
*
*/
@PutMapping(value = "/{shortName}/blurb", produces = { MediaType.APPLICATION_JSON_VALUE })
public Article updateBlurb(@PathVariable("shortName") String shortName, @RequestBody OrganizationBlurbJson blurb) throws CRMException {
public Article updateBlurb(@PathVariable("shortName") String shortName, @RequestBody Article blurb) throws CRMException {
Organization org = organizationService.getOrganization(shortName);
return organizationService.updateAbout(org, blurb.blurb, blurb.summary, blurb.getLocale());
return organizationService.updateAbout(org, blurb.getBody(), blurb.getSummary(), blurb.getLang() == null ? Locale.ENGLISH : new Locale(blurb.getLang()));
}
/**
* Get organization details
* Get network details
*
* @return
*/
......@@ -141,7 +141,7 @@ public class NetworkController extends ApiBaseController {
}
/**
* Get organization institutes' codes
* Get network institutes' codes
*
* @return
*/
......@@ -152,7 +152,7 @@ public class NetworkController extends ApiBaseController {
}
/**
* Get organization details
* Get network details
*
* @return
*/
......@@ -193,28 +193,18 @@ public class NetworkController extends ApiBaseController {
}
public static class OrganizationDetails {
public Organization organization;
public static class NetworkDetails {
public Organization network;
public Article blurb;
public Page<FaoInstitute> institutes;
public static OrganizationDetails from(Organization organization, Article blurb, Page<FaoInstitute> institutes) {
OrganizationDetails details = new OrganizationDetails();
details.organization = organization;
public static NetworkDetails from(Organization organization, Article blurb, Page<FaoInstitute> institutes) {
NetworkDetails details = new NetworkDetails();
details.network = organization;
details.blurb = blurb;
details.institutes = institutes;
return details;
}
}
public static class OrganizationBlurbJson {
public String summary;
public String blurb;
public String locale;
public Locale getLocale() {
return locale == null ? Locale.ENGLISH : new Locale(locale);
}
}
}
......@@ -22,6 +22,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Set;
import javax.validation.Valid;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.Article;
......@@ -40,14 +42,11 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
@Service
@Transactional(readOnly = true)
@Validated
......@@ -88,14 +87,14 @@ public class OrganizationServiceImpl implements OrganizationService {
@Override
public Article getBlurb(Organization organization, Locale locale) {
return contentService.getArticle(organization, "blurb", locale);
return contentService.getArticle(organization, "blurp", locale);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(organization, 'write')")
@Transactional(readOnly = false)
public Article updateAbout(@Valid Organization organization, String body, String summary, Locale locale) throws CRMException {
return contentService.updateArticle(organization, "blurb", null, body, summary, locale);
return contentService.updateArticle(organization, "blurp", null, body, summary, locale);
}
@Override
......
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