/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.sync.internal.model.listener; import com.liferay.document.library.kernel.model.DLFileEntry; import com.liferay.document.library.kernel.model.DLFolder; import com.liferay.portal.kernel.model.BaseModel; import com.liferay.portal.kernel.model.BaseModelListener; import com.liferay.portal.kernel.model.ResourcePermission; import com.liferay.portal.kernel.service.ResourcePermissionLocalService; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.sync.constants.SyncDLObjectConstants; import com.liferay.sync.model.SyncDLObject; import com.liferay.sync.service.SyncDLObjectLocalService; import java.util.List; import org.osgi.service.component.annotations.Reference; /** * @author Shinn Lok */ public abstract class SyncBaseModelListener<T extends BaseModel<T>> extends BaseModelListener<T> { protected SyncDLObject getSyncDLObject( ResourcePermission resourcePermission) { String modelName = resourcePermission.getName(); if (modelName.equals(DLFileEntry.class.getName())) { return syncDLObjectLocalService.fetchSyncDLObject( SyncDLObjectConstants.TYPE_FILE, GetterUtil.getLong(resourcePermission.getPrimKey())); } else if (modelName.equals(DLFolder.class.getName())) { return syncDLObjectLocalService.fetchSyncDLObject( SyncDLObjectConstants.TYPE_FOLDER, GetterUtil.getLong(resourcePermission.getPrimKey())); } return null; } protected void updateSyncDLObject(SyncDLObject syncDLObject) { syncDLObject.setModifiedTime(System.currentTimeMillis()); syncDLObjectLocalService.updateSyncDLObject(syncDLObject); String type = syncDLObject.getType(); if (!type.equals(SyncDLObjectConstants.TYPE_FOLDER)) { return; } List<SyncDLObject> childSyncDLObjects = syncDLObjectLocalService.getSyncDLObjects( syncDLObject.getRepositoryId(), syncDLObject.getTypePK()); for (SyncDLObject childSyncDLObject : childSyncDLObjects) { updateSyncDLObject(childSyncDLObject); } } @Reference protected ResourcePermissionLocalService resourcePermissionLocalService; @Reference protected SyncDLObjectLocalService syncDLObjectLocalService; }