Example usage for javax.persistence EntityNotFoundException EntityNotFoundException

List of usage examples for javax.persistence EntityNotFoundException EntityNotFoundException

Introduction

In this page you can find the example usage for javax.persistence EntityNotFoundException EntityNotFoundException.

Prototype

public EntityNotFoundException(String message) 

Source Link

Document

Constructs a new EntityNotFoundException exception with the specified detail message.

Usage

From source file:eu.trentorise.smartcampus.permissionprovider.manager.ResourceManager.java

/**
 * Remove specified resource mapping/* w w w. ja va  2s . co m*/
 * @param serviceId
 * @param id
 * @param ownerId
 * @return
 * @throws ResourceException 
 */
public Object removeMapping(String serviceId, String id, String ownerId) throws ResourceException {
    ServiceDescriptor sd = serviceRepository.findOne(serviceId);
    if (sd == null)
        throw new EntityNotFoundException("Not found: " + serviceId);
    Service s = Utils.toServiceObject(sd);
    for (Iterator<ResourceMapping> iterator = s.getResourceMapping().iterator(); iterator.hasNext();) {
        ResourceMapping rm = iterator.next();
        if (rm.getId().equals(id)) {
            iterator.remove();
        }
    }
    updateService(s, ownerId);
    return s;
}

From source file:com.yunguchang.data.ApplicationRepository.java

@TransactionAttribute(REQUIRES_NEW)
public void deleteApply(String applyId, PrincipalExt principalExt) {
    TBusApplyinfoEntity applyinfoEntity = getApplicationById(applyId, principalExt);
    if (applyinfoEntity == null) {
        throw new EntityNotFoundException("Apply is not exist!");
    }//  w ww  . ja  v  a2s.c  om
    em.remove(applyinfoEntity);
}

From source file:com.eucalyptus.blockstorage.DASManager.java

@Override
public String getSnapshotPath(String snapshotId) throws EucalyptusCloudException {
    VolumeEntityWrapperManager volumeManager = new VolumeEntityWrapperManager();
    LVMVolumeInfo volInfo = volumeManager.getVolumeInfo(snapshotId);
    if (volInfo != null) {
        String snapPath = volInfo.getLoFileName();
        volumeManager.finish();/*www  .  ja  va  2 s.c  o  m*/
        return snapPath;
    } else {
        volumeManager.abort();
        throw new EntityNotFoundException("Unable to find snapshot with id: " + snapshotId);
    }
}

From source file:com.yunguchang.data.ApplicationRepository.java

@TransactionAttribute(REQUIRES_NEW)
public TBusApproveSugEntity approveApplication(String applyId, String applyNo,
        TBusApproveSugEntity approveSugInfo, PrincipalExt principalExtOrNull) {
    if (StringUtils.isBlank(applyId) && (StringUtils.isBlank(applyNo)
            && (approveSugInfo == null || approveSugInfo.getApplication() == null
                    || StringUtils.isBlank(approveSugInfo.getApplication().getApplyno())))) {
        throw new InvalidParameterException("Approve info can not be null!");
    }/*  w  w  w .jav a2s  . co m*/

    TSysUserEntity userEntity;
    if (approveSugInfo.getUser() != null) {
        userEntity = em.find(TSysUserEntity.class, approveSugInfo.getUser().getUserid());
        if (userEntity == null) {
            throw new EntityNotFoundException("User is not found!");
        }
    } else {
        userEntity = em.find(TSysUserEntity.class, principalExtOrNull.getUserIdOrNull());
    }
    approveSugInfo.setUser(userEntity);
    approveSugInfo.setDepartment(userEntity.getDepartment());
    approveSugInfo.setOperatedate(new Timestamp(DateTime.now().getMillis()));

    if (StringUtils.isNotBlank(approveSugInfo.getUuid())) {
        TBusApproveSugEntity approveSugEntity = em.find(TBusApproveSugEntity.class, approveSugInfo.getUuid());
        if (approveSugEntity != null) {
            TBusApplyinfoEntity applyinfoEntity = getApplicationByNo(applyNo, principalExtOrNull);
            if (applyinfoEntity == null) {
                throw new EntityNotFoundException("Apply is not found!");
            }
            approveSugInfo.setApplication(applyinfoEntity);
            return updateApproveInfo(approveSugEntity.getUuid(), approveSugInfo, principalExtOrNull);
        }
    }

    TBusApplyinfoEntity applyinfoEntity;
    if (StringUtils.isNotBlank(applyId)) {
        applyinfoEntity = em.find(TBusApplyinfoEntity.class, applyId);
        if (applyinfoEntity == null && StringUtils.isBlank(applyNo)) {
            throw new EntityNotFoundException("Apply info is not found!");
        }
    } else {
        applyinfoEntity = getApplicationByNo(applyNo, principalExtOrNull);
    }
    if (applyinfoEntity == null) {
        throw new EntityNotFoundException("Apply is not found!");
    }
    String applyNewStatus = ApplyStatus.APPLY.toStringValue(); // 
    if (!"01".equals(approveSugInfo.getSuggest())) {
        applyNewStatus = ApplyStatus.APPLY_REJECT.toStringValue(); // 
    }
    if (approveSugInfo.getUpdateBySync() != null && approveSugInfo.getUpdateBySync()) {
        approveSugInfo.setUpdateBySync(true);
    } else {
        approveSugInfo.setUpdateBySync(false);
    }
    updateApplicationStatus(applyinfoEntity.getUuid(), applyNewStatus, approveSugInfo.getUpdateBySync(),
            principalExtOrNull);

    approveSugInfo.setApplication(applyinfoEntity);
    if (StringUtils.isNotBlank(approveSugInfo.getUuid())) {
        approveSugInfo = em.merge(approveSugInfo);
    } else {
        em.persist(approveSugInfo);
    }

    return approveSugInfo;
}

