Skip to content

Commit

Permalink
#813 - source compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Nov 1, 2024
1 parent c6f3caa commit 054b8b4
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import jakarta.persistence.EntityManager;
import jakarta.persistence.TypedQuery;
import java.io.Serializable;
import java.util.List;

public class CustomJpaRepositoryImpl<T extends CHSEntity, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements CustomCHSJpaRepository<T, ID> {

public CustomJpaRepositoryImpl(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
super(entityInformation, entityManager);
}
Expand All @@ -25,6 +24,11 @@ public Slice<T> findAllAsSlice(Specification<T> specification, Pageable pageable
return pageable.isUnpaged() ? new SliceImpl<>(query.getResultList()) : readSlice(query, pageable, specification);
}

@Override
public void deleteInBatch(Iterable<T> entities) {
entities.forEach(this::delete);
}

private Slice<T> readSlice(TypedQuery<T> query, Pageable pageable, Specification<T> specification){
if (pageable.isPaged()){
query.setFirstResult((int) pageable.getOffset());
Expand All @@ -37,4 +41,4 @@ private Slice<T> readSlice(TypedQuery<T> query, Pageable pageable, Specification
}
return new SliceImpl<>(content, pageable, hasNextPage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.avni.server.web.api.EncounterSearchRequest;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;
import javax.transaction.Transactional;
import java.math.BigInteger;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import javax.transaction.Transactional;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import javax.transaction.Transactional;

@Repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import org.avni.server.framework.security.UserContextHolder;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import jakarta.persistence.Query;

public abstract class RoleSwitchableRepository {
@PersistenceContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import jakarta.persistence.Query;
import javax.transaction.Transactional;
import java.math.BigInteger;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.Sort;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.file.FlatFileItemWriter;
import org.springframework.batch.item.file.transform.DelimitedLineAggregator;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.core.io.FileSystemResource;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -86,7 +87,8 @@ private void createFileWriter(String uuid, ExecutionContext executionContext) {

private void writeToFile(List<ExportItemRow> rows) throws Exception {
if (rows.size() == 0) return;
writer.write(rows);

writer.write(Chunk.of(rows.toArray(new ExportItemRow[0])));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.file.FlatFileItemWriter;
import org.springframework.batch.item.file.transform.DelimitedLineAggregator;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.core.io.FileSystemResource;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -92,7 +93,7 @@ private void createFileWriter(String uuid, ExecutionContext executionContext) {

private void writeToFile(List<LongitudinalExportItemRow> rows) throws Exception {
if (rows.isEmpty()) return;
writer.write(rows);
writer.write(Chunk.of(rows.toArray(new LongitudinalExportItemRow[0])));
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.avni.server.framework.postgres;

import org.hibernate.dialect.PostgreSQL10Dialect;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;

import java.sql.Types;

public class CHSPostgreSQLDialect extends PostgreSQL10Dialect {
private static final String JSONB = "jsonb";
private static final String JSON = "json";

public CHSPostgreSQLDialect() {
super();
// this.registerColumnTypes();
// this.registerColumnType(Types.JAVA_OBJECT, JSONB);
// this.registerColumnType(Types.JAVA_OBJECT, JSON);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import javax.transaction.Transactional;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public EntityModel<CatchmentContract> getById(@PathVariable Long id) {
CatchmentContract catchmentContract = CatchmentContract.fromEntity(catchment);
boolean fastSyncExists = s3Service.fileExists(String.format("MobileDbBackup-%s", catchment.getUuid()));
catchmentContract.setFastSyncExists(fastSyncExists);
return new EntityModel<>(catchmentContract);
return EntityModel.of(catchmentContract);
}

@GetMapping(value = "catchment/search/findAllById")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConversionException;
import org.springframework.web.bind.MethodArgumentNotValidException;
Expand Down Expand Up @@ -72,7 +73,7 @@ public ErrorInterceptors(@Value("${spring.servlet.multipart.max-file-size}") Str
}

@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
Map<String, Object> body = new HashMap<>();
List<ApiError> errors = ex.getBindingResult()
.getFieldErrors()
Expand Down Expand Up @@ -121,8 +122,8 @@ public ResponseEntity unknownException(Exception e) {
}

@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) {
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatusCode statusCode, WebRequest request) {
bugsnagReporter.logAndReportToBugsnag(ex);
return super.handleExceptionInternal(ex, errorBodyBuilder.getErrorBody(body), headers, status, request);
return super.handleExceptionInternal(ex, errorBodyBuilder.getErrorBody(body), headers, statusCode, request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import java.util.stream.Collectors;

import static java.lang.String.format;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

@RestController
public class FormController implements RestControllerResourceProcessor<BasicFormDetails> {
Expand Down Expand Up @@ -103,9 +105,9 @@ public CollectionModel<EntityModel<BasicFormDetails>> getAllFormsWeb(
@RequestParam(value = "includeVoided", required = false) boolean includeVoided,
Pageable pageable) {
Long organisationId = UserContextHolder.getUserContext().getOrganisation().getId();
Sort sortWithId = pageable.getSort().and(new Sort("id"));
Sort sortWithId = pageable.getSort().and(Sort.by("id"));

PageRequest pageRequest = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), sortWithId);
PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sortWithId);

Page<Form> forms = formRepository.findAll((root, query, builder) -> {
Predicate predicate = builder.equal(root.get("organisationId"), organisationId);
Expand Down Expand Up @@ -388,11 +390,11 @@ private List<BasicFormDetails> getFormsByProgram(Program program, Pageable pagea
Form form = fm.getForm();
BasicFormDetails formDetail = new BasicFormDetails(form, program.getOperationalProgramName());
formDetail.add(linkTo(methodOn(FormController.class).getForms(programId, pageable)).withSelfRel());
Link formLink = entityLinks.linkToSingleResource(Form.class, form.getId());
Link formLink = entityLinks.linkToItemResource(Form.class, form.getId());
formDetail.add(formLink);
formDetail.add(Link.of(formLink.getHref() + "/formElementGroups", "formElementGroups"));
formDetail.add(entityLinks.linkToSingleResource(User.class, form.getCreatedBy().getId()).withRel("createdBy"));
formDetail.add(entityLinks.linkToSingleResource(User.class, form.getLastModifiedBy().getId()).withRel("lastModifiedBy"));
formDetail.add(entityLinks.linkToItemResource(User.class, form.getCreatedBy().getId()).withRel("createdBy"));
formDetail.add(entityLinks.linkToItemResource(User.class, form.getLastModifiedBy().getId()).withRel("lastModifiedBy"));
return formDetail;
}).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.stream.Collectors;

import static org.avni.server.web.resourceProcessors.ResourceProcessor.addAuditFields;
import static org.springframework.data.jpa.domain.Specification.where;

@RestController
public class IndividualController extends AbstractController<Individual> implements RestControllerResourceProcessor<Individual> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public SyncSubjectController(SubjectSyncResponseBuilderService subjectSyncRespon

public EntityModel<HashMap<String, Object>> process(SyncSubjectResponse syncSubjectResponse) {
HashMap<String, Object> result = new HashMap<>();
result.put("individual", new IndividualResourceProcessor().process(new EntityModel<>(syncSubjectResponse.getIndividual())));
result.put("programEnrolments", syncSubjectResponse.getProgramEnrolments().stream().map(programEnrolment -> new ProgramEnrolmentResourceProcessor().process(new EntityModel<>(programEnrolment))));
result.put("programEncounters", syncSubjectResponse.getProgramEncounters().stream().map(programEncounter1 -> new ProgramEncounterResourceProcessor().process(new EntityModel<>(programEncounter1))));
result.put("encounters", syncSubjectResponse.getEncounters().stream().map(encounter -> new EncounterResourceProcessor().process(new EntityModel<>(encounter))));
result.put("checklists", syncSubjectResponse.getChecklists().stream().map(checklist -> new ChecklistResourceProcessor().process(new EntityModel<>(checklist))));
result.put("checklistItems", syncSubjectResponse.getChecklistItems().stream().map(checklistItem -> new ChecklistItemResourceProcessor().process(new EntityModel<>(checklistItem))));
result.put("groupSubjects", syncSubjectResponse.getGroupSubjects().stream().map(groupSubject -> new GroupSubjectResourceProcessor().process(new EntityModel<>(groupSubject))));
result.put("individualRelationships", syncSubjectResponse.getIndividualRelationships().stream().map(individualRelationship -> new IndividualRelationshipResourceProcessor().process(new EntityModel<>(individualRelationship))));
return new EntityModel<>(result);
result.put("individual", new IndividualResourceProcessor().process(EntityModel.of(syncSubjectResponse.getIndividual())));
result.put("programEnrolments", syncSubjectResponse.getProgramEnrolments().stream().map(programEnrolment -> new ProgramEnrolmentResourceProcessor().process(EntityModel.of(programEnrolment))));
result.put("programEncounters", syncSubjectResponse.getProgramEncounters().stream().map(programEncounter1 -> new ProgramEncounterResourceProcessor().process(EntityModel.of(programEncounter1))));
result.put("encounters", syncSubjectResponse.getEncounters().stream().map(encounter -> new EncounterResourceProcessor().process(EntityModel.of(encounter))));
result.put("checklists", syncSubjectResponse.getChecklists().stream().map(checklist -> new ChecklistResourceProcessor().process(EntityModel.of(checklist))));
result.put("checklistItems", syncSubjectResponse.getChecklistItems().stream().map(checklistItem -> new ChecklistItemResourceProcessor().process(EntityModel.of(checklistItem))));
result.put("groupSubjects", syncSubjectResponse.getGroupSubjects().stream().map(groupSubject -> new GroupSubjectResourceProcessor().process(EntityModel.of(groupSubject))));
result.put("individualRelationships", syncSubjectResponse.getIndividualRelationships().stream().map(individualRelationship -> new IndividualRelationshipResourceProcessor().process(EntityModel.of(individualRelationship))));
return EntityModel.of(result);
}

@GetMapping("/subject/{uuid}/allEntities")
Expand Down
4 changes: 2 additions & 2 deletions avni-server-api/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.jadira.usertype.databaseZone=jvm
spring.jpa.properties.jadira.usertype.javaZone=jvm
spring.jpa.properties.jadira.usertype.autoRegisterUserTypes=true
spring.jpa.properties.hibernate.dialect=org.avni.server.framework.postgres.CHSPostgreSQL94Dialect
spring.jpa.properties.hibernate.dialect=org.avni.server.framework.postgres.CHSPostgreSQLDialect
spring.jpa.properties.hibernate.ejb.interceptor=org.avni.server.framework.hibernate.UpdateOrganisationHibernateInterceptor
spring.jpa.database-platform=org.avni.server.framework.postgres.CHSPostgreSQL94Dialect
spring.jpa.database-platform=org.avni.server.framework.postgres.CHSPostgreSQLDialect
spring.jpa.hibernate.use-new-id-generator-mappings=true
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
avni.custom.query.timeout=${AVNI_CUSTOM_QUERY_TIMEOUT:3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.net.URL;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;
import java.util.Arrays;
import java.util.Map;

Expand Down
4 changes: 2 additions & 2 deletions avni-server-api/src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.jadira.usertype.databaseZone=jvm
spring.jpa.properties.jadira.usertype.javaZone=jvm
spring.jpa.properties.jadira.usertype.autoRegisterUserTypes=true
spring.jpa.properties.hibernate.dialect=org.avni.server.framework.postgres.CHSPostgreSQL94Dialect
spring.jpa.properties.hibernate.dialect=org.avni.server.framework.postgres.CHSPostgreSQLDialect
spring.jpa.properties.hibernate.ejb.interceptor=org.avni.server.framework.hibernate.UpdateOrganisationHibernateInterceptor
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.use_query_cache=true
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
spring.cache.jcache.config=${AVNI_EHCACHE_FILE:classpath:ehcache.xml}
spring.jpa.database-platform=org.avni.server.framework.postgres.CHSPostgreSQL94Dialect
spring.jpa.database-platform=org.avni.server.framework.postgres.CHSPostgreSQLDialect
spring.jpa.hibernate.use-new-id-generator-mappings=true
spring.profiles.active=${OPENCHS_MODE:test}
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
Expand Down

0 comments on commit 054b8b4

Please sign in to comment.