Skip to content
Snippets Groups Projects
Commit 2d663b19 authored by Konrad Krasnodebski's avatar Konrad Krasnodebski
Browse files

Add feature flag

parent ad45b9c8
No related branches found
No related tags found
2 merge requests!620Update version of default branch to 0.27.0-SNAPSHOT,!535Extend cron to catch about to expire legal tags
Pipeline #246703 failed
......@@ -10,11 +10,14 @@ import org.opengroup.osdu.legal.tags.LegalTagConstraintValidator;
import org.opengroup.osdu.legal.tags.LegalTagService;
import org.opengroup.osdu.core.common.model.legal.LegalTag;
import org.opengroup.osdu.core.common.model.legal.Properties;
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Value;
import org.opengroup.osdu.legal.jobs.models.LegalTagJobResult;
import org.opengroup.osdu.legal.jobs.models.AboutToExpireLegalTags;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.feature.IFeatureFlag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Value;
import java.util.ArrayList;
import java.util.Collection;
......@@ -35,9 +38,14 @@ public class LegalTagStatusJob {
@Inject
private JaxRsDpsLog log;
@Autowired
private IFeatureFlag aboutToExpireLegalTagFeatureFlag;
@Value("${LEGALTAG_EXPIRATION}")
private String legalTagExpiration;
private String aboutToExpireFeatureFlagName = "featureFlag.aboutToExpireLegalTag.enabled";
public LegalTagJobResult run(String projectId, DpsHeaders headers, String tenantName) throws Exception {
LegalTagJobResult legalTagJobResult = new LegalTagJobResult(new StatusChangedTags(), new AboutToExpireLegalTags());
validator.setHeaders(headers);
......@@ -45,7 +53,9 @@ public class LegalTagStatusJob {
legalTagJobResult = checkAndUpdateLegalTagStatus(false, tenantName, legalTagJobResult);
publishLegalTagStatusUpdateEvents(!legalTagJobResult.statusChangedTags.getStatusChangedTags().isEmpty(), projectId, headers, legalTagJobResult.statusChangedTags);
publisAboutToExpireLegalTagEvents(!legalTagJobResult.aboutToExpireLegalTags.getAboutToExpireLegalTags().isEmpty(), projectId, headers, legalTagJobResult.aboutToExpireLegalTags);
if (isAboutToExpireFeatureFlagEnabled()) {
publisAboutToExpireLegalTagEvents(!legalTagJobResult.aboutToExpireLegalTags.getAboutToExpireLegalTags().isEmpty(), projectId, headers, legalTagJobResult.aboutToExpireLegalTags);
}
return legalTagJobResult;
}
......@@ -56,7 +66,7 @@ public class LegalTagStatusJob {
String errors = validator.getErrors(tag);
Boolean hasErrors = errors != null;
if (isCurrentlyValid) {
if (isAboutToExpireFeatureFlagEnabled() && isCurrentlyValid) {
checkAboutToExpireLegalTag(tag, tenantName, legalTagJobResult.aboutToExpireLegalTags, hasErrors);
}
......@@ -123,4 +133,8 @@ public class LegalTagStatusJob {
aboutToExpireLegalTagPublisher.publish(projectId, headers, aboutToExpireLegalTags);
}
}
private Boolean isAboutToExpireFeatureFlagEnabled() {
return aboutToExpireLegalTagFeatureFlag.isFeatureEnabled(aboutToExpireFeatureFlagName);
}
}
......@@ -74,7 +74,7 @@ public class LegalTagStatusJobControllerTest {
ResponseEntity<HttpStatus> result = sut.checkLegalTagStatusChanges();
assertEquals(HttpStatus.NO_CONTENT, result.getStatusCode());
verify(auditLogger).legalTagJobRanSuccess(Collections.singletonList(statusChangedTags.toString()));
verify(auditLogger).legalTagJobRanSuccess(Collections.singletonList(legalTagJobResult.toString()));
}
@Test
......
......@@ -13,6 +13,7 @@ import org.opengroup.osdu.core.common.model.legal.LegalTag;
import org.opengroup.osdu.core.common.model.legal.Properties;
import org.opengroup.osdu.legal.jobs.models.LegalTagJobResult;
import org.opengroup.osdu.legal.jobs.models.AboutToExpireLegalTags;
import org.opengroup.osdu.core.common.feature.IFeatureFlag;
import org.junit.Before;
import org.junit.Test;
......@@ -21,6 +22,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.Collection;
......@@ -33,6 +35,7 @@ import static org.mockito.Mockito.*;
import static junit.framework.TestCase.fail;
@RunWith(MockitoJUnitRunner.class)
@SpringBootTest(classes = {IFeatureFlag.class})
public class LegalTagStatusJobTests {
@Mock
private LegalTagConstraintValidator validator;
......@@ -46,6 +49,8 @@ public class LegalTagStatusJobTests {
private IAboutToExpireLegalTagPublisher aboutToExpireLegalTagPublisherMock;
@Mock
private JaxRsDpsLog log;
@Mock
private IFeatureFlag aboutToExpireLegalTagFeatureFlag;
@InjectMocks
LegalTagStatusJob sut;
......@@ -58,6 +63,8 @@ public class LegalTagStatusJobTests {
headers.put(DpsHeaders.DATA_PARTITION_ID, "SIS-INTERNAL-HQ");
headers.put(DpsHeaders.CORRELATION_ID, "12345-12345");
headers.put(DpsHeaders.USER_EMAIL, "nonexistent@nonexisent.domain");
// aboutToExpireFeatureFlag
when(aboutToExpireLegalTagFeatureFlag.isFeatureEnabled(any())).thenReturn(true);
ReflectionTestUtils.setField(sut, "legalTagExpiration", "1d");
}
......
......@@ -64,3 +64,7 @@ repository.implementation=${LEGAL_SERVICE_REPOSITORY_IMPLEMENTATION:dynamodb}
#Tomcat limits
server.tomcat.threads.max=${TOMCAT_THREADS_MAX:300}
# Feature flag settings
featureFlag.strategy=appProperty
featureFlag.aboutToExpireLegalTag.enabled=true
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment