/**
 * 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.KaleoLog;
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 KaleoLogUADAnonymizer extends BaseKaleoLogUADAnonymizer {

	@Override
	public void autoAnonymize(
			KaleoLog kaleoLog, long userId, User anonymousUser)
		throws PortalException {

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

			autoAnonymizeAssetEntry(kaleoLog, anonymousUser);
		}

		if (kaleoLog.getCurrentAssigneeClassPK() == userId) {
			kaleoLog.setCurrentAssigneeClassPK(anonymousUser.getUserId());
		}

		if (kaleoLog.getPreviousAssigneeClassPK() == userId) {
			kaleoLog.setPreviousAssigneeClassPK(anonymousUser.getUserId());
		}

		kaleoLogLocalService.updateKaleoLog(kaleoLog);
	}

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

}