From source file:com.eucalyptus.blockstorage.DASManager.java

@Override
public String getVolumePath(String volumeId) throws EucalyptusCloudException {
    VolumeEntityWrapperManager volumeManager = new VolumeEntityWrapperManager();
    LVMVolumeInfo volInfo = volumeManager.getVolumeInfo(volumeId);
    if (volInfo != null) {
        String volumePath = lvmRootDirectory + File.separator + volInfo.getVgName() + File.separator
                + volInfo.getLvName();//from w  w  w . j  av a  2s . co  m
        volumeManager.finish();
        return volumePath;
    } else {
        volumeManager.abort();
        throw new EntityNotFoundException("Unable to find volume with id: " + volumeId);
    }
}

From source file:com.yunguchang.data.ApplicationRepository.java

@TransactionAttribute(REQUIRES_NEW)
public TBusApproveSugEntity updateApproveInfo(String uuid, TBusApproveSugEntity approveSugInfo,
        PrincipalExt principalExtOrNull) {
    TBusApproveSugEntity approveSugEntity = em.find(TBusApproveSugEntity.class, uuid);
    if (approveSugEntity == null) {
        throw new EntityNotFoundException("Approve info is not found!");
    }// w  w  w .  j  a  v  a 2 s  . c  o m
    approveSugEntity.setSuggest(approveSugInfo.getSuggest());
    approveSugEntity.setRemark(approveSugInfo.getRemark());
    approveSugEntity.setOperatedate(approveSugInfo.getOperatedate());

    if (approveSugInfo.getApplication() != null) {
        TBusApplyinfoEntity applyEntity = getApplicationByNo(approveSugInfo.getApplication().getApplyno(),
                principalExtOrNull);
        if (applyEntity == null) {
            throw new EntityNotFoundException("Apply is not found!");
        }
        approveSugEntity.setApplication(applyEntity);
        String applyNewStatus = ApplyStatus.DEP_APPROVE.toStringValue();
        if ("01".equals(approveSugInfo.getSuggest())) {
            applyNewStatus = ApplyStatus.APPLY.toStringValue();
        }
        applyEntity.setUpdateBySync(approveSugInfo.getUpdateBySync());

        updateApplicationStatus(applyEntity.getUuid(), applyNewStatus, approveSugInfo.getUpdateBySync(),
                principalExtOrNull);
    }
    if (approveSugInfo.getUser() != null) {
        TSysUserEntity userEntity = em.find(TSysUserEntity.class, approveSugInfo.getUser().getUserid());
        if (userEntity == null) {
            throw new EntityNotFoundException("User is not found!");
        }
        approveSugEntity.setUser(userEntity);
    }

    return approveSugEntity;
}

From source file:org.eclipse.jubula.client.core.persistence.EditSupport.java

