Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ buildNumber.properties
*.iml
out
gen
/storage/
### Groovy template
# .gitignore created from Groovy contributors in https://github.com/apache/groovy/blob/master/.gitignore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -59,7 +61,7 @@ public void removeExpiredUsers() {
@Scheduled(cron = "0 0 1 * * *")
public void resetExpiredToken() {
log.info("Resetting expired user tokens");
List<User> users = userService.findAllByStateAndExpirationDateBefore(UserState.BLOCKED, LocalDateTime.now(), null);
Page<User> users = userService.findAllByStateAndExpirationDateBefore(UserState.BLOCKED, LocalDateTime.now(), null, Pageable.unpaged());
if (users == null || users.isEmpty()) {
log.info("There are none expired tokens. Everything is awesome.");
return;
Expand All @@ -69,8 +71,8 @@ public void resetExpiredToken() {
user.setToken(null);
user.setExpirationDate(null);
});
users = userService.saveUsers(users.stream().map(u -> (IUser) u).collect(Collectors.toList()));
log.info("Reset " + users.size() + " expired user tokens");
userService.saveUsers(users.stream().map(u -> (IUser) u).collect(Collectors.toList()));
log.info("Reset " + users.getContent().size() + " expired user tokens");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public ResponseEntity<ResponseMessage> assignNegativeRolesToUser(@PathVariable("
@ApiResponse(responseCode = "500", description = "Internal server error")
})
public ResponseEntity<List<Authority>> getAllAuthorities() {
return ResponseEntity.ok(authorityService.findAll());
return ResponseEntity.ok(authorityService.findAll(Pageable.unpaged()).stream().toList());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here may would be good idea to provide pageable property as request param.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree, but currently it is not needed, because authority set will never be large enough. This would need more rework through all repos.

}

@PreAuthorize("@authorizationService.hasAuthority('ADMIN')")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@

import java.util.List;

/**
* Repository interface for managing {@link ElasticPetriNet} entities in Elasticsearch.
* Extends {@link ElasticsearchRepository} to provide CRUD operations and additional query methods.
*/
@Repository
public interface ElasticPetriNetRepository extends ElasticsearchRepository<ElasticPetriNet, String> {

/**
* Finds an {@link ElasticPetriNet} entity by its string ID.
*
* @param stringId the string ID of the {@link ElasticPetriNet} to find
* @return the {@link ElasticPetriNet} entity with the given string ID, or {@code null} if none found
*/
ElasticPetriNet findByStringId(String stringId);

List<ElasticPetriNet> findAllByUriNodeId(String uriNodeId);

/**
* Deletes all {@link ElasticPetriNet} entities with the given string ID.
*
* @param id the string ID of the {@link ElasticPetriNet} entities to delete
*/
void deleteAllByStringId(String id);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package com.netgrif.application.engine.elastic.service;

import com.netgrif.application.engine.objects.elastic.domain.ElasticPetriNet;
import com.netgrif.application.engine.elastic.domain.ElasticPetriNetRepository;
import com.netgrif.application.engine.elastic.service.executors.Executor;
import com.netgrif.application.engine.elastic.service.interfaces.IElasticPetriNetService;
import com.netgrif.application.engine.objects.petrinet.domain.PetriNet;
import com.netgrif.application.engine.petrinet.service.interfaces.IPetriNetService;
import com.netgrif.application.engine.objects.elastic.domain.ElasticPetriNet;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class ElasticPetriNetService implements IElasticPetriNetService {
Expand All @@ -23,19 +16,11 @@ public class ElasticPetriNetService implements IElasticPetriNetService {

private final Executor executors;

private IPetriNetService petriNetService;

public ElasticPetriNetService(ElasticPetriNetRepository repository, Executor executors) {
this.repository = repository;
this.executors = executors;
}

@Lazy
@Autowired
public void setPetriNetService(IPetriNetService petriNetService) {
this.petriNetService = petriNetService;
}

@Override
public void index(ElasticPetriNet net) {
executors.execute(net.getStringId(), () -> {
Expand Down Expand Up @@ -69,24 +54,4 @@ public void remove(String id) {
log.info("[" + id + "]: PetriNet \"" + id + "\" deleted");
});
}

@Override
public String findUriNodeId(PetriNet net) {
if (net == null) {
return null;
}
ElasticPetriNet elasticPetriNet = repository.findByStringId(net.getStringId());
if (elasticPetriNet == null) {
log.warn("[" + net.getStringId() + "] PetriNet with id [" + net.getStringId() + "] is not indexed.");
return null;
}

return elasticPetriNet.getUriNodeId();
}

@Override
public List<PetriNet> findAllByUriNodeId(String uriNodeId) {
List<com.netgrif.application.engine.adapter.spring.elastic.domain.ElasticPetriNet> elasticPetriNets = repository.findAllByUriNodeId(uriNodeId);
return petriNetService.findAllById(elasticPetriNets.stream().map(ElasticPetriNet::getStringId).collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.netgrif.application.engine.elastic.service.interfaces;

import com.netgrif.application.engine.objects.elastic.domain.ElasticPetriNet;
import com.netgrif.application.engine.objects.petrinet.domain.PetriNet;
import org.springframework.scheduling.annotation.Async;

import java.util.List;

public interface IElasticPetriNetService {

@Async
Expand All @@ -14,9 +11,4 @@ public interface IElasticPetriNetService {
void indexNow(ElasticPetriNet net);

void remove(String id);

String findUriNodeId(PetriNet net);

List<PetriNet> findAllByUriNodeId(String uriNodeId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public List<Authority> getAuthorities(List<Case> configs, IUser impersonated) {
return new ArrayList<>();
}
Set<String> authIds = extractSetFromField(configs, "impersonated_authorities");
return authorityService.findAllByIds(new ArrayList<>(authIds)).stream()
return authorityService.findAllByIds(new ArrayList<>(authIds), Pageable.unpaged()).stream()
.filter(configAuth -> impersonated.getAuthorities().stream().anyMatch(userAuth -> userAuth.getStringId().equals(configAuth.getStringId())))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ protected void createRole(Role importRole) {
if (shouldInitializeRole(importRole)) {
role = initRole(importRole);
} else {
role = new ArrayList<>(processRoleService.findAllByImportId(ProcessRole.GLOBAL + importRole.getId())).get(0);
role = processRoleService.findByImportId(ProcessRole.GLOBAL + importRole.getId());
}
role.set_id(new ProcessResourceId(new ObjectId(net.getStringId())));

Expand All @@ -1071,7 +1071,7 @@ protected void createRole(Role importRole) {

protected boolean shouldInitializeRole(Role importRole) {
return importRole.isGlobal() == null || !importRole.isGlobal() ||
(importRole.isGlobal() && processRoleService.findAllByImportId(ProcessRole.GLOBAL + importRole.getId()).isEmpty());
(importRole.isGlobal() && processRoleService.findByImportId(ProcessRole.GLOBAL + importRole.getId()) == null);
}

protected ProcessRole initRole(Role importRole) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.netgrif.application.engine.petrinet.config;

import com.netgrif.application.engine.adapter.spring.petrinet.service.ProcessRoleService;
import com.netgrif.application.engine.adapter.spring.utils.PaginationProperties;
import com.netgrif.application.engine.auth.service.GroupService;
import com.netgrif.application.engine.auth.service.RealmService;
import com.netgrif.application.engine.petrinet.domain.dataset.logic.action.runner.RoleActionsRunner;
import com.netgrif.application.engine.petrinet.domain.repositories.PetriNetRepository;
import com.netgrif.application.engine.petrinet.domain.roles.ProcessRoleRepository;
Expand All @@ -27,7 +29,9 @@ public ProcessRoleService processRoleService(ProcessRoleRepository processRoleRe
@Lazy PetriNetService petriNetService,
@Lazy UserService userService,
ISecurityContextService securityContextService,
@Lazy GroupService groupService
@Lazy GroupService groupService,
@Lazy RealmService realmService,
@Lazy PaginationProperties paginationProperties
) {
return new com.netgrif.application.engine.petrinet.service.ProcessRoleService(
processRoleRepository,
Expand All @@ -37,7 +41,9 @@ public ProcessRoleService processRoleService(ProcessRoleRepository processRoleRe
petriNetService,
userService,
securityContextService,
groupService
groupService,
realmService,
paginationProperties
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,52 @@
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

import java.util.List;

/**
* Repository interface for handling operations on {@link PetriNet} entities.
* Extends {@link MongoRepository} for standard CRUD operations and {@link QuerydslPredicateExecutor}
* to support dynamic queries.
*/
public interface PetriNetRepository extends MongoRepository<PetriNet, String>, QuerydslPredicateExecutor<PetriNet> {

List<PetriNet> findByTitle_DefaultValue(String title);

/**
* Finds a {@link PetriNet} entity by its import identifier.
*
* @param id the import identifier of the desired PetriNet.
* @return the {@link PetriNet} entity matching the given import identifier, or {@code null} if none found.
*/
PetriNet findByImportId(String id);

List<PetriNet> findAllByIdentifier(String identifier);

/**
* Finds a {@link PetriNet} entity by its identifier and version.
*
* @param identifier the unique identifier of the PetriNet.
* @param version the version of the PetriNet.
* @return the {@link PetriNet} entity matching the given identifier and version, or {@code null} if none found.
*/
PetriNet findByIdentifierAndVersion(String identifier, Version version);

/**
* Finds a paginated list of {@link PetriNet} entities by their identifier.
*
* @param identifier the unique identifier of the PetriNet.
* @param pageable the pagination details.
* @return a {@link Page} containing the list of matching {@link PetriNet} entities.
*/
Page<PetriNet> findByIdentifier(String identifier, Pageable pageable);

Page<PetriNet> findByIdentifierIn(List<String> identifier, Pageable pageable);

List<PetriNet> findAllByVersion(Version version);

List<PetriNet> findAllByUriNodeId(String uri);

/**
* Finds a paginated list of {@link PetriNet} entities by their version.
*
* @param version the version of the PetriNet.
* @param pageable the pagination details.
* @return a {@link Page} containing the list of matching {@link PetriNet} entities.
*/
Page<PetriNet> findAllByVersion(Version version, Pageable pageable);

/**
* Deletes a {@link PetriNet} entity by its unique object ID.
*
* @param id the unique ID of the PetriNet to delete.
*/
void deleteBy_id(ObjectId id);
}
}
Loading
Loading