List of usage examples for javax.ejb EJBException EJBException
public EJBException(Exception ex)
From source file:org.cesecore.certificates.certificate.CertificateCreateSessionBean.java
/** * Help Method that extracts the CA specified in the request. * //from www.j a v a2s .c om * @throws AuthorizationDeniedException * @throws CADoesntExistsException */ private CA getCAFromRequest(final AuthenticationToken admin, final RequestMessage req) throws CADoesntExistsException, AuthorizationDeniedException { CA ca = null; // See if we can get issuerDN directly from request if (req.getIssuerDN() != null) { String dn = certificateStoreSession.getCADnFromRequest(req); ca = caSession.getCA(admin, dn.hashCode()); if (log.isDebugEnabled()) { log.debug("Using CA (from issuerDN) with id: " + ca.getCAId() + " and DN: " + ca.getSubjectDN()); } } else { throw new CADoesntExistsException(intres.getLocalizedMessage("createcert.canotfoundissuerusername", req.getIssuerDN(), req.getUsername())); } if (ca.getStatus() != CAConstants.CA_ACTIVE) { final String msg = intres.getLocalizedMessage("createcert.canotactive", ca.getSubjectDN()); throw new EJBException(msg); } return ca; }
From source file:com.egt.ejb.toolkit.ToolKitSessionBean.java
@Override public void generarJasperReport() { try {/*w w w . j a va 2 s . c o m*/ VelocityContext context = new VelocityContext(); String query = VelocityEngineer.write(context, "sdk-query-generar-jasper-report.vm").toString(); List<Dominio> dominios = dominioFacade.findByQuery(query, EnumTipoQuery.NATIVE, REFRESH); generarJasperReport(dominios); TLC.getBitacora().info(Bundle.getString("generar.informes.ok"), dominios.size()); } catch (Exception ex) { // TLC.getBitacora().fatal(ex); throw ex instanceof EJBException ? (EJBException) ex : new EJBException(ex); } }
From source file:edu.harvard.iq.dvn.core.analysis.NetworkDataServiceBean.java
private void saveNetworkDBFiles(StudyFileEditBean editBean) { File temploc = new File(editBean.getTempSystemFileLocation()); File tempDir = temploc.getParentFile(); File ingestedDir = new File(tempDir, "ingested"); if (!ingestedDir.exists()) { ingestedDir.mkdirs();/*from www . j a va2 s . c o m*/ } String neo4jDirName = FileUtil.replaceExtension(temploc.getName(), this.NEO4J_EXTENSION); File neo4jDir = new File(ingestedDir, neo4jDirName); neo4jDir.mkdirs(); String sqliteFileName = FileUtil.replaceExtension(temploc.getName(), this.SQLITE_EXTENSION); File sqliteFile = new File(ingestedDir, sqliteFileName); try { if (batchInserterFactory == null) { batchInserterFactory = new GraphBatchInserterFactory(LIB_PATH); } dvnGBI = batchInserterFactory.newInstance(neo4jDir.getAbsolutePath(), sqliteFile.getAbsolutePath(), SQLITE_CONFIG_FILE, NEO4J_CONFIG_FILE); dvnGBI.ingest(editBean.getTempSystemFileLocation()); } catch (Exception e) { throw new EJBException(e); } }
From source file:edu.harvard.iq.dvn.core.study.StudyFileServiceBean.java
private void addFiles(StudyVersion studyVersion, List<StudyFileEditBean> newFiles, VDCUser user, String ingestEmail, int messageLevel) { Study study = studyVersion.getStudy(); MD5Checksum md5Checksum = new MD5Checksum(); // step 1: divide the files, based on subsettable or not List subsettableFiles = new ArrayList(); List otherFiles = new ArrayList(); Iterator iter = newFiles.iterator(); while (iter.hasNext()) { StudyFileEditBean fileBean = (StudyFileEditBean) iter.next(); // Note that for the "special" OtherFiles we want to utilize the // same ingest scheme as for subsettables: they will be queued and // processed asynchronously, and the user will be notified by email. // - L.A. if (fileBean.getStudyFile().isSubsettable() || fileBean.getStudyFile() instanceof SpecialOtherFile) { subsettableFiles.add(fileBean); } else {//from w ww . j a va 2s. co m otherFiles.add(fileBean); // also add to study, so that it will be flushed for the ids fileBean.getStudyFile().setStudy(study); study.getStudyFiles().add(fileBean.getStudyFile()); } } if (otherFiles.size() > 0) { // Only persist the studyVersion we are adding a file that doesn't need to be ingested (non-subsettable) if (studyVersion.getId() == null) { em.persist(studyVersion); em.flush(); // populates studyVersion_id } else { // There is a problem merging the existing studyVersion, // so since all we need from the exisiting version is the versionNote, // we get a fresh copy of the object from the database, and update it with the versionNote. String versionNote = studyVersion.getVersionNote(); studyVersion = em.find(StudyVersion.class, studyVersion.getId()); studyVersion.setVersionNote(versionNote); } } // step 2: iterate through nonsubsettable files, moving from temp to new location File newDir = FileUtil.getStudyFileDir(study); iter = otherFiles.iterator(); while (iter.hasNext()) { StudyFileEditBean fileBean = (StudyFileEditBean) iter.next(); StudyFile f = fileBean.getStudyFile(); File tempFile = new File(fileBean.getTempSystemFileLocation()); File newLocationFile = new File(newDir, f.getFileSystemName()); try { FileUtil.copyFile(tempFile, newLocationFile); tempFile.delete(); f.setFileSystemLocation(newLocationFile.getAbsolutePath()); fileBean.getFileMetadata().setStudyVersion(studyVersion); em.persist(fileBean.getStudyFile()); em.persist(fileBean.getFileMetadata()); } catch (IOException ex) { throw new EJBException(ex); } f.setMd5(md5Checksum.CalculateMD5(f.getFileSystemLocation())); } // step 3: iterate through subsettable files, sending a message via JMS if (subsettableFiles.size() > 0) { QueueConnection conn = null; QueueSession session = null; QueueSender sender = null; try { conn = factory.createQueueConnection(); session = conn.createQueueSession(false, 0); sender = session.createSender(queue); DSBIngestMessage ingestMessage = new DSBIngestMessage(messageLevel); ingestMessage.setFileBeans(subsettableFiles); ingestMessage.setIngestEmail(ingestEmail); ingestMessage.setIngestUserId(user.getId()); ingestMessage.setStudyId(study.getId()); ingestMessage.setStudyVersionId(studyVersion.getId()); ingestMessage.setVersionNote(studyVersion.getVersionNote()); ingestMessage.setStudyTitle(studyVersion.getMetadata().getTitle()); ingestMessage.setStudyGlobalId(studyVersion.getStudy().getGlobalId()); ingestMessage.setStudyVersionNumber(studyVersion.getVersionNumber().toString()); ingestMessage.setDataverseName(studyVersion.getStudy().getOwner().getName()); Message message = session.createObjectMessage(ingestMessage); String detail = "Ingest processing for " + subsettableFiles.size() + " file(s)."; studyService.addStudyLock(study.getId(), user.getId(), detail); try { sender.send(message); } catch (Exception ex) { // If anything goes wrong, remove the study lock. studyService.removeStudyLock(study.getId()); ex.printStackTrace(); } // send an e-mail if (ingestMessage.sendInfoMessage()) { mailService.sendIngestRequestedNotification(ingestMessage, subsettableFiles); } } catch (JMSException ex) { ex.printStackTrace(); } finally { try { if (sender != null) { sender.close(); } if (session != null) { session.close(); } if (conn != null) { conn.close(); } } catch (JMSException ex) { ex.printStackTrace(); } } } if (!otherFiles.isEmpty()) { studyService.saveStudyVersion(studyVersion, user.getId()); } }
From source file:edu.harvard.iq.dataverse.harvest.client.HarvesterServiceBean.java
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public Long processRecord(DataverseRequest dataverseRequest, Logger hdLogger, PrintWriter importCleanupLog, OaiHandler oaiHandler, String identifier, MutableBoolean recordErrorOccurred, MutableLong processedSizeThisBatch, List<String> deletedIdentifiers) { String errMessage = null;//w w w.j av a 2 s . c o m Dataset harvestedDataset = null; logGetRecord(hdLogger, oaiHandler, identifier); File tempFile = null; try { FastGetRecord record = oaiHandler.runGetRecord(identifier); errMessage = record.getErrorMessage(); if (errMessage != null) { hdLogger.log(Level.SEVERE, "Error calling GetRecord - " + errMessage); } else if (record.isDeleted()) { hdLogger.info( "Deleting harvesting dataset for " + identifier + ", per the OAI server's instructions."); Dataset dataset = datasetService .getDatasetByHarvestInfo(oaiHandler.getHarvestingClient().getDataverse(), identifier); if (dataset != null) { hdLogger.info("Deleting dataset " + dataset.getGlobalId()); deleteHarvestedDataset(dataset, dataverseRequest, hdLogger); // TODO: // check the status of that Delete - see if it actually succeeded deletedIdentifiers.add(identifier); } else { hdLogger.info("No dataset found for " + identifier + ", skipping delete. "); } } else { hdLogger.info("Successfully retrieved GetRecord response."); tempFile = record.getMetadataFile(); PrintWriter cleanupLog; harvestedDataset = importService.doImportHarvestedDataset(dataverseRequest, oaiHandler.getHarvestingClient(), identifier, oaiHandler.getMetadataPrefix(), record.getMetadataFile(), importCleanupLog); hdLogger.fine("Harvest Successful for identifier " + identifier); hdLogger.fine("Size of this record: " + record.getMetadataFile().length()); processedSizeThisBatch.add(record.getMetadataFile().length()); } } catch (Throwable e) { logGetRecordException(hdLogger, oaiHandler, identifier, e); errMessage = "Caught exception while executing GetRecord on " + identifier; //logException(e, hdLogger); } finally { if (tempFile != null) { // temporary - let's not delete the temp metadata file if anything went wrong, for now: if (errMessage == null) { try { tempFile.delete(); } catch (Throwable t) { } ; } } } // TODO: the message below is taken from DVN3; - figure out what it means... // // If we got an Error from the OAI server or an exception happened during import, then // set recordErrorOccurred to true (if recordErrorOccurred is being used) // otherwise throw an exception (if recordErrorOccurred is not used, i.e null) if (errMessage != null) { if (recordErrorOccurred != null) { recordErrorOccurred.setValue(true); } else { throw new EJBException(errMessage); } } return harvestedDataset != null ? harvestedDataset.getId() : null; }
From source file:com.egt.ejb.toolkit.ToolKitSessionBean.java
@Override public void generarJasperViews() { try {//from ww w . j av a 2s . com VelocityContext context = new VelocityContext(); String query = VelocityEngineer.write(context, "sdk-query-generar-jasper-query.vm").toString(); List<Dominio> dominios = dominioFacade.findByQuery(query, EnumTipoQuery.NATIVE, REFRESH); generarJasperViews(dominios); TLC.getBitacora().info(Bundle.getString("generar.views.ok"), dominios.size()); } catch (Exception ex) { // TLC.getBitacora().fatal(ex); throw ex instanceof EJBException ? (EJBException) ex : new EJBException(ex); } }
From source file:org.ejbca.core.ejb.ca.store.CertificateStoreSessionBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @Override//from ww w .ja va 2 s .c o m public void setArchivedStatus(Admin admin, String fingerprint) throws AuthorizationDeniedException { if (admin.getAdminType() != Admin.TYPE_INTERNALUSER) { throw new AuthorizationDeniedException("Unauthorized"); } CertificateData rev = CertificateData.findByFingerprint(entityManager, fingerprint); if (rev != null) { rev.setStatus(SecConst.CERT_ARCHIVED); if (log.isDebugEnabled()) { log.debug("Set status ARCHIVED for certificate with fp: " + fingerprint + ", revocation reason is: " + rev.getRevocationReason()); } } else { String msg = intres.getLocalizedMessage("store.errorcertinfo", fingerprint); logSession.log(admin, 0, LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_ERROR_UNKNOWN, msg); throw new EJBException(msg); } }
From source file:edu.harvard.iq.dvn.core.harvest.HarvesterServiceBean.java
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public ResumptionTokenType harvestFromIdentifiers(Logger hdLogger, ResumptionTokenType resumptionToken, HarvestingDataverse dataverse, String from, String until, List<Long> harvestedStudyIds, List<String> failedIdentifiers, MutableBoolean harvestErrorOccurred) throws java.io.IOException, ParserConfigurationException, SAXException, TransformerException, JAXBException { String encodedSet = dataverse.getHarvestingSet() == null ? null : URLEncoder.encode(dataverse.getHarvestingSet(), "UTF-8"); ListIdentifiers listIdentifiers = null; if (resumptionToken == null) { listIdentifiers = new ListIdentifiers(dataverse.getServerUrl(), from, until, encodedSet, URLEncoder.encode(dataverse.getHarvestFormatType().getMetadataPrefix(), "UTF-8")); } else {/*from w w w . j av a2 s .co m*/ hdLogger.log(Level.INFO, "harvestFromIdentifiers(), resumptionToken=" + resumptionToken.getValue()); listIdentifiers = new ListIdentifiers(dataverse.getServerUrl(), resumptionToken.getValue()); } Document doc = listIdentifiers.getDocument(); // JAXBContext jc = JAXBContext.newInstance("edu.harvard.hmdc.vdcnet.jaxb.oai"); // Unmarshaller unmarshaller = jc.createUnmarshaller(); JAXBElement unmarshalObj = (JAXBElement) unmarshaller.unmarshal(doc); OAIPMHtype oaiObj = (OAIPMHtype) unmarshalObj.getValue(); if (oaiObj.getError() != null && oaiObj.getError().size() > 0) { if (oaiObj.getError().get(0).getCode().equals(OAIPMHerrorcodeType.NO_RECORDS_MATCH)) { hdLogger.info("ListIdentifiers returned NO_RECORDS_MATCH - no studies found to be harvested."); } else { handleOAIError(hdLogger, oaiObj, "calling listIdentifiers, oaiServer= " + dataverse.getServerUrl() + ",from=" + from + ",until=" + until + ",encodedSet=" + encodedSet + ",format=" + dataverse.getHarvestFormatType().getMetadataPrefix()); throw new EJBException("Received OAI Error response calling ListIdentifiers"); } } else { ListIdentifiersType listIdentifiersType = oaiObj.getListIdentifiers(); if (listIdentifiersType != null) { resumptionToken = listIdentifiersType.getResumptionToken(); for (Iterator it = listIdentifiersType.getHeader().iterator(); it.hasNext();) { HeaderType header = (HeaderType) it.next(); MutableBoolean getRecordErrorOccurred = new MutableBoolean(false); Long studyId = getRecord(hdLogger, dataverse, header.getIdentifier(), dataverse.getHarvestFormatType().getMetadataPrefix(), getRecordErrorOccurred); if (studyId != null) { harvestedStudyIds.add(studyId); } if (getRecordErrorOccurred.booleanValue() == true) { failedIdentifiers.add(header.getIdentifier()); } } } } String logMsg = "Returning from harvestFromIdentifiers"; if (resumptionToken == null) { logMsg += " resumptionToken is null"; } else if (!StringUtil.isEmpty(resumptionToken.getValue())) { logMsg += " resumptionToken is " + resumptionToken.getValue(); } else { // Some OAIServers return an empty resumptionToken element when all // the identifiers have been sent, so need to check for this, and // treat it as if resumptiontoken is null. logMsg += " resumptionToken is empty, setting return value to null."; resumptionToken = null; } hdLogger.info(logMsg); return resumptionToken; }
From source file:io.hops.hopsworks.common.user.AuthController.java
private void resetProjectCertPassword(Users p, String oldPass) { //For every project, change the certificate secret in the database //Get cert password by decrypting it with old password List<Project> projects = projectFacade.findAllMemberStudies(p); List<ProjectGenericUserCerts> pguCerts = null; try {//from ww w .j av a 2 s . c o m for (Project project : projects) { UserCerts userCert = userCertsFacade.findUserCert(project.getName(), p.getUsername()); String masterEncryptionPassword = certificatesMgmService.getMasterEncryptionPassword(); String certPassword = HopsUtils.decrypt(oldPass, userCert.getUserKeyPwd(), masterEncryptionPassword); //Encrypt it with new password and store it in the db String newSecret = HopsUtils.encrypt(p.getPassword(), certPassword, masterEncryptionPassword); userCert.setUserKeyPwd(newSecret); userCertsFacade.update(userCert); //If user is owner of the project, update projectgenericuser certs as well if (project.getOwner().equals(p)) { if (pguCerts == null) { pguCerts = new ArrayList<>(); } ProjectGenericUserCerts pguCert = userCertsFacade .findProjectGenericUserCerts(project.getName() + Settings.PROJECT_GENERIC_USER_SUFFIX); pguCerts.add(userCertsFacade .findProjectGenericUserCerts(project.getName() + Settings.PROJECT_GENERIC_USER_SUFFIX)); String pguCertPassword = HopsUtils.decrypt(oldPass, pguCert.getCertificatePassword(), masterEncryptionPassword); //Encrypt it with new password and store it in the db String newPguSecret = HopsUtils.encrypt(p.getPassword(), pguCertPassword, masterEncryptionPassword); pguCert.setCertificatePassword(newPguSecret); userCertsFacade.updatePGUCert(pguCert); } } } catch (Exception ex) { LOGGER.log(Level.SEVERE, null, ex); throw new EJBException(ex); } }
From source file:org.ejbca.core.ejb.ca.store.CertificateStoreSessionBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @Override//from w w w . j ava2s .com public void setRevokeStatus(Admin admin, String issuerdn, BigInteger serno, Date revokedate, Collection<Integer> publishers, int reason, String userDataDN) { if (log.isTraceEnabled()) { log.trace(">setRevokeStatus(), issuerdn=" + issuerdn + ", serno=" + serno.toString(16) + ", reason=" + reason); } try { Certificate certificate = findCertificateByIssuerAndSerno(admin, issuerdn, serno); setRevokeStatus(admin, certificate, revokedate, publishers, reason, userDataDN); } catch (FinderException e) { String msg = intres.getLocalizedMessage("store.errorfindcertserno", serno.toString(16)); logSession.log(admin, issuerdn.hashCode(), LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_ERROR_REVOKEDCERT, msg); throw new EJBException(e); } if (log.isTraceEnabled()) { log.trace("<setRevokeStatus(), issuerdn=" + issuerdn + ", serno=" + serno.toString(16) + ", reason=" + reason); } }