@ManagedRole("administrators")
@ManagedOperation(name = OperationNames.UPDATE_RESOURCE, description = "Updates a page of the portal")
public ModelObject updatePage(@MappedPath("page-name") String name, @ManagedContext ModelObject pageModel) {
// Retrieve page from api, ensuring it exists
PageId pageId = new PageId(siteId, name);
Page page = portal.getPage(pageId);
if (page == null) {
throw notFound("Could not update page", pageId);
}
boolean changed = false;
// Update displayName
if (pageModel.has("displayName")) {
ModelString displayNameModel = get(pageModel, ModelString.class, "displayName");
page.setDisplayName(displayNameModel.getValue());
changed = true;
}
// Update description
if (pageModel.has("description")) {
ModelString descModel = get(pageModel, ModelString.class, "description");
page.setDescription(descModel.getValue());
changed = true;
}
// Update access-permissions
if (pageModel.has("access-permissions")) {
Permission permission = getPermission(pageModel, false, "access-permissions");
page.setAccessPermission(permission);
changed = true;
}
// Update edit-permissions
if (pageModel.has("edit-permissions")) {
Permission permission = getPermission(pageModel, true, "edit-permissions");
page.setEditPermission(permission);
changed = true;
}
// Save changes
if (changed) {