Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AF-2700: Create Heatmap internal component #1080

Merged
merged 8 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ public class ExternalComponentServlet extends HttpServlet {
ComponentLoader loader;

String cacheControlHeaderValue = "no-cache";
private MimetypesFileTypeMap mimetypesFileTypeMap;
private MimetypesFileTypeMap mimeTypes;

@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
mimetypesFileTypeMap = new MimetypesFileTypeMap();
mimeTypes = new MimetypesFileTypeMap();
String cacheControl = config.getInitParameter(CACHE_CONTROL_PARAM);
if (cacheControl != null) {
cacheControlHeaderValue = cacheControl;
}
addAdditionalMimeTypes();
}

@Override
Expand Down Expand Up @@ -95,7 +96,7 @@ private void handle(HttpServletRequest req, HttpServletResponse resp) throws IOE

try (InputStream assetStream = assetProvider.openAsset(assetPath)) {
int size = IOUtils.copy(assetStream, resp.getOutputStream());
String mimeType = mimetypesFileTypeMap.getContentType(pathInfo);
String mimeType = mimeTypes.getContentType(pathInfo);
resp.setContentType(mimeType);
resp.setContentLength(size);
resp.setHeader(CACHE_CONTROL_PARAM, cacheControlHeaderValue);
Expand All @@ -119,4 +120,9 @@ private void errorResponse(HttpServletResponse resp) {
}
}

