use of de.sub.goobi.config.ConfigurationHelper in project goobi-workflow by intranda.
the class MetadatenImagesHelper method scaleFile.
/**
* scale given image file to png using internal embedded content server
*
* @throws ImageManagerException
* @throws IOException
* @throws ImageManipulatorException
*/
public void scaleFile(String inFileName, String outFileName, int inSize, int intRotation) throws ContentLibException, IOException, ImageManipulatorException {
ConfigurationHelper conf = ConfigurationHelper.getInstance();
Path inPath = Paths.get(inFileName);
URI s3URI = null;
try {
s3URI = new URI("s3://" + conf.getS3Bucket() + "/" + S3FileUtils.path2Key(inPath));
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
log.error(e);
}
log.trace("start scaleFile");
int tmpSize = inSize;
if (tmpSize < 1) {
tmpSize = 1;
}
log.trace("Scale to " + tmpSize + "%");
if (ConfigurationHelper.getInstance().getContentServerUrl() == null) {
log.trace("api");
ImageManager im = null;
JpegInterpreter pi = null;
try {
im = conf.useS3() ? new ImageManager(s3URI) : new ImageManager(inPath.toUri());
// im = new ImageManager(Paths.get(inFileName).toUri());
log.trace("im");
ImageInterpreter ii = im.getMyInterpreter();
Dimension inputResolution = new Dimension((int) ii.getXResolution(), (int) ii.getYResolution());
log.trace("input resolution: " + inputResolution.width + "x" + inputResolution.height + "dpi");
Dimension outputResolution = new Dimension(144, 144);
log.trace("output resolution: " + outputResolution.width + "x" + outputResolution.height + "dpi");
Dimension dim = new Dimension(tmpSize * outputResolution.width / inputResolution.width, tmpSize * outputResolution.height / inputResolution.height);
log.trace("Absolute scale: " + dim.width + "x" + dim.height + "%");
RenderedImage ri = im.scaleImageByPixel(dim, ImageManager.SCALE_BY_PERCENT, intRotation);
log.trace("ri");
pi = new JpegInterpreter(ri);
log.trace("pi");
pi.setXResolution(outputResolution.width);
log.trace("xres = " + pi.getXResolution());
pi.setYResolution(outputResolution.height);
log.trace("yres = " + pi.getYResolution());
FileOutputStream outputFileStream = new FileOutputStream(outFileName);
log.trace("output");
pi.writeToStream(null, outputFileStream);
log.trace("write stream");
outputFileStream.close();
log.trace("close stream");
} finally {
if (im != null) {
im.close();
}
if (pi != null) {
pi.close();
}
}
} else {
String imageURIString = conf.useS3() ? s3URI.toString() : inFileName;
String cs = conf.getContentServerUrl() + imageURIString + "&scale=" + tmpSize + "&rotate=" + intRotation + "&format=jpg";
cs = cs.replace("\\", "/");
log.trace("url: " + cs);
URL csUrl = new URL(cs);
CloseableHttpClient httpclient = null;
HttpGet method = null;
InputStream istr = null;
OutputStream fos = null;
try {
httpclient = HttpClientBuilder.create().build();
method = new HttpGet(csUrl.toString());
log.trace("get");
Integer contentServerTimeOut = ConfigurationHelper.getInstance().getGoobiContentServerTimeOut();
Builder builder = RequestConfig.custom();
builder.setSocketTimeout(contentServerTimeOut);
RequestConfig rc = builder.build();
method.setConfig(rc);
byte[] response = httpclient.execute(method, HttpClientHelper.byteArrayResponseHandler);
if (response == null) {
log.error("Response stream is null");
return;
}
istr = new ByteArrayInputStream(response);
fos = new FileOutputStream(outFileName);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = istr.read(buf)) > 0) {
fos.write(buf, 0, len);
}
} catch (Exception e) {
log.error("Unable to connect to url " + cs, e);
return;
} finally {
method.releaseConnection();
if (httpclient != null) {
httpclient.close();
}
if (istr != null) {
try {
istr.close();
} catch (IOException e) {
log.error(e);
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
log.error(e);
}
}
}
}
}
use of de.sub.goobi.config.ConfigurationHelper in project goobi-workflow by intranda.
the class ExportMets method writeMetsFile.
// Write the MetsFile to the given path, possibly as .zip file together with the anchor mets file.
//
protected boolean writeMetsFile(Process myProzess, String targetFileName, Fileformat gdzfile, boolean writeLocalFilegroup, boolean addAnchorFile) throws PreferencesException, WriteException, IOException, InterruptedException, SwapException, DAOException, TypeNotAllowedForParentException {
ConfigurationHelper config = ConfigurationHelper.getInstance();
ExportFileformat mm = collectMetadataToSave(myProzess, gdzfile, writeLocalFilegroup, config);
if (mm == null) {
return false;
}
// otherwise
saveFinishedMetadata(myProzess, targetFileName, config, mm, addAnchorFile);
Helper.setMeldung(null, myProzess.getTitel() + ": ", "ExportFinished");
return true;
}
use of de.sub.goobi.config.ConfigurationHelper in project goobi-workflow by intranda.
the class S3FileUtils method createS3Client.
public static AmazonS3 createS3Client() {
AmazonS3 mys3;
ConfigurationHelper conf = ConfigurationHelper.getInstance();
if (conf.useCustomS3()) {
AWSCredentials credentials = new BasicAWSCredentials(conf.getS3AccessKeyID(), conf.getS3SecretAccessKey());
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setSignerOverride("AWSS3V4SignerType");
mys3 = AmazonS3ClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(conf.getS3Endpoint(), Regions.US_EAST_1.name())).withPathStyleAccessEnabled(true).withClientConfiguration(clientConfiguration).withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
} else {
ClientConfiguration cc = new ClientConfiguration().withMaxErrorRetry(ConfigurationHelper.getInstance().getS3ConnectionRetries()).withConnectionTimeout(ConfigurationHelper.getInstance().getS3ConnectionTimeout()).withSocketTimeout(ConfigurationHelper.getInstance().getS3SocketTimeout()).withTcpKeepAlive(true);
mys3 = AmazonS3ClientBuilder.standard().withClientConfiguration(cc).build();
}
return mys3;
}
use of de.sub.goobi.config.ConfigurationHelper in project goobi-workflow by intranda.
the class ShellScript method run.
/**
* The function run() will execute the system command. First, the call sequence is created, including the parameters passed to run(). Then, the
* underlying OS is contacted to run the command. Afterwards, the results are being processed and stored.
*
* The behaviour is slightly different from the legacy callShell2() command, as it returns the error level as reported from the system process.
* Use this to get the old behaviour:
*
* <pre>
* Integer err = scr.run(args);
* if (scr.getStdErr().size() > 0)
* err = ShellScript.ERRORLEVEL_ERROR;
* </pre>
*
* @param args A list of arguments passed to the script. May be null.
* @throws IOException If an I/O error occurs.
* @throws InterruptedException If the current thread is interrupted by another thread while it is waiting, then the wait is ended and an
* InterruptedException is thrown.
*/
public int run(List<String> args) throws IOException, InterruptedException {
List<String> commandLine = new ArrayList<>();
commandLine.add(command);
if (args != null) {
commandLine.addAll(args);
}
Process process = null;
try {
String[] callSequence = commandLine.toArray(new String[commandLine.size()]);
ProcessBuilder pb = new ProcessBuilder(callSequence);
// If we call another java process with JDK_JAVA_OPTIONS set, we will get a message on stderr
// which in turn will make Goobi think this process failed. For this reason,
// JDK_JAVA_OPTIONS is unset here.
pb.environment().remove("JDK_JAVA_OPTIONS");
ConfigurationHelper config = ConfigurationHelper.getInstance();
if (config.useCustomS3()) {
pb.environment().put("CUSTOM_S3", "true");
pb.environment().put("S3_ENDPOINT_URL", config.getS3Endpoint());
pb.environment().put("S3_ACCESSKEYID", config.getS3AccessKeyID());
pb.environment().put("S3_SECRETACCESSKEY", config.getS3SecretAccessKey());
}
process = pb.start();
InputStream stdOut = process.getInputStream();
InputStream stdErr = process.getErrorStream();
FutureTask<LinkedList<String>> stdOutFuture = new FutureTask<LinkedList<String>>(() -> inputStreamToLinkedList(stdOut));
Thread stdoutThread = new Thread(stdOutFuture);
stdoutThread.setDaemon(true);
stdoutThread.start();
FutureTask<LinkedList<String>> stdErrFuture = new FutureTask<LinkedList<String>>(() -> inputStreamToLinkedList(stdErr));
Thread stderrThread = new Thread(stdErrFuture);
stderrThread.setDaemon(true);
stderrThread.start();
outputChannel = stdOutFuture.get();
errorChannel = stdErrFuture.get();
} catch (IOException | ExecutionException error) {
throw new IOException(error.getMessage());
} finally {
if (process != null) {
closeStream(process.getInputStream());
closeStream(process.getOutputStream());
closeStream(process.getErrorStream());
}
}
errorLevel = process.waitFor();
return errorLevel;
}
use of de.sub.goobi.config.ConfigurationHelper in project goobi-workflow by intranda.
the class ExternalConnectionFactory method createQueues.
private static void createQueues(SQSConnection connection) throws JMSException {
ConfigurationHelper config = ConfigurationHelper.getInstance();
AmazonSQSMessagingClientWrapper sqsClient = connection.getWrappedAmazonSQSClient();
// we need to explicitly create the queues in SQS
if (!sqsClient.queueExists(config.getQueueName(QueueType.COMMAND_QUEUE))) {
createFifoQueue(sqsClient, config.getQueueName(QueueType.COMMAND_QUEUE));
}
if (!sqsClient.queueExists(config.getQueueName(QueueType.EXTERNAL_QUEUE))) {
createFifoQueue(sqsClient, config.getQueueName(QueueType.EXTERNAL_QUEUE));
}
}
Aggregations