| 1 | package com.fwmotion.threescale.cms; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 4 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 5 | import com.fwmotion.threescale.cms.exception.*; | |
| 6 | import com.fwmotion.threescale.cms.mappers.CmsFileMapper; | |
| 7 | import com.fwmotion.threescale.cms.mappers.CmsSectionMapper; | |
| 8 | import com.fwmotion.threescale.cms.mappers.CmsTemplateMapper; | |
| 9 | import com.fwmotion.threescale.cms.model.*; | |
| 10 | import com.fwmotion.threescale.cms.support.PagedFilesSpliterator; | |
| 11 | import com.fwmotion.threescale.cms.support.PagedSectionsSpliterator; | |
| 12 | import com.fwmotion.threescale.cms.support.PagedTemplatesSpliterator; | |
| 13 | import com.redhat.threescale.rest.cms.ApiClient; | |
| 14 | import com.redhat.threescale.rest.cms.ApiException; | |
| 15 | import com.redhat.threescale.rest.cms.api.FilesApi; | |
| 16 | import com.redhat.threescale.rest.cms.api.SectionsApi; | |
| 17 | import com.redhat.threescale.rest.cms.api.TemplatesApi; | |
| 18 | import com.redhat.threescale.rest.cms.model.Error; | |
| 19 | import com.redhat.threescale.rest.cms.model.*; | |
| 20 | import jakarta.annotation.Nonnull; | |
| 21 | import jakarta.annotation.Nullable; | |
| 22 | import org.apache.commons.io.FileUtils; | |
| 23 | import org.apache.commons.io.IOUtils; | |
| 24 | import org.apache.commons.lang3.StringUtils; | |
| 25 | import org.apache.hc.client5.http.classic.methods.HttpGet; | |
| 26 | import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; | |
| 27 | import org.apache.hc.core5.http.HttpEntity; | |
| 28 | import org.apache.hc.core5.http.HttpHeaders; | |
| 29 | import org.mapstruct.factory.Mappers; | |
| 30 | ||
| 31 | import java.io.ByteArrayInputStream; | |
| 32 | import java.io.File; | |
| 33 | import java.io.IOException; | |
| 34 | import java.io.InputStream; | |
| 35 | import java.nio.charset.Charset; | |
| 36 | import java.util.Optional; | |
| 37 | import java.util.stream.Stream; | |
| 38 | import java.util.stream.StreamSupport; | |
| 39 | ||
| 40 | public class ThreescaleCmsClientImpl implements ThreescaleCmsClient { | |
| 41 | ||
| 42 | private static final CmsFileMapper FILE_MAPPER = Mappers.getMapper(CmsFileMapper.class); | |
| 43 | private static final CmsSectionMapper SECTION_MAPPER = Mappers.getMapper(CmsSectionMapper.class); | |
| 44 | private static final CmsTemplateMapper TEMPLATE_MAPPER = Mappers.getMapper(CmsTemplateMapper.class); | |
| 45 | ||
| 46 | private final FilesApi filesApi; | |
| 47 | private final SectionsApi sectionsApi; | |
| 48 | private final TemplatesApi templatesApi; | |
| 49 | private final ObjectMapper objectMapper; | |
| 50 | ||
| 51 | public ThreescaleCmsClientImpl(@Nonnull FilesApi filesApi, | |
| 52 | @Nonnull SectionsApi sectionsApi, | |
| 53 | @Nonnull TemplatesApi templatesApi, | |
| 54 | @Nonnull ObjectMapper objectMapper) { | |
| 55 | this.filesApi = filesApi; | |
| 56 | this.sectionsApi = sectionsApi; | |
| 57 | this.templatesApi = templatesApi; | |
| 58 | this.objectMapper = objectMapper; | |
| 59 | } | |
| 60 | ||
| 61 | public ThreescaleCmsClientImpl(@Nonnull ApiClient apiClient) { | |
| 62 | this(new FilesApi(apiClient), | |
| 63 | new SectionsApi(apiClient), | |
| 64 | new TemplatesApi(apiClient), | |
| 65 | apiClient.getObjectMapper()); | |
| 66 | } | |
| 67 | ||
| 68 | private <T> T handleApiErrors( | |
| 69 | @Nonnull ApiBlock<T> apiBlock, | |
| 70 | @Nullable ApiExceptionTransformer<?> exceptionTransformer | |
| 71 | ) throws ThreescaleCmsApiException { | |
| 72 | try { | |
| 73 |
1
1. handleApiErrors : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::handleApiErrors → KILLED |
return apiBlock.callApi(); |
| 74 | } catch (ApiException e) { | |
| 75 | throw handleApiException(exceptionTransformer, e); | |
| 76 | } | |
| 77 | } | |
| 78 | ||
| 79 | private <T> T handleApiErrors(@Nonnull ApiBlock<T> apiBlock) throws ThreescaleCmsException { | |
| 80 |
1
1. handleApiErrors : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::handleApiErrors → KILLED |
return handleApiErrors(apiBlock, null); |
| 81 | } | |
| 82 | ||
| 83 | private void handleApiErrors( | |
| 84 | @Nonnull VoidApiBlock apiBlock, | |
| 85 | @Nullable ApiExceptionTransformer<?> exceptionTransformer | |
| 86 | ) throws ThreescaleCmsException { | |
| 87 | try { | |
| 88 |
1
1. handleApiErrors : removed call to com/fwmotion/threescale/cms/ThreescaleCmsClientImpl$VoidApiBlock::callApi → KILLED |
apiBlock.callApi(); |
| 89 | } catch (ApiException e) { | |
| 90 | throw handleApiException(exceptionTransformer, e); | |
| 91 | } | |
| 92 | } | |
| 93 | ||
| 94 | private void handleApiErrors(@Nonnull VoidApiBlock apiBlock) throws ThreescaleCmsException { | |
| 95 |
1
1. handleApiErrors : removed call to com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::handleApiErrors → KILLED |
handleApiErrors(apiBlock, null); |
| 96 | } | |
| 97 | ||
| 98 | @Nonnull | |
| 99 | private ThreescaleCmsApiException handleApiException(ApiExceptionTransformer<?> exceptionTransformer, ApiException e) { | |
| 100 | int httpStatus = e.getCode(); | |
| 101 | ||
| 102 | // Try to deserialize a REST-modeled Error object type | |
| 103 | Error responseError; | |
| 104 | ||
| 105 | try { | |
| 106 | responseError = objectMapper.readValue(e.getResponseBody(), Error.class); | |
| 107 | } catch (JsonProcessingException jsonProcessingException) { | |
| 108 | // If the response body is not parseable into an Error, throw | |
| 109 | // the response body as-is. | |
| 110 |
1
1. handleApiException : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::handleApiException → NO_COVERAGE |
return new ThreescaleCmsApiException(httpStatus, "Unknown ApiException", e); |
| 111 | } | |
| 112 | ||
| 113 | ThreescaleCmsApiException apiException = new ThreescaleCmsApiException( | |
| 114 | httpStatus, | |
| 115 | responseError, | |
| 116 | e); | |
| 117 | ||
| 118 |
2
1. handleApiException : removed conditional - replaced equality check with true → NO_COVERAGE 2. handleApiException : removed conditional - replaced equality check with false → NO_COVERAGE |
if (exceptionTransformer == null) { |
| 119 |
1
1. handleApiException : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::handleApiException → NO_COVERAGE |
return apiException; |
| 120 | } | |
| 121 | ||
| 122 |
1
1. handleApiException : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::handleApiException → NO_COVERAGE |
return exceptionTransformer.transformException(apiException); |
| 123 | } | |
| 124 | ||
| 125 | @Nonnull | |
| 126 | @Override | |
| 127 | public Stream<CmsSection> streamSections() { | |
| 128 |
1
1. streamSections : replaced return value with Stream.empty for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::streamSections → KILLED |
return StreamSupport.stream(new PagedSectionsSpliterator(sectionsApi, objectMapper), true); |
| 129 | } | |
| 130 | ||
| 131 | @Nonnull | |
| 132 | @Override | |
| 133 | public Stream<CmsFile> streamFiles() { | |
| 134 |
1
1. streamFiles : replaced return value with Stream.empty for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::streamFiles → KILLED |
return StreamSupport.stream(new PagedFilesSpliterator(filesApi, objectMapper), true); |
| 135 | } | |
| 136 | ||
| 137 | @Nonnull | |
| 138 | @Override | |
| 139 | public Optional<InputStream> getFileContent(long fileId) { | |
| 140 |
1
1. getFileContent : replaced return value with Optional.empty for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::getFileContent → KILLED |
return handleApiErrors(() -> { |
| 141 | CloseableHttpClient httpClient = filesApi.getApiClient().getHttpClient(); | |
| 142 | ModelFile file = filesApi.getFile(fileId); | |
| 143 | ProviderAccount account = filesApi.readProviderSettings().getAccount(); | |
| 144 | ||
| 145 | HttpGet request = new HttpGet(account.getBaseUrl() + file.getPath()); | |
| 146 |
1
1. lambda$getFileContent$1 : removed call to org/apache/hc/client5/http/classic/methods/HttpGet::setHeader → KILLED |
request.setHeader(HttpHeaders.ACCEPT, "*/*"); |
| 147 |
2
1. lambda$getFileContent$1 : removed conditional - replaced equality check with true → KILLED 2. lambda$getFileContent$1 : removed conditional - replaced equality check with false → KILLED |
if (StringUtils.isNotEmpty(account.getSiteAccessCode())) { |
| 148 |
1
1. lambda$getFileContent$1 : removed call to org/apache/hc/client5/http/classic/methods/HttpGet::addHeader → KILLED |
request.addHeader("Cookie", "access_code=" + account.getSiteAccessCode()); |
| 149 | } | |
| 150 | ||
| 151 | try { | |
| 152 |
1
1. lambda$getFileContent$1 : replaced return value with Optional.empty for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$getFileContent$1 → KILLED |
return httpClient.execute(request, response -> { |
| 153 |
2
1. lambda$getFileContent$0 : removed conditional - replaced equality check with false → SURVIVED 2. lambda$getFileContent$0 : removed conditional - replaced equality check with true → KILLED |
if (response == null) { |
| 154 | return Optional.empty(); | |
| 155 | } | |
| 156 | ||
| 157 | // TODO: Validate response headers, status code, etc | |
| 158 | ||
| 159 | HttpEntity entity = response.getEntity(); | |
| 160 |
2
1. lambda$getFileContent$0 : removed conditional - replaced equality check with false → SURVIVED 2. lambda$getFileContent$0 : removed conditional - replaced equality check with true → KILLED |
if (entity == null) { |
| 161 | return Optional.empty(); | |
| 162 | } | |
| 163 | ||
| 164 |
1
1. lambda$getFileContent$0 : replaced return value with Optional.empty for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$getFileContent$0 → KILLED |
return Optional.of( |
| 165 | new ByteArrayInputStream(entity.getContent().readAllBytes()) | |
| 166 | ); | |
| 167 | }); | |
| 168 | } catch (IOException e) { | |
| 169 | throw new ThreescaleCmsNonApiException("IOException while retrieving file content", e); | |
| 170 | } | |
| 171 | }); | |
| 172 | } | |
| 173 | ||
| 174 | @Nonnull | |
| 175 | @Override | |
| 176 | public Stream<CmsTemplate> streamTemplates(boolean includeContent) { | |
| 177 |
1
1. streamTemplates : replaced return value with Stream.empty for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::streamTemplates → KILLED |
return StreamSupport.stream(new PagedTemplatesSpliterator(templatesApi, objectMapper, includeContent), true); |
| 178 | } | |
| 179 | ||
| 180 | @Nonnull | |
| 181 | @Override | |
| 182 | public Optional<InputStream> getTemplateDraft(long templateId) { | |
| 183 |
1
1. getTemplateDraft : replaced return value with Optional.empty for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::getTemplateDraft → KILLED |
return handleApiErrors(() -> { |
| 184 | Template template = templatesApi.getTemplate(templateId); | |
| 185 | ||
| 186 | Optional<InputStream> result = Optional.ofNullable(template.getDraft()) | |
| 187 | .map(StringUtils::trimToNull) | |
| 188 |
1
1. lambda$getTemplateDraft$2 : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$getTemplateDraft$2 → KILLED |
.map(input -> IOUtils.toInputStream(input, Charset.defaultCharset())); |
| 189 | ||
| 190 | // When there's no draft content, the "draft" should be the same as | |
| 191 | // the "published" content | |
| 192 |
2
1. lambda$getTemplateDraft$4 : removed conditional - replaced equality check with false → KILLED 2. lambda$getTemplateDraft$4 : removed conditional - replaced equality check with true → KILLED |
if (result.isEmpty()) { |
| 193 | result = Optional.ofNullable(template.getPublished()) | |
| 194 | .map(StringUtils::trimToNull) | |
| 195 |
1
1. lambda$getTemplateDraft$3 : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$getTemplateDraft$3 → KILLED |
.map(input -> IOUtils.toInputStream(input, Charset.defaultCharset())); |
| 196 | } | |
| 197 | ||
| 198 |
1
1. lambda$getTemplateDraft$4 : replaced return value with Optional.empty for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$getTemplateDraft$4 → KILLED |
return result; |
| 199 | }); | |
| 200 | } | |
| 201 | ||
| 202 | @Nonnull | |
| 203 | @Override | |
| 204 | public Optional<InputStream> getTemplatePublished(long templateId) { | |
| 205 |
1
1. getTemplatePublished : replaced return value with Optional.empty for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::getTemplatePublished → KILLED |
return handleApiErrors(() -> { |
| 206 | Template template = templatesApi.getTemplate(templateId); | |
| 207 | ||
| 208 |
1
1. lambda$getTemplatePublished$6 : replaced return value with Optional.empty for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$getTemplatePublished$6 → KILLED |
return Optional.ofNullable(template.getPublished()) |
| 209 |
1
1. lambda$getTemplatePublished$5 : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$getTemplatePublished$5 → KILLED |
.map(input -> IOUtils.toInputStream(input, Charset.defaultCharset())); |
| 210 | }); | |
| 211 | } | |
| 212 | ||
| 213 | @Override | |
| 214 | public void save(@Nonnull CmsSection section) { | |
| 215 |
1
1. save : removed call to com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::handleApiErrors → KILLED |
handleApiErrors(() -> { |
| 216 | Section restSection = SECTION_MAPPER.toRest(section); | |
| 217 |
2
1. lambda$save$7 : removed conditional - replaced equality check with false → KILLED 2. lambda$save$7 : removed conditional - replaced equality check with true → KILLED |
if (section.getId() == null) { |
| 218 |
2
1. lambda$save$7 : removed conditional - replaced equality check with true → KILLED 2. lambda$save$7 : removed conditional - replaced equality check with false → KILLED |
if (StringUtils.isBlank(restSection.getTitle()) |
| 219 |
2
1. lambda$save$7 : removed conditional - replaced equality check with true → SURVIVED 2. lambda$save$7 : removed conditional - replaced equality check with false → KILLED |
&& StringUtils.isNotBlank(restSection.getSystemName())) { |
| 220 |
1
1. lambda$save$7 : removed call to com/redhat/threescale/rest/cms/model/Section::setTitle → KILLED |
restSection.setTitle(restSection.getSystemName()); |
| 221 | } | |
| 222 | ||
| 223 | Section response = sectionsApi.createSection( | |
| 224 | restSection.getPublic(), | |
| 225 | restSection.getTitle(), | |
| 226 | restSection.getParentId(), | |
| 227 | restSection.getPartialPath(), | |
| 228 | restSection.getSystemName()); | |
| 229 | ||
| 230 |
1
1. lambda$save$7 : removed call to com/fwmotion/threescale/cms/model/CmsSection::setId → KILLED |
section.setId(response.getId()); |
| 231 | } else { | |
| 232 | sectionsApi.updateSection(restSection.getId(), | |
| 233 | restSection.getPublic(), | |
| 234 | restSection.getTitle(), | |
| 235 | restSection.getParentId()); | |
| 236 | } | |
| 237 | }); | |
| 238 | } | |
| 239 | ||
| 240 | @Override | |
| 241 | public void save(@Nonnull CmsFile file, @Nullable File fileContent) { | |
| 242 |
1
1. save : removed call to com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::handleApiErrors → KILLED |
handleApiErrors(() -> { |
| 243 | ModelFile restFile = FILE_MAPPER.toRest(file); | |
| 244 | ||
| 245 |
2
1. lambda$save$8 : removed conditional - replaced equality check with true → KILLED 2. lambda$save$8 : removed conditional - replaced equality check with false → KILLED |
if (file.getId() == null) { |
| 246 | ModelFile response = filesApi.createFile( | |
| 247 | restFile.getSectionId(), | |
| 248 | restFile.getPath(), | |
| 249 | fileContent, | |
| 250 | restFile.getDownloadable(), | |
| 251 | restFile.getContentType()); | |
| 252 | ||
| 253 |
1
1. lambda$save$8 : removed call to com/fwmotion/threescale/cms/model/CmsFile::setId → KILLED |
file.setId(response.getId()); |
| 254 | } else { | |
| 255 | filesApi.updateFile(file.getId(), | |
| 256 | restFile.getSectionId(), | |
| 257 | restFile.getPath(), | |
| 258 | restFile.getDownloadable(), | |
| 259 | fileContent, | |
| 260 | restFile.getContentType()); | |
| 261 | } | |
| 262 | }); | |
| 263 | } | |
| 264 | ||
| 265 | @Override | |
| 266 | public void save(@Nonnull CmsTemplate template, @Nullable File templateDraft) { | |
| 267 | /* When upgraded to JDK21: | |
| 268 | switch (template) { | |
| 269 | case CmsBuiltinPage cmsBuiltinPage -> saveBuiltinPage(cmsBuiltinPage, templateDraft); | |
| 270 | case CmsBuiltinPartial cmsBuiltinPartial -> saveBuiltinPartial(cmsBuiltinPartial, templateDraft); | |
| 271 | case CmsLayout cmsLayout -> saveLayout(cmsLayout, templateDraft); | |
| 272 | case CmsPage cmsPage -> savePage(cmsPage, templateDraft); | |
| 273 | case CmsPartial cmsPartial -> savePartial(cmsPartial, templateDraft); | |
| 274 | default -> throw new UnsupportedOperationException("Unknown template type: " + template.getClass().getName()); | |
| 275 | } | |
| 276 | */ | |
| 277 |
2
1. save : removed conditional - replaced equality check with true → NO_COVERAGE 2. save : removed conditional - replaced equality check with false → NO_COVERAGE |
if (template instanceof CmsBuiltinPage cmsBuiltinPage) { |
| 278 |
1
1. save : removed call to com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::saveBuiltinPage → NO_COVERAGE |
saveBuiltinPage(cmsBuiltinPage, templateDraft); |
| 279 |
2
1. save : removed conditional - replaced equality check with true → NO_COVERAGE 2. save : removed conditional - replaced equality check with false → NO_COVERAGE |
} else if (template instanceof CmsBuiltinPartial cmsBuiltinPartial) { |
| 280 |
1
1. save : removed call to com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::saveBuiltinPartial → NO_COVERAGE |
saveBuiltinPartial(cmsBuiltinPartial, templateDraft); |
| 281 |
2
1. save : removed conditional - replaced equality check with false → NO_COVERAGE 2. save : removed conditional - replaced equality check with true → NO_COVERAGE |
} else if (template instanceof CmsLayout cmsLayout) { |
| 282 |
1
1. save : removed call to com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::saveLayout → NO_COVERAGE |
saveLayout(cmsLayout, templateDraft); |
| 283 |
2
1. save : removed conditional - replaced equality check with false → NO_COVERAGE 2. save : removed conditional - replaced equality check with true → NO_COVERAGE |
} else if (template instanceof CmsPage cmsPage) { |
| 284 |
1
1. save : removed call to com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::savePage → NO_COVERAGE |
savePage(cmsPage, templateDraft); |
| 285 |
2
1. save : removed conditional - replaced equality check with false → NO_COVERAGE 2. save : removed conditional - replaced equality check with true → NO_COVERAGE |
} else if (template instanceof CmsPartial cmsPartial) { |
| 286 |
1
1. save : removed call to com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::savePartial → NO_COVERAGE |
savePartial(cmsPartial, templateDraft); |
| 287 | } else { | |
| 288 | throw new UnsupportedOperationException("Unknown template type: " + template.getClass().getName()); | |
| 289 | } | |
| 290 | } | |
| 291 | ||
| 292 | private void saveBuiltinPage(@Nonnull CmsBuiltinPage page, @Nullable File templateDraft) { | |
| 293 |
2
1. saveBuiltinPage : removed conditional - replaced equality check with true → NO_COVERAGE 2. saveBuiltinPage : removed conditional - replaced equality check with false → NO_COVERAGE |
if (page.getId() == null) { |
| 294 | throw new ThreescaleCmsCannotCreateBuiltinException("Built-in pages can't be created."); | |
| 295 | } | |
| 296 | ||
| 297 | saveUpdatedTemplate(page.getId(), | |
| 298 | TEMPLATE_MAPPER.toRestBuiltinPage(page), | |
| 299 | templateDraft); | |
| 300 | } | |
| 301 | ||
| 302 | private void saveBuiltinPartial(@Nonnull CmsBuiltinPartial partial, @Nullable File templateDraft) { | |
| 303 |
2
1. saveBuiltinPartial : removed conditional - replaced equality check with false → NO_COVERAGE 2. saveBuiltinPartial : removed conditional - replaced equality check with true → NO_COVERAGE |
if (partial.getId() == null) { |
| 304 | throw new ThreescaleCmsCannotCreateBuiltinException("Built-in partials cannot be created."); | |
| 305 | } | |
| 306 | ||
| 307 | saveUpdatedTemplate(partial.getId(), | |
| 308 | TEMPLATE_MAPPER.toRestBuiltinPartial(partial), | |
| 309 | templateDraft); | |
| 310 | } | |
| 311 | ||
| 312 | private void saveLayout(@Nonnull CmsLayout layout, @Nullable File templateDraft) { | |
| 313 |
2
1. saveLayout : removed conditional - replaced equality check with true → NO_COVERAGE 2. saveLayout : removed conditional - replaced equality check with false → NO_COVERAGE |
if (layout.getId() == null) { |
| 314 | Template response = saveNewTemplate( | |
| 315 | TEMPLATE_MAPPER.toRestLayoutCreation(layout), | |
| 316 | templateDraft); | |
| 317 | ||
| 318 |
1
1. saveLayout : removed call to com/fwmotion/threescale/cms/model/CmsLayout::setId → NO_COVERAGE |
layout.setId(response.getId()); |
| 319 | } else { | |
| 320 | saveUpdatedTemplate(layout.getId(), | |
| 321 | TEMPLATE_MAPPER.toRestLayoutUpdate(layout), | |
| 322 | templateDraft); | |
| 323 | } | |
| 324 | } | |
| 325 | ||
| 326 | private void savePage(@Nonnull CmsPage page, @Nullable File templateDraft) { | |
| 327 |
2
1. savePage : removed conditional - replaced equality check with false → NO_COVERAGE 2. savePage : removed conditional - replaced equality check with true → NO_COVERAGE |
if (page.getId() == null) { |
| 328 | Template response = saveNewTemplate( | |
| 329 | TEMPLATE_MAPPER.toRestPageCreation(page), templateDraft); | |
| 330 | ||
| 331 |
1
1. savePage : removed call to com/fwmotion/threescale/cms/model/CmsPage::setId → NO_COVERAGE |
page.setId(response.getId()); |
| 332 | } else { | |
| 333 | saveUpdatedTemplate(page.getId(), | |
| 334 | TEMPLATE_MAPPER.toRestPageUpdate(page), | |
| 335 | templateDraft); | |
| 336 | } | |
| 337 | } | |
| 338 | ||
| 339 | private void savePartial(@Nonnull CmsPartial partial, @Nullable File templateDraft) { | |
| 340 |
2
1. savePartial : removed conditional - replaced equality check with true → NO_COVERAGE 2. savePartial : removed conditional - replaced equality check with false → NO_COVERAGE |
if (partial.getId() == null) { |
| 341 | Template response = saveNewTemplate( | |
| 342 | TEMPLATE_MAPPER.toRestPartialCreation(partial), | |
| 343 | templateDraft); | |
| 344 | ||
| 345 |
1
1. savePartial : removed call to com/fwmotion/threescale/cms/model/CmsPartial::setId → NO_COVERAGE |
partial.setId(response.getId()); |
| 346 | } else { | |
| 347 | saveUpdatedTemplate(partial.getId(), | |
| 348 | TEMPLATE_MAPPER.toRestPartialUpdate(partial), | |
| 349 | templateDraft); | |
| 350 | } | |
| 351 | } | |
| 352 | ||
| 353 | private Template saveNewTemplate(@Nonnull TemplateCreationRequest template, @Nullable File templateDraft) { | |
| 354 |
2
1. saveNewTemplate : removed conditional - replaced equality check with true → NO_COVERAGE 2. saveNewTemplate : removed conditional - replaced equality check with false → NO_COVERAGE |
if (templateDraft == null) { |
| 355 | throw new IllegalArgumentException("New template must have draft content"); | |
| 356 | } | |
| 357 | ||
| 358 | String draft; | |
| 359 | try { | |
| 360 | draft = FileUtils.readFileToString(templateDraft, Charset.defaultCharset()); | |
| 361 | } catch (IOException e) { | |
| 362 | throw new ThreescaleCmsNonApiException("Exception while reading file content for template draft", e); | |
| 363 | } | |
| 364 | ||
| 365 |
2
1. lambda$saveNewTemplate$9 : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$saveNewTemplate$9 → NO_COVERAGE 2. saveNewTemplate : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::saveNewTemplate → NO_COVERAGE |
return handleApiErrors(() -> templatesApi.createTemplate(template.getType(), |
| 366 | template.getSystemName(), | |
| 367 | template.getTitle(), | |
| 368 | template.getPath(), | |
| 369 | draft, | |
| 370 | template.getSectionId(), | |
| 371 | template.getLayoutName(), | |
| 372 | template.getLayoutId(), | |
| 373 | template.getLiquidEnabled(), | |
| 374 | template.getHandler(), | |
| 375 | template.getContentType())); | |
| 376 | } | |
| 377 | ||
| 378 | @SuppressWarnings("UnusedReturnValue") | |
| 379 | private Template saveUpdatedTemplate(long id, @Nonnull TemplateUpdatableFields template, @Nullable File templateDraft) { | |
| 380 | String draft; | |
| 381 |
2
1. saveUpdatedTemplate : removed conditional - replaced equality check with true → NO_COVERAGE 2. saveUpdatedTemplate : removed conditional - replaced equality check with false → NO_COVERAGE |
if (templateDraft == null) { |
| 382 | draft = null; | |
| 383 | } else { | |
| 384 | try { | |
| 385 | draft = FileUtils.readFileToString(templateDraft, Charset.defaultCharset()); | |
| 386 | } catch (IOException e) { | |
| 387 | throw new ThreescaleCmsNonApiException("Exception while reading file content for template draft", e); | |
| 388 | } | |
| 389 | } | |
| 390 | ||
| 391 |
2
1. saveUpdatedTemplate : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::saveUpdatedTemplate → NO_COVERAGE 2. lambda$saveUpdatedTemplate$10 : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$saveUpdatedTemplate$10 → NO_COVERAGE |
return handleApiErrors(() -> templatesApi.updateTemplate(id, |
| 392 | template.getSystemName(), | |
| 393 | template.getTitle(), | |
| 394 | template.getPath(), | |
| 395 | draft, | |
| 396 | template.getSectionId(), | |
| 397 | template.getLayoutName(), | |
| 398 | template.getLayoutId(), | |
| 399 | template.getLiquidEnabled(), | |
| 400 | template.getHandler(), | |
| 401 | template.getContentType())); | |
| 402 | } | |
| 403 | ||
| 404 | @Override | |
| 405 | public void publish(long templateId) throws ThreescaleCmsApiException { | |
| 406 |
1
1. lambda$publish$11 : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$publish$11 → NO_COVERAGE |
handleApiErrors(() -> templatesApi.publishTemplate(templateId)); |
| 407 | } | |
| 408 | ||
| 409 | @Override | |
| 410 | public void delete(@Nonnull ThreescaleObjectType type, long id) throws ThreescaleCmsApiException { | |
| 411 |
1
1. delete : removed call to com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::handleApiErrors → KILLED |
handleApiErrors( |
| 412 | () -> { | |
| 413 |
1
1. lambda$delete$12 : Changed switch default to be first case → KILLED |
switch (type) { |
| 414 | case SECTION: | |
| 415 |
1
1. lambda$delete$12 : removed call to com/redhat/threescale/rest/cms/api/SectionsApi::deleteSection → KILLED |
sectionsApi.deleteSection(id); |
| 416 | break; | |
| 417 | case FILE: | |
| 418 |
1
1. lambda$delete$12 : removed call to com/redhat/threescale/rest/cms/api/FilesApi::deleteFile → KILLED |
filesApi.deleteFile(id); |
| 419 | break; | |
| 420 | case TEMPLATE: | |
| 421 |
1
1. lambda$delete$12 : removed call to com/redhat/threescale/rest/cms/api/TemplatesApi::deleteTemplate → KILLED |
templatesApi.deleteTemplate(id); |
| 422 | break; | |
| 423 | default: | |
| 424 | throw new UnsupportedOperationException("Unknown type: " + type); | |
| 425 | } | |
| 426 | }, | |
| 427 | apiException -> { | |
| 428 |
2
1. lambda$delete$14 : removed conditional - replaced equality check with false → NO_COVERAGE 2. lambda$delete$14 : removed conditional - replaced equality check with true → NO_COVERAGE |
if (apiException.getHttpStatus() == ThreescaleCmsCannotDeleteBuiltinException.ERROR_HTTP_CODE |
| 429 | && apiException.getApiError() | |
| 430 |
2
1. lambda$delete$13 : replaced boolean return with false for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$delete$13 → NO_COVERAGE 2. lambda$delete$13 : replaced boolean return with true for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$delete$13 → NO_COVERAGE |
.filter(apiError -> ThreescaleCmsCannotDeleteBuiltinException.ERROR_MESSAGE.equals(apiError.getError())) |
| 431 |
2
1. lambda$delete$14 : removed conditional - replaced equality check with false → NO_COVERAGE 2. lambda$delete$14 : removed conditional - replaced equality check with true → NO_COVERAGE |
.isPresent() |
| 432 | ) { | |
| 433 |
1
1. lambda$delete$14 : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$delete$14 → NO_COVERAGE |
return new ThreescaleCmsCannotDeleteBuiltinException( |
| 434 | apiException.getApiError().get() | |
| 435 | ); | |
| 436 | } | |
| 437 | ||
| 438 |
1
1. lambda$delete$14 : replaced return value with null for com/fwmotion/threescale/cms/ThreescaleCmsClientImpl::lambda$delete$14 → NO_COVERAGE |
return apiException; |
| 439 | } | |
| 440 | ); | |
| 441 | } | |
| 442 | ||
| 443 | @FunctionalInterface | |
| 444 | private interface VoidApiBlock { | |
| 445 | void callApi() throws ApiException; | |
| 446 | } | |
| 447 | ||
| 448 | @FunctionalInterface | |
| 449 | private interface ApiBlock<T> { | |
| 450 | T callApi() throws ApiException; | |
| 451 | } | |
| 452 | ||
| 453 | @FunctionalInterface | |
| 454 | private interface ApiExceptionTransformer<T extends ThreescaleCmsApiException> { | |
| 455 | T transformException(ThreescaleCmsApiException e); | |
| 456 | } | |
| 457 | ||
| 458 | } | |
Mutations | ||
| 73 |
1.1 |
|
| 80 |
1.1 |
|
| 88 |
1.1 |
|
| 95 |
1.1 |
|
| 110 |
1.1 |
|
| 118 |
1.1 2.2 |
|
| 119 |
1.1 |
|
| 122 |
1.1 |
|
| 128 |
1.1 |
|
| 134 |
1.1 |
|
| 140 |
1.1 |
|
| 146 |
1.1 |
|
| 147 |
1.1 2.2 |
|
| 148 |
1.1 |
|
| 152 |
1.1 |
|
| 153 |
1.1 2.2 |
|
| 160 |
1.1 2.2 |
|
| 164 |
1.1 |
|
| 177 |
1.1 |
|
| 183 |
1.1 |
|
| 188 |
1.1 |
|
| 192 |
1.1 2.2 |
|
| 195 |
1.1 |
|
| 198 |
1.1 |
|
| 205 |
1.1 |
|
| 208 |
1.1 |
|
| 209 |
1.1 |
|
| 215 |
1.1 |
|
| 217 |
1.1 2.2 |
|
| 218 |
1.1 2.2 |
|
| 219 |
1.1 2.2 |
|
| 220 |
1.1 |
|
| 230 |
1.1 |
|
| 242 |
1.1 |
|
| 245 |
1.1 2.2 |
|
| 253 |
1.1 |
|
| 277 |
1.1 2.2 |
|
| 278 |
1.1 |
|
| 279 |
1.1 2.2 |
|
| 280 |
1.1 |
|
| 281 |
1.1 2.2 |
|
| 282 |
1.1 |
|
| 283 |
1.1 2.2 |
|
| 284 |
1.1 |
|
| 285 |
1.1 2.2 |
|
| 286 |
1.1 |
|
| 293 |
1.1 2.2 |
|
| 303 |
1.1 2.2 |
|
| 313 |
1.1 2.2 |
|
| 318 |
1.1 |
|
| 327 |
1.1 2.2 |
|
| 331 |
1.1 |
|
| 340 |
1.1 2.2 |
|
| 345 |
1.1 |
|
| 354 |
1.1 2.2 |
|
| 365 |
1.1 2.2 |
|
| 381 |
1.1 2.2 |
|
| 391 |
1.1 2.2 |
|
| 406 |
1.1 |
|
| 411 |
1.1 |
|
| 413 |
1.1 |
|
| 415 |
1.1 |
|
| 418 |
1.1 |
|
| 421 |
1.1 |
|
| 428 |
1.1 2.2 |
|
| 430 |
1.1 2.2 |
|
| 431 |
1.1 2.2 |
|
| 433 |
1.1 |
|
| 438 |
1.1 |