Search in sources :

Example 1 with StatusListResponse

use of org.wso2.carbon.identity.api.server.fetch.remote.v1.model.StatusListResponse in project identity-api-server by wso2.

the class ServerRemoteFetchConfigManagementService method createStatusListResponse.

/**
 * This method is used to create status list from list of deployment revisions.
 * This method uses java stream api to count successful deployments and failed deployments.
 *
 * @param deploymentRevisions List of deployment revisions.
 * @return StatusListResponse.
 */
private StatusListResponse createStatusListResponse(List<DeploymentRevision> deploymentRevisions) {
    StatusListResponse statusListResponse = new StatusListResponse();
    if (CollectionUtils.isNotEmpty(deploymentRevisions)) {
        List<StatusListItem> statusListItemList = new ArrayList<>();
        for (DeploymentRevision deploymentRevision : deploymentRevisions) {
            StatusListItem statusListItem = populateDeploymentRevision(deploymentRevision);
            statusListItemList.add(statusListItem);
        }
        statusListResponse.setRemoteFetchRevisionStatuses(statusListItemList);
        statusListResponse.setSuccessfulDeployments((int) deploymentRevisions.stream().filter(Objects::nonNull).filter(deploymentRevision -> deploymentRevision.getDeploymentStatus().name().equals(RemoteFetchConfigurationConstants.SUCCESS)).count());
        statusListResponse.setFailedDeployments((int) deploymentRevisions.stream().filter(Objects::nonNull).filter(deploymentRevision -> deploymentRevision.getDeploymentStatus().name().equals(RemoteFetchConfigurationConstants.FAIL)).count());
        Date date = deploymentRevisions.stream().map(DeploymentRevision::getLastSynchronizedDate).max(Date::compareTo).orElse(null);
        convertDateToStringIfNotNull(date, statusListResponse::setLastSynchronizedTime);
        return statusListResponse;
    } else {
        statusListResponse.setCount(0);
    }
    return statusListResponse;
}
Also used : RepositoryManagerAttributes(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RepositoryManagerAttributes) StringUtils(org.apache.commons.lang.StringUtils) Date(java.util.Date) DIRECTORY(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.DIRECTORY) RemoteFetchConfigurationPatchRequest(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RemoteFetchConfigurationPatchRequest) DeploymentRevision(org.wso2.carbon.identity.remotefetch.common.DeploymentRevision) PushEventWebHookPOSTRequest(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.PushEventWebHookPOSTRequest) PushEventWebHookPOSTRequestCommits(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.PushEventWebHookPOSTRequestCommits) ActionListenerAttributes(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.ActionListenerAttributes) Map(java.util.Map) RemoteFetchConfigurationConstants(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) ACCESS_TOKEN(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.ACCESS_TOKEN) List(java.util.List) Response(javax.ws.rs.core.Response) StatusListItem(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.StatusListItem) ACTION_LISTENER(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.ACTION_LISTENER) IS_ENABLED(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.IS_ENABLED) REPOSITORY_MANAGER(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.REPOSITORY_MANAGER) RemoteFetchConfiguration(org.wso2.carbon.identity.remotefetch.common.RemoteFetchConfiguration) LogFactory(org.apache.commons.logging.LogFactory) REMOTE_FETCH_NAME(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.REMOTE_FETCH_NAME) RemoteFetchUtils.convertDateToStringIfNotNull(org.wso2.carbon.identity.api.server.fetch.remote.v1.core.RemoteFetchUtils.convertDateToStringIfNotNull) BRANCH(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.BRANCH) BasicRemoteFetchConfiguration(org.wso2.carbon.identity.remotefetch.common.BasicRemoteFetchConfiguration) ACTION_LISTENER_ATTRIBUTES(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.ACTION_LISTENER_ATTRIBUTES) ContextLoader(org.wso2.carbon.identity.api.server.common.ContextLoader) StatusListResponse(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.StatusListResponse) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) BeanUtils(org.apache.commons.beanutils.BeanUtils) HashMap(java.util.HashMap) OptionalInt(java.util.OptionalInt) FREQUENCY(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.FREQUENCY) ArrayList(java.util.ArrayList) RemoteFetchServerException(org.wso2.carbon.identity.remotefetch.common.exceptions.RemoteFetchServerException) WEBHOOK_REQUEST(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.WEBHOOK_REQUEST) CollectionUtils(org.apache.commons.collections.CollectionUtils) RemoteFetchCoreException(org.wso2.carbon.identity.remotefetch.common.exceptions.RemoteFetchCoreException) IdentityTenantUtil(org.wso2.carbon.identity.core.util.IdentityTenantUtil) REPOSITORY_MANAGER_ATTRIBUTES(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.REPOSITORY_MANAGER_ATTRIBUTES) RemoteFetchConfigurationListResponse(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RemoteFetchConfigurationListResponse) RemoteFetchConfigurationPOSTRequest(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RemoteFetchConfigurationPOSTRequest) RemoteFetchClientException(org.wso2.carbon.identity.remotefetch.common.exceptions.RemoteFetchClientException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) RemoteFetchConfigurationListItem(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RemoteFetchConfigurationListItem) RemoteFetchConfigurationGetResponse(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RemoteFetchConfigurationGetResponse) CONFIGURATION_DEPLOYER_ATTRIBUTES(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.CONFIGURATION_DEPLOYER_ATTRIBUTES) URI(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.URI) RemoteFetchUtils.setIfNotNull(org.wso2.carbon.identity.api.server.fetch.remote.v1.core.RemoteFetchUtils.setIfNotNull) CONFIGURATION_DEPLOYER(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.CONFIGURATION_DEPLOYER) RemoteFetchServiceHolder(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchServiceHolder) Log(org.apache.commons.logging.Log) USER_NAME(org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants.USER_NAME) Collections(java.util.Collections) StatusListItem(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.StatusListItem) ArrayList(java.util.ArrayList) Objects(java.util.Objects) StatusListResponse(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.StatusListResponse) DeploymentRevision(org.wso2.carbon.identity.remotefetch.common.DeploymentRevision) Date(java.util.Date)

