use of org.wso2.carbon.governance.api.util.GovernanceArtifactConfiguration in project carbon-apimgt by wso2.
the class RegistryPersistenceImpl method changeAPILifeCycle.
@Override
public void changeAPILifeCycle(Organization org, String apiId, String status) throws APIPersistenceException {
GenericArtifactManager artifactManager = null;
boolean isTenantFlowStarted = false;
try {
RegistryHolder holder = getRegistry(org.getName());
Registry registry = holder.getRegistry();
isTenantFlowStarted = holder.isTenantFlowStarted();
if (GovernanceUtils.findGovernanceArtifactConfiguration(APIConstants.API_KEY, registry) != null) {
artifactManager = new GenericArtifactManager(registry, APIConstants.API_KEY);
GenericArtifact apiArtifact = artifactManager.getGenericArtifact(apiId);
String action = LCManagerFactory.getInstance().getLCManager().getTransitionAction(apiArtifact.getLifecycleState().toUpperCase(), status.toUpperCase());
apiArtifact.invokeAction(action, APIConstants.API_LIFE_CYCLE);
} else {
log.warn("Couldn't find GovernanceArtifactConfiguration of RXT: " + APIConstants.API_KEY + ". Tenant id set in registry : " + ((UserRegistry) registry).getTenantId() + ", Tenant domain set in PrivilegedCarbonContext: " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
}
} catch (GovernanceException e) {
throw new APIPersistenceException("Error while changing the lifecycle. ", e);
} catch (RegistryException e) {
throw new APIPersistenceException("Error while accessing the registry. ", e);
} catch (PersistenceException e) {
throw new APIPersistenceException("Error while accessing the lifecycle. ", e);
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
}
use of org.wso2.carbon.governance.api.util.GovernanceArtifactConfiguration in project carbon-apimgt by wso2.
the class RegistryPersistenceDocUtil method getDocumentArtifactManager.
public static GenericArtifactManager getDocumentArtifactManager(Registry registry) throws DocumentationPersistenceException {
GenericArtifactManager artifactManager = null;
String key = "document";
try {
GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
if (GovernanceUtils.findGovernanceArtifactConfiguration(key, registry) != null) {
artifactManager = new GenericArtifactManager(registry, key);
} else {
log.warn("Couldn't find GovernanceArtifactConfiguration of RXT: " + key + ". Tenant id set in registry : " + ((UserRegistry) registry).getTenantId() + ", Tenant domain set in PrivilegedCarbonContext: " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
}
} catch (RegistryException e) {
String msg = "Failed to initialize GenericArtifactManager";
log.error(msg, e);
throw new DocumentationPersistenceException(msg, e);
}
return artifactManager;
}
use of org.wso2.carbon.governance.api.util.GovernanceArtifactConfiguration 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);
}
Aggregations