Example usage for com.liferay.portal.kernel.security.auth CompanyThreadLocal isDeleteInProcess

List of usage examples for com.liferay.portal.kernel.security.auth CompanyThreadLocal isDeleteInProcess

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.security.auth CompanyThreadLocal isDeleteInProcess.

Prototype

public static boolean isDeleteInProcess() 

Source Link

Usage

From source file:com.liferay.dynamic.data.mapping.service.impl.DDMTemplateLocalServiceImpl.java

License:Open Source License

/**
 * Deletes the template and its resources.
 *
 * @param  template the template to be deleted
 * @throws PortalException if a portal exception occurred
 *///from w w w.  j  a v a2 s  . c o  m
@Override
@SystemEvent(type = SystemEventConstants.TYPE_DELETE)
public void deleteTemplate(DDMTemplate template) throws PortalException {

    // Template

    if (!CompanyThreadLocal.isDeleteInProcess()
            && (ddmTemplateLinkPersistence.countByTemplateId(template.getTemplateId()) > 0)) {

        throw new RequiredTemplateException.MustNotDeleteTemplateReferencedByTemplateLinks(
                template.getTemplateId());
    }

    ddmTemplatePersistence.remove(template);

    // Resources

    String resourceName = DDMTemplatePermission.getTemplateModelResourceName(template.getResourceClassName());

    resourceLocalService.deleteResource(template.getCompanyId(), resourceName,
            ResourceConstants.SCOPE_INDIVIDUAL, template.getTemplateId());
}

From source file:com.liferay.exportimport.lar.PortletDataContextFactoryImpl.java

License:Open Source License

protected PortletDataContext createPortletDataContext(long companyId, long groupId) {

    PortletDataContext portletDataContext = new PortletDataContextImpl(_lockManager);

    try {//w ww.j  a  v a 2  s. c om
        Group companyGroup = _groupLocalService.fetchCompanyGroup(companyId);

        if (companyGroup != null) {
            portletDataContext.setCompanyGroupId(companyGroup.getGroupId());
        }
    } catch (Exception e) {
        if (!CompanyThreadLocal.isDeleteInProcess()) {
            throw new IllegalStateException("Unable to create a portlet data context for company " + companyId
                    + " because it is being deleted", e);
        }
    }

    portletDataContext.setCompanyId(companyId);
    portletDataContext.setGroupId(groupId);
    portletDataContext.setScopeGroupId(groupId);

    try {
        Group userPersonalSiteGroup = _groupLocalService.fetchUserPersonalSiteGroup(companyId);

        if (userPersonalSiteGroup != null) {
            portletDataContext.setUserPersonalSiteGroupId(userPersonalSiteGroup.getGroupId());
        }
    } catch (Exception e) {
        if (!CompanyThreadLocal.isDeleteInProcess()) {
            throw new IllegalStateException("Unable to create a portlet data context for company " + companyId
                    + " because it is being deleted", e);
        }
    }

    return portletDataContext;
}