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:com.yunguchang.data.ApplicationRepository.java

@TransactionAttribute(REQUIRES_NEW)
public TBusApplyinfoEntity createApplicationForSync(TBusApplyinfoEntity application,
        PrincipalExt principalExt) {//from ww w  . jav  a2 s  .  com
    applySecurityFilter("applications", principalExt);

    TBusMainUserInfoEntity passenger = em.find(TBusMainUserInfoEntity.class,
            application.getPassenger().getUuid());
    if (passenger == null) {
        //            throw new EntityNotFoundException("Passenger is not exist");      // ? passenger 
    } else {
        application.setPassenger(passenger);
    }
    TSysOrgEntity deparment = em.find(TSysOrgEntity.class, application.getDepartment().getOrgid());
    if (deparment == null) {
        throw new EntityNotFoundException("Department is not exist");
    }
    application.setDepartment(deparment);
    TSysUserEntity coordinator = em.find(TSysUserEntity.class, application.getCoordinator().getUserid());
    if (coordinator == null) {
        throw new EntityNotFoundException("Coordinator is not exist");
    }
    application.setCoordinator(coordinator);
    if (application.getSenduser() != null) {
        application.setSenduser(em.find(TSysUserEntity.class, application.getSenduser().getUserid()));
    }

    if (application.getUpdateBySync() != null && application.getUpdateBySync()) {
        application.setUpdateBySync(true);
    } else {
        application.setUpdateBySync(false);
    }

    //        application.setSfgf("1");   // ?
    application.setApplydate(DateTime.now());
    if (principalExt != null) {
        application.setUpdateuser(principalExt.getUserIdOrNull());
    }
    if (application.getUuid() == null) {
        em.persist(application);
    } else {
        application = em.merge(application);
    }
    //em.refresh(applyinfoEntity);
    return application;
}

From source file:com.haulmont.cuba.core.sys.EntityManagerImpl.java

@Override
public <T extends Entity> T reloadNN(T entity, String... viewNames) {
    T reloaded = reload(entity, viewNames);
    if (reloaded == null)
        throw new EntityNotFoundException("Entity " + entity + " has been deleted");
    return reloaded;
}

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

/**
 * delete the specified client/*from   ww  w  . ja  v a2s.  c  o m*/
 * @param clientId
 * @return {@link ClientAppBasic} descriptor of the deleted client
 */
public ClientAppBasic delete(String clientId) {
    ClientDetailsEntity client = clientDetailsRepository.findByClientId(clientId);
    if (client == null) {
        throw new EntityNotFoundException("client app not found");
    }
    clientDetailsRepository.delete(client);
    return convertToClientApp(client);
}

From source file:edu.cmu.cs.lti.discoursedb.annotation.lightside.io.LightSideService.java

/**
 * Imports a file that was previously generated by exportDataForAnnotation() and then annotated by LightSide classifiers
 * //  w  w  w  .j  av  a2 s . com
 * @param inputFilePath path to the file that should be imported
 */
public void importAnnotatedData(String inputFilePath) {
    CsvMapper mapper = new CsvMapper();
    mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
    File csvFile = new File(inputFilePath);
    try {
        MappingIterator<String[]> it = mapper.readerFor(String[].class).readValues(csvFile);

        //process header
        String[] header = it.next();
        Map<String, Integer> headerId = new HashMap<>();
        for (int i = 0; i < header.length; i++) {
            headerId.put(header[i], i);
        }

        //process data
        while (it.hasNext()) {
            String[] row = it.next();
            Contribution curContrib = null;
            List<AnnotationInstance> curAnnos = new ArrayList<>();
            for (int i = 0; i < row.length; i++) {
                String field = row[i];
                if (i == headerId.get(TEXT_COL)) {
                    //we don't need the text column
                } else if (i == headerId.get(ID_COL)) {
                    curContrib = contribService.findOne(Long.parseLong(field)).orElseThrow(
                            () -> new EntityNotFoundException("Cannot find annotated entity in database."));
                } else {
                    //we don't need to create an annotation if it's a binary label set to false
                    if (!field.equalsIgnoreCase(LABEL_MISSING_VAL)) {
                        String label = header[i].split(LIGHTSIDE_PREDICTION_COL_SUFFIX)[0]; //remove suffix from label if it exists                    
                        AnnotationInstance newAnno = annoService.createTypedAnnotation(label);
                        annoService.saveAnnotationInstance(newAnno);
                        curAnnos.add(newAnno);
                        //if we have any other value than true or false, store this value as a feature
                        if (!field.equalsIgnoreCase(LABEL_ASSIGNED_VAL)) {
                            Feature newFeat = annoService.createFeature(field);
                            annoService.saveFeature(newFeat);
                            annoService.addFeature(newAnno, newFeat);
                        }
                    }
                }
            }
            //wipe old annotations  
            //TODO we might not want to delete ALL annotations
            delete(annoService.findAnnotations(curContrib));

            //add new annotations to the contribution it belongs to 
            for (AnnotationInstance newAnno : curAnnos) {
                annoService.addAnnotation(curContrib, newAnno);
            }
        }
    } catch (IOException e) {
        log.error("Error reading and parsing data from csv");
    }
}

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

