private MetadataElementEntity getEntity(final MetadataElementEntity bean) {
   if (bean != null && StringUtils.isNotBlank(bean.getId())) {
     return elementDAO.findById(bean.getId());
   } else {
     return null;
   }
 }
 @Override
 @Transactional
 public void addRequiredAttributes(ResourceEntity resource) {
   if (resource != null
       && resource.getType() != null
       && StringUtils.isNotBlank(resource.getType().getId())) {
     MetadataElementSearchBean sb = new MetadataElementSearchBean();
     sb.addTypeId(resource.getType().getId());
     List<MetadataElementEntity> elementList = elementDAO.getByExample(sb, -1, -1);
     if (CollectionUtils.isNotEmpty(elementList)) {
       for (MetadataElementEntity element : elementList) {
         if (element.isRequired()) {
           resourcePropDao.save(AttributeUtil.buildResAttribute(resource, element));
         }
       }
     }
   }
 }
  @Override
  @Transactional
  public void validateResourceDeletion(final String resourceId) throws BasicDataServiceException {
    final ResourceEntity entity = resourceDao.findById(resourceId);
    if (entity != null) {

      final List<ManagedSysEntity> managedSystems = managedSysDAO.findByResource(resourceId);
      if (CollectionUtils.isNotEmpty(managedSystems)) {
        throw new BasicDataServiceException(
            ResponseCode.LINKED_TO_MANAGED_SYSTEM, managedSystems.get(0).getName());
      }

      final List<ContentProviderEntity> contentProviders =
          contentProviderDAO.getByResourceId(resourceId);
      if (CollectionUtils.isNotEmpty(contentProviders)) {
        throw new BasicDataServiceException(
            ResponseCode.LINKED_TO_CONTENT_PROVIDER, contentProviders.get(0).getName());
      }

      final List<URIPatternEntity> uriPatterns = uriPatternDAO.getByResourceId(resourceId);
      if (CollectionUtils.isNotEmpty(uriPatterns)) {
        throw new BasicDataServiceException(
            ResponseCode.LINKED_TO_URI_PATTERN, uriPatterns.get(0).getPattern());
      }

      final List<AuthProviderEntity> authProviders = authProviderDAO.getByResourceId(resourceId);
      if (CollectionUtils.isNotEmpty(authProviders)) {
        throw new BasicDataServiceException(
            ResponseCode.LINKED_TO_AUTHENTICATION_PROVIDER, authProviders.get(0).getName());
      }

      final List<MetadataElementEntity> metadataElements = elementDAO.getByResourceId(resourceId);
      if (CollectionUtils.isNotEmpty(metadataElements)) {
        throw new BasicDataServiceException(
            ResponseCode.LINKED_TO_METADATA_ELEMENT, metadataElements.get(0).getAttributeName());
      }

      final List<MetadataElementPageTemplateEntity> pageTemplates =
          templateDAO.getByResourceId(resourceId);
      if (CollectionUtils.isNotEmpty(pageTemplates)) {
        throw new BasicDataServiceException(
            ResponseCode.LINKED_TO_PAGE_TEMPLATE, pageTemplates.get(0).getName());
      }

      final ResourceEntity searchBean = new ResourceEntity();
      searchBean.setAdminResource(new ResourceEntity(resourceId));
      final List<ResourceEntity> adminOfResources = resourceDao.getByExample(searchBean);
      if (CollectionUtils.isNotEmpty(adminOfResources)) {
        throw new BasicDataServiceException(
            ResponseCode.RESOURCE_IS_AN_ADMIN_OF_RESOURCE, adminOfResources.get(0).getName());
      }

      final RoleEntity roleSearchBean = new RoleEntity();
      roleSearchBean.setAdminResource(new ResourceEntity(resourceId));
      final List<RoleEntity> adminOfRoles = roleDao.getByExample(roleSearchBean);
      if (CollectionUtils.isNotEmpty(adminOfRoles)) {
        throw new BasicDataServiceException(
            ResponseCode.RESOURCE_IS_AN_ADMIN_OF_ROLE, adminOfRoles.get(0).getName());
      }

      final GroupEntity groupSearchBean = new GroupEntity();
      groupSearchBean.setAdminResource(new ResourceEntity(resourceId));
      final List<GroupEntity> adminOfGroups = groupDao.getByExample(groupSearchBean);
      if (CollectionUtils.isNotEmpty(adminOfGroups)) {
        throw new BasicDataServiceException(
            ResponseCode.RESOURCE_IS_AN_ADMIN_OF_GROUP, adminOfGroups.get(0).getName());
      }

      final OrganizationEntity orgSearchBean = new OrganizationEntity();
      orgSearchBean.setAdminResource(new ResourceEntity(resourceId));
      final List<OrganizationEntity> adminOfOrgs = orgDAO.getByExample(orgSearchBean);
      if (CollectionUtils.isNotEmpty(adminOfOrgs)) {
        throw new BasicDataServiceException(
            ResponseCode.RESOURCE_IS_AN_ADMIN_OF_ORG, adminOfOrgs.get(0).getName());
      }
    }
  }