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

feat(bos import) Ensure that fragments can't be imported in a community edition (#1502)


closes [BS-19124](https://bonitasoft.atlassian.net/browse/BS-19124)
parent af92bc87
...@@ -18,12 +18,14 @@ import java.util.zip.ZipFile; ...@@ -18,12 +18,14 @@ import java.util.zip.ZipFile;
import org.bonitasoft.studio.common.ProductVersion; import org.bonitasoft.studio.common.ProductVersion;
import org.bonitasoft.studio.common.log.BonitaStudioLog; import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.Messages; import org.bonitasoft.studio.common.repository.Messages;
import org.bonitasoft.studio.common.repository.Repository; import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager; import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.model.IRepository; import org.bonitasoft.studio.common.repository.model.IRepository;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore; import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore; import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.bonitasoft.studio.designer.core.repository.WebFragmentRepositoryStore;
import org.bonitasoft.studio.importer.bos.BosArchiveImporterPlugin; import org.bonitasoft.studio.importer.bos.BosArchiveImporterPlugin;
import org.eclipse.core.databinding.validation.ValidationStatus; import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
...@@ -61,17 +63,19 @@ public class BosArchive { ...@@ -61,17 +63,19 @@ public class BosArchive {
public ImportArchiveModel toImportModel(Repository repository, IProgressMonitor monitor) throws IOException { public ImportArchiveModel toImportModel(Repository repository, IProgressMonitor monitor) throws IOException {
final IStatus validationStatus = validate(); final IStatus validationStatus = validate();
if (!validationStatus.isOK()) { if (!validationStatus.isOK()) {
throw new IOException(Messages.unvalidBossArchive); throw new IllegalArgumentException(validationStatus.getMessage());
} }
final Set<String> resourcesToOpen = getResourcesToOpen(); final Set<String> resourcesToOpen = getResourcesToOpen();
final ImportArchiveModel archiveModel = new ImportArchiveModel(this); final ImportArchiveModel archiveModel = new ImportArchiveModel(this);
try (ZipFile zipFile = new ZipFile(archiveFile)) { try (ZipFile zipFile = new ZipFile(archiveFile)) {
int entryCount = (int) zipFile.stream().filter(entry -> !entry.isDirectory()).count();
monitor.beginTask(org.bonitasoft.studio.importer.bos.i18n.Messages.parsingArchive, monitor.beginTask(org.bonitasoft.studio.importer.bos.i18n.Messages.parsingArchive,
(int) zipFile.stream().filter(e -> !e.isDirectory()).count()); entryCount);
zipFile.stream().filter(e -> !e.isDirectory()) zipFile.stream()
.forEach(e -> { .filter(entry -> !entry.isDirectory())
parseEntry(e, archiveModel, repository, resourcesToOpen); .forEach(entry -> {
parseEntry(entry, archiveModel, repository, resourcesToOpen);
monitor.worked(1); monitor.worked(1);
}); });
} catch (final IOException e) { } catch (final IOException e) {
...@@ -82,7 +86,6 @@ public class BosArchive { ...@@ -82,7 +86,6 @@ public class BosArchive {
private void parseEntry(ZipEntry entry, ImportArchiveModel archiveModel, IRepository repository, private void parseEntry(ZipEntry entry, ImportArchiveModel archiveModel, IRepository repository,
Set<String> resourcesToOpen) { Set<String> resourcesToOpen) {
final String entryName = entry.getName(); final String entryName = entry.getName();
final List<String> segments = Splitter.on('/').splitToList(entryName); final List<String> segments = Splitter.on('/').splitToList(entryName);
segments.stream() segments.stream()
...@@ -138,6 +141,9 @@ public class BosArchive { ...@@ -138,6 +141,9 @@ public class BosArchive {
file.getParent().ifPresent(parent -> parent file.getParent().ifPresent(parent -> parent
.setDisplayName(String.format("%s (%s)", name, parent.getFolderName()))); .setDisplayName(String.format("%s (%s)", name, parent.getFolderName())));
} }
if (isFragment(file) && PlatformUtil.isACommunityBonitaProduct()) {
return;
}
store.addFile(file); store.addFile(file);
} else if (segments.size() > 1 && directStoreChild) { // Folder } else if (segments.size() > 1 && directStoreChild) { // Folder
final Iterable<String> folderParentSegments = concat(parentSegments, segments.subList(0, 1)); final Iterable<String> folderParentSegments = concat(parentSegments, segments.subList(0, 1));
...@@ -157,6 +163,14 @@ public class BosArchive { ...@@ -157,6 +163,14 @@ public class BosArchive {
} }
} }
private boolean isFragment(ImportFileModel file) {
if (file.getParentRepositoryStore().isPresent()) {
IRepositoryStore repositoryStore = file.getParentRepositoryStore().get();
return repositoryStore instanceof WebFragmentRepositoryStore;
}
return false;
}
public IStatus validateDiagram(ImportFileStoreModel file) { public IStatus validateDiagram(ImportFileStoreModel file) {
try (ZipFile archive = getZipFile(); try (ZipFile archive = getZipFile();
InputStream is = archive.getInputStream(archive.getEntry(file.getPath()));) { InputStream is = archive.getInputStream(archive.getEntry(file.getPath()));) {
......
...@@ -15,7 +15,6 @@ public class ImportArchiveModel { ...@@ -15,7 +15,6 @@ public class ImportArchiveModel {
private final List<ImportStoreModel> stores = new ArrayList<>(); private final List<ImportStoreModel> stores = new ArrayList<>();
private final BosArchive bosArchive; private final BosArchive bosArchive;
private IStatus validationStatus = Status.OK_STATUS; private IStatus validationStatus = Status.OK_STATUS;
private IStatus validationStatus2;
public ImportArchiveModel(BosArchive bosArchive) { public ImportArchiveModel(BosArchive bosArchive) {
this.bosArchive = bosArchive; this.bosArchive = bosArchive;
...@@ -43,7 +42,7 @@ public class ImportArchiveModel { ...@@ -43,7 +42,7 @@ public class ImportArchiveModel {
public void removeStore(ImportStoreModel store) { public void removeStore(ImportStoreModel store) {
stores.remove(store); stores.remove(store);
} }
public List<ImportStoreModel> getStores() { public List<ImportStoreModel> getStores() {
Collections.sort(stores, (f1, f2) -> f1.getFolderName().compareTo(f2.getFolderName())); Collections.sort(stores, (f1, f2) -> f1.getFolderName().compareTo(f2.getFolderName()));
return Collections.unmodifiableList(stores); return Collections.unmodifiableList(stores);
......
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