use of org.wso2.carbon.apimgt.rest.api.publisher.dto.FileInfoDTO in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisApiIdImplementationPut.
@Override
public Response compositeApisApiIdImplementationPut(String apiId, InputStream apiImplementationInputStream, FileInfo apiImplementationDetail, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
String existingFingerprint = compositeApisApiIdImplementationGetFingerprint(apiId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && ifMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
apiStore.updateCompositeApiImplementation(apiId, apiImplementationInputStream);
String uriString = RestApiConstants.RESOURCE_PATH_IMPLEMENTATION.replace(RestApiConstants.APIID_PARAM, apiId);
FileInfoDTO infoDTO = new FileInfoDTO();
infoDTO.setRelativePath(uriString);
infoDTO.setMediaType(MediaType.APPLICATION_OCTET_STREAM);
String newFingerprint = compositeApisApiIdImplementationGetFingerprint(apiId, null, null, request);
return Response.ok().header(HttpHeaders.ETAG, "\"" + newFingerprint + "\"").entity(infoDTO).build();
} catch (APIManagementException e) {
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.publisher.dto.FileInfoDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdThumbnailPost.
/**
* Updates the thumbnail image of an API
*
* @param apiId UUID of API
* @param fileInputStream Image data stream
* @param fileDetail meta information of the image
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return meta info about the updated thumbnail image
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdThumbnailPost(String apiId, InputStream fileInputStream, FileInfo fileDetail, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
String existingFingerprint = apisApiIdThumbnailGetFingerprint(apiId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
apiPublisher.saveThumbnailImage(apiId, fileInputStream, fileDetail.getFileName());
String uriString = RestApiConstants.RESOURCE_PATH_THUMBNAIL.replace(RestApiConstants.APIID_PARAM, apiId);
FileInfoDTO infoDTO = new FileInfoDTO();
infoDTO.setRelativePath(uriString);
infoDTO.setMediaType(MediaType.APPLICATION_OCTET_STREAM);
String newFingerprint = apisApiIdThumbnailGetFingerprint(apiId, null, null, request);
return Response.status(Response.Status.CREATED).entity(infoDTO).header(HttpHeaders.ETAG, "\"" + newFingerprint + "\"").build();
} catch (APIManagementException e) {
String errorMessage = "Error while uploading image" + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations