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

Release/1.1.0 #5

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
19 changes: 17 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>com.netgrif</groupId>
<artifactId>etask</artifactId>
<version>1.0.0</version>
<version>1.1.0-SNAPSHOT</version>

<name>eTask backend</name>
<description>eTask application is a quick way to start with Netgrif Application Engine</description>
Expand All @@ -27,6 +27,7 @@
</license>
</licenses>


<organization>
<name>NETGRIF, s.r.o.</name>
<url>https://netgrif.com</url>
Expand Down Expand Up @@ -58,13 +59,27 @@
<maven.compiler.release>11</maven.compiler.release>
</properties>

<repositories>
<repository>
<id>oss.snapshots</id>
<name>OSSRH SNAPSHOT</name>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>

<!-- NETGRIF Application Engine -->
<dependency>
<groupId>com.netgrif</groupId>
<artifactId>application-engine</artifactId>
<version>6.3.1</version>
<version>6.4.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
Expand Down
64 changes: 7 additions & 57 deletions src/main/groovy/com/netgrif/etask/EtaskActionDelegate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,6 @@ class EtaskActionDelegate extends ActionDelegate {
@Autowired
private UriNodeDataRepository uriNodeDataRepository

/**
* create or update menu item of specified type
* @param id
* @param uri
* @param type
* @param query
* @param icon
* @param title
* @param allowedNets
* @param roles
* @param bannedRoles
* @return
*/
Case createOrUpdateMenuItem(String id, String uri, String type, String query, String icon, String title, List<String> allowedNets, Map<String, String> roles = [:], Map<String, String> bannedRoles = [:]) {
collectRolesForPreferenceItem(roles)
Case menuItem = findMenuItem(id)
if (!menuItem) {
Case filter = createFilter(title, query, type, allowedNets, icon, "private", null)
createUri(uri, UriContentType.DEFAULT)
return createMenuItem(uri, id, filter, roles, bannedRoles)
} else {
Case filter = getFilterFromMenuItem(menuItem)
changeFilter filter query { query }
changeFilter filter allowedNets { allowedNets }
changeFilter filter title { title }
changeFilter filter icon { icon }
changeMenuItem menuItem allowedRoles { roles }
changeMenuItem menuItem bannedRoles { bannedRoles }
changeMenuItem menuItem uri { uri }
changeMenuItem menuItem filter { filter }
return workflowService.findOne(menuItem.stringId)
}
}

private Map<String, I18nString> collectRolesForPreferenceItem(Map<String, String> roles) {
Map<String, PetriNet> temp = [:]
return roles.collectEntries { entry ->
if (!temp.containsKey(entry.value)) {
temp.put(entry.value, petriNetService.getNewestVersionByIdentifier(entry.value))
}
PetriNet net = temp[entry.value]
def foundEntry = net.roles.find { it.value.importId == entry.key }
if (!foundEntry) {
throw new IllegalArgumentException("No role $entry.key $net.identifier")
}
ProcessRole role = foundEntry.value
return [(role.importId + ":" + net.identifier), ("$role.name ($net.title)" as String)]
} as Map<String, I18nString>
}

/**
* update menu item property
* @param id
Expand Down Expand Up @@ -101,7 +51,7 @@ class EtaskActionDelegate extends ActionDelegate {
List<PetriNet> nets = uriPaths.collect {
UriNode node = getUri(it) as UriNode
if (!node) return null
return petriNetService.findAllByUri(node.id)
return petriNetService.findAllByUriNodeId(node.id)
}.findAll { it != null }.flatten() as List<PetriNet>
List<String> roleIds = nets.collect { it.roles.keySet() as List }.flatten() as List<String>
setUriNodeDataRoles(uri, roleIds)
Expand All @@ -127,11 +77,11 @@ class EtaskActionDelegate extends ActionDelegate {
*/
void setUriNodeDataFilters(String uri, List<String> menuItemIdentifiers) {
UriNode uriNode = getUri(uri) as UriNode
uriNodeDataRepository.findByUriNodeId(uriNode.getId()).ifPresentOrElse(data -> {
uriNodeDataRepository.findByUriNodeId(uriNode.getStringId()).ifPresentOrElse(data -> {
data.setMenuItemIdentifiers(menuItemIdentifiers)
uriNodeDataRepository.save(data)
}, () -> {
uriNodeDataRepository.save(new UriNodeData(uriNode.getId(), null, null, false, false, null, menuItemIdentifiers))
uriNodeDataRepository.save(new UriNodeData(uriNode.getStringId(), null, null, false, false, null, menuItemIdentifiers))
})
}

Expand All @@ -142,11 +92,11 @@ class EtaskActionDelegate extends ActionDelegate {
*/
void setUriNodeDataRoles(String uri, List<String> roleIds) {
UriNode uriNode = getUri(uri) as UriNode
uriNodeDataRepository.findByUriNodeId(uriNode.getId()).ifPresentOrElse(data -> {
uriNodeDataRepository.findByUriNodeId(uriNode.getStringId()).ifPresentOrElse(data -> {
data.setProcessRolesIds(roleIds as Set)
uriNodeDataRepository.save(data)
}, () -> {
uriNodeDataRepository.save(new UriNodeData(uriNode.getId(), null, null, false, false, roleIds as Set, null))
uriNodeDataRepository.save(new UriNodeData(uriNode.getStringId(), null, null, false, false, roleIds as Set, null))
})
}

Expand All @@ -164,15 +114,15 @@ class EtaskActionDelegate extends ActionDelegate {
UriNode uriNode = getUri(uri) as UriNode
uriNode.setName(title)
uriService.save(uriNode)
uriNodeDataRepository.findByUriNodeId(uriNode.getId()).ifPresentOrElse(data -> {
uriNodeDataRepository.findByUriNodeId(uriNode.getStringId()).ifPresentOrElse(data -> {
data.setIcon(icon)
data.setSection(section)
data.setIconSvg(isSvgIcon)
data.setProcessRolesIds(roleIds as Set)
data.setHidden(isHidden)
uriNodeDataRepository.save(data)
}, () -> {
uriNodeDataRepository.save(new UriNodeData(uriNode.getId(), section, icon, isSvgIcon, isHidden, roleIds as Set, null))
uriNodeDataRepository.save(new UriNodeData(uriNode.getStringId(), section, icon, isSvgIcon, isHidden, roleIds as Set, null))
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public class EtaskUriNode extends UriNode {
protected boolean isHidden = false;

public EtaskUriNode(UriNode node) {
super(node.getId(), node.getUriPath(), node.getName(), node.getParentId(), node.getParent(), node.getChildrenId(), node.getChildren(), node.getLevel(), node.getContentTypes());
super(node.get_id(), node.getUriPath(), node.getName(), node.getParentId(), node.getParent(), node.getChildrenId(), node.getChildren(), node.getLevel(), node.getContentTypes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.netgrif.etask.EtaskActionDelegate;
import com.netgrif.etask.petrinet.service.interfaces.IUriCountService;
import com.netgrif.etask.petrinet.web.requestbodies.UriCountRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -70,34 +69,34 @@ protected Map<String, Integer> countByLegacyQueries(Map<String, String> queries,
List<UriNode> allUri = StreamSupport.stream(uriNodeRepository.findAll().spliterator(), false).collect(Collectors.toList());
allUri.forEach(uriNode -> {
if (uriNode.getLevel() != 0) {
UriNode parent = allUri.stream().filter(uri -> Objects.equals(uri.getId(), uriNode.getParentId())).findFirst().orElse(null);
UriNode parent = allUri.stream().filter(uri -> Objects.equals(uri.getStringId(), uriNode.getParentId())).findFirst().orElse(null);
uriNode.setParent(parent);
}
if (uriNode.getChildrenId() != null && !uriNode.getChildrenId().isEmpty()) {
Set<UriNode> childrens = allUri.stream().filter(uri -> uriNode.getChildrenId().contains(uri.getId())).collect(Collectors.toSet());
Set<UriNode> childrens = allUri.stream().filter(uri -> uriNode.getChildrenId().contains(uri.getStringId())).collect(Collectors.toSet());
uriNode.setChildren(childrens);
}
});

queries.forEach((key, uriId) -> {
UriNode uriNode = allUri.stream().filter(uri -> Objects.equals(uri.getId(), uriId)).findFirst().orElse(null);
UriNode uriNode = allUri.stream().filter(uri -> Objects.equals(uri.getStringId(), uriId)).findFirst().orElse(null);
if (uriNode != null) {
List<CaseSearchRequest> filters = resolveUriTree(uriNode).stream().map(uriIdd -> CaseSearchRequest.builder()
.uriNodeId(uriIdd)
.process(List.of(new CaseSearchRequest.PetriNet(FilterRunner.PREFERRED_FILTER_ITEM_NET_IDENTIFIER)))
.process(List.of(new CaseSearchRequest.PetriNet(FilterRunner.PREFERRED_ITEM_NET_IDENTIFIER)))
.build()).collect(Collectors.toList());
List<Case> filterItems = elasticCaseService.search(filters, user.transformToLoggedUser(), PageRequest.ofSize(10000), locale, false).getContent();
List<Case> filterss = workflowService.findAllById(filterItems.stream()
List<Case> localFilters = workflowService.findAllById(filterItems.stream()
.map(aCase -> (List<String>) aCase.getDataField("filter_case").getValue())
.flatMap(Collection::stream)
.collect(Collectors.toList()));
List<CaseSearchRequest> queres = filterss.stream()
List<CaseSearchRequest> localQueries = localFilters.stream()
.map(aCase -> CaseSearchRequest.builder()
.query((String) aCase.getDataField("filter").getValue())
.build())
.collect(Collectors.toList());

count.put(key, (int) elasticCaseService.count(queres, user.transformToLoggedUser(), locale, false));
count.put(key, (int) elasticCaseService.count(localQueries, user.transformToLoggedUser(), locale, false));
}
});

Expand All @@ -107,7 +106,7 @@ protected Map<String, Integer> countByLegacyQueries(Map<String, String> queries,
private Set<String> resolveUriTree(UriNode uriNode) {
Set<String> uriNodeIdTree = new HashSet<>();
if (uriNode.getLevel() != 0) {
uriNodeIdTree.add(uriNode.getId());
uriNodeIdTree.add(uriNode.getStringId());
}
resolveUriTree(uriNode.getChildren(), uriNodeIdTree);

Expand All @@ -117,8 +116,8 @@ private Set<String> resolveUriTree(UriNode uriNode) {
private void resolveUriTree(Set<UriNode> uriNodes, Set<String> uriNodeIdTree) {
if (uriNodes != null && !uriNodes.isEmpty()) {
uriNodes.forEach(uriNode -> {
if (!uriNodeIdTree.contains(uriNode.getId())) {
uriNodeIdTree.add(uriNode.getId());
if (!uriNodeIdTree.contains(uriNode.getStringId())) {
uriNodeIdTree.add(uriNode.getStringId());
resolveUriTree(uriNode.getChildren(), uriNodeIdTree);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected EtaskUriNode populateDirectRelatives(EtaskUriNode customUriNode) {

protected EtaskUriNode loadUriNode(UriNode node) {
EtaskUriNode customUriNode = new EtaskUriNode(node);
repository.findByUriNodeId(node.getId()).ifPresent(data -> {
repository.findByUriNodeId(node.getStringId()).ifPresent(data -> {
customUriNode.setRoleIds(data.getProcessRolesIds());
customUriNode.setMenuItemIdentifiers(data.getMenuItemIdentifiers());
customUriNode.setIcon(data.getIcon());
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ spring.servlet.multipart.max-request-size=${MAX_UPLOAD_FILE_SIZE:50MB}
spring.data.mongodb.uri=${MONGO_URI:mongodb://localhost:27017}
spring.data.mongodb.database=${DATABASE_NAME:etask}
spring.data.mongodb.drop=false
spring.data.mongodb.runner-ensure-index=true
spring.data.mongodb.auto-index-creation=true

# Elasticsearch
spring.data.elasticsearch.cluster-name=elasticsearch
spring.data.elasticsearch.index.petriNet=${DATABASE_NAME:etask}_petrinet
spring.data.elasticsearch.index.case=${DATABASE_NAME:etask}_case
spring.data.elasticsearch.index.task=${DATABASE_NAME:etask}_task
nae.uri.index=${DATABASE_NAME:etask}_uri
Expand Down
28 changes: 16 additions & 12 deletions src/main/resources/petriNets/configuration_tiles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@
<processEvents>
<event type="upload">
<id>menu_import</id>

<actions phase="pre">
<action>
createOrUpdateMenuItem("general", "general", "Case",
"NOT (processIdentifier:\"filter\" OR processIdentifier:\"import_filters\" OR " +
def body = new com.netgrif.application.engine.workflow.domain.menu.MenuItemBody("/general", "general", "All cases", "settings")
createOrUpdateMenuItemAndFilter(body,"NOT (processIdentifier:\"filter\" OR processIdentifier:\"import_filters\" OR " +
"processIdentifier:\"export_filters\" OR processIdentifier:\"org_group\" OR " +
"processIdentifier:\"impersonation_config\" OR " +
"processIdentifier:\"impersonation_users_select\" OR " +
"processIdentifier:\"preference_filter_item\")",
"folder",
"All cases", [])

createOrUpdateMenuItem("general_system", "general", "Case",
"_exists_:processIdentifier",
"settings",
"All system cases", [])
"Case",
"private",
[""]
)

setUriNodeData("general", "General", null, "folder")
setUriNodeDataFilters("general", ["general"])
setUriNodeData("/general", "General", null, "folder")
setUriNodeDataFilters("/general", ["general"])
</action>
<action>
def body = new com.netgrif.application.engine.workflow.domain.menu.MenuItemBody("/general", "general_system", "All system cases", "settings")
createOrUpdateMenuItemAndFilter(body,"_exists_:processIdentifier",
"Case",
"private",
[""]
)
</action>
</actions>
</event>
Expand Down
Loading
Loading