Search in sources :

Example 21 with Mediation

use of org.wso2.carbon.apimgt.persistence.dto.Mediation in project carbon-apimgt by wso2.

the class MediationMappingUtil method fromMediationInfoToDTO.

/**
 * Converts an Mediation object into MediationInfoDTO
 *
 * @param mediation Mediation object
 * @return MediationInfoDTO object corresponding to the given Mediation object
 */
public static MediationInfoDTO fromMediationInfoToDTO(Mediation mediation) {
    MediationInfoDTO mediationInfoDTO = new MediationInfoDTO();
    mediationInfoDTO.setId(mediation.getUuid());
    mediationInfoDTO.setName(mediation.getName());
    mediationInfoDTO.setType(MediationInfoDTO.TypeEnum.valueOf(mediation.getType().toUpperCase()));
    return mediationInfoDTO;
}
Also used : MediationInfoDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.MediationInfoDTO)

Example 22 with Mediation

use of org.wso2.carbon.apimgt.persistence.dto.Mediation in project carbon-apimgt by wso2.

the class MediationMappingUtil method fromMediationToDTO.

public static MediationDTO fromMediationToDTO(Mediation mediation) {
    MediationDTO mediationDTO = new MediationDTO();
    mediationDTO.setId(mediation.getUuid());
    mediationDTO.setName(mediation.getName());
    mediationDTO.setType(MediationDTO.TypeEnum.valueOf(mediation.getType().toUpperCase()));
    mediationDTO.setConfig(mediation.getConfig());
    return mediationDTO;
}
Also used : MediationDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.MediationDTO)

Example 23 with Mediation

use of org.wso2.carbon.apimgt.persistence.dto.Mediation in project carbon-apimgt by wso2.

the class ExportUtils method writeSOAPToRESTSequencesToArchive.

/**
 * Retrieve SOAP to REST mediation logic for the exporting API for a particular type (in/out) and store it
 * in the archive directory.
 *
 * @param api                   API
 * @param sequencePathInArchive Path to the SOAP to REST sequences in the archive
 * @param type                  Seqeunce type
 * @throws APIManagementException   If an error occurs while reading/writing SOAP to REST sequences
 * @throws APIImportExportException If an error occurs while creating the directory
 */
private static void writeSOAPToRESTSequencesToArchive(API api, String sequencePathInArchive, String type) throws APIManagementException, APIImportExportException {
    String resourcePolicy = SequenceUtils.getRestToSoapConvertedSequence(api, type);
    ResourcePolicyListDTO resourcePolicyInListDTO = APIMappingUtil.fromResourcePolicyStrToDTO(resourcePolicy);
    String individualSequencePathInArchive = sequencePathInArchive + File.separator + type;
    CommonUtil.createDirectory(individualSequencePathInArchive);
    for (ResourcePolicyInfoDTO resourcePolicyInfoDTO : resourcePolicyInListDTO.getList()) {
        String sequenceContent = resourcePolicyInfoDTO.getContent();
        String sequenceName = resourcePolicyInfoDTO.getResourcePath() + "_" + resourcePolicyInfoDTO.getHttpVerb();
        writeSequenceToArchive(sequenceContent, individualSequencePathInArchive, sequenceName);
    }
}
Also used : ResourcePolicyInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePolicyInfoDTO) ResourcePolicyListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePolicyListDTO)

Example 24 with Mediation

use of org.wso2.carbon.apimgt.persistence.dto.Mediation in project carbon-apimgt by wso2.

the class MediationMappingUtil method fromMediationListToDTO.

/**
 * Converts a List mediation objects into a DTO
 *
 * @param mediation a list of mediation objects
 * @param limit     max number of objects returned
 * @param offset    starting index
 * @return MediationListDTO object containing MediationInfoDTO
 */
public static MediationListDTO fromMediationListToDTO(List<Mediation> mediation, int offset, int limit) {
    MediationListDTO mediationListDTO = new MediationListDTO();
    List<MediationInfoDTO> mediationDTOs = mediationListDTO.getList();
    if (mediationDTOs == null) {
        mediationDTOs = new ArrayList<>();
        mediationListDTO.setList(mediationDTOs);
    }
    // identifying the proper start and end indexes
    int size = mediation.size();
    int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
    int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
    for (int i = start; i <= end; i++) {
        mediationDTOs.add(fromMediationInfoToDTO(mediation.get(i)));
    }
    mediationListDTO.setCount(mediationDTOs.size());
    return mediationListDTO;
}
Also used : MediationInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.MediationInfoDTO) MediationListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.MediationListDTO)

Example 25 with Mediation

use of org.wso2.carbon.apimgt.persistence.dto.Mediation in project carbon-apimgt by wso2.

the class MediationMappingUtil method fromMediationToDTO.

/**
 * Converts an Mediation object into MediationDTO
 *
 * @param mediation Mediation object
 * @return MediationDTO object correspond to the given Mediation object
 */
public static MediationDTO fromMediationToDTO(Mediation mediation) {
    MediationDTO mediationDTO = new MediationDTO();
    mediationDTO.setId(mediation.getUuid());
    mediationDTO.setName(mediation.getName());
    mediationDTO.setType(MediationDTO.TypeEnum.valueOf(mediation.getType().toUpperCase()));
    return mediationDTO;
}
Also used : MediationDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.MediationDTO)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)35 Mediation (org.wso2.carbon.apimgt.api.model.Mediation)23 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)22 IOException (java.io.IOException)21 Resource (org.wso2.carbon.registry.core.Resource)19 XMLStreamException (javax.xml.stream.XMLStreamException)12 QName (javax.xml.namespace.QName)11 OMElement (org.apache.axiom.om.OMElement)11 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)11 MediationPolicyPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.MediationPolicyPersistenceException)11 InputStream (java.io.InputStream)10 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)10 ArrayList (java.util.ArrayList)9 Collection (org.wso2.carbon.registry.core.Collection)9 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)8 OMAttribute (org.apache.axiom.om.OMAttribute)7 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)6 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)6 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)6 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)6