Create users and groups using alfresco service java api maven dependencies

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Member II

Create users and groups using alfresco service java api maven dependencies

Jump to solution

Hello, I am trying to create users and groups in my web application using the alfresco java api. The problem is that even though I've tried the code but I do not have the right maven dependencies that would import the libraries that would make the code implementable.

Here's my code, Please tell me what I'm doing wrong, thanks:

public class UserManagement {

    AlfrescoClient client = new AlfrescoClient.Builder().connect("http://localhost:8080/alfresco", "admin", "admin").build();
    PeopleAPI peopleAPI = client.getPeopleAPI();

    public UserManagement(String userName, String password) {
        if (authenticationService.authenticationExists(userName) == false)
        {
            authenticationService.createAuthentication(userName, password.toCharArray());

            Map user = new Map();
            user.put(ContentModel.PROP_USERNAME, userName);
            user.put(ContentModel.PROP_FIRSTNAME, "firstName");
            user.put(ContentModel.PROP_LASTNAME, "lastName");
            user.put(ContentModel.PROP_EMAIL, userName+"@example.com");
            user.put(ContentModel.PROP_JOBTITLE, "jobTitle");

            NodeRef person = personService.createPerson(user);

            // ...
        }
    }


if (!personService.personExists("tuser1")) {
        personService.createPerson(createDefaultProperties("tuser1", "Test", "User1", "tuser1@localhost", "password"));
        if (logger.isDebugEnabled()) logger.debug("Created tuser1 person");
    }

    if (!personService.personExists("tuser1")) {
        personService.createPerson(createDefaultProperties("tuser1", "Test", "User1", "tuser1@localhost", "password"));
        if (logger.isDebugEnabled()) logger.debug("Created tuser1 person");
    }
}

and my pom dependencies:

<dependencies>
<dependency>
    <groupId>org.apache.chemistry.opencmis</groupId>
    <artifactId>chemistry-opencmis-client-impl</artifactId>
    <version>1.1.0</version>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>org.alfresco.cmis.client</groupId>
        <artifactId>alfresco-opencmis-extension</artifactId>
        <version>0.3</version>
        <type>jar</type>
    </dependency>

    <!--<dependency>-->
        <!--<groupId>org.alfresco</groupId>-->
        <!--<artifactId>alfresco-web-client</artifactId>-->
        <!--<version>4.2.e</version>-->
    <!--</dependency>-->
    <!--<dependency>-->
        <!--<groupId>org.alfresco</groupId>-->
        <!--<artifactId>alfresco-repository</artifactId>-->
        <!--<version>4.2.e</version>-->
    <!--</dependency>-->

    <!-- https://mvnrepository.com/artifact/org.alfresco/alfresco-web-service-client -->
    <dependency>
        <groupId>org.alfresco</groupId>
        <artifactId>alfresco-web-service-client</artifactId>
        <version>5.0.a</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.alfresco/share -->
    <dependency>
        <groupId>org.alfresco</groupId>
        <artifactId>share</artifactId>
        <version>5.2.f</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.alfresco/alfresco-core -->
    <dependency>
        <groupId>org.alfresco</groupId>
        <artifactId>alfresco-core</artifactId>
        <version>7.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.alfresco.maven/alfresco-sdk-aggregator -->
    <dependency>
        <groupId>org.alfresco.maven</groupId>
        <artifactId>alfresco-sdk-aggregator</artifactId>
        <version>3.0.1</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.alfresco.client</groupId>
        <artifactId>alfresco-java-client</artifactId>
        <version>1.0.0-</version>
    </dependency>

</dependencies>

<repositories>
    <repository>
        <id>ossrh</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>mavencentral</id>
        <name>Maven Central</name>
        <url>https://repo1.maven.org/maven2/</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>osssonatype</id>
        <name>OSS Sonatype</name>
        <url>https://repo1.maven.org/maven2/</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>sonatype-snapshots</id>
        <name>Sonatype Snapshot Repository</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>maven.alfresco.com</id>
        <name>Alfresco Maven Repository</name>
        <url>http://maven.alfresco.com/nexus/content/groups/public/</url>
    </repository>
    <repository>
        <id>maven.alfresco.com</id>
        <name>Alfresco Maven Repository</name>
        <url>http://maven.alfresco.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
1 Solution

Accepted Solutions
Highlighted
Master

Re: Create users and groups using alfresco service java api maven dependencies

Jump to solution

You are not using the Java API - you are apparently using the public ReST API via the alfresco-java-client library (which is not providing access to the Java API, which might be confusing based on its name). You also have a weird combination of dependencies, including the web services client, which is no longer applicable since web services have been removed for a while now. The alfresco-opencmis-extension is also obsolete/unnecessary since CMIS 1.1 allows you to deal with aspects in a standard way.

If you want to work with the Java API, you may be better off to start with an Alfresco SDK project instead of a custom Maven setup. If you want to continue with a custom Maven setup, you should only need to depend on the alfresco-repository project and should have all dependencies for the Java API.

View solution in original post

2 Replies
Highlighted
Master

Re: Create users and groups using alfresco service java api maven dependencies

Jump to solution

You are not using the Java API - you are apparently using the public ReST API via the alfresco-java-client library (which is not providing access to the Java API, which might be confusing based on its name). You also have a weird combination of dependencies, including the web services client, which is no longer applicable since web services have been removed for a while now. The alfresco-opencmis-extension is also obsolete/unnecessary since CMIS 1.1 allows you to deal with aspects in a standard way.

If you want to work with the Java API, you may be better off to start with an Alfresco SDK project instead of a custom Maven setup. If you want to continue with a custom Maven setup, you should only need to depend on the alfresco-repository project and should have all dependencies for the Java API.

View solution in original post

Member II

Re: Create users and groups using alfresco service java api maven dependencies

Jump to solution

Sorry for the late reply but thank you so much!