Example 2 with StatusListResponse

use of org.wso2.carbon.identity.api.server.fetch.remote.v1.model.StatusListResponse in project identity-api-server by wso2.

the class ServerRemoteFetchConfigManagementService method createRemoteFetchConfigurationResponse.

/**
 * This method is used to create GET response from remote fetch configuration id.
 *
 * @param remoteFetchConfiguration remote fetch configuration domain object.
 * @return RemoteFetchConfigurationGetResponse.
 * @throws RemoteFetchCoreException RemoteFetchCoreException
 */
private RemoteFetchConfigurationGetResponse createRemoteFetchConfigurationResponse(RemoteFetchConfiguration remoteFetchConfiguration) throws RemoteFetchCoreException {
    RemoteFetchConfigurationGetResponse remoteFetchConfigurationGetResponse = new RemoteFetchConfigurationGetResponse();
    ActionListenerAttributes actionListenerAttributes = createActionListenerAttributeProperties(remoteFetchConfiguration);
    RepositoryManagerAttributes repositoryManagerAttributes = createRepositoryManagerAttributeProperties(remoteFetchConfiguration);
    remoteFetchConfigurationGetResponse.setActionListenerAttributes(actionListenerAttributes);
    remoteFetchConfigurationGetResponse.setRepositoryManagerAttributes(repositoryManagerAttributes);
    remoteFetchConfigurationGetResponse.setConfigurationDeployerAttributes(null);
    setIfNotNull(remoteFetchConfiguration.getRemoteFetchConfigurationId(), remoteFetchConfigurationGetResponse::setId);
    setIfNotNull(remoteFetchConfiguration.isEnabled(), remoteFetchConfigurationGetResponse::setIsEnabled);
    setIfNotNull(remoteFetchConfiguration.getRemoteFetchName(), remoteFetchConfigurationGetResponse::setRemoteFetchName);
    setIfNotNull(remoteFetchConfiguration.getRepositoryManagerType(), remoteFetchConfigurationGetResponse::setRepositoryManagerType);
    setIfNotNull(remoteFetchConfiguration.getConfigurationDeployerType(), remoteFetchConfigurationGetResponse::setConfigurationDeployerType);
    setIfNotNull(remoteFetchConfiguration.getRepositoryManagerType(), remoteFetchConfigurationGetResponse::setRepositoryManagerType);
    StatusListResponse statusListResponse = this.createStatusListResponse(RemoteFetchServiceHolder.getRemoteFetchConfigurationService().getDeploymentRevisions(remoteFetchConfiguration.getRemoteFetchConfigurationId()));
    remoteFetchConfigurationGetResponse.setStatus(statusListResponse);
    return remoteFetchConfigurationGetResponse;
}
Also used : RemoteFetchConfigurationGetResponse(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RemoteFetchConfigurationGetResponse) ActionListenerAttributes(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.ActionListenerAttributes) StatusListResponse(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.StatusListResponse) RepositoryManagerAttributes(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RepositoryManagerAttributes)

Aggregations

ActionListenerAttributes (org.wso2.carbon.identity.api.server.fetch.remote.v1.model.ActionListenerAttributes)2 RemoteFetchConfigurationGetResponse (org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RemoteFetchConfigurationGetResponse)2 RepositoryManagerAttributes (org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RepositoryManagerAttributes)2 StatusListResponse (org.wso2.carbon.identity.api.server.fetch.remote.v1.model.StatusListResponse)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 OptionalInt (java.util.OptionalInt)1 Response (javax.ws.rs.core.Response)1 BeanUtils (org.apache.commons.beanutils.BeanUtils)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 StringUtils (org.apache.commons.lang.StringUtils)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 ContextLoader (org.wso2.carbon.identity.api.server.common.ContextLoader)1