Commit 33417022 authored by Adrien's avatar Adrien Committed by Romain Bioteau

feat(java 11) rest api import validation (#1553)

* Add a validator in the bos import validation to warn about rest api
dependencies to update to ensure java11 compliance
* Add a aggregation mechanism for the bos import status (only for some
rest api statuses for now)

closes [BST-25](https://bonitasoft.atlassian.net/browse/BST-25)
parent ed7725d0
......@@ -52,3 +52,4 @@ legacyFormsNotImportedFromWorkspace=6.x forms based on Google Web Toolkit (GWT)
containsLegacyFormsWarning=Contains 6.x forms. They are not supported anymore. They will be removed during migration.
spDiagramCannotBeImportedError=Designed with a Subscription edition. Incompatible with Community edition.
projectConnectorToVCS='%s' is connected to a VCS. You must clone/checkout this project from Team menu.
occurrences=occurrences
\ No newline at end of file
package org.bonitasoft.studio.importer.bos.status;
import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.studio.importer.bos.status.BonitaStatusCodeAggregator.REST_API_BONITA_DEPENDENCY_STATUS_CODE;
import static org.bonitasoft.studio.importer.bos.status.BonitaStatusCodeAggregator.REST_API_JAVA_11_GROOVY_ALL_STATUS_CODE;
import static org.bonitasoft.studio.importer.bos.status.BonitaStatusCodeAggregator.REST_API_JAVA_11_GROOVY_COMPILER_STATUS_CODE;
import org.bonitasoft.studio.importer.bos.i18n.Messages;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.junit.Test;
public class BonitaStatusCodeAggregatorTest {
private static final String PROCESS_STATUS_1 = "a process status";
private static final String PROCESS_STATUS_2 = "an other process status";
private static final String GROOVY_COMPILER_STATUS = "update groovy compiler dependency pls";
private static final String GROOVY_ALL_STATUS = "update groovy all dependency pls";
private static final String BONITA_DEPENDENCY_STATUS = "update bonita dependency pls";
@Test
public void should_factorize_redundant_rest_api_statuses() {
BosArchiveImportStatus initialBosArchiveImportStatus = new BosArchiveImportStatus();
initialBosArchiveImportStatus.add(ValidationStatus.warning(PROCESS_STATUS_1));
initialBosArchiveImportStatus.add(ValidationStatus.warning(PROCESS_STATUS_2));
// one groovy compiler to update status
initialBosArchiveImportStatus.add(createStatusWithCode(
REST_API_JAVA_11_GROOVY_COMPILER_STATUS_CODE, IStatus.WARNING,
GROOVY_COMPILER_STATUS));
// two groovy all to update status
initialBosArchiveImportStatus.add(createStatusWithCode(
REST_API_JAVA_11_GROOVY_ALL_STATUS_CODE, IStatus.WARNING, GROOVY_ALL_STATUS));
initialBosArchiveImportStatus.add(createStatusWithCode(
REST_API_JAVA_11_GROOVY_ALL_STATUS_CODE, IStatus.WARNING, GROOVY_ALL_STATUS));
// three bonita dependency status
initialBosArchiveImportStatus.add(createStatusWithCode(
REST_API_BONITA_DEPENDENCY_STATUS_CODE, IStatus.INFO,
BONITA_DEPENDENCY_STATUS));
initialBosArchiveImportStatus.add(createStatusWithCode(
REST_API_BONITA_DEPENDENCY_STATUS_CODE, IStatus.INFO,
BONITA_DEPENDENCY_STATUS));
initialBosArchiveImportStatus.add(createStatusWithCode(
REST_API_BONITA_DEPENDENCY_STATUS_CODE, IStatus.INFO,
BONITA_DEPENDENCY_STATUS));
assertThat(initialBosArchiveImportStatus.getChildren()).hasSize(8);
BosArchiveImportStatus factorizedBosArchiveImportStatus = new BonitaStatusCodeAggregator()
.aggregateStatus(initialBosArchiveImportStatus);
String expectedGroovyAllMessage = String.format("%s (%s %s)", GROOVY_ALL_STATUS, 2, Messages.occurrences);
String expectedBonitaDependencyMessage = String.format("%s (%s %s)", BONITA_DEPENDENCY_STATUS, 3,
Messages.occurrences);
assertThat(factorizedBosArchiveImportStatus.getChildren()).hasSize(5);
assertThat(factorizedBosArchiveImportStatus.getChildren())
.extracting(IStatus::getMessage)
.containsExactlyInAnyOrder(
PROCESS_STATUS_1,
PROCESS_STATUS_2,
GROOVY_COMPILER_STATUS,
expectedGroovyAllMessage,
expectedBonitaDependencyMessage);
}
private IStatus createStatusWithCode(int code, int severity, String message) {
return new Status(severity, "0", code, message, null);
}
}
......@@ -79,5 +79,6 @@ public class Messages extends NLS {
public static String spDiagramCannotBeImportedError;
public static String containsLegacyFormsWarning;
public static String projectConnectorToVCS;
public static String occurrences;
}
/**
* Copyright (C) 2019 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.importer.bos.status;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.bonitasoft.studio.importer.bos.i18n.Messages;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
public class BonitaStatusCodeAggregator {
/**
* A status code is considered as a Bonita status code if it is greater or equals than 1000.
*/
public static boolean isBonitaStatusCode(int code) {
return code >= 1000;
}
public static final int REST_API_JAVA_11_GROOVY_ALL_STATUS_CODE = 1000;
public static final int REST_API_JAVA_11_GROOVY_COMPILER_STATUS_CODE = 1001;
public static final int REST_API_JAVA_11_GROOVY_BATCH_STATUS_CODE = 1002;
public static final int REST_API_BONITA_DEPENDENCY_STATUS_CODE = 1003;
public BosArchiveImportStatus aggregateStatus(BosArchiveImportStatus bosArchiveImportStatus) {
BosArchiveImportStatus bosArchiveStatusAggregated = new BosArchiveImportStatus();
List<RedundantStatus> statusToAggregate = new ArrayList<>();
for (IStatus status : bosArchiveImportStatus.getChildren()) {
if (isBonitaStatusCode(status.getCode())) {
statusToAggregate.stream()
.filter(redundantStatus -> redundantStatus.match(status))
.findFirst()
.orElseGet(() -> createRedundantStatus(status, statusToAggregate))
.incrementOccurence();
} else {
bosArchiveStatusAggregated.add(status);
}
}
statusToAggregate.stream()
.map(RedundantStatus::createAggregatedStatus)
.forEach(bosArchiveStatusAggregated::add);
return bosArchiveStatusAggregated;
}
private RedundantStatus createRedundantStatus(IStatus status, List<RedundantStatus> statusToAggregate) {
RedundantStatus redundantStatus = new RedundantStatus(status);
statusToAggregate.add(redundantStatus);
return redundantStatus;
}
}
class RedundantStatus {
private IStatus status;
private int occurrence = 0;
public RedundantStatus(IStatus status) {
this.status = status;
}
public boolean match(IStatus aStatus) {
return Objects.equals(status.getCode(), aStatus.getCode());
}
public void incrementOccurence() {
occurrence += 1;
}
public int getOccurrence() {
return occurrence;
}
public IStatus createAggregatedStatus() {
String message = occurrence > 1
? String.format("%s (%s %s)", status.getMessage(), occurrence, Messages.occurrences)
: status.getMessage();
switch (status.getSeverity()) {
case IStatus.OK:
case IStatus.INFO:
return ValidationStatus.info(message);
case IStatus.WARNING:
return ValidationStatus.warning(message);
default:
return ValidationStatus.error(message);
}
}
}
......@@ -35,7 +35,7 @@ public class ImportBosArchiveStatusBuilder {
}
public BosArchiveImportStatus done() {
return status;
return new BonitaStatusCodeAggregator().aggregateStatus(status);
}
public ImportBosArchiveStatusBuilder addStatus(final IStatus status) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment