mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
review comments changes
This commit is contained in:
@@ -640,26 +640,4 @@ public abstract class BaseAPI
|
|||||||
{
|
{
|
||||||
return FILE_PLAN_PATH;
|
return FILE_PLAN_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* List of existing records management custom references.
|
|
||||||
*/
|
|
||||||
public enum CUSTOM_DEFINITIONS
|
|
||||||
{
|
|
||||||
ATTACHMENT("Attachment"),
|
|
||||||
MESSAGE("Message"),
|
|
||||||
NEXT_VERSION("Next Version"),
|
|
||||||
RENDITION("Rendition");
|
|
||||||
String definition;
|
|
||||||
|
|
||||||
private CUSTOM_DEFINITIONS(String definition)
|
|
||||||
{
|
|
||||||
this.definition = definition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDefinition()
|
|
||||||
{
|
|
||||||
return definition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Records Management Module
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* -
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
* -
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* -
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* -
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.rest.rm.community.model.custom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of existing records management custom references.
|
||||||
|
*
|
||||||
|
* @author Rodica Sutu
|
||||||
|
* @since 2.6
|
||||||
|
*/
|
||||||
|
public enum CustomDefinitions
|
||||||
|
{
|
||||||
|
ATTACHMENT("Attachment"),
|
||||||
|
MESSAGE("Message"),
|
||||||
|
NEXT_VERSION("Next Version"),
|
||||||
|
RENDITION("Rendition");
|
||||||
|
/**
|
||||||
|
* The name of custom reference.
|
||||||
|
*/
|
||||||
|
private String definition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private constructor.
|
||||||
|
*/
|
||||||
|
CustomDefinitions(String definition)
|
||||||
|
{
|
||||||
|
this.definition = definition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the custom reference.
|
||||||
|
*
|
||||||
|
* @return The value of custom reference.
|
||||||
|
*/
|
||||||
|
public String getDefinition()
|
||||||
|
{
|
||||||
|
return definition;
|
||||||
|
}
|
||||||
|
}
|
@@ -29,6 +29,7 @@ package org.alfresco.rest.v0;
|
|||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
import org.alfresco.rest.core.v0.BaseAPI;
|
import org.alfresco.rest.core.v0.BaseAPI;
|
||||||
|
import org.alfresco.rest.rm.community.model.custom.CustomDefinitions;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -55,35 +56,52 @@ public class CustomDefinitionsAPI extends BaseAPI
|
|||||||
*/
|
*/
|
||||||
private static final String CREATE_RELATIONSHIP_API_ENDPOINT = "{0}node/{1}/customreferences";
|
private static final String CREATE_RELATIONSHIP_API_ENDPOINT = "{0}node/{1}/customreferences";
|
||||||
|
|
||||||
// logger
|
/**
|
||||||
|
* logger
|
||||||
|
*/
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(CustomDefinitionsAPI.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(CustomDefinitionsAPI.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to get custom references definitions
|
* Helper method to get the reference id for a custom reference
|
||||||
*
|
*
|
||||||
* @param adminUser user with administrative privileges
|
* @param adminUser user with administrative privileges
|
||||||
* @param adminPassword password for adminUser
|
* @param adminPassword password for adminUser
|
||||||
* @param customDefinition custom reference definition name
|
* @param customDefinition custom reference definition name
|
||||||
|
* @return <code>reference id</code> if the customDefinition is found
|
||||||
|
* <code> null </code> otherwise
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
public String getCustomReferenceId(String adminUser, String adminPassword, String customDefinition)
|
||||||
public String getCustomReferencesId(String adminUser, String adminPassword, String customDefinition)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
JSONObject getResponse = doGetRequest(adminUser, adminPassword, CUSTOM_REFERENCE_API_ENDPOINT);
|
JSONObject getResponse = doGetRequest(adminUser, adminPassword, CUSTOM_REFERENCE_API_ENDPOINT);
|
||||||
if (getResponse != null)
|
if (getResponse != null)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
JSONArray customDefinitions = getResponse.getJSONObject("data").getJSONArray("customReferences");
|
JSONArray customDefinitions = getResponse.getJSONObject("data").getJSONArray("customReferences");
|
||||||
for (int i = 0; i < customDefinitions.length(); i++)
|
for (int i = 0; i < customDefinitions.length(); i++)
|
||||||
{
|
{
|
||||||
JSONObject item = customDefinitions.getJSONObject(i);
|
JSONObject item = customDefinitions.getJSONObject(i);
|
||||||
if (customDefinition.equalsIgnoreCase(item.has("source") ? item.getString("source") : null) ||
|
boolean hasSource = customDefinition.equalsIgnoreCase(
|
||||||
customDefinition.equalsIgnoreCase(item.has("target") ? item.getString("target") : null) ||
|
item.has("source") ? item.getString("source") : null
|
||||||
customDefinition.equalsIgnoreCase(item.has("label") ? item.getString("label") : null)
|
);
|
||||||
)
|
|
||||||
|
boolean hasTarget = customDefinition.equalsIgnoreCase(
|
||||||
|
item.has("target") ? item.getString("target") : null
|
||||||
|
);
|
||||||
|
|
||||||
|
boolean hasLabel = customDefinition.equalsIgnoreCase(
|
||||||
|
item.has("label") ? item.getString("label") : null
|
||||||
|
);
|
||||||
|
if ( hasSource || hasTarget || hasLabel)
|
||||||
{
|
{
|
||||||
return item.getString("refId");
|
return item.getString("refId");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -91,6 +109,7 @@ public class CustomDefinitionsAPI extends BaseAPI
|
|||||||
{
|
{
|
||||||
LOGGER.error("Unable to get the refId for the custom reference definition " + customDefinition);
|
LOGGER.error("Unable to get the refId for the custom reference definition " + customDefinition);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +119,8 @@ public class CustomDefinitionsAPI extends BaseAPI
|
|||||||
* @param adminUser user with administrative privileges
|
* @param adminUser user with administrative privileges
|
||||||
* @param adminPassword password for adminUser
|
* @param adminPassword password for adminUser
|
||||||
* @param recordNodeIdFrom node ref to set a custom reference
|
* @param recordNodeIdFrom node ref to set a custom reference
|
||||||
* @param recordNodeIdto node ref of the to record
|
* @param recordNodeIdTo node ref of the to record
|
||||||
|
* @param relationshipType relation type to be created
|
||||||
* @return <code>true</code> if creating relationship was successful,
|
* @return <code>true</code> if creating relationship was successful,
|
||||||
* <code>false</code> otherwise
|
* <code>false</code> otherwise
|
||||||
*/
|
*/
|
||||||
@@ -108,15 +128,15 @@ public class CustomDefinitionsAPI extends BaseAPI
|
|||||||
String adminUser,
|
String adminUser,
|
||||||
String adminPassword,
|
String adminPassword,
|
||||||
String recordNodeIdFrom,
|
String recordNodeIdFrom,
|
||||||
String recordNodeIdto,
|
String recordNodeIdTo,
|
||||||
CUSTOM_DEFINITIONS relationshipType)
|
CustomDefinitions relationshipType)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//create the request body
|
//create the request body
|
||||||
JSONObject requestParams = new JSONObject();
|
JSONObject requestParams = new JSONObject();
|
||||||
requestParams.put("toNode", NODE_REF_WORKSPACE_SPACES_STORE + recordNodeIdto);
|
requestParams.put("toNode", NODE_REF_WORKSPACE_SPACES_STORE + recordNodeIdTo);
|
||||||
requestParams.put("refId", getCustomReferencesId(adminUser, adminPassword, relationshipType
|
requestParams.put("refId", getCustomReferenceId(adminUser, adminPassword, relationshipType
|
||||||
.getDefinition()));
|
.getDefinition()));
|
||||||
//send the API request to create the relationship
|
//send the API request to create the relationship
|
||||||
JSONObject setRelationshipStatus = doPostRequest(adminUser, adminPassword, requestParams,
|
JSONObject setRelationshipStatus = doPostRequest(adminUser, adminPassword, requestParams,
|
||||||
|
Reference in New Issue
Block a user