use of org.hisp.dhis.external.location.LocationManagerException in project dhis2-core by dhis2.
the class DefaultDhisConfigurationProvider method loadDhisConf.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private Properties loadDhisConf() throws IllegalStateException {
try (InputStream in = locationManager.getInputStream(CONF_FILENAME)) {
Properties conf = PropertiesLoaderUtils.loadProperties(new InputStreamResource(in));
substituteEnvironmentVariables(conf);
return conf;
} catch (LocationManagerException | IOException | SecurityException ex) {
log.debug(String.format("Could not load %s", CONF_FILENAME), ex);
throw new IllegalStateException("Properties could not be loaded", ex);
}
}
use of org.hisp.dhis.external.location.LocationManagerException in project dhis2-core by dhis2.
the class DefaultDocumentService method deleteDocument.
@Override
public void deleteDocument(Document document) {
// Remove files is !external
if (!document.isExternal()) {
if (document.getFileResource() != null) {
deleteFileFromDocument(document);
log.info("Document " + document.getUrl() + " successfully deleted");
} else {
try {
File file = locationManager.getFileForReading(document.getUrl(), DocumentService.DIR);
if (file.delete()) {
log.info("Document " + document.getUrl() + " successfully deleted");
} else {
log.warn("Document " + document.getUrl() + " could not be deleted");
}
} catch (LocationManagerException ex) {
log.warn("An error occured while deleting " + document.getUrl());
}
}
}
documentStore.delete(document);
}
use of org.hisp.dhis.external.location.LocationManagerException in project dhis2-core by dhis2.
the class StaticContentController method updateStaticContent.
/**
* Uploads PNG images based on a key. Only accepts PNG and white listed keys.
*
* @param key the key.
* @param file the image file.
*/
@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@ResponseStatus(HttpStatus.NO_CONTENT)
@RequestMapping(value = "/{key}", method = RequestMethod.POST)
public void updateStaticContent(@PathVariable("key") String key, @RequestParam(value = "file") MultipartFile file) throws WebMessageException, IOException {
if (file == null || file.isEmpty()) {
throw new WebMessageException(WebMessageUtils.badRequest("Missing parameter 'file'"));
}
// Only PNG is accepted at the current time
MimeType mimeType = MimeTypeUtils.parseMimeType(file.getContentType());
if (!mimeType.isCompatibleWith(MimeTypeUtils.IMAGE_PNG)) {
throw new WebMessageException(new WebMessage(Status.WARNING, HttpStatus.UNSUPPORTED_MEDIA_TYPE));
}
if (!KEY_WHITELIST_MAP.containsKey(key)) {
throw new WebMessageException(WebMessageUtils.badRequest("This key is not supported."));
}
File out = null;
try {
out = locationManager.getFileForWriting(key + ".png", "static");
} catch (LocationManagerException e) {
throw new WebMessageException(WebMessageUtils.error(e.getMessage()));
}
try {
file.transferTo(out);
} catch (IOException e) {
throw new WebMessageException(WebMessageUtils.error("Could not save file."));
}
}
use of org.hisp.dhis.external.location.LocationManagerException in project dhis2-core by dhis2.
the class DefaultSystemService method getFixedSystemInfo.
private SystemInfo getFixedSystemInfo() {
Configuration config = configurationService.getConfiguration();
// ---------------------------------------------------------------------
// Version
// ---------------------------------------------------------------------
SystemInfo info = loadBuildProperties();
// ---------------------------------------------------------------------
// External directory
// ---------------------------------------------------------------------
info.setEnvironmentVariable(locationManager.getEnvironmentVariable());
try {
File directory = locationManager.getExternalDirectory();
info.setExternalDirectory(directory.getAbsolutePath());
} catch (LocationManagerException ex) {
info.setExternalDirectory("Not set");
}
info.setFileStoreProvider(dhisConfig.getProperty(ConfigurationKey.FILESTORE_PROVIDER));
info.setReadOnlyMode(dhisConfig.getProperty(ConfigurationKey.SYSTEM_READ_ONLY_MODE));
info.setNodeId(dhisConfig.getProperty(ConfigurationKey.NODE_ID));
info.setSystemMonitoringUrl(dhisConfig.getProperty(ConfigurationKey.SYSTEM_MONITORING_URL));
info.setSystemId(config.getSystemId());
info.setClusterHostname(dhisConfig.getProperty(ConfigurationKey.CLUSTER_HOSTNAME));
info.setRedisEnabled(dhisConfig.isEnabled(ConfigurationKey.REDIS_ENABLED));
if (info.isRedisEnabled()) {
info.setRedisHostname(dhisConfig.getProperty(ConfigurationKey.REDIS_HOST));
}
// ---------------------------------------------------------------------
// Database
// ---------------------------------------------------------------------
info.setDatabaseInfo(databaseInfo.instance());
info.setReadReplicaCount(Integer.valueOf(dhisConfig.getProperty(ConfigurationKey.ACTIVE_READ_REPLICAS)));
try {
info.setJavaOpts(System.getenv("JAVA_OPTS"));
} catch (SecurityException ex) {
info.setJavaOpts("Unknown");
}
Properties props = System.getProperties();
info.setJavaVersion(props.getProperty("java.version"));
info.setJavaVendor(props.getProperty("java.vendor"));
info.setOsName(props.getProperty("os.name"));
info.setOsArchitecture(props.getProperty("os.arch"));
info.setOsVersion(props.getProperty("os.version"));
info.setMemoryInfo(SystemUtils.getMemoryString());
info.setCpuCores(SystemUtils.getCpuCores());
info.setEncryption(dhisConfig.getEncryptionStatus().isOk());
return info;
}
use of org.hisp.dhis.external.location.LocationManagerException in project dhis2-core by dhis2.
the class JCloudsAppStorageService method getAppResource.
@Override
public Resource getAppResource(App app, String pageName) throws IOException {
if (app == null || !app.getAppStorageSource().equals(AppStorageSource.JCLOUDS)) {
log.warn("Can't look up resource " + pageName + ". The specified app was not found in JClouds storage.");
return null;
}
String key = (app.getFolderName() + ("/" + pageName)).replaceAll("//", "/");
URI uri = getSignedGetContentUri(key);
if (uri == null) {
String filepath = configurationProvider.getProperty(ConfigurationKey.FILESTORE_CONTAINER) + "/" + key;
filepath = filepath.replaceAll("//", "/");
File res;
try {
res = locationManager.getFileForReading(filepath);
} catch (LocationManagerException e) {
return null;
}
if (res.isDirectory()) {
String indexPath = pageName.replaceAll("/+$", "") + "/index.html";
log.info("Resource " + pageName + " (" + filepath + " is a directory, serving " + indexPath);
return getAppResource(app, indexPath);
} else if (res.exists()) {
return new FileSystemResource(res);
} else {
return null;
}
}
return new UrlResource(uri);
}
Aggregations