@Override public A apply(Function<EntityManager, A> transactional) { return tx(transactional); } };
/** Fetch all localizations from the database. */ private Map<String, String> fetchTextsFromDb() { final Map<String, String> locs = new HashMap<String, String>(); for (IncidentTextDto a : getPenv().tx(IncidentTextDto.findAll)) { locs.put(a.getId(), a.getText()); } return locs; }
@Override public <A> Either<F, A> tx(Function<EntityManager, A> transactional) { try { return Either.right(penv.tx(transactional)); } catch (Exception e) { return Either.left(exHandler.apply(e)); } }
private <A> A tx(Function<EntityManager, A> f) { return getPersistenceEnv().<A> tx().rethrow(exTransformer).apply(f); }
private void storeIncidentTexts(Bundle bundle) { logger.debug("Scanning bundle {}, (ID {}) for incident localizations", bundle.getSymbolicName(), bundle.getBundleId()); final Enumeration<?> l10n = bundle.findEntries(INCIDENT_L10N_DIR, PROPERTIES_GLOB, false); while (l10n != null && l10n.hasMoreElements()) { final URL resourceUrl = (URL) l10n.nextElement(); final String resourceFileName = resourceUrl.getPath(); // e.g. org.opencastproject.composer.properties or org.opencastproject.composer_de.properties final String fullResourceName = FilenameUtils.getBaseName(resourceFileName); final String[] fullResourceNameParts = fullResourceName.split("_"); // part 0 contains the key base, e.g. org.opencastproject.composer final String keyBase = fullResourceNameParts[0]; final List<String> locale = mlist(fullResourceNameParts).drop(1).value(); final Properties texts = loadPropertiesFromUrl(resourceUrl); for (String key : texts.stringPropertyNames()) { final String text = texts.getProperty(key); final String dbKey = mlist(keyBase, key).concat(locale).mkString("."); logger.debug("Storing text {}={}", dbKey, text); penv.tx(Queries.persistOrUpdate(IncidentTextDto.mk(dbKey, text))); } } } }
@Override public Incident storeIncident(Job job, Date timestamp, String code, Incident.Severity severity, Map<String, String> descriptionParameters, List<Tuple<String, String>> details) throws IncidentServiceException, IllegalStateException { try { job = getServiceRegistry().getJob(job.getId()); final IncidentDto dto = getPenv().tx( Queries.persist(IncidentDto.mk(job.getId(), timestamp, code, severity, descriptionParameters, details))); return toIncident(job, dto); } catch (NotFoundException e) { throw new IllegalStateException("Can't create incident for not-existing job"); } catch (Exception e) { logger.error("Could not store job incident: {}", e.getMessage()); throw new IncidentServiceException(e); } }
private List<Incident> getIncidentsOfJob(long jobId) throws NotFoundException, IncidentServiceException { final Job job = findJob(jobId); try { return mlist(getPenv().tx(IncidentDto.findByJobId(jobId))).map(toIncident(job)).value(); } catch (Exception e) { logger.error("Could not retrieve incidents of job '{}': {}", job.getId(), e.getMessage()); throw new IncidentServiceException(e); } }
@Override public Incident getIncident(long id) throws IncidentServiceException, NotFoundException { for (IncidentDto dto : getPenv().tx(Queries.find(IncidentDto.class, id))) { final Job job = findJob(dto.getJobId()); if (job != null) { return toIncident(job, dto); } } throw new NotFoundException(); }