mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
show model in the aspect/type api (#285)
This commit is contained in:
@@ -26,6 +26,9 @@
|
||||
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.NamespaceDefinition;
|
||||
import org.alfresco.service.cmr.i18n.MessageLookup;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -38,6 +41,7 @@ public abstract class AbstractClass extends ClassDefinition implements Comparabl
|
||||
String title;
|
||||
String description;
|
||||
String parentId;
|
||||
Model model;
|
||||
|
||||
public String getId()
|
||||
{
|
||||
@@ -79,6 +83,16 @@ public abstract class AbstractClass extends ClassDefinition implements Comparabl
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public Model getModel()
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(Model model)
|
||||
{
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
<T> List<T> setList(List<T> sourceList)
|
||||
{
|
||||
if (sourceList == null)
|
||||
@@ -97,6 +111,23 @@ public abstract class AbstractClass extends ClassDefinition implements Comparabl
|
||||
return null;
|
||||
}
|
||||
|
||||
Model getModelInfo(org.alfresco.service.cmr.dictionary.ClassDefinition classDefinition, MessageLookup messageLookup)
|
||||
{
|
||||
final ModelDefinition modelDefinition = classDefinition.getModel();
|
||||
final String prefix = classDefinition.getName().toPrefixString().split(":")[0];
|
||||
|
||||
final NamespaceDefinition namespaceDefinition = modelDefinition.getNamespaces().stream()
|
||||
.filter(definition -> definition.getPrefix().equals(prefix))
|
||||
.findFirst()
|
||||
.get();
|
||||
|
||||
final String modelId = modelDefinition.getName().toPrefixString();
|
||||
final String author = modelDefinition.getAuthor();
|
||||
final String description = modelDefinition.getDescription(messageLookup);
|
||||
|
||||
return new Model(modelId, author, description, namespaceDefinition.getUri(), namespaceDefinition.getPrefix());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
|
@@ -44,6 +44,7 @@ public class Aspect extends AbstractClass
|
||||
this.description = aspectDefinition.getDescription(messageLookup);
|
||||
this.parentId = getParentNameAsString(aspectDefinition.getParentName());
|
||||
this.properties = setList(properties);
|
||||
this.model = getModelInfo(aspectDefinition, messageLookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
105
remote-api/src/main/java/org/alfresco/rest/api/model/Model.java
Normal file
105
remote-api/src/main/java/org/alfresco/rest/api/model/Model.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2021 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.api.model;
|
||||
|
||||
public class Model implements Comparable<Model>
|
||||
{
|
||||
private String id;
|
||||
private String author;
|
||||
private String description;
|
||||
private String namespaceUri;
|
||||
private String namespacePrefix;
|
||||
|
||||
public Model()
|
||||
{
|
||||
}
|
||||
|
||||
public Model(String name, String author, String description, String namespaceUri, String namespacePrefix)
|
||||
{
|
||||
this.id = name;
|
||||
this.author = author;
|
||||
this.description = description;
|
||||
this.namespaceUri = namespaceUri;
|
||||
this.namespacePrefix = namespacePrefix;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAuthor()
|
||||
{
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author)
|
||||
{
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getNamespaceUri()
|
||||
{
|
||||
return namespaceUri;
|
||||
}
|
||||
|
||||
public void setNamespaceUri(String namespaceUri)
|
||||
{
|
||||
this.namespaceUri = namespaceUri;
|
||||
}
|
||||
|
||||
public String getNamespacePrefix()
|
||||
{
|
||||
return namespacePrefix;
|
||||
}
|
||||
|
||||
public void setNamespacePrefix(String namespacePrefix)
|
||||
{
|
||||
this.namespacePrefix = namespacePrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Model model)
|
||||
{
|
||||
return this.id.compareTo(model.getId());
|
||||
}
|
||||
}
|
@@ -44,6 +44,7 @@ public class Type extends AbstractClass
|
||||
this.description = typeDefinition.getDescription(messageLookup);
|
||||
this.parentId = getParentNameAsString(typeDefinition.getParentName());
|
||||
this.properties = setList(properties);
|
||||
this.model = getModelInfo(typeDefinition, messageLookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2021 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.api.tests;
|
||||
|
||||
import org.alfresco.rest.api.model.Model;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BaseModelApiTest extends AbstractBaseApiTest
|
||||
{
|
||||
PublicApiClient.ListResponse<org.alfresco.rest.api.tests.client.data.Aspect> aspects = null;
|
||||
org.alfresco.rest.api.tests.client.data.Aspect aspect = null, childAspect = null, smartFilter = null, rescanAspect = null;
|
||||
|
||||
|
||||
PublicApiClient.ListResponse<org.alfresco.rest.api.tests.client.data.Type> types = null;
|
||||
org.alfresco.rest.api.tests.client.data.Type type = null, whitePaperType = null, docType = null;
|
||||
|
||||
|
||||
PublicApiClient.Paging paging = getPaging(0, 10);
|
||||
Map<String, String> otherParams = new HashMap<>();
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
super.setup();
|
||||
|
||||
Model myCompanyModel = new Model();
|
||||
myCompanyModel.setAuthor("Administrator");
|
||||
myCompanyModel.setId("mycompany:model");
|
||||
myCompanyModel.setNamespaceUri("http://www.mycompany.com/model/finance/1.0");
|
||||
myCompanyModel.setNamespacePrefix("mycompany");
|
||||
|
||||
Model scanModel = new Model();
|
||||
scanModel.setAuthor("Administrator");
|
||||
scanModel.setId("test:scan");
|
||||
scanModel.setNamespaceUri("http://www.test.com/model/account/1.0");
|
||||
scanModel.setNamespacePrefix("test");
|
||||
|
||||
childAspect = new org.alfresco.rest.api.tests.client.data.Aspect();
|
||||
childAspect.setId("mycompany:childAspect");
|
||||
childAspect.setTitle("Child Aspect");
|
||||
childAspect.setDescription("Child Aspect Description");
|
||||
childAspect.setParentId("smf:smartFolder");
|
||||
childAspect.setModel(myCompanyModel);
|
||||
|
||||
rescanAspect = new org.alfresco.rest.api.tests.client.data.Aspect();
|
||||
rescanAspect.setId("test:rescan");
|
||||
rescanAspect.setTitle("rescan");
|
||||
rescanAspect.setDescription("Doc that required to scan ");
|
||||
rescanAspect.setModel(scanModel);
|
||||
|
||||
smartFilter = new org.alfresco.rest.api.tests.client.data.Aspect();
|
||||
smartFilter.setId("test:smartFilter");
|
||||
smartFilter.setTitle("Smart filter");
|
||||
smartFilter.setDescription("Smart Filter");
|
||||
smartFilter.setParentId("cm:auditable");
|
||||
smartFilter.setModel(scanModel);
|
||||
|
||||
whitePaperType = new org.alfresco.rest.api.tests.client.data.Type();
|
||||
whitePaperType.setId("mycompany:whitepaper");
|
||||
whitePaperType.setTitle("whitepaper");
|
||||
whitePaperType.setDescription("Whitepaper");
|
||||
whitePaperType.setParentId("mycompany:doc");
|
||||
whitePaperType.setModel(myCompanyModel);
|
||||
|
||||
docType = new org.alfresco.rest.api.tests.client.data.Type();
|
||||
docType.setId("mycompany:doc");
|
||||
docType.setTitle("doc");
|
||||
docType.setDescription("Doc");
|
||||
docType.setParentId("cm:content");
|
||||
docType.setModel(myCompanyModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScope()
|
||||
{
|
||||
return "public";
|
||||
}
|
||||
}
|
@@ -27,53 +27,19 @@
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiException;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
||||
public class TestAspects extends AbstractBaseApiTest
|
||||
public class TestAspects extends BaseModelApiTest
|
||||
{
|
||||
|
||||
private PublicApiClient.Paging paging = getPaging(0, 10);
|
||||
PublicApiClient.ListResponse<org.alfresco.rest.api.tests.client.data.Aspect> aspects = null;
|
||||
org.alfresco.rest.api.tests.client.data.Aspect aspect, childAspect = null, smartFilter = null, rescanAspect = null;
|
||||
Map<String, String> otherParams = new HashMap<>();
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
super.setup();
|
||||
|
||||
childAspect = new org.alfresco.rest.api.tests.client.data.Aspect();
|
||||
childAspect.setId("mycompany:childAspect");
|
||||
childAspect.setTitle("Child Aspect");
|
||||
childAspect.setDescription("Child Aspect Description");
|
||||
childAspect.setParentId("smf:smartFolder");
|
||||
|
||||
rescanAspect = new org.alfresco.rest.api.tests.client.data.Aspect();
|
||||
rescanAspect.setId("test:rescan");
|
||||
rescanAspect.setTitle("rescan");
|
||||
rescanAspect.setDescription("Doc that required to scan ");
|
||||
|
||||
smartFilter = new org.alfresco.rest.api.tests.client.data.Aspect();
|
||||
smartFilter.setId("test:smartFilter");
|
||||
smartFilter.setTitle("Smart filter");
|
||||
smartFilter.setDescription("Smart Filter");
|
||||
smartFilter.setParentId("cm:auditable");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAspects() throws PublicApiException
|
||||
{
|
||||
@@ -234,11 +200,4 @@ public class TestAspects extends AbstractBaseApiTest
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getScope()
|
||||
{
|
||||
return "public";
|
||||
}
|
||||
}
|
||||
|
@@ -27,47 +27,18 @@
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiException;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
||||
public class TestTypes extends AbstractBaseApiTest
|
||||
public class TestTypes extends BaseModelApiTest
|
||||
{
|
||||
|
||||
private PublicApiClient.Paging paging = getPaging(0, 10);
|
||||
PublicApiClient.ListResponse<org.alfresco.rest.api.tests.client.data.Type> types = null;
|
||||
org.alfresco.rest.api.tests.client.data.Type type = null, whitePaperType = null, docType = null;
|
||||
Map<String, String> otherParams = new HashMap<>();
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
super.setup();
|
||||
whitePaperType = new org.alfresco.rest.api.tests.client.data.Type();
|
||||
whitePaperType.setId("mycompany:whitepaper");
|
||||
whitePaperType.setTitle("whitepaper");
|
||||
whitePaperType.setDescription("Whitepaper");
|
||||
whitePaperType.setParentId("mycompany:doc");
|
||||
|
||||
docType = new org.alfresco.rest.api.tests.client.data.Type();
|
||||
docType.setId("mycompany:doc");
|
||||
docType.setTitle("doc");
|
||||
docType.setDescription("Doc");
|
||||
docType.setParentId("cm:content");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllTypes() throws PublicApiException
|
||||
{
|
||||
@@ -181,7 +152,7 @@ public class TestTypes extends AbstractBaseApiTest
|
||||
|
||||
testListTypeException("(modelIds in ('mycompany:model','unknown:model'))");
|
||||
testListTypeException("(modelIds in ('unknown:model','unknown1:another'))");
|
||||
testListTypeException("(modelIds=' , , ')");
|
||||
testListTypeException("(modelIds in (' ', '')");
|
||||
testListTypeException("(parentIds in ('cm:content','unknown:type')");
|
||||
testListTypeException("(parentIds in ('unknown:type','cm:content'))");
|
||||
testListTypeException("(parentIds in ('unknown:type','unknown:types'))");
|
||||
@@ -228,11 +199,4 @@ public class TestTypes extends AbstractBaseApiTest
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getScope()
|
||||
{
|
||||
return "public";
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.tests.client.data;
|
||||
|
||||
import org.alfresco.rest.api.model.Model;
|
||||
import org.alfresco.rest.api.model.PropertyDefinition;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.json.simple.JSONArray;
|
||||
@@ -51,6 +52,14 @@ public class Aspect extends org.alfresco.rest.api.model.Aspect implements Serial
|
||||
AssertUtil.assertEquals("title", getTitle(), other.getTitle());
|
||||
AssertUtil.assertEquals("description", getDescription(), other.getDescription());
|
||||
AssertUtil.assertEquals("parenId", getParentId(), other.getParentId());
|
||||
|
||||
if (getModel() != null && other.getModel() != null)
|
||||
{
|
||||
AssertUtil.assertEquals("modelId", getModel().getId(), other.getModel().getId());
|
||||
AssertUtil.assertEquals("author", getModel().getAuthor(), other.getModel().getAuthor());
|
||||
AssertUtil.assertEquals("namespaceUri", getModel().getNamespaceUri(), other.getModel().getNamespaceUri());
|
||||
AssertUtil.assertEquals("namespacePrefix", getModel().getNamespacePrefix(), other.getModel().getNamespacePrefix());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -79,6 +88,11 @@ public class Aspect extends org.alfresco.rest.api.model.Aspect implements Serial
|
||||
jsonObject.put("properties", getProperties());
|
||||
}
|
||||
|
||||
if (getModel() != null)
|
||||
{
|
||||
jsonObject.put("model", getModel());
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@@ -91,12 +105,21 @@ public class Aspect extends org.alfresco.rest.api.model.Aspect implements Serial
|
||||
String parentId = (String) jsonObject.get("parentId");
|
||||
List<PropertyDefinition> properties = (List<PropertyDefinition>) jsonObject.get("properties");
|
||||
|
||||
JSONObject jsonModel = (JSONObject) jsonObject.get("model");
|
||||
Model model = new Model();
|
||||
model.setId((String) jsonModel.get("id"));
|
||||
model.setDescription((String) jsonModel.get("description"));
|
||||
model.setNamespacePrefix((String) jsonModel.get("namespacePrefix"));
|
||||
model.setNamespaceUri((String) jsonModel.get("namespaceUri"));
|
||||
model.setAuthor((String) jsonModel.get("author"));
|
||||
|
||||
Aspect action = new Aspect();
|
||||
action.setId(id);
|
||||
action.setTitle(title);
|
||||
action.setDescription(description);
|
||||
action.setParentId(parentId);
|
||||
action.setProperties(properties);
|
||||
action.setModel(model);
|
||||
|
||||
return action;
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.tests.client.data;
|
||||
|
||||
import org.alfresco.rest.api.model.Model;
|
||||
import org.alfresco.rest.api.model.PropertyDefinition;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.json.simple.JSONArray;
|
||||
@@ -51,6 +52,14 @@ public class Type extends org.alfresco.rest.api.model.Type implements Serializab
|
||||
AssertUtil.assertEquals("title", getTitle(), other.getTitle());
|
||||
AssertUtil.assertEquals("description", getDescription(), other.getDescription());
|
||||
AssertUtil.assertEquals("parenId", getParentId(), other.getParentId());
|
||||
|
||||
if (getModel() != null && other.getModel() != null)
|
||||
{
|
||||
AssertUtil.assertEquals("modelId", getModel().getId(), other.getModel().getId());
|
||||
AssertUtil.assertEquals("author", getModel().getAuthor(), other.getModel().getAuthor());
|
||||
AssertUtil.assertEquals("namespaceUri", getModel().getNamespaceUri(), other.getModel().getNamespaceUri());
|
||||
AssertUtil.assertEquals("namespacePrefix", getModel().getNamespacePrefix(), other.getModel().getNamespacePrefix());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -79,6 +88,11 @@ public class Type extends org.alfresco.rest.api.model.Type implements Serializab
|
||||
jsonObject.put("properties", getProperties());
|
||||
}
|
||||
|
||||
if (getModel() != null)
|
||||
{
|
||||
jsonObject.put("model", getModel());
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@@ -91,12 +105,21 @@ public class Type extends org.alfresco.rest.api.model.Type implements Serializab
|
||||
String parentId = (String) jsonObject.get("parentId");
|
||||
List<PropertyDefinition> properties = (List<PropertyDefinition>) jsonObject.get("properties");
|
||||
|
||||
JSONObject jsonModel = (JSONObject) jsonObject.get("model");
|
||||
Model model = new Model();
|
||||
model.setId((String) jsonModel.get("id"));
|
||||
model.setDescription((String) jsonModel.get("description"));
|
||||
model.setNamespacePrefix((String) jsonModel.get("namespacePrefix"));
|
||||
model.setNamespaceUri((String) jsonModel.get("namespaceUri"));
|
||||
model.setAuthor((String) jsonModel.get("author"));
|
||||
|
||||
Type action = new Type();
|
||||
action.setId(id);
|
||||
action.setTitle(title);
|
||||
action.setDescription(description);
|
||||
action.setParentId(parentId);
|
||||
action.setProperties(properties);
|
||||
action.setModel(model);
|
||||
|
||||
return action;
|
||||
}
|
||||
|
Reference in New Issue
Block a user