REPO-1646: V1 REST API - cannot unset optional fields (eg. when updating person / site details ...)

- part 1 (Update Site)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133290 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2016-11-30 12:03:30 +00:00
parent cdd3bb0a38
commit c6a643ae99
5 changed files with 97 additions and 34 deletions

View File

@@ -132,35 +132,49 @@ public class SiteEntityResource implements EntityResourceAction.Read<Site>,
@Override
@WebApiDescription(title="Update site", description="Update the Share site")
public Site update(String siteId, Site site, Parameters parameters)
{
return sites.updateSite(siteId, convert(site), parameters);
}
protected SiteUpdate convert(Site site)
{
// Until REPO-110 is solved, we need to explicitly test for the presence of fields
// on the Site object that aren't valid SiteUpdate fields. Once REPO-110 is solved,
// the update method will take a SiteUpdate as a parameter rather than a Site
// and only the correct fields will be exposed. Any attempt to access illegal fields
// should then result in the framework returning a 400 automatically.
if (site.getId() != null)
if (site.wasSet(Site.ID))
{
throw new InvalidArgumentException("Site update does not support field: id");
}
if (site.getGuid() != null)
if (site.wasSet(Site.GUID))
{
throw new InvalidArgumentException("Site update does not support field: guid");
}
if (site.getRole() != null)
if (site.wasSet(Site.ROLE))
{
throw new InvalidArgumentException("Site update does not support field: role");
}
if (site.getPreset() != null)
if (site.wasSet(Site.PRESET))
{
throw new InvalidArgumentException("Site update does not support field: preset");
}
// Bind valid fields to a SiteUpdate instance.
final String title = site.getTitle();
final String description = site.getDescription();
final SiteVisibility visibility = site.getVisibility();
SiteUpdate update = new SiteUpdate(title, description, visibility);
SiteUpdate siteUpdate = new SiteUpdate();
if (site.wasSet(Site.TITLE))
{
siteUpdate.setTitle(site.getTitle());
}
if (site.wasSet(Site.DESCRIPTION))
{
siteUpdate.setDescription(site.getDescription());
}
if (site.wasSet(Site.VISIBILITY))
{
siteUpdate.setVisibility(site.getVisibility());
}
return sites.updateSite(siteId, update, parameters);
return siteUpdate;
}
}