Search in sources :

Example 26 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class AttachResource method saveResourceInstances.

@Override
public void saveResourceInstances(ResourceDataBean bean) throws ApsSystemException {
    try {
        String fileName = this.getNewInstanceFileName(bean.getFileName());
        String subPath = this.getDiskSubFolder() + fileName;
        this.getStorageManager().saveFile(subPath, this.isProtectedResource(), bean.getInputStream());
        ResourceInstance instance = new ResourceInstance();
        instance.setSize(0);
        instance.setFileName(fileName);
        String mimeType = bean.getMimeType();
        instance.setMimeType(mimeType);
        instance.setFileLength(bean.getFileSize() + " Kb");
        this.addInstance(instance);
    } catch (Throwable t) {
        _logger.error("Error on saving attach resource instances", t);
        throw new ApsSystemException("Error on saving attach resource instances", t);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 27 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class AbstractImageResizer method saveResizedImage.

@Override
public ResourceInstance saveResizedImage(String subPath, boolean isProtectedResource, ImageIcon imageIcon, ImageResourceDimension dimension) throws ApsSystemException {
    ResourceInstance resizedInstance = new ResourceInstance();
    resizedInstance.setSize(dimension.getIdDim());
    BufferedImage outImage = this.getResizedImage(imageIcon, dimension.getDimx(), dimension.getDimy());
    String filename = subPath.substring(subPath.lastIndexOf("/") + 1);
    resizedInstance.setFileName(filename);
    String tempFilePath = System.getProperty("java.io.tmpdir") + File.separator + "temp_" + filename;
    try {
        File tempFile = new File(tempFilePath);
        ImageIO.write(outImage, this.getFileExtension(tempFilePath), tempFile);
        this.getStorageManager().saveFile(subPath, isProtectedResource, new FileInputStream(tempFile));
        // resizedInstance.setMimeType(bean.getMimeType());
        long realLength = tempFile.length() / 1000;
        resizedInstance.setFileLength(String.valueOf(realLength) + " Kb");
        tempFile.delete();
    } catch (Throwable t) {
        _logger.error("Error creating resized Image", t);
        String msg = "Error creating resigned Image";
        // ApsSystemUtils.logThrowable(t, this, "saveImageResized", msg);
        throw new ApsSystemException(msg, t);
    }
    String mimeType = URLConnection.guessContentTypeFromName(filename);
    resizedInstance.setMimeType(mimeType);
    return resizedInstance;
}
Also used : ResourceInstance(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) FileInputStream(java.io.FileInputStream)

Example 28 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class DefaultImageResizer method saveResizedImage.

@Override
@Deprecated
public void saveResizedImage(ImageIcon imageIcon, String filePath, ImageResourceDimension dimension) throws ApsSystemException {
    BufferedImage outImage = this.getResizedImage(imageIcon, dimension.getDimx(), dimension.getDimy());
    try {
        File file = new File(filePath);
        ImageIO.write(outImage, this.getFileExtension(filePath), file);
    } catch (Throwable t) {
        _logger.error("Error creating resized Image", t);
        // ApsSystemUtils.logThrowable(t, this, "saveImageResized", msg);
        throw new ApsSystemException("Error creating resized Image", t);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 29 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class PNGImageResizer method hasAlpha.

protected boolean hasAlpha(Image image) throws ApsSystemException {
    // If buffered image, the color model is readily available
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage) image;
        return bimage.getColorModel().hasAlpha();
    }
    // Use a pixel grabber to retrieve the image's color model;
    // grabbing a single pixel is usually sufficient
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        throw new ApsSystemException("Error grabbing a single pixel", e);
    }
    // Get the image's color model
    ColorModel cm = pg.getColorModel();
    return cm.hasAlpha();
}
Also used : ColorModel(java.awt.image.ColorModel) PixelGrabber(java.awt.image.PixelGrabber) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BufferedImage(java.awt.image.BufferedImage)

Example 30 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class IndexerDAO method add.

@Override
public synchronized void add(IApsEntity entity) throws ApsSystemException {
    IndexWriter writer = null;
    try {
        writer = new IndexWriter(this._dir, this.getIndexWriterConfig());
        Document document = this.createDocument(entity);
        writer.addDocument(document);
    } catch (Throwable t) {
        _logger.error("Errore saving entity {}", entity.getId(), t);
        throw new ApsSystemException("Error saving entity", t);
    } finally {
        if (null != writer) {
            try {
                writer.close();
            } catch (IOException ex) {
                _logger.error("Error closing IndexWriter", ex);
            }
        }
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IOException(java.io.IOException) Document(org.apache.lucene.document.Document)

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