use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class ResourceManager method addResource.
/**
* Salva una risorsa nel db, indipendentemente dal tipo.
* @param resource La risorsa da salvare.
* @throws ApsSystemException in caso di errore.
*/
@Override
public void addResource(ResourceInterface resource) throws ApsSystemException {
try {
this.generateAndSetResourceId(resource, resource.getId());
this.getResourceDAO().addResource(resource);
} catch (Throwable t) {
logger.error("Error adding resource", t);
throw new ApsSystemException("Error adding resource", t);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class ResourceManager method deleteResource.
/**
* Cancella una risorsa dal db ed i file di ogni istanza dal filesystem.
* @param resource La risorsa da cancellare.
* @throws ApsSystemException in caso di errore nell'accesso al db.
*/
@Override
public void deleteResource(ResourceInterface resource) throws ApsSystemException {
try {
this.getResourceDAO().deleteResource(resource.getId());
resource.deleteResourceInstances();
} catch (Throwable t) {
logger.error("Error deleting resource", t);
throw new ApsSystemException("Error deleting resource", t);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class AbstractMonoInstanceResource method deleteResourceInstances.
@Override
public void deleteResourceInstances() throws ApsSystemException {
try {
if (null == this.getInstance()) {
_logger.debug("Null instance for resource {}", this.getId());
return;
}
String docName = this.getInstance().getFileName();
String subPath = this.getDiskSubFolder() + docName;
this.getStorageManager().deleteFile(subPath, this.isProtectedResource());
} catch (Throwable t) {
_logger.error("Error on deleting resource instances", t);
throw new ApsSystemException("Error on deleting resource instances", t);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class AbstractMultiInstanceResource method deleteResourceInstances.
@Override
public void deleteResourceInstances() throws ApsSystemException {
try {
Collection<ResourceInstance> instances = this.getInstances().values();
Iterator<ResourceInstance> instancesIter = instances.iterator();
while (instancesIter.hasNext()) {
ResourceInstance currentInstance = instancesIter.next();
String fileName = currentInstance.getFileName();
String subPath = this.getDiskSubFolder() + fileName;
this.getStorageManager().deleteFile(subPath, this.isProtectedResource());
}
} catch (Throwable t) {
_logger.error("Error on deleting resource instances", t);
throw new ApsSystemException("Error on deleting resource instances", t);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class AbstractResource method saveTempFile.
protected File saveTempFile(String filename, InputStream is) throws ApsSystemException, IOException {
String tempDir = System.getProperty("java.io.tmpdir");
String filePath = tempDir + File.separator + filename;
FileOutputStream outStream = null;
try {
byte[] buffer = new byte[1024];
int length = -1;
outStream = new FileOutputStream(filePath);
while ((length = is.read(buffer)) != -1) {
outStream.write(buffer, 0, length);
outStream.flush();
}
} catch (Throwable t) {
_logger.error("Error on saving temporary file '{}'", filename, t);
throw new ApsSystemException("Error on saving temporary file", t);
} finally {
if (null != outStream) {
outStream.close();
}
if (null != is) {
is.close();
}
}
return new File(filePath);
}
Aggregations