use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class IdentityProviderUpgrader method getActivationsTarget.
private ActivationTarget[] getActivationsTarget(int providerIndex) {
List<String> targetStrings = getListOfString("security.providers[" + providerIndex + "].activations");
List<ActivationTarget> activationTargets = new ArrayList<>();
targetStrings.forEach(target -> {
final String[] orgEnv = target.split(":");
if (orgEnv.length == 1) {
try {
this.organizationService.findById(orgEnv[0]);
activationTargets.add(new ActivationTarget(orgEnv[0], IdentityProviderActivationReferenceType.ORGANIZATION));
} catch (OrganizationNotFoundException onfe) {
logger.warn("Organization {} does not exist", orgEnv[0]);
}
} else if (orgEnv.length == 2) {
try {
this.organizationService.findById(orgEnv[0]);
EnvironmentEntity env = this.environmentService.findById(orgEnv[1]);
if (env.getOrganizationId().equals(orgEnv[0])) {
activationTargets.add(new ActivationTarget(orgEnv[1], IdentityProviderActivationReferenceType.ENVIRONMENT));
} else {
logger.warn("Environment {} does not exist in organization {}", orgEnv[1], orgEnv[0]);
}
} catch (OrganizationNotFoundException onfe) {
logger.warn("Organization {} does not exist", orgEnv[0]);
} catch (EnvironmentNotFoundException Enfe) {
logger.warn("Environment {} does not exist", orgEnv[1]);
}
}
});
return activationTargets.toArray(new ActivationTarget[activationTargets.size()]);
}
use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class ParameterServiceTest method shouldFindAsBooleanDefaultValue.
@Test
public void shouldFindAsBooleanDefaultValue() throws TechnicalException {
when(parameterRepository.findById(PORTAL_USERCREATION_ENABLED.key(), "DEFAULT", ParameterReferenceType.ENVIRONMENT)).thenReturn(empty());
when(parameterRepository.findById(PORTAL_USERCREATION_ENABLED.key(), "DEFAULT_ORG", ParameterReferenceType.ORGANIZATION)).thenReturn(empty());
EnvironmentEntity defaultEnv = new EnvironmentEntity();
defaultEnv.setOrganizationId("DEFAULT_ORG");
when(environmentService.findById("DEFAULT")).thenReturn(defaultEnv);
assertTrue(parameterService.findAsBoolean(PORTAL_USERCREATION_ENABLED, io.gravitee.rest.api.model.parameters.ParameterReferenceType.ENVIRONMENT));
}
use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class CategoryService_CreateTest method shouldCreateCategory.
@Test
public void shouldCreateCategory() throws TechnicalException {
NewCategoryEntity v1 = new NewCategoryEntity();
v1.setName("v1");
when(mockCategoryRepository.create(argThat(cat -> cat.getCreatedAt() != null))).thenReturn(new Category());
when(mockEnvironmentService.findById("DEFAULT")).thenReturn(new EnvironmentEntity());
CategoryEntity category = categoryService.create(v1);
assertNotNull("result is null", category);
verify(mockAuditService, times(1)).createEnvironmentAuditLog(any(), eq(CATEGORY_CREATED), any(), isNull(), any());
verify(mockCategoryRepository, times(1)).create(argThat(arg -> arg != null && arg.getName().equals("v1")));
}
Aggregations