use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.
the class ApiDuplicatorServiceImpl method duplicate.
@Override
public ApiEntity duplicate(final ApiEntity apiEntity, final DuplicateApiEntity duplicateApiEntity, String organizationId, String environmentId) {
requireNonNull(apiEntity, "Missing ApiEntity");
final String apiId = apiEntity.getId();
LOGGER.debug("Duplicate API {}", apiId);
final UpdateApiEntity newApiEntity = convert(apiEntity);
final Proxy proxy = apiEntity.getProxy();
proxy.setVirtualHosts(singletonList(new VirtualHost(duplicateApiEntity.getContextPath())));
newApiEntity.setProxy(proxy);
newApiEntity.setVersion(duplicateApiEntity.getVersion() == null ? apiEntity.getVersion() : duplicateApiEntity.getVersion());
if (duplicateApiEntity.getFilteredFields().contains("groups")) {
newApiEntity.setGroups(null);
} else {
newApiEntity.setGroups(apiEntity.getGroups());
}
final ApiEntity duplicatedApi = apiService.createWithApiDefinition(newApiEntity, getAuthenticatedUsername(), null);
if (!duplicateApiEntity.getFilteredFields().contains("members")) {
final Set<MembershipEntity> membershipsToDuplicate = membershipService.getMembershipsByReference(io.gravitee.rest.api.model.MembershipReferenceType.API, apiId);
RoleEntity primaryOwnerRole = roleService.findPrimaryOwnerRoleByOrganization(organizationId, RoleScope.API);
if (primaryOwnerRole != null) {
String primaryOwnerRoleId = primaryOwnerRole.getId();
membershipsToDuplicate.forEach(membership -> {
String roleId = membership.getRoleId();
if (!primaryOwnerRoleId.equals(roleId)) {
membershipService.addRoleToMemberOnReference(io.gravitee.rest.api.model.MembershipReferenceType.API, duplicatedApi.getId(), membership.getMemberType(), membership.getMemberId(), roleId);
}
});
}
}
if (!duplicateApiEntity.getFilteredFields().contains("pages")) {
final List<PageEntity> pages = pageService.search(new PageQuery.Builder().api(apiId).build(), true, environmentId);
pageService.duplicatePages(pages, environmentId, duplicatedApi.getId());
}
if (!duplicateApiEntity.getFilteredFields().contains("plans")) {
final Set<PlanEntity> plans = planService.findByApi(apiId);
planService.duplicatePlans(plans, environmentId, duplicatedApi.getId());
}
return duplicatedApi;
}
use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceTest method validate_nullIsNotASubDomain.
@Test
public void validate_nullIsNotASubDomain() {
VirtualHost vhost = new VirtualHost();
vhost.setHost(null);
vhost.setPath("/validVhostPath");
EnvironmentEntity environmentEntity = new EnvironmentEntity();
environmentEntity.setDomainRestrictions(Arrays.asList("test.gravitee.io", "other.gravitee.io"));
when(environmentService.findById(any())).thenReturn(environmentEntity);
final Collection<VirtualHost> virtualHosts = virtualHostService.sanitizeAndValidate(Collections.singletonList(vhost));
Assert.assertEquals(1, virtualHosts.size());
Assert.assertEquals("test.gravitee.io", virtualHosts.iterator().next().getHost());
}
use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceTest method validate_hostSubDomainOfDomainConstraint.
@Test
public void validate_hostSubDomainOfDomainConstraint() {
VirtualHost vhost = getValidVirtualHost();
String domainConstraint = vhost.getHost();
vhost.setHost("level2.level1." + domainConstraint);
EnvironmentEntity environmentEntity = new EnvironmentEntity();
environmentEntity.setDomainRestrictions(Collections.singletonList(domainConstraint));
when(environmentService.findById(any())).thenReturn(environmentEntity);
virtualHostService.sanitizeAndValidate(Collections.singletonList(vhost));
}
use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceTest method shouldFail_create_existingPath.
@Test(expected = ApiContextPathAlreadyExistsException.class)
public void shouldFail_create_existingPath() {
Api api1 = createMock("mock1", "/context");
when(apiRepository.search(null)).thenReturn(Collections.singletonList(api1));
virtualHostService.sanitizeAndValidate(Collections.singletonList(new VirtualHost("/context")));
}
use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceTest method getValidVirtualHost.
private VirtualHost getValidVirtualHost() {
VirtualHost vhost = new VirtualHost();
vhost.setHost("valid.host.gravitee.io");
vhost.setPath("/validVhostPath");
return vhost;
}
Aggregations