@TransactionAttribute(REQUIRES_NEW)
public TBusApplyinfoEntity concertApply(String applyId, String sendUserId, String sscd, String isSend,
        Boolean bySync, PrincipalExt principalExt) {
    TBusApplyinfoEntity applyinfoEntity = em.find(TBusApplyinfoEntity.class, applyId);
    if (applyinfoEntity == null) {
        throw logger.entityNotFound(TBusApplyinfoEntity.class, applyId);
    }//  w ww. j av  a  2s  .  c o  m
    if (StringUtils.isNotBlank(sendUserId)) {
        TSysUserEntity userEntity = em.find(TSysUserEntity.class, sendUserId);
        if (userEntity == null) {
            throw new EntityNotFoundException("User is not found!");
        }
        applyinfoEntity.setSenduser(userEntity);
    }
    if (StringUtils.isNotBlank(sscd)) {
        TSysOrgEntity fleet = em.find(TSysOrgEntity.class, sscd);
        if (fleet == null) {
            throw new EntityNotFoundException("SSCD is not found!");
        }
        applyinfoEntity.setFleet(fleet);
    }
    if (bySync != null && bySync) {
        applyinfoEntity.setUpdateBySync(true);
    } else {
        applyinfoEntity.setUpdateBySync(false);
    }
    applyinfoEntity.setIssend(isSend);

    return applyinfoEntity;
}

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

@TransactionAttribute(REQUIRES_NEW)
public TBusEvaluateinfoEntity evaluateApplication(String applyId, String applyNo,
        TBusEvaluateinfoEntity evaluateInfoEntity, PrincipalExt principalExt) {
    if (evaluateInfoEntity.getApplication() != null) {
        TBusApplyinfoEntity application;
        if (StringUtils.isNotBlank(applyId)) {
            application = em.find(TBusApplyinfoEntity.class, applyId);
        } else {/*w  w w .  j av a2s  .  c  o m*/
            application = getApplicationByNo(applyNo, principalExt);
        }
        if (application == null) {
            throw logger.entityNotFound(TBusApplyinfoEntity.class, applyId == null ? applyNo : applyId);
        }
        evaluateInfoEntity.setApplication(application);
    }
    if (evaluateInfoEntity.getCar() != null) {
        TAzCarinfoEntity car = em.find(TAzCarinfoEntity.class, evaluateInfoEntity.getCar().getId());
        if (car == null) {
            throw new EntityNotFoundException("Car is not exist!");
        }
        evaluateInfoEntity.setCar(car);
    }
    if (evaluateInfoEntity.getDriver() != null) {
        TRsDriverinfoEntity driver = em.find(TRsDriverinfoEntity.class,
                evaluateInfoEntity.getDriver().getUuid());
        if (driver == null) {
            throw new EntityNotFoundException("Driver is not exist!");
        }
        evaluateInfoEntity.setDriver(driver);
    }
    if (evaluateInfoEntity.getSchedule() != null) {
        TBusScheduleRelaEntity schedule = em.find(TBusScheduleRelaEntity.class,
                evaluateInfoEntity.getSchedule().getUuid());
        if (schedule == null) {
            throw new EntityNotFoundException("Schedule is not exist!");
        }
        evaluateInfoEntity.setSchedule(schedule);
    }

    if (evaluateInfoEntity.getUpdateBySync() != null && evaluateInfoEntity.getUpdateBySync()) {
        evaluateInfoEntity.setUpdateBySync(true);
    } else {
        evaluateInfoEntity.setUpdateBySync(false);
    }
    evaluateInfoEntity.setEvaldate(DateTime.now());
    evaluateInfoEntity.setEvalstatus("1"); // ?(0:1)
    TSysUserEntity userEntity;
    if (principalExt != null && principalExt.getUserIdOrNull() != null
            && evaluateInfoEntity.getUser() == null) {
        userEntity = em.find(TSysUserEntity.class, principalExt.getUserIdOrNull());
    } else {
        userEntity = em.find(TSysUserEntity.class, evaluateInfoEntity.getUser().getUserid());
    }
    evaluateInfoEntity.setUser(userEntity);
    if (StringUtils.isBlank(evaluateInfoEntity.getUuid())) {
        em.persist(evaluateInfoEntity);
    } else {
        evaluateInfoEntity = em.merge(evaluateInfoEntity);
    }

    return evaluateInfoEntity;
}

