Gestito TypeAttach come enum in StbFilesAttached, creata api getSignatureIdAttach ed impostato header ContentDisposition da spring
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good

This commit is contained in:
2025-02-13 10:51:56 +01:00
parent 1e5a4641d3
commit 3270fbf052
11 changed files with 152 additions and 34 deletions

View File

@@ -15,7 +15,7 @@ import org.kie.api.definition.type.PropertyReactive;
public class ${NAME} extends EntityBase { public class ${NAME} extends EntityBase {
public static final String ENTITY = "${TABLE}"; public static final String ENTITY = "${TABLE}";
private final static Logger logger = LogManager.getLogger(); private static final Logger logger = LogManager.getLogger();
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@@ -14,7 +14,7 @@ import org.kie.api.definition.type.PropertyReactive;
public class ${NAME} extends EntityBase { public class ${NAME} extends EntityBase {
public static final String ENTITY = "${TABLE}"; public static final String ENTITY = "${TABLE}";
private final static Logger logger = LogManager.getLogger(); private static final Logger logger = LogManager.getLogger();
public ${NAME}() { public ${NAME}() {
super(logger); super(logger);

View File

@@ -48,6 +48,8 @@ import org.quartz.*;
import org.quartz.impl.matchers.GroupMatcher; import org.quartz.impl.matchers.GroupMatcher;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.http.ContentDisposition;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.mail.javamail.ConfigurableMimeFileTypeMap; import org.springframework.mail.javamail.ConfigurableMimeFileTypeMap;
@@ -746,11 +748,11 @@ public class EmsController {
@RequestMapping(value = EmsRestConstants.PATH_DOWNLOAD_STB_FILE_ATTACHMENT + "/{idAttach}/{filename}", method = RequestMethod.GET) @RequestMapping(value = EmsRestConstants.PATH_DOWNLOAD_STB_FILE_ATTACHMENT + "/{idAttach}/{filename}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<byte[]> downloadStbFileAttachment( public ResponseEntity<byte[]> downloadStbFileAttachment(
@RequestParam(CommonConstants.PROFILE_DB) String config, @RequestParam(CommonConstants.PROFILE_DB) String config,
@PathVariable String idAttach, @PathVariable String idAttach,
@PathVariable String filename, @PathVariable String filename,
@RequestParam(name = "contentDisposition", defaultValue = "attachment") String contentDispositionType,
@RequestParam(defaultValue = "false") boolean requestThumbnail) throws Exception { @RequestParam(defaultValue = "false") boolean requestThumbnail) throws Exception {
AttachmentDTO attachmentDTO = emsServices.downloadStbFileAttachment(idAttach, requestThumbnail); AttachmentDTO attachmentDTO = emsServices.downloadStbFileAttachment(idAttach, requestThumbnail);
@@ -758,7 +760,11 @@ public class EmsController {
return ResponseEntity.ok() return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(attachmentDTO.getMimeType())) .contentType(MediaType.parseMediaType(attachmentDTO.getMimeType()))
.contentLength(attachmentDTO.getFileSize()) .contentLength(attachmentDTO.getFileSize())
.header("Content-Disposition", "attachment; filename=\"" + attachmentDTO.getFileName() + "\"") .header(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition
.builder(contentDispositionType)
.filename(attachmentDTO.getFileName())
.build()
.toString())
.body(attachmentDTO.getFileContent()); .body(attachmentDTO.getFileContent());
} }
@@ -777,7 +783,11 @@ public class EmsController {
return ResponseEntity.ok() return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(attachmentDTO.getMimeType())) .contentType(MediaType.parseMediaType(attachmentDTO.getMimeType()))
.contentLength(attachmentDTO.getFileSize()) .contentLength(attachmentDTO.getFileSize())
.header("Content-Disposition", "attachment; filename=\"" + attachmentDTO.getFileName() + "\"") .header(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition
.attachment()
.filename(attachmentDTO.getFileName())
.build()
.toString())
.body(attachmentDTO.getFileContent()); .body(attachmentDTO.getFileContent());
} }
@@ -798,7 +808,7 @@ public class EmsController {
if (stbEmailContent != null) { if (stbEmailContent != null) {
response.setContentType("application/octet-stream"); response.setContentType("application/octet-stream");
response.setStatus(HttpServletResponse.SC_OK); response.setStatus(HttpServletResponse.SC_OK);
response.addHeader("Content-Disposition", "attachment; filename=\"email.eml\""); response.addHeader(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.attachment().filename("email.eml").build().toString());
byte[] byteArr = null; byte[] byteArr = null;
@@ -845,7 +855,7 @@ public class EmsController {
if (dtbDocPdf != null) { if (dtbDocPdf != null) {
response.setContentType("application/octet-stream"); response.setContentType("application/octet-stream");
response.setStatus(HttpServletResponse.SC_OK); response.setStatus(HttpServletResponse.SC_OK);
response.addHeader("Content-Disposition", "attachment; filename=\"" + dtbDocPdf.getFilename() + "\""); response.addHeader(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.attachment().filename(dtbDocPdf.getFilename()).build().toString());
byte[] byteArr = null; byte[] byteArr = null;
@@ -890,7 +900,7 @@ public class EmsController {
if (dtbOrdPdf != null) { if (dtbOrdPdf != null) {
response.setContentType("application/octet-stream"); response.setContentType("application/octet-stream");
response.setStatus(HttpServletResponse.SC_OK); response.setStatus(HttpServletResponse.SC_OK);
response.addHeader("Content-Disposition", "attachment; filename=\"" + dtbOrdPdf.getFilename() + "\""); response.addHeader(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.attachment().filename(dtbOrdPdf.getFilename()).build().toString());
byte[] byteArr = dtbOrdPdf.getFilecontentByteArr(true); byte[] byteArr = dtbOrdPdf.getFilecontentByteArr(true);
response.setContentLength(byteArr != null ? byteArr.length : 0); response.setContentLength(byteArr != null ? byteArr.length : 0);
@@ -902,11 +912,10 @@ public class EmsController {
} }
@RequestMapping(value = EmsRestConstants.PATH_UPLOAD_STB_FILE_ATTACHMENT, method = RequestMethod.POST) @RequestMapping(value = EmsRestConstants.PATH_UPLOAD_STB_FILE_ATTACHMENT, method = RequestMethod.POST)
public ServiceRestResponse uploadStbFileAttachment(HttpServletRequest request, HttpServletResponse response, public ServiceRestResponse uploadStbFileAttachment(@RequestParam(CommonConstants.PROFILE_DB) String config,
@RequestParam(CommonConstants.PROFILE_DB) String config,
@RequestParam(required = false) String idAttach, @RequestParam(required = false) String idAttach,
@RequestParam(required = false) String descrizione, @RequestParam(required = false) String descrizione,
@RequestParam(required = false) String typeAttach, @RequestParam(required = false) StbFilesAttached.TypeAttach typeAttach,
@RequestPart() MultipartFile[] files @RequestPart() MultipartFile[] files
) { ) {
try { try {
@@ -926,11 +935,7 @@ public class EmsController {
stbFilesAttached.setOnlyPkMaster(false); stbFilesAttached.setOnlyPkMaster(false);
ServiceRestResponse serviceRestResponse = ServiceRestResponse.createPositiveResponse(); return ServiceRestResponse.createEntityPositiveResponse(stbFilesAttached);
serviceRestResponse.setEntity(stbFilesAttached);
return serviceRestResponse;
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return new ServiceRestResponse(EsitoType.KO, config, e); return new ServiceRestResponse(EsitoType.KO, config, e);

View File

@@ -81,8 +81,10 @@ public abstract class BaseMigration implements MigrationModelInterface {
protected void executeStatement(Connection connection, String... sqls) throws SQLException { protected void executeStatement(Connection connection, String... sqls) throws SQLException {
try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
for (String sql : sqls) { for (String sql : sqls) {
statement.execute(sql); statement.addBatch(sql);
} }
statement.executeBatch();
} }
} }

View File

@@ -0,0 +1,22 @@
package it.integry.ems.migration.model;
import it.integry.ems.migration._base.BaseMigration;
import it.integry.ems.migration._base.MigrationModelInterface;
public class Migration_20250211104843 extends BaseMigration implements MigrationModelInterface {
@Override
public void up() throws Exception {
if (isHistoryDB())
return;
executeStatement(
"ALTER TABLE stb_files_attached\n" +
" ALTER COLUMN type_attach VARCHAR(2) NULL"
);
}
@Override
public void down() throws Exception {
}
}

View File

@@ -510,7 +510,7 @@ public class EmsServices {
@Nonnull byte[] fileContent, @Nonnull byte[] fileContent,
@Nullable String descrizione, @Nullable String descrizione,
@Nullable String mimeType, @Nullable String mimeType,
@Nullable String typeAttach, @Nullable StbFilesAttached.TypeAttach typeAttach,
@Nullable MrlPartitaMagAttached mrlPartitaMagAttached, @Nullable MrlPartitaMagAttached mrlPartitaMagAttached,
@Nullable Date datetimeAttach) throws Exception { @Nullable Date datetimeAttach) throws Exception {

View File

@@ -62,4 +62,11 @@ public class UserController {
return ServiceRestResponse.createPositiveResponse(userService.retrieveAvailableProfiles(username, password)); return ServiceRestResponse.createPositiveResponse(userService.retrieveAvailableProfiles(username, password));
} }
@GetMapping(value = "{username}/getSignatureIdAttach")
public ServiceRestResponse getSignatureIdAttach(@PathVariable String username) throws Exception {
String idAttach = userService.getSignatureIdAttach(username);
return ServiceRestResponse.createPositiveResponse(idAttach);
}
} }

View File

@@ -2,7 +2,9 @@ package it.integry.ems.user.service;
import it.integry.ems.exception.PrimaryDatabaseNotPresentException; import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
import it.integry.ems.javabeans.RequestDataDTO; import it.integry.ems.javabeans.RequestDataDTO;
import it.integry.ems.service.EmsServices;
import it.integry.ems.service.EntityProcessor; import it.integry.ems.service.EntityProcessor;
import it.integry.ems.service.dto.AttachmentDTO;
import it.integry.ems.settings.Model.SettingsModel; import it.integry.ems.settings.Model.SettingsModel;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager; import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems.user.UtilityUser; import it.integry.ems.user.UtilityUser;
@@ -10,6 +12,7 @@ import it.integry.ems.user.dto.ChangePasswordDTO;
import it.integry.ems.utility.UtilityDebug; import it.integry.ems.utility.UtilityDebug;
import it.integry.ems.utility.UtilityEntity; import it.integry.ems.utility.UtilityEntity;
import it.integry.ems_model.config.EmsRestConstants; import it.integry.ems_model.config.EmsRestConstants;
import it.integry.ems_model.entity.StbFilesAttached;
import it.integry.ems_model.entity.StbUser; import it.integry.ems_model.entity.StbUser;
import it.integry.ems_model.types.OperationType; import it.integry.ems_model.types.OperationType;
import it.integry.ems_model.utility.Query; import it.integry.ems_model.utility.Query;
@@ -18,6 +21,10 @@ import it.integry.ems_model.utility.UtilityDate;
import it.integry.ems_model.utility.UtilityString; import it.integry.ems_model.utility.UtilityString;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.http.ContentDisposition;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
@@ -41,7 +48,7 @@ public class UserService {
private UserCacheService userCacheService; private UserCacheService userCacheService;
@Autowired @Autowired
private SettingsModel settingsModel; private EmsServices emsServices;
public StbUser save(StbUser stbUser) throws Exception { public StbUser save(StbUser stbUser) throws Exception {
String sql = String sql =
@@ -118,4 +125,22 @@ public class UserService {
return profiles; return profiles;
} }
public String getSignatureIdAttach(String username) throws Exception {
if (UtilityString.isNullOrEmpty(username)) {
throw new IllegalArgumentException("Username cannot be null or empty");
}
String sql = Query.format(
"SELECT sfa.id_attach\n" +
"FROM srl_user_attached sua\n" +
" INNER JOIN dbo.stb_files_attached sfa ON sua.id_attach = sfa.id_attach\n" +
" AND sfa.type_attach = %s\n" +
"WHERE sua.user_name = %s",
StbFilesAttached.TypeAttach.FIRMA.getValue(),
username
);
return UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
}
} }

View File

@@ -7,30 +7,26 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.kie.api.definition.type.PropertyReactive; import org.kie.api.definition.type.PropertyReactive;
@Master() @PropertyReactive
@PropertyReactive()
@Table(value = SrlUserAttached.ENTITY) @Table(value = SrlUserAttached.ENTITY)
@JsonTypeName(value = SrlUserAttached.ENTITY) @JsonTypeName(value = SrlUserAttached.ENTITY)
public class SrlUserAttached extends EntityBase { public class SrlUserAttached extends EntityBase {
public static final String ENTITY = "srl_user_attached";
public final static String ENTITY = "srl_user_attached"; private static final Logger logger = LogManager.getLogger();
private final static Long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final static Logger logger = LogManager.getLogger();
public SrlUserAttached() { public SrlUserAttached() {
super(logger); super(logger);
} }
@PK() @PK
@SqlField(value = "user_name", maxLength = 40, nullable = false) @SqlField(value = "user_name", maxLength = 40, nullable = false)
@FK(tableName = StbUser.ENTITY, columnName = "user_name")
private String userName; private String userName;
@PK() @PK
@SqlField(value = "id_attach", maxLength = 40, nullable = false) @SqlField(value = "id_attach", maxLength = 40, nullable = false)
@FK(tableName = StbFilesAttached.ENTITY, columnName = "id_attach")
private String idAttach; private String idAttach;
public String getUserName() { public String getUserName() {

View File

@@ -1,10 +1,13 @@
package it.integry.ems_model.entity; package it.integry.ems_model.entity;
import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import it.integry.ems_model.annotation.*; import it.integry.ems_model.annotation.*;
import it.integry.ems_model.base.EntityBase; import it.integry.ems_model.base.EntityBase;
import it.integry.ems_model.entity._enum.IBaseEnum;
import it.integry.ems_model.utility.UtilityDB; import it.integry.ems_model.utility.UtilityDB;
import org.kie.api.definition.type.PropertyReactive; import org.kie.api.definition.type.PropertyReactive;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
@@ -48,8 +51,8 @@ public class StbFilesAttached extends EntityBase {
@SqlField(value = "file_size") @SqlField(value = "file_size")
private BigDecimal fileSize; private BigDecimal fileSize;
@SqlField(value = "type_attach", maxLength = 40) @SqlField(value = "type_attach", maxLength = 2)
private String typeAttach; private TypeAttach typeAttach;
@SqlField(value = "parent_id_attach", maxLength = 40) @SqlField(value = "parent_id_attach", maxLength = 40)
private String parentIdAttach; private String parentIdAttach;
@@ -105,6 +108,9 @@ public class StbFilesAttached extends EntityBase {
@EntityChild(copyPk = false) @EntityChild(copyPk = false)
private CtbAmacHistory ctbAmacHistory; private CtbAmacHistory ctbAmacHistory;
@EntityChild
private SrlUserAttached srlUserAttached;
public StbFilesAttached() { public StbFilesAttached() {
super(logger); super(logger);
} }
@@ -181,11 +187,11 @@ public class StbFilesAttached extends EntityBase {
return this; return this;
} }
public String getTypeAttach() { public TypeAttach getTypeAttach() {
return typeAttach; return typeAttach;
} }
public StbFilesAttached setTypeAttach(String typeAttach) { public StbFilesAttached setTypeAttach(TypeAttach typeAttach) {
this.typeAttach = typeAttach; this.typeAttach = typeAttach;
return this; return this;
} }
@@ -343,6 +349,15 @@ public class StbFilesAttached extends EntityBase {
return this; return this;
} }
public SrlUserAttached getSrlUserAttached() {
return srlUserAttached;
}
public StbFilesAttached setSrlUserAttached(SrlUserAttached srlUserAttached) {
this.srlUserAttached = srlUserAttached;
return this;
}
public String getRefUuid() { public String getRefUuid() {
return refUuid; return refUuid;
} }
@@ -373,5 +388,51 @@ public class StbFilesAttached extends EntityBase {
WtbNotificationImage wtbNotificationImage = new WtbNotificationImage(); WtbNotificationImage wtbNotificationImage = new WtbNotificationImage();
String whereCond = "attach_id = " + UtilityDB.valueToString(idAttach); String whereCond = "attach_id = " + UtilityDB.valueToString(idAttach);
wtbNotificationImage.deleteAllEntities(connection, whereCond); wtbNotificationImage.deleteAllEntities(connection, whereCond);
SrlUserAttached srlUserAttached = new SrlUserAttached();
srlUserAttached.deleteAllEntities(connection, this);
}
public enum TypeAttach implements IBaseEnum<TypeAttach> {
NESSUNO(null),
FATTURA_PASSIVA("FP"),
SCHEDA_TECNICA("ST"),
FIRMA("FI");
private final String value;
TypeAttach(final String value) {
this.value = value;
}
public static TypeAttach from(Object value) {
String castValue = (String) value;
for (TypeAttach b : TypeAttach.values()) {
if (b.value != null && b.value.equalsIgnoreCase(castValue))
return b;
}
return null;
}
@JsonValue
public String getValue() {
return this.value;
}
@Override
public Object get() {
return this.value;
}
@Override
public TypeAttach fromInternal(Object val) {
return from(val);
}
@Override
public String toString() {
return value;
}
} }
} }

View File

@@ -409,7 +409,7 @@ public class PassiveInvoiceService {
.setUserName(requestDataDTO.getUsername()) .setUserName(requestDataDTO.getUsername())
.setFileSize(new BigDecimal(fileContent.length)) .setFileSize(new BigDecimal(fileContent.length))
.setFlagLock("S") .setFlagLock("S")
.setTypeAttach("FP") .setTypeAttach(StbFilesAttached.TypeAttach.FATTURA_PASSIVA)
.setParentIdAttach(parentActivityId) .setParentIdAttach(parentActivityId)
.setContent(fileContent); .setContent(fileContent);