Commit a1f6279c authored by Bonita CI's avatar Bonita CI
Browse files

Merge branch 'MasterBugFixing' into 'master'

parents a61933a8 fe608885
......@@ -31,7 +31,6 @@ import java.util.Set;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.designer.core.bos.WebFormBOSArchiveFileStoreProvider;
import org.bonitasoft.studio.designer.core.repository.WebFragmentFileStore;
import org.bonitasoft.studio.designer.core.repository.WebFragmentRepositoryStore;
import org.bonitasoft.studio.designer.core.repository.WebPageFileStore;
......@@ -90,9 +89,9 @@ public class WebFormBOSArchiveFileStoreProviderTest {
webFormArtifactsFileStoreProvider = spy(new WebFormBOSArchiveFileStoreProvider(repositoryAccessor, null));
doReturn(newHashSet("resources/widgets/customTestWidget/customTestWidget.json")).when(webFormArtifactsFileStoreProvider)
.findFormRelatedEntries(processFormFileStore);
.findFormRelatedEntries(processFormFileStore);
doReturn(newHashSet("resources/fragments/fragmentDep/fragmentDep.json")).when(webFormArtifactsFileStoreProvider)
.findFormRelatedEntries(taskFormFileStore);
.findFormRelatedEntries(taskFormFileStore);
}
......@@ -104,6 +103,14 @@ public class WebFormBOSArchiveFileStoreProviderTest {
assertThat(fileStores).contains(processFormFileStore, taskFormFileStore, customWidgetFileStore, fragmentFileStore);
}
@Test
public void should_not_contains_fileStore_if_file_does_not_exists() throws Exception {
final Set<IRepositoryFileStore> fileStores = webFormArtifactsFileStoreProvider.getFileStoreForConfiguration(aProcessWithInvalidFormMappings(),
aConfiguration().build());
assertThat(fileStores).isEmpty();
}
private AbstractProcess aProcessWithFormMappings() {
return aPool().withName("Pool1").withVersion("1.0")
.havingOverviewFormMapping(aFormMapping().withType(FormMappingType.URL).withURL("http://www.bonitasoft.com"))
......@@ -113,4 +120,10 @@ public class WebFormBOSArchiveFileStoreProviderTest {
aFormMapping().havingTargetForm(anExpression().withName("StepForm").withContent("step-form-id"))))
.build();
}
private AbstractProcess aProcessWithInvalidFormMappings() {
return aPool().withName("Pool1").withVersion("1.0")
.havingFormMapping(aFormMapping().havingTargetForm(anExpression().withName("processForm").withContent("invalid-process-form-id")))
.build();
}
}
......@@ -41,6 +41,7 @@ import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.provider.IBOSArchiveFileStoreProvider;
import org.bonitasoft.studio.designer.UIDesignerPlugin;
import org.bonitasoft.studio.designer.core.bar.BarResourceCreationException;
import org.bonitasoft.studio.designer.core.bar.CustomPageBarResourceFactory;
import org.bonitasoft.studio.designer.core.repository.WebFragmentFileStore;
......@@ -74,33 +75,40 @@ public class WebFormBOSArchiveFileStoreProvider implements IBOSArchiveFileStoreP
private final CustomPageBarResourceFactory customPageBarResourceFactory;
@Inject
public WebFormBOSArchiveFileStoreProvider(final RepositoryAccessor repositoryAccessor, final CustomPageBarResourceFactory customPageBarResourceFactory) {
public WebFormBOSArchiveFileStoreProvider(final RepositoryAccessor repositoryAccessor,
final CustomPageBarResourceFactory customPageBarResourceFactory) {
this.repositoryAccessor = repositoryAccessor;
this.customPageBarResourceFactory = customPageBarResourceFactory;
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.common.repository.provider.IBOSArchiveFileStoreProvider#getFileStoreForConfiguration(org.bonitasoft.studio.model.process.
* AbstractProcess, org.bonitasoft.studio.model.configuration.Configuration)
* @see org.bonitasoft.studio.common.repository.provider.
* IBOSArchiveFileStoreProvider#getFileStoreForConfiguration(org.bonitasoft.
* studio.model.process. AbstractProcess,
* org.bonitasoft.studio.model.configuration.Configuration)
*/
@Override
public Set<IRepositoryFileStore> getFileStoreForConfiguration(final AbstractProcess process, final Configuration configuration) {
public Set<IRepositoryFileStore> getFileStoreForConfiguration(final AbstractProcess process,
final Configuration configuration) {
final Set<IRepositoryFileStore> result = new HashSet<IRepositoryFileStore>();
final List<FormMapping> allFormMappings = getAllItemsOfType(process, ProcessPackage.Literals.FORM_MAPPING);
for (final WebPageFileStore fStore : transform(filter(allFormMappings, withInternalType()),
formMappingToFileStore())) {
result.add(fStore);
try {
result.addAll(getRelatedFileStore(fStore));
} catch (final BarResourceCreationException | IOException e) {
BonitaStudioLog.error("Failed to retrieve related Form resoruces", e);
if (fStore != null) {
result.add(fStore);
try {
result.addAll(getRelatedFileStore(fStore));
} catch (final BarResourceCreationException | IOException e) {
BonitaStudioLog.error("Failed to retrieve related form resources", e);
}
}
}
return result;
}
protected Set<String> findFormRelatedEntries(final WebPageFileStore fStore) throws BarResourceCreationException, IOException {
protected Set<String> findFormRelatedEntries(final WebPageFileStore fStore)
throws BarResourceCreationException, IOException {
final BarResource barResource = customPageBarResourceFactory.newBarResource(fStore.getName(), fStore.getId());
final byte[] zipContent = barResource.getContent();
final Set<String> zipEntries = zipEntries(zipContent);
......@@ -121,8 +129,8 @@ public class WebFormBOSArchiveFileStoreProvider implements IBOSArchiveFileStoreP
}
private Set<WebWidgetFileStore> relatedWidgets(final Set<String> zipEntries) {
return newHashSet(filter(transform(filter(zipEntries, containsPattern(WIDGET_ENTRY_REGEXP)), toWidgetFileStore(compile(WIDGET_ENTRY_REGEXP))),
customWidgetOnly()));
return newHashSet(filter(transform(filter(zipEntries, containsPattern(WIDGET_ENTRY_REGEXP)),
toWidgetFileStore(compile(WIDGET_ENTRY_REGEXP))), customWidgetOnly()));
}
private Predicate<WebWidgetFileStore> customWidgetOnly() {
......@@ -148,7 +156,8 @@ public class WebFormBOSArchiveFileStoreProvider implements IBOSArchiveFileStoreP
}
private Set<WebFragmentFileStore> relatedFragments(final Set<String> zipEntries) {
return newHashSet(transform(filter(zipEntries, containsPattern(FRAGMENT_ENTRY_REGEXP)), toFragmentFileStore(compile(FRAGMENT_ENTRY_REGEXP))));
return newHashSet(transform(filter(zipEntries, containsPattern(FRAGMENT_ENTRY_REGEXP)),
toFragmentFileStore(compile(FRAGMENT_ENTRY_REGEXP))));
}
private Function<String, WebFragmentFileStore> toFragmentFileStore(final Pattern fragmentPattern) {
......@@ -158,8 +167,8 @@ public class WebFormBOSArchiveFileStoreProvider implements IBOSArchiveFileStoreP
public WebFragmentFileStore apply(final String matchingEntry) {
final Matcher matcher = fragmentPattern.matcher(matchingEntry);
checkState(matcher.matches() == true);
return repositoryAccessor.getRepositoryStore(WebFragmentRepositoryStore.class).getChild(
matcher.group(1));
return repositoryAccessor.getRepositoryStore(WebFragmentRepositoryStore.class)
.getChild(matcher.group(1));
}
};
}
......@@ -169,7 +178,12 @@ public class WebFormBOSArchiveFileStoreProvider implements IBOSArchiveFileStoreP
@Override
public WebPageFileStore apply(final FormMapping mapping) {
return fileStoreFromFormUUID(mapping.getTargetForm().getContent());
final String formUUID = mapping.getTargetForm().getContent();
final WebPageFileStore store = fileStoreFromFormUUID(formUUID);
if(store == null){
BonitaStudioLog.warning(String.format("Page with id %s doesn't exist.", formUUID), UIDesignerPlugin.PLUGIN_ID);
}
return store;
}
};
......@@ -190,7 +204,8 @@ public class WebFormBOSArchiveFileStoreProvider implements IBOSArchiveFileStoreP
};
}
public Set<IRepositoryFileStore> getRelatedFileStore(final WebPageFileStore webPageFileStore) throws BarResourceCreationException, IOException {
public Set<IRepositoryFileStore> getRelatedFileStore(final WebPageFileStore webPageFileStore)
throws BarResourceCreationException, IOException {
final Set<String> zipEntries = findFormRelatedEntries(webPageFileStore);
final Set<IRepositoryFileStore> result = new HashSet<IRepositoryFileStore>();
result.addAll(relatedFragments(zipEntries));
......
......@@ -22,6 +22,7 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
......@@ -213,6 +214,22 @@ public class EngineFlowElementBuilderTest {
assertThat(argument.getValue().getExpressionType()).isEqualTo(ExpressionType.TYPE_BUSINESS_DATA_REFERENCE.name());
}
@Test
public void testAddIteratorToContext_robustnessWithNullValue() {
final Data collectionDataToMultiInstantiate = BusinessObjectDataBuilder.aBusinessData().withName("bData").withClassname("classname").build();
final TaskBuilder taskB = TaskBuilder.aTask().havingCollectionDataToMultiInstantiate(collectionDataToMultiInstantiate)
.havingData(collectionDataToMultiInstantiate);
final Pool pool = PoolBuilder.aPool().havingElements(taskB).build();
final MainProcess mainProcess = MainProcessBuilder.aMainProcess().build();
mainProcess.getElements().add(pool);
mainProcess.getDatatypes().add(BusinessObjectDataTypeBuilder.aBusinessObjectDataType().withName("classname").build());
flowElementSwitch.addContext(taskBuilder, (Task) pool.getElements().get(0));
verify(taskBuilder, times(0)).addContextEntry(anyString(), any(Expression.class));
}
@Test
public void testAddInputMappingAssignedToData() {
final Pool pool = PoolBuilder.aPool()
......
......@@ -272,17 +272,17 @@ public abstract class AbstractProcessBuilder extends ProcessSwitch<Element> {
protected void addContext(final Object contextBuilder, final Task task) {
final Pool pool = ModelHelper.getParentPool(task);
addContext(contextBuilder, pool);
final org.bonitasoft.studio.model.expression.Expression iteratorExpression = task.getIteratorExpression();
addIteratorToContext(contextBuilder, task, iteratorExpression);
addIteratorToContext(contextBuilder, task);
}
/**
* @param contextBuilder
* @param task
* @param iteratorExpression
*/
protected void addIteratorToContext(final Object contextBuilder, final Task task, final org.bonitasoft.studio.model.expression.Expression iteratorExpression) {
if (ExpressionConstants.MULTIINSTANCE_ITERATOR_TYPE.equals(iteratorExpression.getType())
protected void addIteratorToContext(final Object contextBuilder, final Task task) {
final org.bonitasoft.studio.model.expression.Expression iteratorExpression = task.getIteratorExpression();
if (iteratorExpression != null &&
ExpressionConstants.MULTIINSTANCE_ITERATOR_TYPE.equals(iteratorExpression.getType())
&& iteratorExpression.getName() != null
&& !iteratorExpression.getName().isEmpty()
&& task instanceof DataAware) {
......
......@@ -261,7 +261,7 @@ public class StringToExpressionConverter {
content, returnType, expressionType, fixedReturnType);
if (ExpressionConstants.VARIABLE_TYPE.equals(expressionType)
|| ExpressionConstants.SIMULATION_VARIABLE_TYPE
.equals(expressionType)) {
.equals(expressionType)) {
resolveDataDependencies(exp);
} else if (ExpressionConstants.FORM_FIELD_TYPE
.equals(expressionType)) {
......@@ -298,7 +298,7 @@ public class StringToExpressionConverter {
.get("referencedElements");
if (!dependancyAlreadyExists(instList, dependencyInstance)) {
expression
.add("referencedElements", dependencyInstance);
.add("referencedElements", dependencyInstance);
}
}
}
......@@ -462,9 +462,9 @@ public class StringToExpressionConverter {
private Instance createFormFieldDependencyInstance(
final Instance widgetInstance) {
final Instance widget = widgetInstance.copy();
final List<Instance> widgetDependencies = widget.get("dependOn");
for (final Instance w : widgetDependencies) {
model.delete(w);
//clean nested content
for (final Instance content : widget.getContents()) {
model.delete(content);
}
widget.set("dependOn", Collections.emptyList());
return widget;
......@@ -478,7 +478,7 @@ public class StringToExpressionConverter {
if (defaultValue != null
&& defaultValue instanceof Instance
&& ((Instance) defaultValue)
.instanceOf("expression.Expression")) {
.instanceOf("expression.Expression")) {
model.delete((Instance) defaultValue);
copy.set("defaultValue", null);
}
......
......@@ -35,7 +35,8 @@ Require-Bundle: org.eclipse.ui,
org.junit;bundle-version="4.11.0";resolution:=optional,
assertj-core;bundle-version="1.5.0";resolution:=optional,
org.mockito;bundle-version="1.10.19";resolution:=optional,
org.bonitasoft.studio.tests-utils;bundle-version="7.0.2";resolution:=optional
org.bonitasoft.studio.tests-utils;bundle-version="7.0.2";resolution:=optional,
org.eclipse.emf.ecore
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.validators.descriptor.validator,
......
/**
* Copyright (C) 2015 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.validators.provider;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import org.assertj.core.api.Assertions;
import org.bonitasoft.engine.bpm.bar.BarResource;
import org.bonitasoft.engine.bpm.bar.BusinessArchiveBuilder;
import org.bonitasoft.studio.common.FragmentTypes;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.filestore.PackageFileStore;
import org.bonitasoft.studio.common.repository.filestore.SourceFileStore;
import org.bonitasoft.studio.model.configuration.Configuration;
import org.bonitasoft.studio.model.configuration.builders.ConfigurationBuilder;
import org.bonitasoft.studio.model.configuration.builders.FragmentContainerBuilder;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.validators.descriptor.validator.ValidatorDescriptor;
import org.bonitasoft.studio.validators.repository.ValidatorDescriptorFileStore;
import org.bonitasoft.studio.validators.repository.ValidatorDescriptorRepositoryStore;
import org.bonitasoft.studio.validators.repository.ValidatorSourceRepositorySotre;
import org.eclipse.emf.ecore.EObject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class ValidatorBarResourceProviderTest {
private ValidatorBarResourceProvider provider;
@Mock
private ValidatorDescriptorRepositoryStore validatorDescStore;
@Mock
private ValidatorSourceRepositorySotre validatorSourceStore;
@Mock
private RepositoryAccessor repoAccessor;
@Mock
private BusinessArchiveBuilder builder;
@Mock
private ValidatorDescriptorFileStore defFile;
@Mock
private ValidatorDescriptor descriptor;
@Mock
private PackageFileStore packageFileStore;
@Mock
private SourceFileStore sourceFileStore;
@Before
public void setUp() throws Exception {
provider = spy(new ValidatorBarResourceProvider());
doReturn(repoAccessor).when(provider).getRepositoryAccessor();
doReturn(validatorDescStore).when(repoAccessor).getRepositoryStore(ValidatorDescriptorRepositoryStore.class);
doReturn(validatorSourceStore).when(repoAccessor).getRepositoryStore(ValidatorSourceRepositorySotre.class);
}
@Test
public void testInvalidValidatorDefinitionThrowExplicitException() {
final String validatorId = "org.bonitasoft.invalid.";
final String className = "org.bonitasoft.invalid.";
doReturn(defFile).when(validatorDescStore).getChild(validatorId + "." + ValidatorDescriptorRepositoryStore.VALIDATOR_EXT);
doReturn(true).when(defFile).canBeShared();
doReturn(descriptor).when(defFile).getContent();
doReturn(className).when(descriptor).getClassName();
doReturn(packageFileStore).when(validatorSourceStore).getChild(className);
final FragmentContainerBuilder dependencies = FragmentContainerBuilder.aFragmentContainer(FragmentTypes.VALIDATOR).
havingChildren(FragmentContainerBuilder.aFragmentContainer(validatorId));
final Configuration configuration = ConfigurationBuilder.aConfiguration().havingApplicationDependencies(dependencies).build();
try {
provider.addResourcesForConfiguration(builder, (AbstractProcess) null, configuration, Collections.<EObject> emptySet());
} catch (final RuntimeException e) {
Assertions.assertThat(e.getMessage()).isEqualTo("Invalid validator definition " + validatorId + "!");
return;
} catch (final FileNotFoundException e) {
e.printStackTrace();
}
fail("A clean RuntimeException should have been thrown.");
}
@Test
public void testNotExistingValidatorDefinitionThrowExplicitException() {
final String validatorId = "org.bonitasoft.invalid.";
final String className = "org.bonitasoft.invalid.";
doReturn(defFile).when(validatorDescStore).getChild(validatorId + "." + ValidatorDescriptorRepositoryStore.VALIDATOR_EXT);
doReturn(true).when(defFile).canBeShared();
doReturn(descriptor).when(defFile).getContent();
doReturn(className).when(descriptor).getClassName();
doReturn(null).when(validatorSourceStore).getChild(className);
final FragmentContainerBuilder dependencies = FragmentContainerBuilder.aFragmentContainer(FragmentTypes.VALIDATOR).
havingChildren(FragmentContainerBuilder.aFragmentContainer(validatorId));
final Configuration configuration = ConfigurationBuilder.aConfiguration().havingApplicationDependencies(dependencies).build();
try {
provider.addResourcesForConfiguration(builder, (AbstractProcess) null, configuration, Collections.<EObject> emptySet());
} catch (final RuntimeException e) {
e.printStackTrace();
} catch (final FileNotFoundException e) {
Assertions.assertThat(e.getMessage()).isEqualTo(
"Validator class " + className + " not found for validator definition " + validatorId + "!");
return;
}
fail("A clean RuntimeException should have been thrown.");
}
@Test
public void testValidatorDefinitionAdded() throws InvocationTargetException, FileNotFoundException, IOException, InterruptedException {
final String validatorId = "org.bonitasoft.valid.Test";
final String className = "org.bonitasoft.valid.Test";
doReturn(defFile).when(validatorDescStore).getChild(validatorId + "." + ValidatorDescriptorRepositoryStore.VALIDATOR_EXT);
doReturn(true).when(defFile).canBeShared();
doReturn(descriptor).when(defFile).getContent();
doReturn(className).when(descriptor).getClassName();
doReturn(sourceFileStore).when(validatorSourceStore).getChild(className);
doReturn("test".getBytes()).when(provider).createJarContentAsByteArray(sourceFileStore);
final FragmentContainerBuilder dependencies = FragmentContainerBuilder.aFragmentContainer(FragmentTypes.VALIDATOR).
havingChildren(FragmentContainerBuilder.aFragmentContainer(validatorId));
final Configuration configuration = ConfigurationBuilder.aConfiguration().havingApplicationDependencies(dependencies).build();
provider.addResourcesForConfiguration(builder, (AbstractProcess) null, configuration, Collections.<EObject> emptySet());
verify(builder).addExternalResource(any(BarResource.class));
}
}
/**
* Copyright (C) 2012-2014 Bonitasoft S.A.
* Copyright (C) 2012-2015 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
......@@ -29,7 +29,8 @@ import org.bonitasoft.studio.common.FragmentTypes;
import org.bonitasoft.studio.common.ProjectUtil;
import org.bonitasoft.studio.common.extension.BARResourcesProvider;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.filestore.AbstractFileStore;
import org.bonitasoft.studio.common.repository.filestore.SourceFileStore;
import org.bonitasoft.studio.model.configuration.Configuration;
import org.bonitasoft.studio.model.configuration.FragmentContainer;
......@@ -47,31 +48,32 @@ public class ValidatorBarResourceProvider implements BARResourcesProvider {
@Override
public void addResourcesForConfiguration(final BusinessArchiveBuilder builder, final AbstractProcess process, final Configuration configuration,
final Set<EObject> exludedObject) {
final Set<EObject> exludedObject) throws FileNotFoundException {
if (configuration == null) {
return;
}
final List<BarResource> resources = findAndCreateBarResourceForValidator(configuration);
for (final BarResource barResource : resources) {
builder.addExternalResource(barResource);
}
}
protected List<BarResource> findAndCreateBarResourceForValidator(final Configuration configuration) throws FileNotFoundException {
final List<BarResource> resources = new ArrayList<BarResource>();
final ValidatorDescriptorRepositoryStore validatorDescStore = RepositoryManager.getInstance().getRepositoryStore(
ValidatorDescriptorRepositoryStore.class);
final ValidatorSourceRepositorySotre validatorSourceStore = RepositoryManager.getInstance().getRepositoryStore(ValidatorSourceRepositorySotre.class);
final ValidatorDescriptorRepositoryStore validatorDescStore = getRepositoryAccessor().getRepositoryStore(ValidatorDescriptorRepositoryStore.class);
final ValidatorSourceRepositorySotre validatorSourceStore = getRepositoryAccessor().getRepositoryStore(ValidatorSourceRepositorySotre.class);
final FragmentContainer validatorContainer = getContainer(configuration);
if (validatorContainer != null) {
for (final FragmentContainer validator : validatorContainer.getChildren()) {
final String validatorId = validator.getId();
final ValidatorDescriptorFileStore defFile = validatorDescStore.getChild(validatorId + "."
+ ValidatorDescriptorRepositoryStore.VALIDATOR_EXT);
if (defFile == null) {
throw new RuntimeException("Validator descriptor not found for id " + validatorId + "!");
}
if (defFile != null && defFile.canBeShared()) {
} else if (defFile.canBeShared()) {
final ValidatorDescriptor descriptor = defFile.getContent();
final SourceFileStore file = (SourceFileStore) validatorSourceStore.getChild(descriptor.getClassName());
if (file == null) {
throw new RuntimeException("Validator class " + descriptor.getClassName() + " not found for validator definition " + validatorId + "!");
}
final SourceFileStore file = findSourceFileStoreForValidator(validatorSourceStore, validatorId, descriptor);
try {
final byte[] content = createJarContentAsByteArray(file);
resources.add(new BarResource(ValidatorSourceRepositorySotre.VALIDATOR_PATH_IN_BAR + descriptor.getClassName() + ".jar", content));
......@@ -81,13 +83,22 @@ public class ValidatorBarResourceProvider implements BARResourcesProvider {
}
}
}
return resources;
}
for (final BarResource barResource : resources) {
builder.addExternalResource(barResource);
protected SourceFileStore findSourceFileStoreForValidator(final ValidatorSourceRepositorySotre validatorSourceStore, final String validatorId,
final ValidatorDescriptor descriptor) throws FileNotFoundException {
final AbstractFileStore child = validatorSourceStore.getChild(descriptor.getClassName());
if (child == null) {
throw new FileNotFoundException("Validator class " + descriptor.getClassName() + " not found for validator definition " + validatorId + "!");
}
if (!(child instanceof SourceFileStore)) {
throw new RuntimeException("Invalid validator definition " + validatorId + "!");
}
return (SourceFileStore) child;
}
private byte[] createJarContentAsByteArray(final SourceFileStore file) throws IOException, InvocationTargetException, InterruptedException,
protected byte[] createJarContentAsByteArray(final SourceFileStore file) throws IOException, InvocationTargetException, InterruptedException,
FileNotFoundException {
final File tmpFile = File.createTempFile(file.getName(), ".jar", ProjectUtil.getBonitaStudioWorkFolder());
tmpFile.deleteOnExit();
......@@ -102,11 +113,17 @@ public class ValidatorBarResourceProvider implements BARResourcesProvider {
private FragmentContainer getContainer(final Configuration configuration) {
for (final FragmentContainer container : configuration.getApplicationDependencies()) {
if (container.getId().equals(FragmentTypes.VALIDATOR)) {
if (FragmentTypes.VALIDATOR.equals(container.getId())) {
return container;
}
}
return null;
}
protected RepositoryAccessor getRepositoryAccessor() {
final RepositoryAccessor repositoryAccessor = new RepositoryAccessor();
repositoryAccessor.init();
return repositoryAccessor;
}
}
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