Skip to content

Commit

Permalink
export unimarc: configurazione tramite file template
Browse files Browse the repository at this point in the history
  • Loading branch information
IstitutoCentraleCatalogoUnicoBiblio committed Jun 26, 2023
1 parent 33d4d0e commit 8111fdf
Show file tree
Hide file tree
Showing 12 changed files with 408 additions and 237 deletions.
1 change: 1 addition & 0 deletions SBNWeb/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
<classpathentry kind="lib" path="lib/common/commons-discovery-0.2.jar"/>
<classpathentry kind="lib" path="lib/common/saaj.jar"/>
<classpathentry kind="lib" path="lib/common/wsdl4j.jar"/>
<classpathentry kind="lib" path="lib/common/gson-2.3.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,11 @@
<td align="center"><html:submit property="methodMap_esporta">
<bean:message key="button.prenota" bundle="esportaLabels" />
</html:submit></td>
<sbn:checkAttivita idControllo="TEMPLATE">
<td align="center"><html:submit property="methodMap_esporta">
<bean:message key="button.scarica.template.conf" bundle="esportaLabels" />
</html:submit></td>
</sbn:checkAttivita>
</tr>

</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ button.cercaspecificazioneA=Specificazione a
button.cercasezione=Sezione
button.cercabiblioteche=CercaBiblioteche
button.tutteLeBiblio=Tutte le biblioteche
button.scarica.template.conf=Scarica template conf.

#intestazione schede
label.schedalistadocarchivio=Prepara&nbsp;lista&nbsp;documenti&nbsp;da&nbsp;Archivio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<class-b>java.io.Serializable</class-b>
</mapping>

<!-- ExportSchedulableBatchVO -->
<mapping bean-factory="it.iccu.sbn.util.cloning.DozerCloneFactory" >
<class-a>it.iccu.sbn.batch.unimarc.ExportSchedulableBatchVO</class-a>
<class-b>java.io.Serializable</class-b>
</mapping>

