/** * Add MDRecord to database * * @param request * @param ingestedRecords */ protected void addMdRecord2Database(Request request, List<RecordRepox> ingestedRecords) { try { Repox2Sip repox2Sip = RepoxContextUtil.getRepoxManager().getDataManager().getRepox2sip(); List<MetadataRecord> allMetadataRecords = new ArrayList<MetadataRecord>(); for (RecordRepox rp : ingestedRecords) { allMetadataRecords.add(rp.createRecordSip()); // rp.addRecord2DataBase(request.getId(), repox2Sip); } repox2Sip.addMetadataRecords(request.getId(), allMetadataRecords); } catch (Repox2SipException e) { log.error("Could not add MetadataRecord to Data Base", e); e.printStackTrace(); } }
protected void checkRequest(boolean addedNewRecords, Request newRequest) { try { if (!addedNewRecords) { Repox2Sip repox2sip = RepoxContextUtil.getRepoxManager().getDataManager().getRepox2sip(); List<Request> requestList = repox2sip.getDataSetRequests(this.getIdDb()); Collections.sort(requestList, new DateSorter()); for (Request request : requestList) { if (request.getStatus().equals(RequestStatus.IMPORT_COMPLETED)) { Long myId = request.getId(); repox2sip.addMetadataRecords( newRequest.getId(), repox2sip.getRequestMetadataRecords(myId)); break; } } } } catch (Repox2SipException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } }
/** * Update DataSet in the database * * @param repox2sip * @throws IOException * @throws Repox2SipException */ public synchronized void updateDataSet2Database(Repox2Sip repox2sip) throws IOException, Repox2SipException { DataSet dataSet = repox2sip.getDataSet(this.getIdDb()); dataSet.setNameCode(this.getNameCode()); dataSet.setLanguage(this.getLanguage()); dataSet.setType(DataSetType.ESE); dataSet.setIdQName(this.getId()); dataSet.setName(this.getName()); dataSet.setDescription(this.getDescription()); dataSet.setProvider(repox2sip.getProvider(getDataProvider().getIdDb())); if (this.getRecordIdPolicy() instanceof IdExtracted) { dataSet.setIdQName(((IdExtracted) this.getRecordIdPolicy()).getIdentifierXpath()); } else { dataSet.setIdQName("Calculated by Repox"); } addSpecificInformation(dataSet); repox2sip.updateDataSet(dataSet); }
/** * Create an DataSet object, and add it to the database * * @param repox2sip * @return * @throws eu.europeana.repox2sip.Repox2SipException */ public DataSet addDataSource2Database(Repox2Sip repox2sip) throws Repox2SipException { DataSet dataSetSip = new DataSet(); dataSetSip.setProvider(repox2sip.getProvider(getDataProvider().getIdDb())); dataSetSip.setNameCode(this.getNameCode()); dataSetSip.setLanguage(this.getLanguage()); dataSetSip.setType(DataSetType.ESE); dataSetSip.setName(this.getName()); dataSetSip.setDescription(this.getDescription()); dataSetSip.setOaiSetOutput(this.getId()); if (this.getRecordIdPolicy() instanceof IdExtracted) { dataSetSip.setIdQName(((IdExtracted) this.getRecordIdPolicy()).getIdentifierXpath()); } else { dataSetSip.setIdQName("Calculated by Repox"); } addSpecificInformation(dataSetSip); dataSetSip = repox2sip.addDataSet(dataSetSip); this.setIdDb(dataSetSip.getId()); return dataSetSip; }
/** * Delete DataSet from the database * * @param repox2sip * @throws IOException * @throws eu.europeana.repox2sip.Repox2SipException */ public synchronized void deleteDataSourceFromDatabase(Repox2Sip repox2sip) throws IOException, Repox2SipException { repox2sip.removeDataSet(repox2sip.getDataSet(this.getIdDb())); }
public Task.Status startIngest(String taskId, boolean fullIngest) { Repox2Sip repox2sip = RepoxContextUtil.getRepoxManager().getDataManager().getRepox2sip(); Request request = new Request(); File logFile = getLogFile(taskId); Task.Status exitStatus = Task.Status.OK; try { if (RepoxContextUtil.getRepoxManager() .getConfiguration() .getUseSipDataBase() .equals("true")) { // REPOX2SIP Create request DataSet dataSet = repox2sip.getDataSet(this.getIdDb()); request.setDataSet(dataSet); request.setStatus(RequestStatus.UNDER_CONSTRUCTION); request.setCreationDate(new Date()); request = setRequestName(request); repox2sip.addRequest(request); } stopExecution = false; StringUtil.simpleLog( "Starting to import from Data Source with id " + id, this.getClass(), logFile); lastUpdate = getSynchronizationDate(); Date now = new Date(); exitStatus = ingestRecords(request, logFile, fullIngest); if (RepoxContextUtil.getRepoxManager() .getConfiguration() .getUseSipDataBase() .equals("true")) { // REPOX2SIP Change request status request.setStatus(getCorrespondentRequestStatus(exitStatus)); repox2sip.updateRequest(request); } lastUpdate = now; if (exitStatus.isSuccessful()) { signalSynchronizationFinished(lastUpdate); } StringUtil.simpleLog( "Finished importing from Data Source with id " + id + ". Exit status: " + exitStatus.toString(), this.getClass(), logFile); sendEmail(exitStatus, logFile); request.setStatus(RequestStatus.IMPORT_COMPLETED); } catch (TemplateException e) { log.error(e.getMessage(), e); StringUtil.simpleLog( "TemplateException: ERROR importing from Data Source with id " + id + ": " + e.getMessage(), this.getClass(), logFile); request.setStatus(RequestStatus.ABORTED); } catch (Repox2SipException e) { log.error(e.getMessage(), e); StringUtil.simpleLog( "Repox2SipException: ERROR importing from Data Source with id " + id + ": " + e.getMessage(), this.getClass(), logFile); request.setStatus(RequestStatus.ABORTED); } catch (MessagingException e) { log.error(e.getMessage(), e); StringUtil.simpleLog( "MessagingException: ERROR importing from Data Source with id " + id + ": " + e.getMessage(), this.getClass(), logFile); request.setStatus(RequestStatus.ABORTED); } catch (IOException e) { log.error(e.getMessage(), e); StringUtil.simpleLog( "IOException: ERROR importing from Data Source with id " + id + ": " + e.getMessage(), this.getClass(), logFile); request.setStatus(RequestStatus.ABORTED); } catch (Exception e) { log.error(e.getMessage(), e); StringUtil.simpleLog( "ERROR importing from Data Source with id " + id + ": " + e.getMessage(), this.getClass(), logFile); request.setStatus(RequestStatus.ABORTED); } return exitStatus; }