Skip to content

Commit

Permalink
chore: too many cycles 😢
Browse files Browse the repository at this point in the history
  • Loading branch information
teleivo committed Jan 22, 2025
1 parent c5158d8 commit 6aa9c8a
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
<one-to-many class="org.hisp.dhis.relationship.RelationshipItem" />
</set>

<list name="notes" table="enrollment_notes" cascade="all-delete-orphan">
<!-- eagerly fetch notes to avoid lazy init exceptions in code outside a hibernate session we do not
exclude notes like we do other collections if the fields parameter does not contain them like in
fields=!notes. reconsider this if we do implement that optimization -->
<list name="notes" table="enrollment_notes" cascade="all-delete-orphan" lazy="false" fetch="join">
<key column="enrollmentid" foreign-key="fk_programinstancecomments_programinstanceid" />
<list-index column="sort_order" base="1" />
<many-to-many class="org.hisp.dhis.note.Note" column="noteid"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@

<property name="eventDataValues" type="jsbEventDataValues" />

<list name="notes" table="event_notes" cascade="all-delete-orphan">
<!-- eagerly fetch notes to avoid lazy init exceptions in code outside a hibernate session we do not
exclude notes like we do other collections if the fields parameter does not contain them like in
fields=!notes. reconsider this if we do implement that optimization -->
<list name="notes" table="event_notes" cascade="all-delete-orphan" lazy="false" fetch="join">
<key column="eventid" foreign-key="fk_programstageinstancecomments_programstageinstanceid" />
<list-index column="sort_order" base="1" />
<many-to-many class="org.hisp.dhis.note.Note" column="noteid"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2004-2022, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.tracker.export;

import org.hisp.dhis.program.Enrollment;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.tracker.imports.preheat.mappers.AttributeValuesMapper;
import org.hisp.dhis.tracker.imports.preheat.mappers.OrganisationUnitMapper;
import org.hisp.dhis.tracker.imports.preheat.mappers.PreheatMapper;
import org.mapstruct.BeanMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

