Search in sources :

Example 1 with Association

use of org.wso2.carbon.identity.workflow.mgt.stub.metadata.Association 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);
    }
}
Also used : Association(org.wso2.carbon.registry.core.Association) Resource(org.wso2.carbon.registry.core.Resource)

Example 2 with Association

use of org.wso2.carbon.identity.workflow.mgt.stub.metadata.Association in project carbon-apimgt by wso2.

the class APIProviderImplTest method prepareForGetAPIsByProvider.

/**
 * This method can be used when invoking getAPIsByProvider()
 */
private void prepareForGetAPIsByProvider(GenericArtifactManager artifactManager, APIProviderImplWrapper apiProvider, String providerId, API api1, API api2) throws APIManagementException, RegistryException {
    String providerPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + providerId;
    // Mocking API1 association
    Association association1 = Mockito.mock(Association.class);
    String apiPath1 = "/API1/1.0.0";
    Resource resource1 = Mockito.mock(Resource.class);
    String apiArtifactId1 = "76897689";
    Mockito.when(apiProvider.registry.resourceExists(apiPath1)).thenReturn(true);
    Mockito.when(association1.getDestinationPath()).thenReturn(apiPath1);
    Mockito.when(apiProvider.registry.get(apiPath1)).thenReturn(resource1);
    Mockito.when(resource1.getUUID()).thenReturn(apiArtifactId1);
    GenericArtifact apiArtifact1 = Mockito.mock(GenericArtifact.class);
    Mockito.when(artifactManager.getGenericArtifact(apiArtifactId1)).thenReturn(apiArtifact1);
    Mockito.when(APIUtil.getAPI(apiArtifact1, apiProvider.registry)).thenReturn(api1);
    // Mocking API2 association
    Association association2 = Mockito.mock(Association.class);
    String apiPath2 = "/API2/1.0.0";
    Resource resource2 = Mockito.mock(Resource.class);
    String apiArtifactId2 = "76897622";
    Mockito.when(apiProvider.registry.resourceExists(apiPath2)).thenReturn(true);
    Mockito.when(association2.getDestinationPath()).thenReturn(apiPath2);
    Mockito.when(apiProvider.registry.get(apiPath2)).thenReturn(resource2);
    Mockito.when(resource2.getUUID()).thenReturn(apiArtifactId2);
    GenericArtifact apiArtifact2 = Mockito.mock(GenericArtifact.class);
    Mockito.when(artifactManager.getGenericArtifact(apiArtifactId2)).thenReturn(apiArtifact2);
    Mockito.when(APIUtil.getAPI(apiArtifact2, apiProvider.registry)).thenReturn(api2);
    Association[] associactions = { association1, association2 };
    Mockito.when(apiProvider.registry.getAssociations(providerPath, APIConstants.PROVIDER_ASSOCIATION)).thenReturn(associactions);
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) Association(org.wso2.carbon.registry.core.Association) Resource(org.wso2.carbon.registry.core.Resource)

Example 3 with Association

use of org.wso2.carbon.identity.workflow.mgt.stub.metadata.Association in project carbon-apimgt by wso2.

the class APIUtil 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);
    }
}
Also used : Association(org.wso2.carbon.registry.core.Association) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) APIResource(org.wso2.carbon.apimgt.api.doc.model.APIResource)

Example 4 with Association

use of org.wso2.carbon.identity.workflow.mgt.stub.metadata.Association in project carbon-identity-framework by wso2.

the class CORSOriginDAOImpl method addCORSOrigins.

/**
 * {@inheritDoc}
 */
