Commit f1cc6613 authored by Matija Obreza's avatar Matija Obreza
Browse files

CRUDController update returns reloaded object

parent 0d687926
......@@ -101,7 +101,7 @@ public abstract class CRUDController<T extends EmptyModel, S extends CRUDService
@PutMapping(value = "", produces = { MediaType.APPLICATION_JSON_VALUE })
@Operation(operationId = "update", description = "Update an existing record", summary = "Update")
public T update(@RequestBody @Valid @NotNull final T entity) {
return crudService.update(entity, crudService.reload(entity));
return crudService.reload(crudService.update(entity));
}
}
\ No newline at end of file
......@@ -49,6 +49,7 @@ import org.gringlobal.custom.elasticsearch.SearchField;
import org.gringlobal.custom.validation.javax.CodeValueField;
import org.gringlobal.custom.validation.javax.OneLine;
import org.gringlobal.model.community.IWebVisible;
import org.hibernate.Hibernate;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
......@@ -66,6 +67,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@BoostedFields({ "accessionNumber", "accessionNumberPart2", "taxonomySpecies.name", "names.plantName", "accessionSources.geography.countryCode" })
@JsonIdentityInfo(scope = Accession.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Accession extends CooperatorOwnedModel implements IWebVisible, Copyable<Accession>, ElasticLoader, ElasticTrigger {
private static final long serialVersionUID = -6016814457794861535L;
@Id
@JsonProperty
......@@ -471,6 +473,8 @@ public class Accession extends CooperatorOwnedModel implements IWebVisible, Copy
if (this.taxonomySpecies != null) {
this.taxonomySpecies.getId();
}
Hibernate.initialize(this.backupLocation1Site);
Hibernate.initialize(this.backupLocation2Site);
}
@Override
......
......@@ -29,6 +29,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.gringlobal.model.community.CommunityCodeValues;
import org.gringlobal.model.community.IWebVisible;
import org.hibernate.Hibernate;
/**
* Auto-generated by:
......@@ -170,6 +171,7 @@ public class AccessionInvName extends CooperatorOwnedModel implements IWebVisibl
@Override
public Object[] reindexedEntities() {
Hibernate.initialize(this.inventory); // assures maybeReindex will work
return new Object[] { this.inventory };
}
}
\ No newline at end of file
......@@ -34,6 +34,7 @@ import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Min;
import org.genesys.blocks.annotations.NotCopyable;
import org.genesys.blocks.model.Copyable;
import org.hibernate.Hibernate;
......@@ -65,12 +66,14 @@ public class InventoryViabilityData extends CooperatorOwnedModel implements Copy
@JoinColumn(name = "inventory_viability_id", nullable = false, updatable = false)
@JsonIdentityReference(alwaysAsId = true)
@JsonIdentityInfo(scope = InventoryViability.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@NotCopyable
private InventoryViability inventoryViability;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "order_request_item_id", updatable = false)
@JsonIdentityReference(alwaysAsId = true)
@JsonIdentityInfo(scope = OrderRequestItem.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@NotCopyable
private OrderRequestItem orderRequestItem;
@OneToMany(fetch = FetchType.LAZY, cascade = {}, mappedBy = "inventoryViabilityData")
......
......@@ -25,6 +25,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.genesys.blocks.model.Copyable;
import org.gringlobal.custom.validation.javax.CodeValueField;
import org.gringlobal.custom.validation.javax.OneLine;
import org.hibernate.Hibernate;
/**
* Auto-generated by:
......@@ -207,4 +208,10 @@ public class Method extends CooperatorOwnedModel implements Copyable<Method> {
public void setUncertainty(final Integer uncertainty) {
this.uncertainty = uncertainty;
}
}
\ No newline at end of file
@Override
public void lazyLoad() {
super.lazyLoad();
Hibernate.initialize(this.geography);
}
}
......@@ -43,7 +43,6 @@ import org.gringlobal.model.QInventoryViabilityAction;
import org.gringlobal.model.QInventoryViabilityData;
import org.gringlobal.model.Site;
import org.gringlobal.model.community.CommunityCodeValues;
import org.gringlobal.persistence.CooperatorRepository;
import org.gringlobal.persistence.InventoryRepository;
import org.gringlobal.persistence.InventoryViabilityActionRepository;
import org.gringlobal.persistence.InventoryViabilityDataRepository;
......@@ -351,15 +350,12 @@ public class InventoryViabilityServiceImpl extends FilteredCRUDServiceImpl<Inven
@Autowired
private InventoryViabilityRepository inventoryViabilityRepository;
@Autowired
private CooperatorRepository cooperatorRepository;
@Override
@Transactional
@PostAuthorize("@ggceSec.actionAllowed('ViabilityTest', 'WRITE', returnObject.inventoryViability.inventory.site)")
public InventoryViabilityData create(InventoryViabilityData source) {
assert(source.getId() == null);
// reload from database
// reload from database: for post-authorize
source.setInventoryViability(inventoryViabilityRepository.getOne(source.getInventoryViability().getId()));
var saved = repository.save(source);
......@@ -379,9 +375,6 @@ public class InventoryViabilityServiceImpl extends FilteredCRUDServiceImpl<Inven
LOG.debug("Update InventoryViabilityData. Input data {}", input);
target.apply(input);
if (target.getCounterCooperator() != null) {
target.setCounterCooperator(cooperatorRepository.getOne(target.getCounterCooperator().getId()));
}
var saved = repository.save(target);
......
......@@ -535,7 +535,7 @@ public class InventoryViabilityControllerTest extends AbstractApiV1Test {
.characterEncoding("UTF8")
.content(clientMapper.writeValueAsString(viabilityData).replaceFirst("\\\"inventoryViability\\\":(\\d+),", "\"inventoryViability\":{\"id\":$1},"))
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$", notNullValue()))
......
......@@ -98,7 +98,8 @@ public class MethodControllerTest extends AbstractApiV1Test {
.andExpect(jsonPath("$.ownedBy", is(AbstractServicesTest.USER_CURATOR1)))
.andExpect(jsonPath("$.studyReasonCode", is(STUDY_REASON_CODE_1)))
.andExpect(jsonPath("$.name", is(METHOD_NAME_1)))
.andExpect(jsonPath("$.geography", is(nullValue())))
.andExpect(jsonPath("$.geography", is(notNullValue())))
.andExpect(jsonPath("$.geography.id", is(geography.getId().intValue())))
;
}
......@@ -156,8 +157,8 @@ public class MethodControllerTest extends AbstractApiV1Test {
.andExpect(jsonPath("$.ownedBy", is(AbstractServicesTest.USER_CURATOR1)))
.andExpect(jsonPath("$.studyReasonCode", is(STUDY_REASON_CODE_2)))
.andExpect(jsonPath("$.name", is(METHOD_NAME_2)))
// .andExpect(jsonPath("$.geography", is(notNullValue())))
// .andExpect(jsonPath("$.geography.id", is(geography.getId().intValue())))
.andExpect(jsonPath("$.geography", is(notNullValue())))
.andExpect(jsonPath("$.geography.id", is(geography.getId().intValue())))
;
assertThat(methodRepository.count(), is(1L));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment