Skip to content

Commit

Permalink
Merge branch 'develop' into feature/remove-vitagroup-package-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ramueSVA authored Apr 2, 2024
2 parents 6e12df7 + 9208b50 commit 0c6b751
Show file tree
Hide file tree
Showing 280 changed files with 26,576 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/org/highmed/NumPortalApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.highmed;



import org.highmed.service.atna.AtnaProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@EnableAsync
@SpringBootApplication
@EnableConfigurationProperties({AtnaProperties.class})
public class NumPortalApplication {

public static void main(String[] args) {
SpringApplication.run(NumPortalApplication.class, args);
}
}
26 changes: 26 additions & 0 deletions src/main/java/org/highmed/attachment/AttachmentRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.highmed.attachment;

import org.highmed.attachment.domain.dto.AttachmentDto;
import org.highmed.attachment.domain.model.Attachment;

import java.util.List;
import java.util.Optional;

public interface AttachmentRepository {

List<Attachment> getAttachments();

void saveAttachment(AttachmentDto model);

void deleteAttachment(Long id);

Optional<Attachment> findById(Long id);

void updateReviewCounterByProjectId(Long projectId);

Optional<Attachment> findByIdAndProjectId(Long id, Long projectId);

List<Attachment> findAttachmentsByProjectId(Long projectId);

void deleteByProjectId(Long projectId);
}
39 changes: 39 additions & 0 deletions src/main/java/org/highmed/attachment/domain/dto/AttachmentDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.highmed.attachment.domain.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.OffsetDateTime;

@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@NoArgsConstructor
@AllArgsConstructor
public class AttachmentDto {

@Schema(accessMode = Schema.AccessMode.READ_ONLY)
private Long id;

private String name;

private String description;

private String type;

private byte[] content;

private Long projectId;

@Schema(accessMode = Schema.AccessMode.READ_ONLY)
private OffsetDateTime uploadDate;

private String authorId;

@Schema(accessMode = Schema.AccessMode.READ_ONLY)
private int reviewCounter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.highmed.attachment.domain.dto;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.web.multipart.MultipartFile;

@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@NoArgsConstructor
@AllArgsConstructor
public class LightAttachmentDto {

private List<String> description;

private MultipartFile[] files;

}
51 changes: 51 additions & 0 deletions src/main/java/org/highmed/attachment/domain/model/Attachment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.highmed.attachment.domain.model;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.OffsetDateTime;

@Data
@Builder
@Entity
@NoArgsConstructor
@AllArgsConstructor
public class Attachment implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;

private String description;

@Column(name = "upload_date", nullable = false)
private OffsetDateTime uploadDate;

private String type;

private byte[] content;

@Column(name = "author_id")
private String authorId;

@Column(name = "review_counter", nullable = false, columnDefinition = "INTEGER DEFAULT 0")
private int reviewCounter;

@Column(name = "project_id", nullable = false, columnDefinition = "BIGINT DEFAULT 0")
private Long projectId;


public Attachment(Long id, String name, String description, OffsetDateTime uploadDate, int reviewCounter) {
this.id = id;
this.name = name;
this.description = description;
this.uploadDate = uploadDate;
this.reviewCounter = reviewCounter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.highmed.attachment.domain.repository;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.highmed.attachment.AttachmentRepository;
import org.highmed.attachment.domain.dto.AttachmentDto;
import org.highmed.attachment.domain.model.Attachment;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.time.OffsetDateTime;
import java.util.List;
import java.util.Optional;

@Component
@Log4j2
@AllArgsConstructor
@ConditionalOnProperty(prefix = "num", name = "enableAttachmentDatabase", havingValue = "true")
public class AttachmentRepositoryImpl implements AttachmentRepository {

private final AttachmentRepositoryJpa attachmentRepositoryJpa;

@Override
public List<Attachment> getAttachments() {
return attachmentRepositoryJpa.getAttachments();
}

@Override
public void saveAttachment(AttachmentDto model) {
Attachment entity = Attachment.builder()
.name(model.getName())
.description(model.getDescription())
.authorId(model.getAuthorId())
.projectId(model.getProjectId())
.uploadDate(OffsetDateTime.now())
.type(model.getType())
.content(model.getContent())
.projectId(model.getProjectId())
.build();
entity = attachmentRepositoryJpa.save(entity);
log.info("New attachment with id {} and name {} saved by {} ", entity.getId(), entity.getName(), entity.getAuthorId());
}

@Override
public void deleteAttachment(Long id) {
attachmentRepositoryJpa.deleteById(id);
}

@Override
public Optional<Attachment> findById(Long id) {
return attachmentRepositoryJpa.findById(id);
}

@Override
@Transactional(transactionManager = "attachmentTransactionManager")
public void updateReviewCounterByProjectId(Long projectId) {
attachmentRepositoryJpa.updateReviewCounterByProjectId(projectId);
}

@Override
public Optional<Attachment> findByIdAndProjectId(Long id, Long projectId) {
return attachmentRepositoryJpa.findByIdAndProjectId(id, projectId);
}

@Override
public List<Attachment> findAttachmentsByProjectId(Long projectId) {
return attachmentRepositoryJpa.findAttachmentsByProjectId(projectId);
}

@Override
public void deleteByProjectId(Long projectId) {
attachmentRepositoryJpa.deleteByProjectId(projectId);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.highmed.attachment.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface AttachmentRepositoryJpa extends JpaRepository<org.highmed.attachment.domain.model.Attachment, Long> {

@Query("SELECT new Attachment (atc.id, atc.name, atc.description, atc.uploadDate, atc.reviewCounter) " +
"FROM Attachment atc ")
List<org.highmed.attachment.domain.model.Attachment> getAttachments();

@Modifying
@Query("UPDATE Attachment atch SET atch.reviewCounter = atch.reviewCounter + 1 WHERE atch.projectId = :projectId")
void updateReviewCounterByProjectId(@Param("projectId") Long projectId);

Optional<org.highmed.attachment.domain.model.Attachment> findByIdAndProjectId(Long id, Long projectId);

@Query("SELECT new Attachment (atc.id, atc.name, atc.description, atc.uploadDate, atc.reviewCounter) " +
"FROM Attachment atc " +
"WHERE atc.projectId = :projectId")
List<org.highmed.attachment.domain.model.Attachment> findAttachmentsByProjectId(@Param("projectId") Long projectId);

@Modifying
@Query("DELETE FROM Attachment atch WHERE atch.projectId = :projectId")
void deleteByProjectId(@Param("projectId") Long projectId);
}
Loading

0 comments on commit 0c6b751

Please sign in to comment.