Coding standards and consistency sweep across new services code in remote-api project.

Covers spacing, trailing {, @since tags, tabs and copyright headers.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30216 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2011-09-03 21:52:43 +00:00
parent 6a98ee59eb
commit 7efdd5aa2f
80 changed files with 1389 additions and 1389 deletions

View File

@@ -96,7 +96,7 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
protected String getOrNull(JSONObject json, String key)
{
if(json.containsKey(key))
if (json.containsKey(key))
{
return (String)json.get(key);
}
@@ -106,14 +106,14 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
protected List<String> getTags(JSONObject json)
{
List<String> tags = null;
if(json.containsKey("tags"))
if (json.containsKey("tags"))
{
// Is it "tags":"" or "tags":[...] ?
if(json.get("tags") instanceof String)
if (json.get("tags") instanceof String)
{
// This is normally an empty string, skip
String tagsS = (String)json.get("tags");
if("".equals(tagsS))
if ("".equals(tagsS))
{
// No tags were given
return null;
@@ -130,7 +130,7 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
{
tags = new ArrayList<String>();
JSONArray jsTags = (JSONArray)json.get("tags");
for(int i=0; i<jsTags.size(); i++)
for (int i=0; i<jsTags.size(); i++)
{
tags.add( (String)jsTags.get(i) );
}
@@ -147,7 +147,7 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
{
String pageNumberS = req.getParameter("page");
String pageSizeS = req.getParameter("pageSize");
if(pageNumberS == null || pageSizeS == null)
if (pageNumberS == null || pageSizeS == null)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters missing");
}
@@ -159,7 +159,7 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
pageNumber = Integer.parseInt(pageNumberS);
pageSize = Integer.parseInt(pageSizeS);
}
catch(NumberFormatException e)
catch (NumberFormatException e)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters invalid");
}
@@ -177,14 +177,14 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
{
// What page is this for?
String page = req.getParameter("page");
if(page == null && json != null)
if (page == null && json != null)
{
if(json.containsKey("page"))
if (json.containsKey("page"))
{
page = (String)json.get("page");
}
}
if(page == null)
if (page == null)
{
// Default
page = "links";
@@ -203,10 +203,9 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
"org.alfresco.links.link-" + event,
site.getShortName(),
LINKS_SERVICE_ACTIVITY_APP_NAME,
activityJson.toString()
);
activityJson.toString());
}
catch(Exception e)
catch (Exception e)
{
// Warn, but carry on
logger.warn("Error adding link " + event + " to activities feed", e);
@@ -229,7 +228,7 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
// FTL needs a script node of the person
String creator = link.getCreator();
Object creatorO;
if(creator == null)
if (creator == null)
{
creatorO = "";
}
@@ -241,9 +240,9 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
res.put("creator", creatorO);
// We want blank instead of null
for(String key : res.keySet())
for (String key : res.keySet())
{
if(res.get(key) == null)
if (res.get(key) == null)
{
res.put(key, "");
}
@@ -257,7 +256,7 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
Status status, Cache cache)
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
if(templateVars == null)
if (templateVars == null)
{
String error = "No parameters supplied";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
@@ -267,18 +266,18 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
// Parse the JSON, if supplied
JSONObject json = null;
String contentType = req.getContentType();
if(contentType != null && contentType.indexOf(';') != -1)
if (contentType != null && contentType.indexOf(';') != -1)
{
contentType = contentType.substring(0, contentType.indexOf(';'));
}
if(MimetypeMap.MIMETYPE_JSON.equals(contentType))
if (MimetypeMap.MIMETYPE_JSON.equals(contentType))
{
JSONParser parser = new JSONParser();
try
{
json = (JSONObject)parser.parse(req.getContent().getContent());
}
catch(IOException io)
catch (IOException io)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + io.getMessage());
}
@@ -291,22 +290,22 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
// Get the site short name. Try quite hard to do so...
String siteName = templateVars.get("site");
if(siteName == null)
if (siteName == null)
{
siteName = req.getParameter("site");
}
if(siteName == null && json != null)
if (siteName == null && json != null)
{
if(json.containsKey("siteid"))
if (json.containsKey("siteid"))
{
siteName = (String)json.get("siteid");
}
else if(json.containsKey("site"))
else if (json.containsKey("site"))
{
siteName = (String)json.get("site");
}
}
if(siteName == null)
if (siteName == null)
{
String error = "No site given";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
@@ -314,7 +313,7 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
// Grab the requested site
SiteInfo site = siteService.getSite(siteName);
if(site == null)
if (site == null)
{
String error = "Could not find site: " + siteName;
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);

View File

@@ -40,12 +40,13 @@ public class LinkDelete extends AbstractLinksWebScript
{
@Override
protected Map<String, Object> executeImpl(SiteInfo site, String linkName,
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
WebScriptRequest req, JSONObject json, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>();
// Try to find the link
LinkInfo link = linksService.getLink(site.getShortName(), linkName);
if(link == null)
if (link == null)
{
String message = "No link found with that name";
throw new WebScriptException(Status.STATUS_NOT_FOUND, message);
@@ -56,7 +57,7 @@ public class LinkDelete extends AbstractLinksWebScript
{
linksService.deleteLink(link);
}
catch(AccessDeniedException e)
catch (AccessDeniedException e)
{
String message = "You don't have permission to delete that link";
throw new WebScriptException(Status.STATUS_FORBIDDEN, message);

View File

@@ -39,12 +39,13 @@ public class LinkGet extends AbstractLinksWebScript
{
@Override
protected Map<String, Object> executeImpl(SiteInfo site, String linkName,
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
WebScriptRequest req, JSONObject json, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>();
// Try to find the link
LinkInfo link = linksService.getLink(site.getShortName(), linkName);
if(link == null)
if (link == null)
{
String message = "No link found with that name";
throw new WebScriptException(Status.STATUS_NOT_FOUND, message);

View File

@@ -40,12 +40,13 @@ public class LinkPut extends AbstractLinksWebScript
{
@Override
protected Map<String, Object> executeImpl(SiteInfo site, String linkName,
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
WebScriptRequest req, JSONObject json, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>();
// Try to find the link
LinkInfo link = linksService.getLink(site.getShortName(), linkName);
if(link == null)
if (link == null)
{
String message = "No link found with that name";
@@ -63,7 +64,7 @@ public class LinkPut extends AbstractLinksWebScript
link.setURL(getOrNull(json, "url"));
// Handle internal / not internal
if(json.containsKey("internal"))
if (json.containsKey("internal"))
{
link.setInternal(true);
}
@@ -75,7 +76,7 @@ public class LinkPut extends AbstractLinksWebScript
// Do the tags
link.getTags().clear();
List<String> tags = getTags(json);
if(tags != null && tags.size() > 0)
if (tags != null && tags.size() > 0)
{
link.getTags().addAll(tags);
}
@@ -86,7 +87,7 @@ public class LinkPut extends AbstractLinksWebScript
{
link = linksService.updateLink(link);
}
catch(AccessDeniedException e)
catch (AccessDeniedException e)
{
String message = "You don't have permission to update that link";

View File

@@ -45,20 +45,21 @@ public class LinksDeletePost extends AbstractLinksWebScript
@Override
protected Map<String, Object> executeImpl(SiteInfo site, String linkName,
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
WebScriptRequest req, JSONObject json, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>();
// Get the requested nodes from the JSON
// Silently skips over any invalid ones specified
List<LinkInfo> links = new ArrayList<LinkInfo>();
if(json.containsKey("items"))
if (json.containsKey("items"))
{
JSONArray items = (JSONArray)json.get("items");
for(int i=0; i<items.size(); i++)
for (int i=0; i<items.size(); i++)
{
String name = (String)items.get(i);
LinkInfo link = linksService.getLink(site.getShortName(), name);
if(link != null)
if (link != null)
{
links.add(link);
}
@@ -67,7 +68,7 @@ public class LinksDeletePost extends AbstractLinksWebScript
// Check we got at least one link, and bail if not
if(links.size() == 0)
if (links.size() == 0)
{
String message = "No valid link names supplied";
@@ -79,14 +80,14 @@ public class LinksDeletePost extends AbstractLinksWebScript
// Delete each one in turn
for(LinkInfo link : links)
for (LinkInfo link : links)
{
// Do the delete
try
{
linksService.deleteLink(link);
}
catch(AccessDeniedException e)
catch (AccessDeniedException e)
{
String message = "You don't have permission to delete the link with name '" + link.getSystemName() + "'";

View File

@@ -49,14 +49,15 @@ public class LinksListGet extends AbstractLinksWebScript
@Override
protected Map<String, Object> executeImpl(SiteInfo site, String linkName,
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
WebScriptRequest req, JSONObject json, Status status, Cache cache)
{
// Decide on what kind of request they wanted
String filter = req.getParameter("filter");
// Tagging?
boolean tagFiltering = true;
String tag = req.getParameter("tag");
if(tag == null || tag.length() == 0)
if (tag == null || tag.length() == 0)
{
tagFiltering = false;
}
@@ -64,7 +65,7 @@ public class LinksListGet extends AbstractLinksWebScript
// User?
boolean userFiltering = false;
String user = null;
if("user".equals(filter))
if ("user".equals(filter))
{
userFiltering = true;
user = AuthenticationUtil.getFullyAuthenticatedUser();
@@ -74,7 +75,7 @@ public class LinksListGet extends AbstractLinksWebScript
boolean dateFiltering = false;
Date from = null;
Date to = null;
if("recent".equals(filter))
if ("recent".equals(filter))
{
dateFiltering = true;
Date now = new Date();
@@ -86,17 +87,17 @@ public class LinksListGet extends AbstractLinksWebScript
// Get the links for the list
PagingRequest paging = buildPagingRequest(req);
PagingResults<LinkInfo> links;
if(tagFiltering)
if (tagFiltering)
{
links = linksService.findLinks(site.getShortName(), user, from, to, tag, paging);
}
else
{
if(userFiltering)
if (userFiltering)
{
links = linksService.listLinks(site.getShortName(), user, paging);
}
else if(dateFiltering)
else if (dateFiltering)
{
links = linksService.listLinks(site.getShortName(), from, to, paging);
}
@@ -121,7 +122,7 @@ public class LinksListGet extends AbstractLinksWebScript
data.put("itemCount", items.size());
int total = items.size();
if(links.getTotalResultCount() != null && links.getTotalResultCount().getFirst() != null)
if (links.getTotalResultCount() != null && links.getTotalResultCount().getFirst() != null)
{
total = links.getTotalResultCount().getFirst();
}
@@ -129,7 +130,7 @@ public class LinksListGet extends AbstractLinksWebScript
// We need the container node for permissions checking
NodeRef container;
if(links.getPage().size() > 0)
if (links.getPage().size() > 0)
{
container = links.getPage().get(0).getContainerNodeRef();
}
@@ -137,10 +138,9 @@ public class LinksListGet extends AbstractLinksWebScript
{
// Find the container (if it's been created yet)
container = siteService.getContainer(
site.getShortName(), LinksServiceImpl.LINKS_COMPONENT
);
site.getShortName(), LinksServiceImpl.LINKS_COMPONENT);
if(container == null)
if (container == null)
{
// Brand new site, no write operations on links have happened
// Fudge it for now with the site itself, the first write call

View File

@@ -40,7 +40,8 @@ public class LinksPost extends AbstractLinksWebScript
{
@Override
protected Map<String, Object> executeImpl(SiteInfo site, String linkName,
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
WebScriptRequest req, JSONObject json, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>();
// Get the new link details from the JSON
@@ -68,7 +69,7 @@ public class LinksPost extends AbstractLinksWebScript
{
link = linksService.createLink(site.getShortName(), title, description, url, internal);
}
catch(AccessDeniedException e)
catch (AccessDeniedException e)
{
String message = "You don't have permission to create a link";
@@ -79,7 +80,7 @@ public class LinksPost extends AbstractLinksWebScript
}
// Set the tags if required
if(tags != null && tags.size() > 0)
if (tags != null && tags.size() > 0)
{
link.getTags().addAll(tags);
linksService.updateLink(link);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -55,12 +55,13 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
* Unit Test to test the Links Web Script API
*
* @author Nick Burch
* @since 4.0
*/
public class LinksRestApiTest extends BaseWebScriptTest
{
@SuppressWarnings("unused")
@SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(LinksRestApiTest.class);
private MutableAuthenticationService authenticationService;
private AuthenticationComponent authenticationComponent;
private TransactionService transactionService;
@@ -119,7 +120,7 @@ public class LinksRestApiTest extends BaseWebScriptTest
}
// Ensure the links container is there
if(!siteService.hasContainer(SITE_SHORT_NAME_LINKS, "links"))
if (!siteService.hasContainer(SITE_SHORT_NAME_LINKS, "links"))
{
siteService.createContainer(SITE_SHORT_NAME_LINKS, "links", null, null);
}
@@ -151,7 +152,7 @@ public class LinksRestApiTest extends BaseWebScriptTest
}
personService.deletePerson(USER_TWO);
if(this.authenticationService.authenticationExists(USER_TWO))
if (this.authenticationService.authenticationExists(USER_TWO))
{
this.authenticationService.deleteAuthentication(USER_TWO);
}
@@ -188,14 +189,14 @@ public class LinksRestApiTest extends BaseWebScriptTest
private JSONObject getLinks(String filter, String username) throws Exception
{
String origUser = this.authenticationComponent.getCurrentUserName();
if(username != null)
if (username != null)
{
this.authenticationComponent.setCurrentUser(username);
filter = "user";
}
String url = URL_LINKS_LIST;
if(filter == null)
if (filter == null)
{
filter = "all";
}
@@ -205,7 +206,7 @@ public class LinksRestApiTest extends BaseWebScriptTest
Response response = sendRequest(new GetRequest(url), 200);
JSONObject result = new JSONObject(response.getContentAsString());
if(username != null)
if (username != null)
{
this.authenticationComponent.setCurrentUser(origUser);
}
@@ -219,7 +220,7 @@ public class LinksRestApiTest extends BaseWebScriptTest
if (expectedStatus == Status.STATUS_OK)
{
JSONObject result = new JSONObject(response.getContentAsString());
if(result.has("item"))
if (result.has("item"))
{
return result.getJSONObject("item");
}
@@ -235,8 +236,7 @@ public class LinksRestApiTest extends BaseWebScriptTest
* Creates a single link based on the supplied details
*/
private JSONObject createLink(String title, String description, String url,
boolean internal, int expectedStatus)
throws Exception
boolean internal, int expectedStatus) throws Exception
{
JSONObject json = new JSONObject();
json.put("site", SITE_SHORT_NAME_LINKS);
@@ -244,7 +244,7 @@ public class LinksRestApiTest extends BaseWebScriptTest
json.put("description", description);
json.put("url", url);
json.put("tags", "");
if(internal)
if (internal)
{
json.put("internal", "true");
}
@@ -254,7 +254,7 @@ public class LinksRestApiTest extends BaseWebScriptTest
if (expectedStatus == Status.STATUS_OK)
{
JSONObject result = new JSONObject(response.getContentAsString());
if(result.has("link"))
if (result.has("link"))
{
return result.getJSONObject("link");
}
@@ -285,7 +285,7 @@ public class LinksRestApiTest extends BaseWebScriptTest
if (expectedStatus == Status.STATUS_OK)
{
JSONObject result = new JSONObject(response.getContentAsString());
if(result.has("links"))
if (result.has("links"))
{
return result.getJSONObject("links");
}
@@ -320,7 +320,7 @@ public class LinksRestApiTest extends BaseWebScriptTest
private JSONObject deleteLinks(List<String> names, int expectedStatus) throws Exception
{
JSONArray items = new JSONArray();
for(String name : names)
for (String name : names)
{
items.put(name);
}
@@ -370,7 +370,7 @@ public class LinksRestApiTest extends BaseWebScriptTest
*/
private String getNameFromLink(JSONObject link) throws Exception
{
if(! link.has("name"))
if (! link.has("name"))
{
throw new IllegalArgumentException("No name in " + link.toString());
}
@@ -442,29 +442,22 @@ public class LinksRestApiTest extends BaseWebScriptTest
// Check the comments url
assertEquals(
"/node/workspace/" + nodeRef.getStoreRef().getIdentifier() + "/" + nodeRef.getId() + "/comments",
link.getString("commentsUrl")
);
link.getString("commentsUrl"));
// Check the created date
assertEquals(
ISO8601DateFormat.format((Date)nodeService.getProperty(nodeRef, ContentModel.PROP_CREATED)),
link.getJSONObject("createdOnDate").getString("iso8601")
);
link.getJSONObject("createdOnDate").getString("iso8601"));
// Edit
// We should get a simple message
link = updateLink(name, LINK_TITLE_ONE, "More Thing 1", LINK_URL_ONE, true, Status.STATUS_OK);
assertEquals(
"Incorrect JSON: " + link.toString(),
true, link.has("message")
);
true, link.has("message"));
assertEquals(
"Incorrect JSON: " + link.toString(),
true, link.getString("message").contains("updated")
);
true, link.getString("message").contains("updated"));
// Fetch
@@ -508,13 +501,12 @@ public class LinksRestApiTest extends BaseWebScriptTest
link = deleteLinks(Arrays.asList(new String[]{name}), Status.STATUS_OK);
assertEquals(
"Incorrect JSON: " + link.toString(),
true, link.has("message")
);
true, link.has("message"));
assertEquals(
"Incorrect JSON: " + link.toString(),
true, link.getString("message").contains("deleted")
);
true, link.getString("message").contains("deleted"));
// Fetch, will have gone
link = getLink(name, Status.STATUS_NOT_FOUND);