Skip to content

Commit ee61017

Browse files
mlopezFCjavier-godoy
authored andcommitted
feat: add initial fusion endpoint implementation
1 parent 7ca88c9 commit ee61017

File tree

5 files changed

+186
-2
lines changed

5 files changed

+186
-2
lines changed

pom.xml

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@
107107
</exclusion>
108108
</exclusions>
109109
</dependency>
110-
110+
<dependency>
111+
<groupId>org.springframework</groupId>
112+
<artifactId>spring-context</artifactId>
113+
<version>5.3.0</version>
114+
<optional>true</optional>
115+
</dependency>
111116
<dependency>
112117
<groupId>org.slf4j</groupId>
113118
<artifactId>slf4j-simple</artifactId>
@@ -224,6 +229,16 @@
224229
<profiles>
225230
<profile>
226231
<id>directory</id>
232+
<properties>
233+
<vaadin.productionMode>true</vaadin.productionMode>
234+
</properties>
235+
<dependencies>
236+
<dependency>
237+
<groupId>com.vaadin</groupId>
238+
<artifactId>flow-server-production-mode</artifactId>
239+
<optional>true</optional>
240+
</dependency>
241+
</dependencies>
227242
<build>
228243
<plugins>
229244
<plugin>
@@ -277,14 +292,49 @@
277292
<additionalparam>-Xdoclint:none</additionalparam>
278293
</configuration>
279294
</plugin>
295+
<plugin>
296+
<groupId>com.vaadin</groupId>
297+
<artifactId>vaadin-maven-plugin</artifactId>
298+
<executions>
299+
<execution>
300+
<goals>
301+
<goal>prepare-frontend</goal>
302+
<goal>build-frontend</goal>
303+
</goals>
304+
</execution>
305+
</executions>
306+
</plugin>
307+
<plugin>
308+
<artifactId>maven-resources-plugin</artifactId>
309+
<version>3.2.0</version>
310+
<executions>
311+
<execution>
312+
<id>copy-resources</id>
313+
<!-- here the phase you need -->
314+
<phase>validate</phase>
315+
<goals>
316+
<goal>copy-resources</goal>
317+
</goals>
318+
<configuration>
319+
<outputDirectory>${basedir}/target/classes/META-INF/frontend</outputDirectory>
320+
<resources>
321+
<resource>
322+
<directory>frontend</directory>
323+
<filtering>true</filtering>
324+
</resource>
325+
</resources>
326+
</configuration>
327+
</execution>
328+
</executions>
329+
</plugin>
280330
<plugin>
281331
<groupId>org.apache.maven.plugins</groupId>
282332
<artifactId>maven-jar-plugin</artifactId>
283333
<version>3.1.2</version>
284334
<configuration>
285335
<!-- Generated file that shouldn't be included in add-ons -->
286336
<excludes>
287-
<exclude>META-INF/VAADIN/config/flow-build-info.json</exclude>
337+
<exclude>META-INF/VAADIN/**/*.*</exclude>
288338
</excludes>
289339
</configuration>
290340
</plugin>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.flowingcode.addons.applayout.endpoint;
2+
3+
import java.util.List;
4+
import java.util.stream.Collectors;
5+
6+
import com.vaadin.flow.server.auth.AnonymousAllowed;
7+
import com.vaadin.flow.server.connect.Endpoint;
8+
9+
@Endpoint
10+
@AnonymousAllowed
11+
public class MenuEndpoint {
12+
13+
List<MenuItemsProvider> menuItemsProviders;
14+
15+
public MenuEndpoint(List<MenuItemsProvider> menuItemsProviders) {
16+
this.menuItemsProviders = menuItemsProviders;
17+
}
18+
19+
public List<MenuItemDto> getMenuItems() {
20+
return menuItemsProviders.stream().map(mip->mip.getMenuItems()).flatMap(List::stream).collect(Collectors.toList());
21+
}
22+
23+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.flowingcode.addons.applayout.endpoint;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import javax.annotation.Nullable;
7+
8+
public class MenuItemDto {
9+
10+
private String label;
11+
@Nullable
12+
private String href;
13+
private List<MenuItemDto> children = new ArrayList<>();
14+
15+
public MenuItemDto(String label, List<MenuItemDto> children) {
16+
this(label,null,children);
17+
}
18+
19+
public MenuItemDto(String label, String href) {
20+
this(label,href,new ArrayList<>());
21+
}
22+
23+
public MenuItemDto(String label, String href, List<MenuItemDto> children) {
24+
this.label = label;
25+
this.href = href;
26+
this.children = children;
27+
}
28+
29+
public List<MenuItemDto> getChildren() {
30+
return children;
31+
}
32+
33+
public void setChildren(List<MenuItemDto> children) {
34+
this.children = children;
35+
}
36+
37+
public String getLabel() {
38+
return label;
39+
}
40+
public String getHref() {
41+
return href;
42+
}
43+
public void setHref(String href) {
44+
this.href = href;
45+
}
46+
public void setLabel(String label) {
47+
this.label = label;
48+
}
49+
50+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.flowingcode.addons.applayout.endpoint;
2+
3+
import java.util.List;
4+
5+
@FunctionalInterface
6+
public interface MenuItemsProvider {
7+
8+
List<MenuItemDto> getMenuItems();
9+
10+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.flowingcode.addons.applayout.listener;
2+
3+
import java.lang.reflect.InvocationTargetException;
4+
import java.lang.reflect.Method;
5+
6+
import com.flowingcode.addons.applayout.endpoint.MenuEndpoint;
7+
import com.vaadin.flow.server.ServiceInitEvent;
8+
import com.vaadin.flow.server.VaadinServiceInitListener;
9+
import com.vaadin.flow.server.connect.Endpoint;
10+
import com.vaadin.flow.server.connect.EndpointRegistry;
11+
12+
import org.springframework.beans.BeansException;
13+
import org.springframework.beans.factory.annotation.Autowired;
14+
import org.springframework.context.ApplicationContext;
15+
import org.springframework.context.ApplicationContextAware;
16+
import org.springframework.stereotype.Component;
17+
18+
@Component
19+
public class RegisterEndpointServiceInitListener implements VaadinServiceInitListener, ApplicationContextAware {
20+
21+
private ApplicationContext context;
22+
23+
@Autowired
24+
private EndpointRegistry endpointRegistry;
25+
26+
@Override
27+
public void serviceInit(ServiceInitEvent event) {
28+
context.getBeansWithAnnotation(Endpoint.class)
29+
.forEach((name, endpointBean) -> {
30+
if (endpointBean instanceof MenuEndpoint) {
31+
registerEndpoint(endpointBean);
32+
}
33+
});
34+
}
35+
36+
private void registerEndpoint(Object endpointBean) {
37+
try {
38+
Method m = EndpointRegistry.class.getDeclaredMethod("registerEndpoint", Object.class);
39+
m.setAccessible(true);
40+
m.invoke(endpointRegistry, endpointBean);
41+
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
42+
throw new RuntimeException("Problem registering endpoint",e);
43+
}
44+
}
45+
46+
@Override
47+
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
48+
this.context = applicationContext;
49+
}
50+
51+
}

0 commit comments

Comments
 (0)