Expand my Community achievements bar.

[AEM 6.3] Projects - Unable to update team members for project

Avatar

Level 3

Hi All,

I get this below error while updating the project team using Projects API in AEM 6.3. I checked that our custom bundle is using 0.3.0 version of Projects API - com.adobe.cq.projects.api

com.adobe.cq.projects.api.ProjectException: Unable to update team members for project /content/projects/sampleproject

at com.adobe.cq.projects.impl.ProjectImpl.updateMembers(ProjectImpl.java:116)

at com.hero.belkin.dam.core.workflow.AbstractUpdateProjectTeamStep.execute(AbstractUpdateProjectTeamStep.java:65)

at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:193)

at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:258)

at org.apache.sling.event.impl.jobs.JobConsumerManager$JobConsumerWrapper.process(JobConsumerManager.java:500)

at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.startJob(JobQueueImpl.java:291)

at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.access$100(JobQueueImpl.java:58)

at org.apache.sling.event.impl.jobs.queues.JobQueueImpl$1.run(JobQueueImpl.java:227)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

As suggested in one of the discussion, I have added the user with owner role before adding users with other project role. Below is the code used:

session.refresh(true);

        List<String> userIds = new ArrayList<String>();

        userIds.add("user1");

        userIds.add("user1");

        List<String> roleIds = new ArrayList<String>();

        roleIds.add("owner");

        roleIds.add("observer");

      

        if(project != null) {

        project.updateMembers(userIds, roleIds);

        }

      

        session.save();

Note: user1 is a valid user ID.

Does anyone know why I am seeing this issue?

Appreciate your help!

Thanks,

Ramya

2 Replies

Avatar

Level 10

Can you point the community to the online resource you are using to perform this task. See if this can be reproduced.

Avatar

Level 3

Hi smacdonald2008

I am using the below code in my custom workflow process step. This workflow gets triggered once any project is created.

Users projectuser1, projectuser2 are valid Project users(users added to projects-administrators group) used for testing. 'ownerid', 'observerid' are the roleid's for owner and observer roles for this project template.

Are you aware if there are any privileges missing in the workflowSession to update the Project team? Do you know why there is an issue at

com.adobe.cq.projects.api.ProjectException: Unable to update team members for project /content/projects/sampleproject

at com.adobe.cq.projects.impl.ProjectImpl.updateMembers(ProjectImpl.java:116)

@Override

public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metadataMap)

throws WorkflowException {

    try {

            ResourceResolver resolver = workflowSession.adaptTo(ResourceResolver.class);

            Project project = getProject(resolver, workItem.getWorkflowData());

            if (project != null) {

                updateProjectTeamMembers(project);

            }

        } catch (Exception e) {

            logger.error("Unable to complete Project Team Update Step for data: " + workItem.getWorkflowData(), e);

        }

}

    private void updateProjectTeamMembers(Project project) throws Exception {

       

        List<String> userIds = new ArrayList<String>();

        userIds.add("projectuser1");

        userIds.add("projectuser2");

        List<String> roleIds = new ArrayList<String>();

        roleIds.add("ownerid");

        roleIds.add("observerid");

       

        project.updateMembers(userIds, roleIds);

    }

   

    private Project getProject(ResourceResolver resolver, WorkflowData workflowData) throws Exception {

        if (workflowData != null && "jcr_path".equalsIgnoreCase(workflowData.getPayloadType()) && workflowData.getPayload() != null) {

            String payloadPath = workflowData.getPayload().toString();

            String projectPath = getProjectPath(payloadPath, resolver);

            logger.debug("projectPath"+ projectPath);

            Resource projectResource = projectPath != null ? resolver.getResource(projectPath): null;

            if (projectResource != null) {

                return projectResource.adaptTo(Project.class);

            }

        }

        return null;

    }

    private String getProjectPath(String payloadPath, ResourceResolver resolver) {

        if (payloadPath.startsWith("/content/projects")) {

            return StringUtils.substringBeforeLast(payloadPath, "/");

        }

        return null;

    }

Thanks for your help!

-Ramya