package pt.utl.ist.scripts.utils; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.documents.GeneratedDocument; import net.sourceforge.fenixedu.domain.documents.GeneratedDocumentType; import net.sourceforge.fenixedu.domain.documents.GeneratedDocumentWithoutSource; import pt.utl.ist.scripts.commons.AtomicScript.AtomicAction; /** * Utility Action to store a {@link GeneratedDocument} from a script. The * operator is assumed {@code null} because script have no information about * who's running them. * * @author Pedro Santos (pmrsa) */ public class StoreGeneratedDocument extends AtomicAction { private final GeneratedDocumentType type; private final String filename; private final byte[] report; private final Person addressee; public StoreGeneratedDocument(GeneratedDocumentType type, String filename, byte[] report, Person addressee) { this.type = type; this.filename = filename; this.report = report; this.addressee = addressee; try { setupDspace(); } catch (IOException e) { throw new RuntimeException(e); } } private void setupDspace() throws IOException { Properties properties; File file = new File("/var/local/fenix/scripts/build.properties"); if (!file.exists()) { file = new File("build.properties"); if (!file.exists()) { file = new File("/build.properties"); } } if (!file.exists()) { throw new Error("build.properties was not found."); } final FileInputStream fileInputStream = new FileInputStream(file); properties = new Properties(); properties.load(fileInputStream); System.setProperty("javax.net.ssl.trustStore", properties.getProperty("dspace.trustStore")); System.setProperty("javax.net.ssl.trust", properties.getProperty("dspace.trustStore.password")); } @Override public void doIt() { new GeneratedDocumentWithoutSource(type, addressee, null, filename, report); } }