use of org.wso2.carbon.registry.core.Association in project carbon-apimgt by wso2.
the class RegistryPersistenceUtilTestCase method testGetArtifactManager.
@Test
public void testGetArtifactManager() throws RegistryException, APIPersistenceException {
Registry registry = Mockito.mock(UserRegistry.class);
GovernanceArtifactConfiguration conf = Mockito.mock(GovernanceArtifactConfiguration.class);
PowerMockito.when(GovernanceUtils.findGovernanceArtifactConfiguration(APIConstants.API_KEY, registry)).thenReturn(conf);
Association[] assosiations = new Association[0];
Mockito.when(conf.getRelationshipDefinitions()).thenReturn(assosiations);
GenericArtifactManager manager = RegistryPersistenceUtil.getArtifactManager(registry, APIConstants.API_KEY);
Assert.assertNotNull("Manager is null", manager);
}
use of org.wso2.carbon.registry.core.Association in project carbon-apimgt by wso2.
the class APIProviderImplTest method testRemoveDocumentation.
@Test
public void testRemoveDocumentation() throws APIManagementException, RegistryException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
PowerMockito.when(APIUtil.getAPIDocPath(apiId) + "testDoc").thenReturn("testPath");
Resource resource = Mockito.mock(Resource.class);
Mockito.when(apiProvider.registry.get("testPathtestDoc")).thenReturn(resource);
Mockito.when(resource.getUUID()).thenReturn("1111");
PowerMockito.when(APIUtil.getArtifactManager(apiProvider.registry, APIConstants.DOCUMENTATION_KEY)).thenReturn(artifactManager);
GenericArtifact genericArtifact = Mockito.mock(GenericArtifact.class);
Mockito.when(artifactManager.getGenericArtifact("1111")).thenReturn(genericArtifact);
Mockito.when(genericArtifact.getAttribute(APIConstants.DOC_FILE_PATH)).thenReturn("testDocPath");
Association association = Mockito.mock(Association.class);
Association[] associations = new Association[] { association };
Mockito.when(apiProvider.registry.getAssociations("testPathtestDoc", APIConstants.DOCUMENTATION_KEY)).thenReturn(associations);
apiProvider.removeDocumentation(apiId, "testDoc", "testType", "carbon.super");
Mockito.verify(apiProvider.registry);
}
use of org.wso2.carbon.registry.core.Association in project carbon-apimgt by wso2.
the class APIProviderImplTest method testRemoveDocumentation1.
@Test
public void testRemoveDocumentation1() throws APIManagementException, RegistryException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO, null, null);
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
PowerMockito.when(APIUtil.getArtifactManager(apiProvider.registry, APIConstants.DOCUMENTATION_KEY)).thenReturn(artifactManager);
GenericArtifact artifact = Mockito.mock(GenericArtifact.class);
Mockito.when(artifactManager.getGenericArtifact("testId")).thenReturn(artifact);
Mockito.when(artifact.getPath()).thenReturn("docPath");
Mockito.when(artifact.getAttribute(APIConstants.DOC_FILE_PATH)).thenReturn("docFilePath");
Association association = Mockito.mock(Association.class);
Association[] associations = new Association[] { association };
Mockito.when(apiProvider.registry.getAssociations("docPath", APIConstants.DOCUMENTATION_KEY)).thenReturn(associations);
apiProvider.removeDocumentation(apiId, "testId", "carbon.super");
Mockito.verify(apiProvider.registry);
}
use of org.wso2.carbon.registry.core.Association in project carbon-apimgt by wso2.
the class APIProviderImpl method createDocumentation.
/**
* Create a product documentation
*
* @param product APIProduct
* @param documentation Documentation
* @throws APIManagementException if failed to add documentation
*/
private void createDocumentation(APIProduct product, Documentation documentation) throws APIManagementException {
try {
APIProductIdentifier productId = product.getId();
GenericArtifactManager artifactManager = new GenericArtifactManager(registry, APIConstants.DOCUMENTATION_KEY);
GenericArtifact artifact = artifactManager.newGovernanceArtifact(new QName(documentation.getName()));
artifactManager.addGenericArtifact(APIUtil.createDocArtifactContent(artifact, productId, documentation));
String productPath = APIUtil.getAPIProductPath(productId);
// Adding association from api to documentation . (API Product -----> doc)
registry.addAssociation(productPath, artifact.getPath(), APIConstants.DOCUMENTATION_ASSOCIATION);
String docVisibility = documentation.getVisibility().name();
String[] authorizedRoles = getAuthorizedRoles(productPath);
String visibility = product.getVisibility();
if (docVisibility != null) {
if (APIConstants.DOC_SHARED_VISIBILITY.equalsIgnoreCase(docVisibility)) {
authorizedRoles = null;
visibility = APIConstants.DOC_SHARED_VISIBILITY;
} else if (APIConstants.DOC_OWNER_VISIBILITY.equalsIgnoreCase(docVisibility)) {
authorizedRoles = null;
visibility = APIConstants.DOC_OWNER_VISIBILITY;
}
}
APIUtil.setResourcePermissions(product.getId().getProviderName(), visibility, authorizedRoles, artifact.getPath(), registry);
String docFilePath = artifact.getAttribute(APIConstants.DOC_FILE_PATH);
if (docFilePath != null && !StringUtils.EMPTY.equals(docFilePath)) {
// The docFilePatch comes as /t/tenanatdoman/registry/resource/_system/governance/apimgt/applicationdata..
// We need to remove the /t/tenanatdoman/registry/resource/_system/governance section to set permissions.
int startIndex = docFilePath.indexOf(APIConstants.GOVERNANCE) + (APIConstants.GOVERNANCE).length();
String filePath = docFilePath.substring(startIndex, docFilePath.length());
APIUtil.setResourcePermissions(product.getId().getProviderName(), visibility, authorizedRoles, filePath, registry);
registry.addAssociation(artifact.getPath(), filePath, APIConstants.DOCUMENTATION_FILE_ASSOCIATION);
}
documentation.setId(artifact.getId());
} catch (RegistryException e) {
handleException("Failed to add documentation", e);
} catch (UserStoreException e) {
handleException("Failed to add documentation", e);
}
}
use of org.wso2.carbon.registry.core.Association in project carbon-apimgt by wso2.
the class APIProviderImpl method getAPIsByProvider.
/**
* Get a list of APIs published by the given provider. If a given API has multiple APIs,
* only the latest version will
* be included in this list.
*
* @param providerId , provider id
* @return set of API
* @throws org.wso2.carbon.apimgt.api.APIManagementException if failed to get set of API
*/
@Override
public List<API> getAPIsByProvider(String providerId) throws APIManagementException {
List<API> apiSortedList = new ArrayList<API>();
try {
providerId = APIUtil.replaceEmailDomain(providerId);
String providerPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + providerId;
GenericArtifactManager artifactManager = APIUtil.getArtifactManager(registry, APIConstants.API_KEY);
Association[] associations = registry.getAssociations(providerPath, APIConstants.PROVIDER_ASSOCIATION);
for (Association association : associations) {
String apiPath = association.getDestinationPath();
if (registry.resourceExists(apiPath)) {
Resource resource = registry.get(apiPath);
String apiArtifactId = resource.getUUID();
if (apiArtifactId != null) {
GenericArtifact apiArtifact = artifactManager.getGenericArtifact(apiArtifactId);
if (apiArtifact != null) {
String type = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_TYPE);
if (!APIConstants.API_PRODUCT.equals(type)) {
apiSortedList.add(getAPI(apiArtifact));
}
}
} else {
throw new GovernanceException("artifact id is null of " + apiPath);
}
}
}
} catch (RegistryException e) {
handleException("Failed to get APIs for provider : " + providerId, e);
}
Collections.sort(apiSortedList, new APINameComparator());
return apiSortedList;
}
Aggregations