public static void checkImage(Document document) { // Checks the image type if (document != null && !ArrayUtils.contains(ACCEPTED_IMAGE_TYPES, document.getType())) { throw new ImageTypeNotAcceptedException(document.getType(), ACCEPTED_IMAGE_TYPES); } // Checks the image length int size = document != null ? document.getContent().length : 0; if (size > ICON_IMAGE_SIZE_MAX) { throw new ImageFileSizeException(size, ICON_IMAGE_SIZE_MAX); } } }
@Override public <T> T upload(ResponseParser<T> responseParser, String name, Document document, String fileName, String path, Object... parameters) { HttpPost post = new HttpPost(getUrl(path)); // Sets the content post.setEntity( MultipartEntityBuilder.create() .addBinaryBody( name, document.getContent(), ContentType.parse(document.getType()), fileName ) .build() ); // OK return request(post, responseParser); }
@Override public <T> T upload(ResponseParser<T> responseParser, String name, Document document, String fileName, String path, Object... parameters) { HttpPost post = new HttpPost(getUrl(path)); // Sets the content post.setEntity( MultipartEntityBuilder.create() .addBinaryBody( name, document.getContent(), ContentType.parse(document.getType()), fileName ) .build() ); // OK return request(post, responseParser); }
@Override public void setPromotionLevelImage(ID promotionLevelId, Document document) { getNamedParameterJdbcTemplate().update( "UPDATE PROMOTION_LEVELS SET IMAGETYPE = :type, IMAGEBYTES = :content WHERE ID = :id", params("id", promotionLevelId.getValue()) .addValue("type", document != null ? document.getType() : null) .addValue("content", document != null ? document.getContent() : null) ); }
@Override public void setPredefinedValidationStampImage(ID predefinedValidationStampId, Document document) { getNamedParameterJdbcTemplate().update( "UPDATE PREDEFINED_VALIDATION_STAMPS SET IMAGETYPE = :type, IMAGEBYTES = :content WHERE ID = :id", params("id", predefinedValidationStampId.getValue()) .addValue("type", Document.isValid(document) ? document.getType() : null) .addValue("content", Document.isValid(document) ? document.getContent() : null) ); }
@Override public void setValidationStampImage(ID validationStampId, Document document) { getNamedParameterJdbcTemplate().update( "UPDATE VALIDATION_STAMPS SET IMAGETYPE = :type, IMAGEBYTES = :content WHERE ID = :id", params("id", validationStampId.getValue()) .addValue("type", Document.isValid(document) ? document.getType() : null) .addValue("content", Document.isValid(document) ? document.getContent() : null) ); }
@Override public void setPredefinedPromotionLevelImage(ID predefinedPromotionLevelId, Document document) { getNamedParameterJdbcTemplate().update( "UPDATE PREDEFINED_PROMOTION_LEVELS SET IMAGETYPE = :type, IMAGEBYTES = :content WHERE ID = :id", params("id", predefinedPromotionLevelId.getValue()) .addValue("type", Document.isValid(document) ? document.getType() : null) .addValue("content", Document.isValid(document) ? document.getContent() : null) ); }
@Override public void bulkUpdatePromotionLevels(ID promotionLevelId) { // Description & name PromotionLevel promotionLevel = getPromotionLevel(promotionLevelId); String description = promotionLevel.getDescription(); String name = promotionLevel.getName(); // Image Document image = getPromotionLevelImage(promotionLevelId); // Bulk update getNamedParameterJdbcTemplate().update( "UPDATE PROMOTION_LEVELS SET IMAGETYPE = :type, IMAGEBYTES = :content, DESCRIPTION = :description " + "WHERE ID <> :id AND NAME = :name", params("id", promotionLevelId.getValue()) .addValue("name", name) .addValue("description", description) .addValue("type", Document.isValid(image) ? image.getType() : null) .addValue("content", Document.isValid(image) ? image.getContent() : null) ); }
@Override public void bulkUpdateValidationStamps(ID validationStampId) { // Description & name ValidationStamp validationStamp = getValidationStamp(validationStampId); String description = validationStamp.getDescription(); String name = validationStamp.getName(); // Image Document image = getValidationStampImage(validationStampId); // Bulk update getNamedParameterJdbcTemplate().update( "UPDATE VALIDATION_STAMPS SET IMAGETYPE = :type, IMAGEBYTES = :content, DESCRIPTION = :description, " + "DATA_TYPE_ID = :dataTypeId, DATA_TYPE_CONFIG = CAST(:dataTypeConfig AS JSONB) " + "WHERE ID <> :id AND NAME = :name", params("id", validationStampId.getValue()) .addValue("name", name) .addValue("description", description) .addValue("type", Document.isValid(image) ? image.getType() : null) .addValue("content", Document.isValid(image) ? image.getContent() : null) .addValue("dataTypeId", validationStamp.getDataType() != null ? validationStamp.getDataType().getDescriptor().getId() : null) .addValue("dataTypeConfig", validationStamp.getDataType() != null ? writeJson(validationStamp.getDataType().getConfig()) : null) ); }