Example usage for com.liferay.portal.kernel.service PersistedModelLocalService getPersistedModel

List of usage examples for com.liferay.portal.kernel.service PersistedModelLocalService getPersistedModel

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service PersistedModelLocalService getPersistedModel.

Prototype

public PersistedModel getPersistedModel(Serializable primaryKeyObj) throws PortalException;

Source Link

Usage

From source file:com.liferay.osb.scv.connector.internal.model.SCVModel.java

License:Open Source License

@Override
public void onBeforeUpdate(T model) throws ModelListenerException {
    long mappingDataSourceId = MappingDataSourceUtil.getMappingDataSourceId();

    if (mappingDataSourceId == 0) {
        return;/*from w  ww  . j a  v  a 2s .  c  o  m*/
    }

    PersistedModel originalModel = null;

    try {
        PersistedModelLocalService persistedModelLocalService = PersistedModelLocalServiceRegistryUtil
                .getPersistedModelLocalService(model.getModelClassName());
        originalModel = persistedModelLocalService.getPersistedModel(model.getPrimaryKeyObj());

        _models.put(model.getPrimaryKeyObj(), originalModel);
    } catch (Exception e) {
        throw new ModelListenerException();
    }
}

From source file:com.liferay.ratings.internal.exportimport.data.handler.RatingsEntryStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, RatingsEntry entry) throws Exception {

    long userId = portletDataContext.getUserId(entry.getUserUuid());

    Map<Long, Long> relatedClassPKs = (Map<Long, Long>) portletDataContext
            .getNewPrimaryKeysMap(entry.getClassName());

    long newClassPK = MapUtil.getLong(relatedClassPKs, entry.getClassPK(), entry.getClassPK());

    try {/* ww w  .j  a  v a2s  .  com*/
        PersistedModelLocalService persistedModelLocalService = PersistedModelLocalServiceRegistryUtil
                .getPersistedModelLocalService(entry.getClassName());

        if (persistedModelLocalService instanceof PersistedResourcedModelLocalService) {

            PersistedResourcedModelLocalService persistedResourcedModelLocalService = (PersistedResourcedModelLocalService) persistedModelLocalService;

            List<? extends PersistedModel> persistedModels = persistedResourcedModelLocalService
                    .getPersistedModel(newClassPK);

            if (ListUtil.isEmpty(persistedModels)) {
                return;
            }
        } else {
            persistedModelLocalService.getPersistedModel(newClassPK);
        }
    } catch (PortalException pe) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to import ratings entry " + entry.getEntryId(), pe);
        }

        return;
    }

    ServiceContext serviceContext = portletDataContext.createServiceContext(entry);

    RatingsEntry importedEntry = _ratingsEntryLocalService.updateEntry(userId, entry.getClassName(), newClassPK,
            entry.getScore(), serviceContext);

    portletDataContext.importClassedModel(entry, importedEntry);
}

From source file:com.liferay.ratings.internal.page.ratings.exportimport.data.handler.PageRatingsPortletDataHandler.java

License:Open Source License

protected long getGroupId(RatingsEntry ratingsEntry) throws PortalException {

    PersistedModelLocalService persistedModelLocalService = PersistedModelLocalServiceRegistryUtil
            .getPersistedModelLocalService(ratingsEntry.getClassName());

    if (persistedModelLocalService == null) {
        return GroupConstants.DEFAULT_PARENT_GROUP_ID;
    }/* ww  w .j a  v  a 2 s  .  c o m*/

    PersistedModel persistedModel = null;

    try {
        persistedModel = persistedModelLocalService.getPersistedModel(ratingsEntry.getClassPK());
    } catch (NoSuchModelException nsme) {
        if (_log.isDebugEnabled()) {
            _log.debug(nsme.getMessage(), nsme);
        }

        return GroupConstants.DEFAULT_PARENT_GROUP_ID;
    }

    if (!(persistedModel instanceof GroupedModel)) {
        return GroupConstants.DEFAULT_PARENT_GROUP_ID;
    }

    GroupedModel groupedModel = (GroupedModel) persistedModel;

    return groupedModel.getGroupId();
}