Commit 97225878 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

Merge branch...

Merge branch '120-introduce-a-new-reset-route-for-a-failed-order-is-on-the-branch' into 109-integrate-flyway-in-tmf-api-for-db-migration-actions
parents 6b557fd4 883cc68d
Loading
Loading
Loading
Loading
Loading
+20 −2
Changes for src/main/java/org/etsi/osl/tmf/so641/reposervices/ServiceOrderRepoService.java: 20 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -1024,8 +1024,14 @@ public class ServiceOrderRepoService {

	/**
	 * Same as {@link #resetServiceOrder(String, List, String)}, for the message bus: the request is a map
	 * with "dropItemIds" (a list of order item ids) and "note", the reply the eager order as JSON
	 * with "dropItemIds" (a list of order item ids) and "note", the reply the eager order as JSON.
	 * <p>
	 * The transaction is opened here, not by {@link #resetServiceOrder}: that call is made on this, so it
	 * does not pass through the transactional proxy, and the order's lazy item collection would have no
	 * session. The reply is serialised inside the same transaction too, because
	 * {@link #getServiceORderEager} opens a separate session that cannot see the not yet committed reset.
	 */
	@Transactional
	public String resetServiceOrderAsString(String id, Map<String, Object> request) throws JsonProcessingException {
		List<String> dropItemIds = new ArrayList<>();
		String note = null;
@@ -1043,7 +1049,19 @@ public class ServiceOrderRepoService {
		if (so == null) {
			return null;
		}
		return getServiceOrderEagerAsString(so.getUuid());
		Hibernate.initialize(so.getRelatedParty());
		Hibernate.initialize(so.getNote());
		for (ServiceOrderItem soi : so.getOrderItem()) {
			if (soi.getService() != null) {
				Hibernate.initialize(soi.getService().getSupportingService());
				Hibernate.initialize(soi.getService().getSupportingResource());
				Hibernate.initialize(soi.getService().getServiceCharacteristic());
				Hibernate.initialize(soi.getService().getRelatedParty());
			}
		}
		ObjectMapper mapper = new ObjectMapper();
		mapper.registerModule(new Hibernate5JakartaModule());
		return mapper.writeValueAsString(so);
	}

	public ServiceOrder findByUuid(String id) {
+44
Changes for src/test/java/org/etsi/osl/services/api/so641/ServiceOrderRepoServiceTest.java: 44 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequ
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;


@@ -612,6 +614,48 @@ public class ServiceOrderRepoServiceTest extends BaseIT {
        assertThat(serviceOrderRepoService.resetServiceOrderAsString("no-such-order", Map.of())).isNull();
    }

    /**
     * The message bus calls the reset with no transaction open, unlike the other tests here, which all
     * run inside the test's own. The reset must open its own, and commit it: it used to fail on the
     * order's lazy item collection
     */
    @WithMockUser(username="osadmin", roles = {"ADMIN","USER"})
    @Test
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void testResetServiceOrderOutsideAnyTransaction() throws Exception {

        ServiceOrder createdServiceOrder = JsonUtils.toJsonObj(createServiceOrder(), ServiceOrder.class);
        String soId = createdServiceOrder.getId();

        ServiceOrderUpdate failed = new ServiceOrderUpdate();
        failed.setState(ServiceOrderStateType.FAILED);
        for (ServiceOrderItem soi : serviceOrderFromDb(soId).getOrderItem()) {
            ServiceOrderItem upd = new ServiceOrderItem();
            upd.setUuid(soi.getId());
            upd.setState(ServiceOrderStateType.FAILED);
            ServiceRestriction restriction = new ServiceRestriction();
            ServiceRef ref = new ServiceRef();
            ref.setId("created-" + soi.getId());
            ref.setName("created");
            restriction.addSupportingServiceItem(ref);
            upd.setService(restriction);
            failed.addOrderItemItem(upd);
        }
        serviceOrderRepoService.updateServiceOrder(soId, failed);

        String json = serviceOrderRepoService.resetServiceOrderAsString(soId, Map.of("note", "bus call"));

        ServiceOrder reset = JsonUtils.toJsonObj(json, ServiceOrder.class);
        assertThat(reset.getState()).isEqualTo(ServiceOrderStateType.INITIAL);
        // committed: a separate session reads the reset back
        ServiceOrder stored = serviceOrderFromDb(soId);
        assertThat(stored.getState()).isEqualTo(ServiceOrderStateType.INITIAL);
        assertThat(stored.getOrderItem()).allSatisfy(soi -> {
            assertThat(soi.getState()).isEqualTo(ServiceOrderStateType.INITIAL);
            assertThat(soi.getService().getSupportingService()).isEmpty();
        });
    }


    /**
     * An update of an existing order item that carries only its id and an action