/**
 * @param po/*from w  w w . j ava  2  s.c o m*/
 *            the persistent object for which the working version shall be
 *            created.
 * @return a working version of the PO supplied to the constructor. This
 *         version is db identical to its original, but not Java identical.
 * @throws PMException
 *             in case of unspecified db error
 * 
 */
public IPersistentObject createWorkVersion(IPersistentObject po) throws PMException {
    Assert.verify(m_isValid, Messages.InvalidInstanceForInvokingOfThisMethod);
    Validate.notNull(po, Messages.OriginalObjectForCreatingOfWorkversionIsNull + StringConstants.DOT);
    try {
        IPersistentObject result = m_session.find(po.getClass(), po.getId());
        if (result == null) {
            throw new EntityNotFoundException(
                    Messages.UnableToFind + StringConstants.SPACE + po.getClass().getName()
                            + StringConstants.SPACE + Messages.WithID + StringConstants.SPACE + po.getId());
        }
        /* if po in the mastersession is newer than the corresponding
           object in the editor session, the instance in the editor session
           must be from the session cache; therefore the instance from the
           editor session must be evicted and reloaded */
        if ((result.getVersion() == null) || (po.getVersion().intValue() > result.getVersion().intValue())) {
            m_session.detach(result);
            result = m_session.find(po.getClass(), po.getId());
            if (result == null) {
                throw new EntityNotFoundException(
                        Messages.UnableToFind + StringConstants.SPACE + po.getClass().getName()
                                + StringConstants.SPACE + Messages.WithID + StringConstants.SPACE + po.getId());
            }
        }
        return result;
    } catch (PersistenceException e) {
        PersistenceManager.handleDBExceptionForEditor(po, e, this);
    }
    return null;
}

From source file:org.eclipse.jubula.client.core.persistence.EditSupport.java

/**
 * @return project associated with current session
 * @throws PMException/*from  w w  w .  ja  v  a 2  s . c  om*/
 *           in case of unspecified db error
 * 
 */
public IProjectPO getWorkProject() throws PMException {
    IProjectPO masterProj = GeneralStorage.getInstance().getProject();
    IProjectPO workProj = null;

    try {
        workProj = m_session.find(masterProj.getClass(), masterProj.getId());
        if (workProj == null) {
            throw new EntityNotFoundException(Messages.UnableToFind + StringConstants.SPACE
                    + masterProj.getClass().getName() + StringConstants.SPACE + Messages.WithID
                    + StringConstants.SPACE + masterProj.getId());
        }
        return workProj;
    } catch (PersistenceException e) {
        PersistenceManager.handleDBExceptionForEditor(masterProj, e, this);
    }
    return null;
}

From source file:org.rhq.enterprise.server.configuration.ConfigurationManagerBean.java

public ConfigurationDefinition getPackageTypeConfigurationDefinition(Subject subject, int packageTypeId) {
    Query query = entityManager/*from w  ww . ja  v  a  2 s. c  o  m*/
            .createNamedQuery(ConfigurationDefinition.QUERY_FIND_DEPLOYMENT_BY_PACKAGE_TYPE_ID);
    query.setParameter("packageTypeId", packageTypeId);
    ConfigurationDefinition configurationDefinition = null;
    try {
        configurationDefinition = (ConfigurationDefinition) query.getSingleResult();
    } catch (NoResultException e) {
        PackageType packageType = entityManager.find(PackageType.class, packageTypeId);
        if (packageType == null) {
            throw new EntityNotFoundException("A package type with id " + packageTypeId + " does not exist.");
        }
    }

    return configurationDefinition;
}

From source file:org.rhq.enterprise.server.configuration.ConfigurationManagerBean.java

@Nullable
public ConfigurationDefinition getResourceConfigurationDefinitionForResourceType(Subject subject,
        int resourceTypeId) {
    Query query = entityManager/*  ww w . j  av a  2  s  .  c om*/
            .createNamedQuery(ConfigurationDefinition.QUERY_FIND_RESOURCE_BY_RESOURCE_TYPE_ID);
    query.setParameter("resourceTypeId", resourceTypeId);
    ConfigurationDefinition configurationDefinition = null;
    try {
        configurationDefinition = (ConfigurationDefinition) query.getSingleResult();
    } catch (NoResultException e) {
        ResourceType resourceType = entityManager.find(ResourceType.class, resourceTypeId);
        if (resourceType == null) {
            throw new EntityNotFoundException("A resource type with id " + resourceTypeId + " does not exist.");
        }
    }

    return configurationDefinition;
}