Skip to content
Open
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 @@ -145,6 +145,11 @@ public SampleResponse sampleWriteRead(SampleRequest sampleRequest) throws BaseEx
throw new TechnicalException("Unexpected data integrity error, some mandatory field is empty or not equal!");
}

//set all entity to done
transactionHelper.executeWithTransaction(() -> {
sampleEntityService.updateAllStatusAndInputValue(SampleStatus.DONE, "done");
});

SampleResponse response = new SampleResponse();
response.setSample(sampleTypeConverter.convert(readed));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import jakarta.persistence.QueryHint;

import org.apache.deltaspike.data.api.EntityRepository;
import org.apache.deltaspike.data.api.Modifying;
import org.apache.deltaspike.data.api.Query;
import org.apache.deltaspike.data.api.QueryParam;
import org.apache.deltaspike.data.api.Repository;
import org.apache.deltaspike.data.api.criteria.CriteriaSupport;
import org.hibernate.jpa.HibernateHints;
Expand Down Expand Up @@ -74,4 +76,15 @@ public interface SampleEntityRepository extends EntityRepository<SampleEntity, S
// @Query(value = "SELECT s FROM SampleEntity s WHERE s.status = ?1")
List<SampleEntity> findAllByStatus(SampleStatus status);

/**
* update all sampleEntity by params
*
* @param status status
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

formazas volt?

* @param inputValue input value
* @return status of update
*/
@Modifying
@Query("UPDATE SampleEntity s SET s.status = :status, s.inputValue = :inputValue")
int updateAllSampleStatusAndInputValue(@QueryParam("status") SampleStatus status, @QueryParam("inputValue") String inputValue);

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import hu.icellmobilsoft.coffee.dto.exception.BaseException;
import hu.icellmobilsoft.sampler.common.system.jpa.service.BaseService;
import hu.icellmobilsoft.sampler.model.sample.SampleEntity;
import hu.icellmobilsoft.sampler.model.sample.SampleEntity_;
import hu.icellmobilsoft.sampler.model.sample.enums.SampleStatus;
import hu.icellmobilsoft.sampler.sample.jpaservice.repository.SampleEntityRepository;

Expand Down Expand Up @@ -60,4 +61,24 @@ public class SampleEntityService extends BaseService<SampleEntity> {
public List<SampleEntity> findAllByStatus(SampleStatus status) throws BaseException {
return wrapListValidated(sampleEntityRepository::findAllByStatus, status, "findAllByStatus", "status");
}

/**
* Updates all SampleEntity entity with the given params
*
* @param sampleStatus new sampleStatus
* @param inputValue new inputValue
* @return status of update
* @throws BaseException on error
*/
public int updateAllStatusAndInputValue(SampleStatus sampleStatus, String inputValue) throws BaseException {

return wrapValidated(
sampleEntityRepository::updateAllSampleStatusAndInputValue,
sampleStatus,
inputValue,
"updateAllSampleStatusAndInputValue",
SampleEntity_.STATUS,
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.

*Service szinten nem szabad hogy legyen barmi rejtett logika, mindent az action szinten keresunk

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

A SampleEntity_.STATUS ban csak az entity field neve van stringként generálva az entityből. Így változás biztos.
A két kódrészlet egyenlő:

 return wrapValidated(
                sampleEntityRepository::updateAllSampleStatusAndInputValue,
                sampleStatus,
                inputValue,
                "updateAllSampleStatusAndInputValue",
                "status",
                "inputValue"
        );
 

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.

wrapValidated parametereit eredetileg arra szantuk hogy a valos metodus valtozo neveit irja ki a logokban. Logikailag helyes ahogy irod, mivel a vegso mezo neve a entityben SampleEntity_.STATUS csak a metodusban az ehhez tartozo valtozo neve "sampleStatus". Ez most csak tenyleg aprosag, de igy keressuk a logokban mashol is.

SampleEntity_.INPUT_VALUE
);
}
}