Skip to content
Snippets Groups Projects
Commit bd376abb authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6300 OZG-6388 Feature toggle for collaboration

parent 4281bb2c
Branches
Tags
No related merge requests found
...@@ -10,6 +10,7 @@ server: ...@@ -10,6 +10,7 @@ server:
ozgcloud: ozgcloud:
feature: feature:
reply-always-allowed: true reply-always-allowed: true
collaboration-enabled: true
production: false production: false
stage: stage:
production: false production: false
......
...@@ -18,6 +18,7 @@ grpc: ...@@ -18,6 +18,7 @@ grpc:
ozgcloud: ozgcloud:
feature: feature:
reply-always-allowed: true reply-always-allowed: true
collaboration-enabled: true
production: false production: false
user-assistance: user-assistance:
documentation: documentation:
......
package de.ozgcloud.alfa.collaboration;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
import java.util.Objects;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.server.RepresentationModelProcessor;
import org.springframework.stereotype.Component;
import de.ozgcloud.alfa.common.ModelBuilder;
import de.ozgcloud.alfa.common.command.CommandController;
import de.ozgcloud.alfa.vorgang.VorgangWithEingang;
@Component
@ConditionalOnProperty("ozgcloud.feature.collaboration-enabled")
class CollaborationVorgangProcessor implements RepresentationModelProcessor<EntityModel<VorgangWithEingang>> {
static final LinkRelation REL_CREATE_COLLABORATION_REQUEST = LinkRelation.of("createCollaborationRequest");
@Override
public EntityModel<VorgangWithEingang> process(EntityModel<VorgangWithEingang> model) {
var vorgang = model.getContent();
if (Objects.isNull(vorgang)) {
return model;
}
return ModelBuilder.fromModel(model)
.addLink(linkTo(methodOn(CommandController.CommandByRelationController.class).createCommand(vorgang.getId(), vorgang.getId(),
vorgang.getVersion(), null)).withRel(REL_CREATE_COLLABORATION_REQUEST))
.buildModel();
}
}
...@@ -16,4 +16,9 @@ public class FeatureToggleProperties { ...@@ -16,4 +16,9 @@ public class FeatureToggleProperties {
* Enable mail reply option regardless of other configuration. * Enable mail reply option regardless of other configuration.
*/ */
private boolean replyAlwaysAllowed = false; private boolean replyAlwaysAllowed = false;
/**
* Enable collaboration-feature in Vorgang
*/
private boolean collaborationEnabled = false;
} }
package de.ozgcloud.alfa.collaboration;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
class CollaborationVorgangProcessorITCase {
@SpringBootTest(properties = {"ozgcloud.feature.collaboration-enabled=true"})
@Nested
class OnFeatureEnabled {
@Test
void shouldExistInApplicationContext(ApplicationContext context) {
assertThat(context.getBean(CollaborationVorgangProcessor.class)).isNotNull();
}
}
@SpringBootTest
@Nested
class OnFeatureDisabled {
@Test
void shouldNotExistInApplicationContext(ApplicationContext context) {
assertThatThrownBy(() -> context.getBean(CollaborationVorgangProcessor.class)).isInstanceOf(NoSuchBeanDefinitionException.class);
}
}
}
package de.ozgcloud.alfa.collaboration;
import static de.ozgcloud.alfa.common.UserProfileUrlProviderTestFactory.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.Spy;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.UriTemplate;
import de.ozgcloud.alfa.common.UserProfileUrlProvider;
import de.ozgcloud.alfa.common.command.CommandController;
import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
import de.ozgcloud.alfa.vorgang.VorgangWithEingangTestFactory;
class CollaborationVorgangProcessorTest {
@Spy
private CollaborationVorgangProcessor processor;
private final UserProfileUrlProvider urlProvider = new UserProfileUrlProvider();
@Nested
class TestProcess {
@Nested
class OnNullVorgang {
@Test
void shouldNotAddLinksIfVorgangIsNull() {
var model = processor.process(new EntityModel<>() {});
assertThat(model.hasLinks()).isFalse();
}
}
@Nested
class OnNonNullVorgang {
@BeforeEach
void prepareBuilder() {
initUserProfileUrlProvider(urlProvider);
}
@Test
void shouldAddCreateCollaborationRequestRelation() {
var model = processor.process(EntityModel.of(VorgangWithEingangTestFactory.create()));
assertThat(model.getLink(CollaborationVorgangProcessor.REL_CREATE_COLLABORATION_REQUEST)).isPresent().get()
.extracting(Link::getHref)
.isEqualTo(UriTemplate.of(CommandController.CommandByRelationController.COMMAND_BY_RELATION_PATH)
.expand(VorgangHeaderTestFactory.ID, VorgangHeaderTestFactory.ID, VorgangHeaderTestFactory.VERSION).toString());
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment