/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * Subscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */

package com.liferay.portal.workflow.kaleo.uad.anonymizer;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.workflow.kaleo.model.KaleoTaskAssignmentInstance;
import com.liferay.user.associated.data.anonymizer.UADAnonymizer;

import org.osgi.service.component.annotations.Component;

/**
 * @author Brian Wing Shun Chan
 */
@Component(service = UADAnonymizer.class)
public class KaleoTaskAssignmentInstanceUADAnonymizer
	extends BaseKaleoTaskAssignmentInstanceUADAnonymizer {

	@Override
	public void autoAnonymize(
			KaleoTaskAssignmentInstance kaleoTaskAssignmentInstance,
			long userId, User anonymousUser)
		throws PortalException {

		if (kaleoTaskAssignmentInstance.getUserId() == userId) {
			kaleoTaskAssignmentInstance.setUserId(anonymousUser.getUserId());
			kaleoTaskAssignmentInstance.setUserName(
				anonymousUser.getFullName());

			autoAnonymizeAssetEntry(kaleoTaskAssignmentInstance, anonymousUser);
		}

		if (kaleoTaskAssignmentInstance.getAssigneeClassPK() == userId) {
			kaleoTaskAssignmentInstance.setAssigneeClassPK(
				anonymousUser.getUserId());
		}

		kaleoTaskAssignmentInstanceLocalService.
			updateKaleoTaskAssignmentInstance(kaleoTaskAssignmentInstance);
	}

	@Override
	protected String[] doGetUserIdFieldNames() {
		return new String[] {"assigneeClassPK", "userId"};
	}

}