@Mapper(
uses = {
EventMapper.class,
OrganisationUnitMapper.class,
AttributeValuesMapper.class
})
public interface EnrollmentMapper extends PreheatMapper<Enrollment> {
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id")
@Mapping(target = "uid")
@Mapping(target = "code")
@Mapping(target = "user")
@Mapping(target = "completedBy")
@Mapping(target = "completedDate")
@Mapping(target = "program", qualifiedByName = "program")
@Mapping(target = "trackedEntity")
@Mapping(target = "organisationUnit")
@Mapping(target = "created")
@Mapping(target = "occurredDate")
@Mapping(target = "enrollmentDate")
@Mapping(target = "notes")
@Mapping(target = "deleted")
@Mapping(target = "createdByUserInfo")
@Mapping(target = "lastUpdatedByUserInfo")
@Mapping(target = "status")
Enrollment map(Enrollment enrollment);

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
PreheatMapper.map
; it is advisable to add an Override annotation.

@Named("program")
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id")
@Mapping(target = "uid")
@Mapping(target = "code")
@Mapping(target = "name")
@Mapping(target = "attributeValues")
@Mapping(target = "trackedEntityType")
@Mapping(target = "programType")
@Mapping(target = "sharing")
@Mapping(target = "accessLevel")
Program mapProgram(Program p);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2004-2022, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.tracker.export;

import org.hisp.dhis.program.Event;
import org.hisp.dhis.tracker.imports.preheat.mappers.OrganisationUnitMapper;
import org.hisp.dhis.tracker.imports.preheat.mappers.PreheatMapper;
import org.hisp.dhis.tracker.imports.preheat.mappers.ProgramStageMapper;
import org.mapstruct.BeanMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(
uses = {
ProgramStageMapper.class,
OrganisationUnitMapper.class,
})
public interface EventMapper extends PreheatMapper<Event> {
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id")
@Mapping(target = "uid")
@Mapping(target = "code")
@Mapping(target = "user")
@Mapping(target = "enrollment")
@Mapping(target = "programStage")
@Mapping(target = "status")
@Mapping(target = "organisationUnit")
@Mapping(target = "created")
@Mapping(target = "eventDataValues")
@Mapping(target = "notes")
@Mapping(target = "scheduledDate")
@Mapping(target = "occurredDate")
@Mapping(target = "completedDate")
@Mapping(target = "completedBy")
@Mapping(target = "deleted")
@Mapping(target = "createdByUserInfo")
@Mapping(target = "lastUpdatedByUserInfo")
@Mapping(target = "geometry")
Event map(Event event);

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
PreheatMapper.map
; it is advisable to add an Override annotation.
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@

import org.hisp.dhis.relationship.Relationship;
import org.hisp.dhis.relationship.RelationshipItem;
import org.hisp.dhis.tracker.imports.preheat.mappers.EnrollmentMapper;
import org.hisp.dhis.tracker.imports.preheat.mappers.EventMapper;
import org.hisp.dhis.tracker.imports.preheat.mappers.RelationshipTypeMapper;
import org.hisp.dhis.tracker.imports.preheat.mappers.TrackedEntityMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
Expand All @@ -44,7 +41,7 @@
RelationshipTypeMapper.class,
TrackedEntityMapper.class,
EnrollmentMapper.class,
EventMapper.class,
EventMapper.class
})
public interface RelationshipItemMapper {
RelationshipItemMapper RELATIONSHIP_ITEM_MAPPER =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2004-2022, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.tracker.export;

import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.tracker.imports.preheat.mappers.AttributeValuesMapper;
import org.hisp.dhis.tracker.imports.preheat.mappers.PreheatMapper;
import org.hisp.dhis.tracker.imports.preheat.mappers.TrackedEntityTypeMapper;
import org.mapstruct.BeanMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

@Mapper(uses = { TrackedEntityTypeMapper.class, EnrollmentMapper.class, AttributeValuesMapper.class})
public interface TrackedEntityMapper extends PreheatMapper<TrackedEntity> {
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id")
@Mapping(target = "uid")
@Mapping(target = "code")
@Mapping(target = "user")
@Mapping(target = "organisationUnit", qualifiedByName = "organisationUnit")
@Mapping(target = "trackedEntityType")
@Mapping(target = "inactive")
@Mapping(target = "enrollments")
@Mapping(target = "created")
@Mapping(target = "trackedEntityAttributeValues")
@Mapping(target = "deleted")
@Mapping(target = "createdByUserInfo")
@Mapping(target = "lastUpdatedByUserInfo")
TrackedEntity map(TrackedEntity trackedEntity);

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
PreheatMapper.map
; it is advisable to add an Override annotation.

@Named("organisationUnit")
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id")
@Mapping(target = "uid")
@Mapping(target = "code")
@Mapping(target = "name")
@Mapping(target = "attributeValues")
@Mapping(target = "user")
@Mapping(target = "parent", qualifiedByName = "organisationUnit")
OrganisationUnit map(OrganisationUnit organisationUnit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.hisp.dhis.feedback.BadRequestException;
import org.hisp.dhis.feedback.ForbiddenException;
import org.hisp.dhis.feedback.NotFoundException;
import org.hisp.dhis.note.Note;
import org.hisp.dhis.program.Enrollment;
import org.hisp.dhis.program.Event;
import org.hisp.dhis.relationship.RelationshipItem;
Expand Down Expand Up @@ -177,12 +176,7 @@ private Enrollment getEnrollment(
result.setCreatedByUserInfo(enrollment.getCreatedByUserInfo());
result.setLastUpdatedByUserInfo(enrollment.getLastUpdatedByUserInfo());
result.setDeleted(enrollment.isDeleted());
List<Note> notes = new ArrayList<>();
// eagerly fetch notes
for (Note note : enrollment.getNotes()) {
notes.add(note);
}
result.setNotes(notes);
result.setNotes(enrollment.getNotes());
if (params.isIncludeEvents()) {
result.setEvents(
getEvents(
Expand Down

0 comments on commit 6aa9c8a

Please sign in to comment.