Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: added QueriesV1 api #1

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
target/
bin/
.project
.classpath
.classpath
.idea
*.iml
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ This library aims to provide some common interfaces / classes that could be used

```java
ResteasyJackson2Provider resteasyJacksonProvider = new ResteasyJackson2Provider();

SimpleModule module = new SimpleModule();
module.setDeserializerModifier(new RestAPIBeanDeserializerModifier());

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
mapper.setSerializationInclusion(Include.NON_EMPTY);
resteasyJacksonProvider.setMapper(mapper);

LocalResteasyProviderFactory resteasyProviderFactory = new LocalResteasyProviderFactory(new ResteasyProviderFactory());
resteasyProviderFactory.register(resteasyJacksonProvider);
resteasyProviderFactory.register(new MultiValuedParamConverterProvider());
RegisterBuiltin.register(resteasyProviderFactory);

String alfrescoBaseUrl = "https://example.com/alfresco";
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<groupId>de.acosix.alfresco.rest.client</groupId>
<artifactId>de.acosix.alfresco.rest.client</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
<packaging>jar</packaging>

<name>Acosix Alfresco v1 ReST API Client</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ public static enum IncludeOption
/**
* Include {@link NodeResponseEntity#getPermissions() permissions}
*/
PERMISSIONS("permissions");
PERMISSIONS("permissions"),

PROPERTIES("properties");

private final String simpleName;

Expand Down
89 changes: 89 additions & 0 deletions src/main/java/de/acosix/alfresco/rest/client/api/QueriesV1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2019 Acosix GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.acosix.alfresco.rest.client.api;

import de.acosix.alfresco.rest.client.model.common.MultiValuedParam;
import de.acosix.alfresco.rest.client.model.nodes.ChildNodeResponseEntity;
import de.acosix.alfresco.rest.client.model.nodes.NodeResponseEntity;
import de.acosix.alfresco.rest.client.model.nodes.PaginatedNodeChildrenList;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import java.util.List;

/**
* Instances of this API provide operations to work with queries: nodes.
*
* @author Kanagat Nugusbayev
*/
@Path("/api/-default-/public/alfresco/versions/1/queries")
public interface QueriesV1 {

/**
* Note: this endpoint is available in Alfresco 5.2 and newer versions.
* <p>
* Gets a list of nodes that match the given search criteria.
* <p>
* The search term is used to look for nodes that match against name, title, description, full text content or tags.
* <p>
* The search term:
* <p>
* - must contain a minimum of 3 alphanumeric characters
* - allows "quoted term"
* - can optionally use '*' for wildcard matching
* By default, file and folder types will be searched unless a specific type is provided as a query parameter.
* <p>
* By default, the search will be across the repository unless a specific root node id is provided to start the search from.
* <p>
* You can sort the result list using the orderBy parameter. You can specify one or more of the following fields in the orderBy parameter:
* <p>
* - name
* - modifiedAt
* - createdAt
*
* @param term - The term to search for.
* @param rootNodeId - The id of the node to start the search from. Supports the aliases -my-, -root- and -shared-.
* @param skipCount - The number of entities that exist in the collection before those included in this list. If not supplied then the default value is 0.
* @param maxItems - The maximum number of items to return in the list. If not supplied then the default value is 100.
* @param nodeType - Restrict the returned results to only those of the given node type and its sub-types
* @param include - Returns additional information about the node. The following optional fields can be requested:
* allowableOperations
* aspectNames
* isLink
* isFavorite
* isLocked
* path
* properties
* @param orderBy - A string to control the order of the entities returned in a list. To sort the entities in a specific order,
* you can use the ASC and DESC keywords for any field.
* @param fields - A list of field names.
* @return the retrieved node in the detail requested
*/
@GET
@Path("/nodes")
@Produces("application/json")
PaginatedNodeChildrenList queryNodes(@QueryParam("term") String term,
@QueryParam("rootNodeId") String rootNodeId,
@QueryParam("skipCount") Integer skipCount,
@QueryParam("maxItems") Integer maxItems,
@QueryParam("nodeType") String nodeType,
@QueryParam("include") MultiValuedParam<String> include,
@QueryParam("orderBy") MultiValuedParam<String> orderBy,
@QueryParam("fields") MultiValuedParam<String> fields);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright 2019 Acosix GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.acosix.alfresco.rest.client.api.integration;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import de.acosix.alfresco.rest.client.api.AuthenticationV1;
import de.acosix.alfresco.rest.client.api.NodesV1;
import de.acosix.alfresco.rest.client.api.QueriesV1;
import de.acosix.alfresco.rest.client.jackson.RestAPIBeanDeserializerModifier;
import de.acosix.alfresco.rest.client.model.authentication.TicketEntity;
import de.acosix.alfresco.rest.client.model.authentication.TicketRequest;
import de.acosix.alfresco.rest.client.model.common.MultiValuedParam;
import de.acosix.alfresco.rest.client.model.nodes.NodeCreationRequestEntity;
import de.acosix.alfresco.rest.client.model.nodes.NodeResponseEntity;
import de.acosix.alfresco.rest.client.model.nodes.PaginatedNodeChildrenList;
import de.acosix.alfresco.rest.client.resteasy.MultiValuedParamConverterProvider;
import org.apache.commons.codec.binary.Base64;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory;
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
import org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.UriBuilder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

/**
* @author Nugusbayev Kanagat
*/
public class QueriesV1Tests {

private ResteasyWebTarget target;

private QueriesV1 queriesAPI;

private NodesV1 nodesAPI;

@Before
public void setup() {
final SimpleModule module = new SimpleModule();
module.setDeserializerModifier(new RestAPIBeanDeserializerModifier());

final ResteasyJackson2Provider resteasyJacksonProvider = new ResteasyJackson2Provider();
final ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_EMPTY);
mapper.registerModule(module);
resteasyJacksonProvider.setMapper(mapper);

final LocalResteasyProviderFactory resteasyProviderFactory = new LocalResteasyProviderFactory(new ResteasyProviderFactory());
resteasyProviderFactory.register(resteasyJacksonProvider);
resteasyProviderFactory.register(new MultiValuedParamConverterProvider());
// will cause a warning regarding Jackson provider which is already registered
RegisterBuiltin.register(resteasyProviderFactory);

final ResteasyClient client = new ResteasyClientBuilder().providerFactory(resteasyProviderFactory).build();
this.target = client.target(UriBuilder.fromPath("http://localhost:8082/alfresco"));

final TicketRequest rq = new TicketRequest();
rq.setUserId("admin");
rq.setPassword("admin");

final AuthenticationV1 authenticationAPI = this.target.proxy(AuthenticationV1.class);
final TicketEntity ticket = authenticationAPI.createTicket(rq);

final ClientRequestFilter rqAuthFilter = (requestContext) -> {
final String base64Token = Base64.encodeBase64String(ticket.getId().getBytes(StandardCharsets.UTF_8));
requestContext.getHeaders().add("Authorization", "Basic " + base64Token);
};
this.target.register(rqAuthFilter);

this.queriesAPI = this.target.proxy(QueriesV1.class);
this.nodesAPI = this.target.proxy(NodesV1.class);
}

@Test
public void createNewNodeAndFindItViaQueries() throws InterruptedException {
final NodeCreationRequestEntity nodeToCreate = new NodeCreationRequestEntity();
nodeToCreate.setNodeType("cm:folder");
final String name = "foobar";
nodeToCreate.setName(name);
final Map<String, Object> properties = new HashMap<>();
properties.put("cm:title", "foo bar");
nodeToCreate.setProperties(properties);

final NodeResponseEntity createdNode = this.nodesAPI.createNode("-root-", nodeToCreate);

PaginatedNodeChildrenList paginatedNodeChildrenList = this.queriesAPI.queryNodes("foobar", "-root-", 0, 10, "cm:folder", new MultiValuedParam<String>("properties"), null, new MultiValuedParam<String>("id", "name", "parentId"));

Assert.assertNotNull(paginatedNodeChildrenList);

System.out.println(paginatedNodeChildrenList.getEntries());
System.out.println(paginatedNodeChildrenList.getPagination());
System.out.println(paginatedNodeChildrenList.getSource());
}

}