001/*
002 *  Copyright 2016 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.workspaces.activities.tasks;
017
018import java.util.List;
019import java.util.Map;
020import java.util.stream.Collectors;
021
022import javax.jcr.RepositoryException;
023
024import org.apache.commons.lang.StringUtils;
025
026import org.ametys.plugins.repository.activities.Activity;
027import org.ametys.plugins.repository.activities.ActivityType;
028import org.ametys.plugins.workspaces.ObservationConstants;
029import org.ametys.plugins.workspaces.tasks.Task;
030
031/**
032 * {@link ActivityType} implementation for the assignment of a task
033 */
034public class TaskAssignedActivityType extends TasksActivityType
035{
036    /** data name for the assignees */
037    public static final String ASSIGNEES = "assignees";
038    
039    @Override
040    public void setAdditionalActivityData(Activity activity, Map<String, Object> parameters) throws RepositoryException
041    {
042        super.setAdditionalActivityData(activity, parameters);
043        
044        Task task = (Task) parameters.get(ObservationConstants.ARGS_TASK);
045        
046        // FIXME WORKSPACES-1407 Store user identity instead of fullname in task assigned
047        List<String> assignees = task.getAssignments().stream().map(identity -> _userHelper.getUserFullName(identity)).collect(Collectors.toList());
048        activity.setValue(ASSIGNEES, StringUtils.join(assignees, ", "));
049    }
050    
051    @Override
052    public boolean isMergeable(Activity activity1, Activity activity2)
053    {
054        return false;
055    }
056}