Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,10 @@ Optional<FileResource> findByUidAndDomain(

List<FileResource> getUnassignedPassedGracePeriod(
Set<FileResourceDomain> domainsToDeleteWhenUnassigned, DateTime minus);

/**
* Updates the assignment state and owner of the file resource with the given uid via a single
* JDBC UPDATE. No-op if no file resource with that uid exists.
*/
void updateAssignment(@Nonnull String uid, boolean assigned, @Nonnull String fileResourceOwner);
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ and fr.uid not in (select uid from jobconfiguration where schedulingtype = 'ONCE
return nativeSynchronizedTypedQuery(sql).list();
}

@Override
public void updateAssignment(
@Nonnull String uid, boolean assigned, @Nonnull String fileResourceOwner) {
jdbcTemplate.update(
"update fileresource set isassigned = ?, fileresourceowner = ?, lastupdated = now() where uid = ?",
assigned,
fileResourceOwner,
uid);
}

@Override
public List<FileResource> getUnassignedPassedGracePeriod(
Set<FileResourceDomain> domainsToDeleteWhenUnassigned, DateTime gracePeriod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void testTrackedEntityProgramAttributeFileResourceValue() throws IOException {
List<TrackedEntityAttributeValue> attributeValues =
trackedEntityAttributeValueService.getTrackedEntityAttributeValues(trackedEntity);
assertEquals(5, attributeValues.size());
manager.clear();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these needed now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and if you clear before flush I think there is nothing to flush

fileResource = fileResourceService.getFileResource(fileResource.getUid());
assertTrue(fileResource.isAssigned());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void testTrackedEntityProgramAttributeFileResourceValue() throws IOException {
List<TrackedEntityAttributeValue> attributeValues =
trackedEntityAttributeValueService.getTrackedEntityAttributeValues(trackedEntity);
assertEquals(1, attributeValues.size());
manager.clear();
fileResource = fileResourceService.getFileResource(fileResource.getUid());
assertTrue(fileResource.isAssigned());
}
Expand Down Expand Up @@ -137,6 +138,7 @@ void testFileAlreadyAssign() throws IOException {
List<TrackedEntityAttributeValue> attributeValues =
trackedEntityAttributeValueService.getTrackedEntityAttributeValues(trackedEntity);
assertEquals(1, attributeValues.size());
manager.clear();
fileResource = fileResourceService.getFileResource(fileResource.getUid());
assertTrue(fileResource.isAssigned());
trackerObjects =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.hisp.dhis.common.UID;
import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.fileresource.FileResource;
import org.hisp.dhis.fileresource.FileResourceStore;
import org.hisp.dhis.program.notification.ProgramNotificationTemplate;
import org.hisp.dhis.reservedvalue.ReservedValueService;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
Expand Down Expand Up @@ -99,6 +100,8 @@ public abstract class AbstractTrackerPersister<T extends TrackerDto, V extends I

protected final DataSource dataSource;

protected final FileResourceStore fileResourceStore;

/**
* Template method that can be used by classes extending this class to execute the persistence
* flow of Tracker entities
Expand Down Expand Up @@ -365,9 +368,7 @@ private void assignFileResource(
return;
}

fileResource.setAssigned(isAssign);
fileResource.setFileResourceOwner(fileResourceOwner);
entityManager.merge(fileResource);
fileResourceStore.updateAssignment(fileResource.getUid(), isAssign, fileResourceOwner);
}

protected void handleTrackedEntityAttributeValues(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Set;
import javax.sql.DataSource;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.fileresource.FileResourceStore;
import org.hisp.dhis.program.EnrollmentStatus;
import org.hisp.dhis.program.notification.NotificationTrigger;
import org.hisp.dhis.program.notification.ProgramNotificationTemplate;
Expand All @@ -60,8 +61,9 @@ public class EnrollmentPersister
public EnrollmentPersister(
ReservedValueService reservedValueService,
DataSource dataSource,
FileResourceStore fileResourceStore,
TrackedEntityProgramOwnerService trackedEntityProgramOwnerService) {
super(reservedValueService, dataSource);
super(reservedValueService, dataSource, fileResourceStore);
this.trackedEntityProgramOwnerService = trackedEntityProgramOwnerService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Set;
import javax.sql.DataSource;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.fileresource.FileResourceStore;
import org.hisp.dhis.reservedvalue.ReservedValueService;
import org.hisp.dhis.tracker.TrackerType;
import org.hisp.dhis.tracker.imports.TrackerImportStrategy;
Expand All @@ -50,8 +51,11 @@
public class RelationshipPersister
extends AbstractTrackerPersister<Relationship, org.hisp.dhis.tracker.model.Relationship> {

public RelationshipPersister(ReservedValueService reservedValueService, DataSource dataSource) {
super(reservedValueService, dataSource);
public RelationshipPersister(
ReservedValueService reservedValueService,
DataSource dataSource,
FileResourceStore fileResourceStore) {
super(reservedValueService, dataSource, fileResourceStore);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.eventdatavalue.EventDataValue;
import org.hisp.dhis.fileresource.FileResourceStore;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.UserInfoSnapshot;
import org.hisp.dhis.program.notification.NotificationTrigger;
Expand All @@ -74,8 +75,11 @@
public class SingleEventPersister
extends AbstractTrackerPersister<
org.hisp.dhis.tracker.imports.domain.SingleEvent, SingleEvent> {
public SingleEventPersister(ReservedValueService reservedValueService, DataSource dataSource) {
super(reservedValueService, dataSource);
public SingleEventPersister(
ReservedValueService reservedValueService,
DataSource dataSource,
FileResourceStore fileResourceStore) {
super(reservedValueService, dataSource, fileResourceStore);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Set;
import javax.sql.DataSource;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.fileresource.FileResourceStore;
import org.hisp.dhis.reservedvalue.ReservedValueService;
import org.hisp.dhis.tracker.TrackerType;
import org.hisp.dhis.tracker.imports.bundle.TrackerBundle;
Expand All @@ -51,8 +52,11 @@ public class TrackedEntityPersister
extends AbstractTrackerPersister<
org.hisp.dhis.tracker.imports.domain.TrackedEntity, TrackedEntity> {

public TrackedEntityPersister(ReservedValueService reservedValueService, DataSource dataSource) {
super(reservedValueService, dataSource);
public TrackedEntityPersister(
ReservedValueService reservedValueService,
DataSource dataSource,
FileResourceStore fileResourceStore) {
super(reservedValueService, dataSource, fileResourceStore);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.eventdatavalue.EventDataValue;
import org.hisp.dhis.fileresource.FileResourceStore;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.UserInfoSnapshot;
import org.hisp.dhis.program.notification.NotificationTrigger;
Expand All @@ -75,8 +76,11 @@
public class TrackerEventPersister
extends AbstractTrackerPersister<
org.hisp.dhis.tracker.imports.domain.TrackerEvent, TrackerEvent> {
public TrackerEventPersister(ReservedValueService reservedValueService, DataSource dataSource) {
super(reservedValueService, dataSource);
public TrackerEventPersister(
ReservedValueService reservedValueService,
DataSource dataSource,
FileResourceStore fileResourceStore) {
super(reservedValueService, dataSource, fileResourceStore);
}

@Override
Expand Down
Loading