<!-- StatoPrenotazionePosto -->
<mapping bean-factory="it.iccu.sbn.util.cloning.DozerIdentityFactory" >
<class-a>it.iccu.sbn.ejb.vo.servizi.sale.StatoPrenotazionePosto</class-a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class Configuration {
public static final String SBNWEB_EXPORT_CONFIG_FILE = "SBNWEB_EXPORT_CONFIG_FILE";
public static final String SBNWEB_EXPORT_IGNORE_FILE = "SBNWEB_EXPORT_IGNORE_FILE";
public static final String EXPORT_UNIMARC_FILE_ACCESSORI = "EXPORT_UNIMARC_FILE_ACCESSORI";
public static final String EXPORT_UNIMARC_SAVE_TEMPLATE = "EXPORT_UNIMARC_SAVE_TEMPLATE";

public static final String WS_MAX_CONCURRENT_CLIENTS = "WS_MAX_CONCURRENT_CLIENTS";

Expand Down
2 changes: 2 additions & 0 deletions SbnWebCommon/src/vo/it/iccu/sbn/util/config/sbnweb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ EXPORT_UNIMARC_FILE_ACCESSORI=BID-Classificazioni_SBW.txt;CategorieDiFruizione_S
#file che contiene il nr. richiesta dell'ultimo export elaborato
EXPORT_UNIMARC_FILE_ULTIMO_ID=ultimo_exp.txt

EXPORT_UNIMARC_SAVE_TEMPLATE=false

#webservice max clients
WS_MAX_CONCURRENT_CLIENTS=10

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*******************************************************************************
* Copyright (C) 2019 ICCU - Istituto Centrale per il Catalogo Unico
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package it.iccu.sbn.batch.unimarc;

import it.iccu.sbn.ejb.utils.ValidazioneDati;
import it.iccu.sbn.ejb.vo.common.CodiciType;
import it.iccu.sbn.ejb.vo.common.CodiciType.CodiciRicercaType;
import it.iccu.sbn.ejb.vo.common.TB_CODICI;
import it.iccu.sbn.ejb.vo.elaborazioniDifferite.esporta.EsportaVO;
import it.iccu.sbn.servizi.batch.SchedulableBatchVO;
import it.iccu.sbn.servizi.codici.CodiciProvider;
import it.iccu.sbn.util.cloning.ClonePool;
import it.iccu.sbn.util.file.FileUtil;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.StringUtils;

public class ExportSchedulableBatchVO extends SchedulableBatchVO {

private static final long serialVersionUID = -2883771863550034442L;

public ExportSchedulableBatchVO(SchedulableBatchVO sb) {
super(sb.getConfig());
}

public String getTipoScarico() throws Exception {
String cd_flg11 = trimOrEmpty(config.getCd_flg11());
String[] tokens = cd_flg11.split("\\|");
//il flag11 contiene sia il cod.scarico che l'elenco delle biblioteche, viene gestito il codice solo in prima
//posizione
if (tokens.length > 2)
return null;

String tipoScarico = tokens[0].trim().toUpperCase();
TB_CODICI cod = CodiciProvider.cercaCodice(tipoScarico, CodiciType.CODICE_TIPO_ESTRAZIONE_UNIMARC,
CodiciRicercaType.RICERCA_CODICE_SBN, true);

return (cod != null) ? tipoScarico : null;
}

public List<String> getBiblioteche() throws Exception {
Set<String> biblioteche = new HashSet<String>();
String cd_flg11 = trimOrEmpty(config.getCd_flg11());

//il flag11 contiene sia il cod.scarico che l'elenco delle biblioteche,
//le biblioteche sono gestite solo in seconda posizione
if (isFilled(getTipoScarico()) ) {
String[] tokens = cd_flg11.split("\\|");
if (tokens.length != 2) //non ci sono biblioteche
return Collections.emptyList();

cd_flg11 = tokens[1]; //biblioteche nel secondo blocco
} else
//almaviva5_20170712 #6439 eliminazione delimitatore
cd_flg11 = StringUtils.stripStart(cd_flg11, "|");

for (String token : cd_flg11.split(",|;")) {
token = token.trim();
if (token.length() != 2) //cod.bib senza spazio
continue;

biblioteche.add(ValidazioneDati.fillLeft(token.toUpperCase(), ' ', 3));
}

return new ArrayList<String>(biblioteche);
}

public EsportaVO getTemplate() {
EsportaVO esportaVO = null;
String cd_flg11 = trimOrEmpty(config.getCd_flg11());
if (cd_flg11.startsWith("template=")) {
final String filename = cd_flg11.substring("template=".length());
File f = new File(filename);
if (f.exists()) {
try {
String template = FileUtil.streamToString(new FileInputStream(f));
esportaVO = ClonePool.fromJson(template, EsportaVO.class);
} catch (Exception e) {
e.printStackTrace();
}
}
}

return esportaVO;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class ExportUnimarcBatch extends ExternalBatchExecutor implements Schedul
private static final String TAGS_FILE = "tagsToExport.txt";

protected static final String PROPS_FILE = "db_extract.properties";
protected static final String LATEST_EXPORT_ID_FILE = "export.latest";

private AmministrazioneBiblioteca amministrazioneBiblioteca;

Expand Down Expand Up @@ -108,7 +109,7 @@ private AmministrazioneGestioneCodici getCodici() throws Exception {

protected AtomicBoolean status_ok = new AtomicBoolean(false);
protected Logger _log;
private Timestamp tsLastDBExtraction;
private Timestamp tsExportStart;
private UserTransaction tx;

public static final long getDbLastExtractionTime() {
Expand Down Expand Up @@ -151,6 +152,9 @@ public ElaborazioniDifferiteOutputVo execute(String prefissoOutput,
if (ValidazioneDati.isFilled(richiesta.getAteneo()))
status_ok.set( impostaFiltroAteneo(richiesta) );

//almaviva5_20130326 evolutive LO1
this.tsExportStart = DaoManager.now();

// estrazione totale del DB
//almaviva5_20111027 estrazione db solo per unimarc
if (isEsporta && status_ok.get() && richiesta.isExportDB()) {
Expand Down Expand Up @@ -270,6 +274,7 @@ public ElaborazioniDifferiteOutputVo execute(String prefissoOutput,

if (status_ok.get())
output.addDownload(zipFile, mrcPath + File.separator + zipFile);

}

if (status_ok.get()) {
Expand Down Expand Up @@ -469,12 +474,9 @@ protected int execFase1_estrazioneDB(BatchLogWriter log) throws Exception {

try {
_log.debug("execFase1_estrazioneDB()");
long startTime = 0;//System.currentTimeMillis();
long startTime = 0;
status_ok.set(false);

//almaviva5_20130326 evolutive LO1
tsLastDBExtraction = DaoManager.now();

String exportHome = getExportHome();
int exit = exec(log, exportHome, exportHome + File.separator + "export.sh");

Expand Down Expand Up @@ -553,12 +555,20 @@ public static void main (String[] args) {
}

public ParametriRichiestaElaborazioneDifferitaVO buildActivationParameters(
SchedulableBatchVO params, Serializable... otherParams)
SchedulableBatchVO sb, Serializable... otherParams)
throws Exception {

_log = Logger.getLogger(ExportUnimarcBatch.class);

EsportaVO esporta = new EsportaVO();
ExportSchedulableBatchVO params = new ExportSchedulableBatchVO(sb);

EsportaVO template = params.getTemplate();
boolean withTemplate = (template != null);
if (withTemplate) {
_log.debug("export json template: " + sb.getConfig().getCd_flg11());
}

EsportaVO esporta = withTemplate ? template : new EsportaVO();
esporta.setPayload(params);

String userId = params.getUser();
Expand All @@ -570,42 +580,42 @@ public ParametriRichiestaElaborazioneDifferitaVO buildActivationParameters(
esporta.setCodPolo(codPolo);
esporta.setCodBib(codBib);
esporta.setUser(user);
String ticket = SbnSIP2Ticket.getUtenteTicket(codPolo, codBib, user, InetAddress.getLocalHost());
esporta.setTicket(ticket);
esporta.setTicket(SbnSIP2Ticket.getUtenteTicket(codPolo, codBib, user, InetAddress.getLocalHost()));

esporta.setCodAttivita(CodiciAttivita.getIstance().ESPORTA_DOCUMENTI_1040);

esporta.setExportDB(true);
//almaviva5_20131106 segnalazione RML: eliminato filtro su tipo materiale
//esporta.setMateriali(EsportaVO.MATERIALI);
esporta.setMateriali(null);
esporta.setNature(EsportaVO.NATURE);
esporta.setTipoEstrazione(TipoEstrazioneUnimarc.ARCHIVIO);

//almaviva5_20160322 tipo scarico da tabella
String tipoScarico = ValidazioneDati.coalesce(params.getTipoScarico(), "ALL");
_log.debug("tipo scarico unimarc: " + tipoScarico);
esporta.setCodScaricoSelez(tipoScarico);
impostaEtichetteDaEsportare(esporta);

String downloadPath = StampeUtil.getBatchFilesPath();
esporta.setDownloadPath(downloadPath);
esporta.setDownloadPath(StampeUtil.getBatchFilesPath());
esporta.setDownloadLinkPath("/"); // eliminato

//almaviva5_20160308 prepara filtro biblioteche
List<String> biblioteche = params.getBiblioteche();
if (ValidazioneDati.isFilled(biblioteche)) {
_log.debug("preparazione filtro per biblioteca: " + biblioteche);
List<BibliotecaVO> listaBib = new ArrayList<BibliotecaVO>();
for (String cdBib : biblioteche) {
BibliotecaVO bib = DomainEJBFactory.getInstance().getBiblioteca().getBiblioteca(codPolo, cdBib);
if (bib != null)
listaBib.add(bib);
esporta.setCodAttivita(CodiciAttivita.getIstance().ESPORTA_DOCUMENTI_1040);

if (!withTemplate) {
//template mancante: impostazione filtri di default
esporta.setExportDB(true);
//almaviva5_20131106 segnalazione RML: eliminato filtro su tipo materiale
//esporta.setMateriali(EsportaVO.MATERIALI);
esporta.setMateriali(null);
esporta.setNature(EsportaVO.NATURE);
esporta.setTipoEstrazione(TipoEstrazioneUnimarc.ARCHIVIO);

//almaviva5_20160322 tipo scarico da tabella
String tipoScarico = ValidazioneDati.coalesce(params.getTipoScarico(), "ALL");
_log.debug("tipo scarico unimarc: " + tipoScarico);
esporta.setCodScaricoSelez(tipoScarico);
impostaEtichetteDaEsportare(esporta);

//almaviva5_20160308 prepara filtro biblioteche
List<String> biblioteche = params.getBiblioteche();
if (ValidazioneDati.isFilled(biblioteche)) {
_log.debug("preparazione filtro per biblioteca: " + biblioteche);
List<BibliotecaVO> listaBib = new ArrayList<BibliotecaVO>();
for (String cdBib : biblioteche) {
BibliotecaVO bib = DomainEJBFactory.getInstance().getBiblioteca().getBiblioteca(codPolo, cdBib);
if (bib != null)
listaBib.add(bib);
}
esporta.setListaBib(listaBib);
//preparaFileFiltroBiblioteca(esporta);
}
esporta.setListaBib(listaBib);
//preparaFileFiltroBiblioteca(esporta);
}

return esporta;
}

Expand Down Expand Up @@ -641,7 +651,7 @@ public void setEnd(ParametriRichiestaElaborazioneDifferitaVO params, Elaborazion
if (!ValidazioneDati.equals(stato, ConstantsJMS.STATO_OK))
return;

sb.setLatestSuccessfulEnd(tsLastDBExtraction);
sb.setLatestSuccessfulEnd(tsExportStart);

getCodici().salvaTabellaCodici(sb.getConfig(), false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,11 @@
import it.iccu.sbn.ejb.utils.ValidazioneDati;
import it.iccu.sbn.ejb.vo.UniqueIdentifiableVO;
import it.iccu.sbn.ejb.vo.common.CodiciType;
import it.iccu.sbn.ejb.vo.common.CodiciType.CodiciRicercaType;
import it.iccu.sbn.ejb.vo.common.TB_CODICI;
import it.iccu.sbn.servizi.codici.CodiciProvider;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.StringUtils;

/*
* cd_tabella job_name.
Expand All @@ -56,7 +47,7 @@
public class SchedulableBatchVO extends UniqueIdentifiableVO {

private static final long serialVersionUID = -7803792221970476948L;
private final TB_CODICI config;
protected final TB_CODICI config;

public enum ScheduleType {
TIME,
Expand Down Expand Up @@ -148,48 +139,6 @@ public void setParams(String params) {
config.setCd_flg10(params);
}

public String getTipoScarico() throws Exception {
String cd_flg11 = trimOrEmpty(config.getCd_flg11());
String[] tokens = cd_flg11.split("\\|");
//il flag11 contiene sia il cod.scarico che l'elenco delle biblioteche, viene gestito il codice solo in prima
//posizione
if (tokens.length > 2)
return null;

String tipoScarico = tokens[0].trim().toUpperCase();
TB_CODICI cod = CodiciProvider.cercaCodice(tipoScarico, CodiciType.CODICE_TIPO_ESTRAZIONE_UNIMARC,
CodiciRicercaType.RICERCA_CODICE_SBN, true);

return (cod != null) ? tipoScarico : null;
}

public List<String> getBiblioteche() throws Exception {
Set<String> biblioteche = new HashSet<String>();
String cd_flg11 = trimOrEmpty(config.getCd_flg11());

//il flag11 contiene sia il cod.scarico che l'elenco delle biblioteche,
//le biblioteche sono gestite solo in seconda posizione
if (isFilled(getTipoScarico()) ) {
String[] tokens = cd_flg11.split("\\|");
if (tokens.length != 2) //non ci sono biblioteche
return Collections.emptyList();

cd_flg11 = tokens[1]; //biblioteche nel secondo blocco
} else
//almaviva5_20170712 #6439 eliminazione delimitatore
cd_flg11 = StringUtils.stripStart(cd_flg11, "|");

for (String token : cd_flg11.split(",|;")) {
token = token.trim();
if (token.length() != 2) //cod.bib senza spazio
continue;

biblioteche.add(ValidazioneDati.fillLeft(token.toUpperCase(), ' ', 3));
}

return new ArrayList<String>(biblioteche);
}

public boolean isActive() {
Date fineValidita = config.getDt_fine_validita();
return (fineValidita == null || fineValidita.after(creationTime));
Expand Down
Loading

0 comments on commit 8111fdf

Please sign in to comment.