@Override
public void addCORSOrigins(int applicationId, List<CORSOrigin> corsOrigins, int tenantId) throws CORSManagementServiceServerException {
    String tenantDomain = IdentityTenantUtil.getTenantDomain(tenantId);
    try (Connection connection = IdentityDatabaseUtil.getDBConnection(true)) {
        try {
            for (CORSOrigin corsOrigin : corsOrigins) {
                // Check if the origins is there.
                try (NamedPreparedStatement namedPreparedStatement1 = new NamedPreparedStatement(connection, GET_CORS_ORIGIN_ID)) {
                    namedPreparedStatement1.setInt(1, tenantId);
                    namedPreparedStatement1.setString(2, corsOrigin.getOrigin());
                    try (ResultSet resultSet1 = namedPreparedStatement1.executeQuery()) {
                        if (!resultSet1.next()) {
                            // Origin is not present. Therefore add an origin without the tenant association.
                            try (NamedPreparedStatement namedPreparedStatement2 = new NamedPreparedStatement(connection, INSERT_CORS_ORIGIN)) {
                                namedPreparedStatement2.setInt(TENANT_ID, tenantId);
                                namedPreparedStatement2.setString(ORIGIN, corsOrigin.getOrigin());
                                namedPreparedStatement2.setString(UNIQUE_ID, UUID.randomUUID().toString());
                                namedPreparedStatement2.executeUpdate();
                            }
                        }
                    }
                }
                try (NamedPreparedStatement namedPreparedStatement3 = new NamedPreparedStatement(connection, GET_CORS_ORIGIN_ID)) {
                    // Get origin id.
                    namedPreparedStatement3.setInt(TENANT_ID, tenantId);
                    namedPreparedStatement3.setString(ORIGIN, corsOrigin.getOrigin());
                    try (ResultSet resultSet2 = namedPreparedStatement3.executeQuery()) {
                        if (resultSet2.next()) {
                            int corsOriginId = resultSet2.getInt("ID");
                            // Add application associations.
                            try (PreparedStatement preparedStatement4 = connection.prepareStatement(INSERT_CORS_ASSOCIATION)) {
                                preparedStatement4.setInt(1, corsOriginId);
                                preparedStatement4.setInt(2, applicationId);
                                preparedStatement4.executeUpdate();
                            }
                        } else {
                            IdentityDatabaseUtil.rollbackTransaction(connection);
                            throw handleServerException(ERROR_CODE_CORS_ADD, tenantDomain);
                        }
                    }
                }
            }
        } catch (SQLException e) {
            IdentityDatabaseUtil.rollbackTransaction(connection);
            throw handleServerException(ERROR_CODE_CORS_ADD, e, tenantDomain);
        }
        // Commit the transaction as no errors were thrown.
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        throw handleServerException(ERROR_CODE_CORS_ADD, e, tenantDomain);
    }
}
Also used : CORSOrigin(org.wso2.carbon.identity.cors.mgt.core.model.CORSOrigin) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) PreparedStatement(java.sql.PreparedStatement)

Example 5 with Association

use of org.wso2.carbon.identity.workflow.mgt.stub.metadata.Association in project carbon-identity-framework by wso2.

the class WorkflowRequestAssociationDAO method getWorkflowAssociationsForRequest.

/**
 * @param eventId
 * @param tenantId
 * @return
 * @throws InternalWorkflowException
 */
public List<WorkflowAssociation> getWorkflowAssociationsForRequest(String eventId, int tenantId) throws InternalWorkflowException {
    Connection connection = IdentityDatabaseUtil.getDBConnection(false);
    PreparedStatement prepStmt = null;
    ResultSet rs;
    List<WorkflowAssociation> associations = new ArrayList<>();
    String query = SQLConstants.GET_ASSOCIATIONS_FOR_EVENT_QUERY;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, eventId);
        prepStmt.setInt(2, tenantId);
        rs = prepStmt.executeQuery();
        while (rs.next()) {
            int id = rs.getInt(SQLConstants.ID_COLUMN);
            String condition = rs.getString(SQLConstants.CONDITION_COLUMN);
            String workflowId = rs.getString(SQLConstants.WORKFLOW_ID_COLUMN);
            String associationName = rs.getString(SQLConstants.ASSOCIATION_NAME_COLUMN);
            WorkflowAssociation association = new WorkflowAssociation();
            association.setWorkflowId(workflowId);
            association.setAssociationCondition(condition);
            association.setEventId(eventId);
            association.setAssociationId(id);
            association.setAssociationName(associationName);
            associations.add(association);
        }
    } catch (SQLException e) {
        throw new InternalWorkflowException("Error when executing the sql query:" + query, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
    }
    return associations;
}
Also used : SQLException(java.sql.SQLException) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) WorkflowAssociation(org.wso2.carbon.identity.workflow.mgt.bean.WorkflowAssociation)

Aggregations

Association (org.wso2.carbon.registry.core.Association)16 Connection (java.sql.Connection)15 SQLException (java.sql.SQLException)15 ArrayList (java.util.ArrayList)13 Test (org.testng.annotations.Test)13 PreparedStatement (java.sql.PreparedStatement)12 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)12 Association (org.wso2.carbon.identity.workflow.mgt.stub.metadata.Association)11 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)11 RemoteException (java.rmi.RemoteException)10 WorkflowAdminServiceWorkflowException (org.wso2.carbon.identity.workflow.mgt.stub.WorkflowAdminServiceWorkflowException)10 Resource (org.wso2.carbon.registry.core.Resource)10 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)8 ResultSet (java.sql.ResultSet)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 FederatedAssociationManagerException (org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException)7 Association (org.wso2.carbon.identity.workflow.mgt.dto.Association)7 InternalWorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException)6 Test (org.junit.Test)5 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)5