use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact in project carbon-apimgt by wso2.
the class RegistryPersistenceUtil method getDevPortalAPIForSearch.
public static DevPortalAPI getDevPortalAPIForSearch(GenericArtifact apiArtifact) throws APIPersistenceException {
DevPortalAPI api = new DevPortalAPI();
try {
api.setContext(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_CONTEXT_TEMPLATE));
api.setDescription(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION));
api.setId(apiArtifact.getId());
api.setStatus(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_STATUS));
api.setApiName(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_NAME));
api.setProviderName(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER));
;
api.setVersion(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VERSION));
} catch (GovernanceException e) {
throw new APIPersistenceException("Error while extracting api attributes ", e);
}
return api;
}
use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact in project carbon-apimgt by wso2.
the class RegistryPersistenceUtil method notifyAPIStateChangeToAssociatedDocuments.
/**
* Notify document artifacts if an api state change occured. This change is required to re-trigger the document
* indexer so that the documnet indexes will be updated with the new associated api status.
*
* @param apiArtifact
* @param registry
* @throws RegistryException
* @throws APIManagementException
*/
public static void notifyAPIStateChangeToAssociatedDocuments(GenericArtifact apiArtifact, Registry registry) throws RegistryException, APIManagementException {
Association[] docAssociations = registry.getAssociations(apiArtifact.getPath(), APIConstants.DOCUMENTATION_ASSOCIATION);
for (Association association : docAssociations) {
String documentResourcePath = association.getDestinationPath();
Resource docResource = registry.get(documentResourcePath);
String oldStateChangeIndicatorStatus = docResource.getProperty(APIConstants.API_STATE_CHANGE_INDICATOR);
String newStateChangeIndicatorStatus = "false";
if (oldStateChangeIndicatorStatus != null) {
newStateChangeIndicatorStatus = String.valueOf(!Boolean.parseBoolean(oldStateChangeIndicatorStatus));
}
docResource.setProperty(APIConstants.API_STATE_CHANGE_INDICATOR, "false");
registry.put(documentResourcePath, docResource);
}
}
use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact in project carbon-apimgt by wso2.
the class RegistryPersistenceDocUtil method createDocArtifactContent.
public static GenericArtifact createDocArtifactContent(GenericArtifact artifact, String apiName, String apiVersion, String apiProvider, Documentation documentation) throws DocumentationPersistenceException {
try {
artifact.setAttribute(APIConstants.DOC_NAME, documentation.getName());
artifact.setAttribute(APIConstants.DOC_SUMMARY, documentation.getSummary());
artifact.setAttribute(APIConstants.DOC_TYPE, documentation.getType().getType());
artifact.setAttribute(APIConstants.DOC_VISIBILITY, documentation.getVisibility().name());
Documentation.DocumentSourceType sourceType = documentation.getSourceType();
switch(sourceType) {
case INLINE:
sourceType = Documentation.DocumentSourceType.INLINE;
break;
case MARKDOWN:
sourceType = Documentation.DocumentSourceType.MARKDOWN;
break;
case URL:
sourceType = Documentation.DocumentSourceType.URL;
break;
case FILE:
{
sourceType = Documentation.DocumentSourceType.FILE;
}
break;
default:
throw new DocumentationPersistenceException("Unknown sourceType " + sourceType + " provided for documentation");
}
// Therefore setting a default value if it is not set.
if (documentation.getSourceUrl() == null) {
documentation.setSourceUrl(" ");
}
artifact.setAttribute(APIConstants.DOC_SOURCE_TYPE, sourceType.name());
artifact.setAttribute(APIConstants.DOC_SOURCE_URL, documentation.getSourceUrl());
artifact.setAttribute(APIConstants.DOC_FILE_PATH, documentation.getFilePath());
artifact.setAttribute(APIConstants.DOC_OTHER_TYPE_NAME, documentation.getOtherTypeName());
String basePath = RegistryPersistenceUtil.replaceEmailDomain(apiProvider) + RegistryConstants.PATH_SEPARATOR + apiName + RegistryConstants.PATH_SEPARATOR + apiVersion;
artifact.setAttribute(APIConstants.DOC_API_BASE_PATH, basePath);
} catch (GovernanceException e) {
String msg = "Failed to create doc artifact content from :" + documentation.getName();
log.error(msg, e);
throw new DocumentationPersistenceException(msg, e);
}
return artifact;
}
use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact in project carbon-apimgt by wso2.
the class RegistryPersistenceImplTestCase method testGetDevPortalAPI.
@Test
public void testGetDevPortalAPI() throws Exception {
Registry registry = Mockito.mock(UserRegistry.class);
Resource resource = new ResourceImpl();
Mockito.when(registry.get(anyString())).thenReturn(resource);
Tag[] tags = new Tag[1];
Tag tag = new Tag();
tag.setTagName("testTag");
tags[0] = tag;
Mockito.when(registry.getTags(anyString())).thenReturn(tags);
GenericArtifact artifact = PersistenceHelper.getSampleAPIArtifact();
String apiUUID = artifact.getId();
String apiDescription = artifact.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION);
APIPersistence apiPersistenceInstance = new RegistryPersistenceImplWrapper(registry, artifact);
Organization org = new Organization(SUPER_TENANT_DOMAIN);
DevPortalAPI devAPI = apiPersistenceInstance.getDevPortalAPI(org, apiUUID);
Assert.assertEquals("API UUID does not match", apiUUID, devAPI.getId());
Assert.assertEquals("API Description does not match", apiDescription, devAPI.getDescription());
}
use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact in project carbon-apimgt by wso2.
the class RegistryPersistenceImplTestCase method testUpdateAPI.
@Test
public void testUpdateAPI() throws APIPersistenceException, RegistryException, APIManagementException {
PublisherAPI publisherAPI = new PublisherAPI();
publisherAPI.setDescription("Modified description");
API api = APIMapper.INSTANCE.toApi(publisherAPI);
Registry registry = Mockito.mock(UserRegistry.class);
Resource resource = new ResourceImpl();
Mockito.when(registry.get(anyString())).thenReturn(resource);
Tag[] tags = new Tag[0];
Mockito.when(registry.getTags(anyString())).thenReturn(tags);
GenericArtifact existArtifact = PersistenceHelper.getSampleAPIArtifact();
String apiUUID = existArtifact.getId();
PowerMockito.mockStatic(RegistryPersistenceUtil.class);
GenericArtifactManager manager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(RegistryPersistenceUtil.getArtifactManager(registry, APIConstants.API_KEY)).thenReturn(manager);
Mockito.when(manager.getGenericArtifact(apiUUID)).thenReturn(existArtifact);
Mockito.doNothing().when(manager).updateGenericArtifact(existArtifact);
PowerMockito.when(RegistryPersistenceUtil.getArtifactManager(registry, APIConstants.API_KEY)).thenReturn(manager);
GenericArtifact updatedArtifact = PersistenceHelper.getSampleAPIArtifact();
updatedArtifact.setAttribute(APIConstants.API_OVERVIEW_DESCRIPTION, api.getDescription());
PowerMockito.when(RegistryPersistenceUtil.createAPIArtifactContent(any(GenericArtifact.class), any(API.class))).thenReturn(updatedArtifact);
Organization org = new Organization(SUPER_TENANT_DOMAIN);
APIPersistence apiPersistenceInstance = new RegistryPersistenceImplWrapper(registry, existArtifact);
PublisherAPI updatedAPI = apiPersistenceInstance.updateAPI(org, publisherAPI);
Assert.assertEquals("Updated API description does not match", "Modified description", updatedAPI.getDescription());
}
Aggregations