From source file:edu.cmu.cs.lti.discoursedb.annotation.brat.io.BratService.java

/**
 * Generates a Brat annotation.conf file with all DiscourseDB annotation types that occur in the set of annotations on contributions or current revisions within the provided discourse registered as Brat annotations.
 * Relations, events and attribute sections are left empty and not further configuration is generated.
 *     /*w  w  w. j a v  a  2  s.c om*/
 * @param discourseName the name of the discourse for which to export annotation types
 * @param outputFolder the folder to which the config file should be written
 * @throws IOException if an exception occurs writing the config file
 */
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public void generateBratConfig(String discourseName, String outputFolder) throws IOException {
    Assert.hasText(discourseName, "The discourse name cannot be empty.");
    Assert.hasText(outputFolder, "The output folder path  cannot be empty.");
    generateBratConfig(discourseService.findOne(discourseName).orElseThrow(
            () -> new EntityNotFoundException("Discourse with name " + discourseName + " does not exist.")),
            outputFolder);
}

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

/**
 * Add parameter declaration to service//from   w w  w  .  j  av a  2s.  com
 * @param serviceId
 * @param decl
 * @param ownerId
 * @throws ResourceException 
 */
public Service addResourceDeclaration(String serviceId, ResourceDeclaration decl, String ownerId)
        throws ResourceException {
    validateResourceDeclarationData(decl);
    ServiceDescriptor sd = serviceRepository.findOne(serviceId);
    if (sd == null)
        throw new EntityNotFoundException("Not found: " + serviceId);
    Service s = Utils.toServiceObject(sd);
    boolean found = false;
    for (ResourceDeclaration rd : s.getResource()) {
        if (rd.getId().equals(decl.getId())) {
            rd.setDescription(decl.getDescription());
            rd.setName(decl.getName());
            found = true;
            break;
        }
    }
    if (!found) {
        s.getResource().add(decl);
    }
    updateService(s, ownerId);
    return s;
}

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

/**
 * Add parameter declaration to service/*from   ww  w.  jav  a 2  s  .c o  m*/
 * @param serviceId
 * @param mapping
 * @param ownerId
 * @throws ResourceException 
 */
public Service addMapping(String serviceId, ResourceMapping mapping, String ownerId) throws ResourceException {
    validateResourceMappingData(mapping);
    ServiceDescriptor sd = serviceRepository.findOne(serviceId);
    if (sd == null)
        throw new EntityNotFoundException("Not found: " + serviceId);
    Service s = Utils.toServiceObject(sd);
    boolean found = false;
    for (ResourceMapping rm : s.getResourceMapping()) {
        if (rm.getId().equals(mapping.getId())) {
            rm.setAccessibleByOthers(mapping.isAccessibleByOthers());
            rm.setApprovalRequired(mapping.isAccessibleByOthers());
            rm.setAuthority(mapping.getAuthority());
            rm.setDescription(mapping.getDescription());
            rm.setName(mapping.getName());
            rm.setUri(mapping.getUri());
            found = true;
            break;
        }
    }
    if (!found) {
        s.getResourceMapping().add(mapping);
    }
    updateService(s, ownerId);
    return s;
}

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

/**
 * Remove specified resource declaration
 * @param serviceId/*from ww  w .  ja va2 s .  c o  m*/
 * @param id
 * @param ownerId
 * @return
 * @throws ResourceException 
 */
public Object removeResourceDeclaration(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<ResourceDeclaration> iterator = s.getResource().iterator(); iterator.hasNext();) {
        ResourceDeclaration rd = iterator.next();
        if (rd.getId().equals(id)) {
            iterator.remove();
        }
    }
    updateService(s, ownerId);
    return s;
}