use of org.wso2.carbon.apimgt.api.model.ServiceEntry in project carbon-apimgt by wso2.
the class ServicesApiServiceImpl method searchServices.
@Override
public Response searchServices(String name, String version, String definitionType, String key, Boolean shrink, String sortBy, String sortOrder, Integer limit, Integer offset, MessageContext messageContext) throws APIManagementException {
String userName = RestApiCommonUtil.getLoggedInUsername();
int tenantId = APIUtil.getTenantId(userName);
try {
List<ServiceDTO> serviceDTOList = new ArrayList<>();
ServiceFilterParams filterParams = ServiceEntryMappingUtil.getServiceFilterParams(name, version, definitionType, key, sortBy, sortOrder, limit, offset);
List<ServiceEntry> services = serviceCatalog.getServices(filterParams, tenantId, shrink);
int totalServices = serviceCatalog.getServicesCount(tenantId, filterParams);
for (ServiceEntry service : services) {
serviceDTOList.add(ServiceEntryMappingUtil.fromServiceToDTO(service, shrink));
}
ServiceListDTO serviceListDTO = new ServiceListDTO();
serviceListDTO.setList(serviceDTOList);
ServiceEntryMappingUtil.setPaginationParams(serviceListDTO, filterParams.getOffset(), filterParams.getLimit(), totalServices, filterParams);
return Response.ok().entity(serviceListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving Services";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.ServiceEntry in project carbon-apimgt by wso2.
the class ServiceEntryMappingUtil method fromFileToServiceEntry.
/**
* Converts a single metadata file content into a ServiceEntry model
*
* @param file Metadata file
* @return Converted ServiceEntry model object
* @throws IOException
*/
static ServiceEntry fromFileToServiceEntry(File file, ServiceEntry service) throws IOException {
if (service == null) {
service = new ServiceEntry();
}
try {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
service = mapper.readValue(file, ServiceEntry.class);
if (StringUtils.isBlank(service.getKey())) {
service.setKey(generateServiceKey(service));
}
} catch (InvalidFormatException e) {
RestApiUtil.handleBadRequest("One or more parameters contain disallowed values", e, log);
}
return service;
}
use of org.wso2.carbon.apimgt.api.model.ServiceEntry in project carbon-apimgt by wso2.
the class ServiceEntryMappingUtil method fromDirToServiceEntryMap.
/**
* Generate Hash Map to hold all the ServiceEntry objects relevant to the services included in zip
*
* @param path path to the directory which include files
* @return HashMap with service key as key and ServiceEntry object as value
*/
public static HashMap<String, ServiceEntry> fromDirToServiceEntryMap(String path) {
HashMap<String, ServiceEntry> endpointDetails = new HashMap<>();
File[] files = new File(path).listFiles();
assert files != null;
for (File file : files) {
if (file.isDirectory()) {
ServiceEntry serviceInfo = new ServiceEntry();
File metadataFile = getServiceFile(APIConstants.METADATA_FILE, file);
File definitionFile;
if (file.getName().contains(APIConstants.PROXY_SERVICE_NAME_SUFFIX) && new File(file.getAbsoluteFile(), APIConstants.DEFINITION_WSDL_FILE).exists()) {
definitionFile = getServiceFile(APIConstants.DEFINITION_WSDL_FILE, file);
} else {
definitionFile = getServiceFile(APIConstants.DEFINITION_FILE, file);
}
String key = null;
try {
serviceInfo = fromFileToServiceEntry(metadataFile, serviceInfo);
serviceInfo.setMetadata(new ByteArrayInputStream(FileUtils.readFileToByteArray(metadataFile)));
key = serviceInfo.getKey();
serviceInfo.setEndpointDef(new ByteArrayInputStream(FileUtils.readFileToByteArray(definitionFile)));
} catch (IOException e) {
RestApiUtil.handleInternalServerError("Error while reading service resource files. " + "Zip might not include valid data", e, log);
}
endpointDetails.put(key, serviceInfo);
}
}
return endpointDetails;
}
use of org.wso2.carbon.apimgt.api.model.ServiceEntry in project carbon-apimgt by wso2.
the class ServiceEntryMappingUtil method fromServiceEntryToServiceInfoDTO.
/**
* Converts ServiceEntry object to ServiceInfoDTO object
*
* @param serviceEntry ServiceEntry model object
* @return Converted ServiceInfoDTO object
*/
public static ServiceInfoDTO fromServiceEntryToServiceInfoDTO(ServiceEntry serviceEntry) {
ServiceInfoDTO serviceInfoDTO = new ServiceInfoDTO();
serviceInfoDTO.setId(serviceEntry.getUuid());
serviceInfoDTO.setName(serviceEntry.getName());
serviceInfoDTO.setKey(serviceEntry.getKey());
serviceInfoDTO.setVersion(serviceEntry.getVersion());
serviceInfoDTO.setMd5(serviceEntry.getMd5());
return serviceInfoDTO;
}
Aggregations