private void addAdditionalMimeTypes() {
mimeTypes.addMimeTypes("text/javascript js");
mimeTypes.addMimeTypes("text/css css");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void testLoadInternalComponents() throws IOException {
externalComponentLoaderImpl.init();
List<ExternalComponent> internalComponents = externalComponentLoaderImpl.loadProvided();

assertEquals(1, internalComponents.size());
assertEquals(3, internalComponents.size());

ExternalComponent component = internalComponents.get(0);
assertEquals("logo-provided", component.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class DataTransferServicesImpl implements DataTransferServices {
private NavTreeStorage navTreeStorage;
private byte[] buffer = new byte[1024];
private ComponentLoader externalComponentLoader;
private LayoutComponentsHelper layoutComponentsHelper;

private String dashbuilderLocation;
private String exportDir;
Expand All @@ -108,7 +109,8 @@ public DataTransferServicesImpl(
final Event<PluginAdded> pluginAddedEvent,
final Event<NavTreeChangedEvent> navTreeChangedEvent,
final NavTreeStorage navTreeStorage,
final ComponentLoader externalComponentLoader) {
final ComponentLoader externalComponentLoader,
final LayoutComponentsHelper layoutComponentsHelper) {

this.ioService = ioService;
this.datasetsFS = datasetsFS;
Expand All @@ -122,6 +124,7 @@ public DataTransferServicesImpl(
this.navTreeChangedEvent = navTreeChangedEvent;
this.navTreeStorage = navTreeStorage;
this.externalComponentLoader = externalComponentLoader;
this.layoutComponentsHelper = layoutComponentsHelper;
}

@PostConstruct
Expand Down Expand Up @@ -175,13 +178,15 @@ public String doExport(DataTransferExportModel exportModel) throws java.io.IOExc
.append("://")
.append(componentsPath)
.toString());
externalComponentLoader.loadExternal().forEach(c -> {
Path componentPath = componentsBasePath.resolve(c.getId());
zipComponentFiles(componentsBasePath,
componentPath,
zos,
p -> true);
});
Predicate<String> pagesComponentsFilter = page -> exportModel.isExportAll() || exportModel.getPages().contains(page);
layoutComponentsHelper.findComponentsInTemplates(pagesComponentsFilter)
.forEach(c -> {
Path componentPath = componentsBasePath.resolve(c);
zipComponentFiles(componentsBasePath,
componentPath,
zos,
p -> true);
});
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.dashbuilder.transfer;

import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.dashbuilder.external.model.ExternalComponent;
import org.uberfire.ext.layout.editor.api.PerspectiveServices;
import org.uberfire.ext.layout.editor.api.editor.LayoutComponent;
import org.uberfire.ext.layout.editor.api.editor.LayoutRow;
import org.uberfire.ext.layout.editor.api.editor.LayoutTemplate;

@ApplicationScoped
public class LayoutComponentsHelper {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class LayoutComponentsHelper {
public class LayoutComponentHelper {


@Inject
private PerspectiveServices perspectiveServices;

public List<String> findComponentsInTemplates(Predicate<String> pageFilter) {
return perspectiveServices.listLayoutTemplates()
.stream()
.filter(lt -> pageFilter.test(lt.getName()))
.map(LayoutTemplate::getRows)
.flatMap(this::allComponentsStream)
.map(lt -> lt.getProperties().get(ExternalComponent.COMPONENT_ID_KEY))
.filter(Objects::nonNull)
.collect(Collectors.toList());
}

private Stream<LayoutComponent> allComponentsStream(List<LayoutRow> row) {
return row.stream()
.flatMap(r -> r.getLayoutColumns().stream())
.flatMap(cl -> Stream.concat(cl.getLayoutComponents().stream(),
allComponentsStream(cl.getRows())));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public class DataTransferServicesTest {
DataSetDefJSONMarshaller dataSetDefJSONMarshaller;
@Mock
ComponentLoader externalComponentLoader;
@Mock
LayoutComponentsHelper layoutComponentsHelper;

Path componentsDir;

Expand Down Expand Up @@ -124,7 +126,8 @@ public void setup() {
pluginAddedEvent,
navTreeChangedEvent,
navTreeStorage,
externalComponentLoader);
externalComponentLoader,
layoutComponentsHelper);
}

@After
Expand Down Expand Up @@ -301,8 +304,8 @@ public void testDoExportWithoutNavigation() throws Exception {

@Test
public void testDoExportWithComponents() throws Exception {
when(externalComponentLoader.loadExternal()).thenReturn(asList(component("c1")));

when(layoutComponentsHelper.findComponentsInTemplates((any()))).thenReturn(asList("c1"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Please remove these extra spaces.

createFile(perspectivesFS, "page1/perspective_layout", "");
createFile(perspectivesFS, "page1/perspective_layout.plugin", "");

Expand All @@ -314,6 +317,13 @@ public void testDoExportWithComponents() throws Exception {
// lost file in component Dir that should be ignored
createComponentFile("lost", "lostfile", "ignore-me-import");

// Other component that is not used so it should not be exported
createComponentFile("c2", "manifest.json", "manifest");
createComponentFile("c2", "index.html", "html");
createComponentFile("c2", "css/style.css", "style");
createComponentFile("c2", "js/index.js", "js");


dataTransferServices.doExport(DataTransferExportModel.exportAll());

ZipInputStream zis = getZipInputStream();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.dashbuilder.transfer;

import java.util.Arrays;
import java.util.List;

import org.dashbuilder.external.model.ExternalComponent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.uberfire.ext.layout.editor.api.PerspectiveServices;
import org.uberfire.ext.layout.editor.api.editor.LayoutColumn;
import org.uberfire.ext.layout.editor.api.editor.LayoutComponent;
import org.uberfire.ext.layout.editor.api.editor.LayoutRow;
import org.uberfire.ext.layout.editor.api.editor.LayoutTemplate;

import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class LayoutComponentsHelperTest {

@Mock
PerspectiveServices perspectiveServices;

@InjectMocks
LayoutComponentsHelper layoutComponentsHelper;

@Test
public void testComponentId() {
String c1 = "c1";
String c2 = "c2";
LayoutTemplate lt = createLayoutTemplate("lt", c1, c2);
when(perspectiveServices.listLayoutTemplates()).thenReturn(singletonList(lt));

List<String> components = layoutComponentsHelper.findComponentsInTemplates(p -> true);

assertEquals(2, components.size());
assertEquals(components, Arrays.asList(c1, c2));
}

public void testNoComponentId() {
LayoutTemplate lt = createLayoutTemplate("lt");
when(perspectiveServices.listLayoutTemplates()).thenReturn(singletonList(lt));

List<String> components = layoutComponentsHelper.findComponentsInTemplates(p -> true);

assertTrue(components.isEmpty());
}

public void testPageFilter() {
String c1 = "c1";
LayoutTemplate lt = createLayoutTemplate("lt", c1);
when(perspectiveServices.listLayoutTemplates()).thenReturn(singletonList(lt));

List<String> components = layoutComponentsHelper.findComponentsInTemplates(p -> false);

assertTrue(components.isEmpty());
}

private LayoutTemplate createLayoutTemplate(String name, String... componentIds) {
LayoutTemplate lt = new LayoutTemplate(name);
LayoutRow lr = new LayoutRow();
LayoutColumn lc = new LayoutColumn("");

lr.add(lc);
lt.addRow(lr);
for (String componentId : componentIds) {
LayoutComponent lComp = new LayoutComponent();
lComp.addProperty(ExternalComponent.COMPONENT_ID_KEY, componentId);
lc.add(lComp);
}
return lt;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.enterprise.context.Dependent;
import javax.inject.Inject;

import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.user.client.Event;
import org.dashbuilder.client.cms.resources.i18n.ContentManagerConstants;
import org.gwtbootstrap3.client.ui.Modal;
Expand Down Expand Up @@ -187,6 +188,16 @@ public void okClick(final Event event) {
buttonPressed = ButtonPressed.OK;
presenter.onOK();
}

@SinkNative(Event.ONMOUSEDOWN)
@EventHandler("nameInput")
public void nameInputEnter(final Event event) {
if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
buttonPressed = ButtonPressed.OK;
presenter.onOK();
}
}


@SinkNative(Event.ONCLICK)
@EventHandler("cancelButton")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ removeFilter=Remove filter
DisplayerErrorWidget.displayerErrorTitle=Unexpected Error
DisplayerErrorWidget.errorDetails=Details

ExternalComponentView.configurationIssueTitle=Modify DataSet Configuration
ExternalComponentView.configurationIssueDescription=Component does not support the current columns configuration.
ExternalComponentView.configurationIssueTitle=Modify Configuration
ExternalComponentView.configurationIssueDescription=Component does not support the current configuration.

loadingComponent=Loading Component
componentEditor=Component Editor
Expand Down

This file was deleted.

Loading