Search in sources :

Example 21 with ApsSystemException

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);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 22 with ApsSystemException

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);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 23 with ApsSystemException

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);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 24 with ApsSystemException

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);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 25 with ApsSystemException

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);
}
Also used : FileOutputStream(java.io.FileOutputStream) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) File(java.io.File)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)452 ArrayList (java.util.ArrayList)53 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)48 RestServerError (org.entando.entando.aps.system.exception.RestServerError)39 ApsProperties (com.agiletec.aps.util.ApsProperties)26 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)23 HashMap (java.util.HashMap)23 UserDetails (com.agiletec.aps.system.services.user.UserDetails)21 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)21 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)20 Date (java.util.Date)20 StringReader (java.io.StringReader)18 IPage (com.agiletec.aps.system.services.page.IPage)17 List (java.util.List)17 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)16 File (java.io.File)16 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 Widget (com.agiletec.aps.system.services.page.Widget)15 IOException (java.io.IOException)15 Cache (org.springframework.cache.Cache)15