Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ public class PetriNetService implements IPetriNetService {
private IUriService uriService;

private IElasticPetriNetService elasticPetriNetService;

@Autowired
private TaskService taskService;
@Autowired
private IDataService iDataService;

@Autowired
public void setElasticPetriNetService(IElasticPetriNetService elasticPetriNetService) {
Expand Down Expand Up @@ -458,7 +457,7 @@ public List<PetriNetReference> getReferencesByUsersProcessRoles(LoggedUser user,

@Override
public PetriNetReference getReference(String identifier, Version version, LoggedUser user, Locale locale) {
PetriNet net = version == null ? getNewestVersionByIdentifier(identifier) : getPetriNet(identifier, version);
PetriNet net = version == null ? self.getNewestVersionByIdentifier(identifier) : self.getPetriNet(identifier, version);
return net != null ? transformToReference(net, locale) : new PetriNetReference();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.netgrif.application.engine.petrinet.service.interfaces.IPetriNetService;
import com.netgrif.application.engine.petrinet.service.interfaces.IProcessRoleService;
import com.netgrif.application.engine.petrinet.web.responsebodies.*;
import com.netgrif.application.engine.workflow.domain.FileStorageConfiguration;
import com.netgrif.application.engine.workflow.domain.eventoutcomes.petrinetoutcomes.ImportPetriNetEventOutcome;
import com.netgrif.application.engine.workflow.domain.eventoutcomes.response.EventOutcomeWithMessage;
import com.netgrif.application.engine.workflow.domain.eventoutcomes.response.EventOutcomeWithMessageResource;
Expand Down Expand Up @@ -46,7 +45,6 @@

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
Expand All @@ -66,9 +64,6 @@ public class PetriNetController {

private static final Logger log = LoggerFactory.getLogger(PetriNetController.class);

@Autowired
private FileStorageConfiguration fileStorageConfiguration;

@Autowired
private IPetriNetService service;

Expand All @@ -85,14 +80,10 @@ public class PetriNetController {
private AsyncRunner asyncRunner;

public static String decodeUrl(String s1) {
try {
if (s1 == null)
return null;
return URLDecoder.decode(s1, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
log.error("Decoding URL failed: ", e);
return "";
if (s1 == null) {
return null;
}
return URLDecoder.decode(s1, StandardCharsets.UTF_8);
}

@PreAuthorize("@authorizationService.hasAuthority('ADMIN')")
Expand All @@ -106,8 +97,8 @@ public static String decodeUrl(String s1) {
})
@PostMapping(value = "/import", produces = MediaTypes.HAL_JSON_VALUE)
public EntityModel<EventOutcomeWithMessage> importPetriNet(
@RequestParam(value = "file", required = true) MultipartFile multipartFile,
@RequestParam(value = "uriNodeId", required = true) String uriNodeId,
@RequestParam(value = "file") MultipartFile multipartFile,
@RequestParam(value = "uriNodeId") String uriNodeId,
@RequestParam(value = "meta", required = false) String releaseType,
Authentication auth, Locale locale) throws MissingPetriNetMetaDataException, MissingIconKeyException {
try {
Expand All @@ -129,7 +120,7 @@ public PetriNetReferenceResources getAll(@RequestParam(value = "indentifier", re
return new PetriNetReferenceResources(service.getReferencesByIdentifier(identifier, user, locale));
} else if (identifier == null && version != null) {
return new PetriNetReferenceResources(service.getReferencesByVersion(converter.convert(version), user, locale));
} else if (identifier != null && version != null) {
} else if (identifier != null) {
return new PetriNetReferenceResources(Collections.singletonList(service.getReference(identifier, converter.convert(version), user, locale)));
} else {
return new PetriNetReferenceResources(service.getReferences(user, locale));
Expand All @@ -138,13 +129,13 @@ public PetriNetReferenceResources getAll(@RequestParam(value = "indentifier", re

@Operation(summary = "Get process by id", security = {@SecurityRequirement(name = "BasicAuth")})
@GetMapping(value = "/{id}", produces = MediaTypes.HAL_JSON_VALUE)
public PetriNetReferenceResource getOne(@PathVariable("id") String id, Authentication auth, Locale locale) {
public PetriNetReferenceResource getOne(@PathVariable String id, Locale locale) {
return new PetriNetReferenceResource(IPetriNetService.transformToReference(service.getPetriNet(decodeUrl(id)), locale));
}

@Operation(summary = "Get process by identifier and version", security = {@SecurityRequirement(name = "BasicAuth")})
@GetMapping(value = "/{identifier}/{version}", produces = MediaTypes.HAL_JSON_VALUE)
public PetriNetReferenceResource getOne(@PathVariable("identifier") String identifier, @PathVariable("version") String version, Authentication auth, Locale locale) {
public PetriNetReferenceResource getOne(@PathVariable String identifier, @PathVariable String version, Authentication auth, Locale locale) {
String resolvedIdentifier = Base64.isBase64(identifier) ? new String(Base64.decodeBase64(identifier)) : identifier;
return new PetriNetReferenceResource(service.getReference(resolvedIdentifier, converter.convert(version), (LoggedUser) auth.getPrincipal(), locale));
}
Expand All @@ -164,22 +155,23 @@ public DataFieldReferencesResource getDataFieldReferences(@RequestBody List<Tran

@Operation(summary = "Get roles of process", security = {@SecurityRequirement(name = "BasicAuth")})
@GetMapping(value = "/{netId}/roles", produces = MediaTypes.HAL_JSON_VALUE)
public ProcessRolesResource getRoles(@PathVariable("netId") String netId, Locale locale) {
public ProcessRolesResource getRoles(@PathVariable String netId, Locale locale) {
netId = decodeUrl(netId);
return new ProcessRolesResource(roleService.findAll(netId), service.getPetriNet(decodeUrl(netId)).getPermissions(), netId, locale);
return new ProcessRolesResource(roleService.findAll(netId), service.getPetriNet(netId).getPermissions(), netId, locale);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

@Operation(summary = "Get transactions of process", security = {@SecurityRequirement(name = "BasicAuth")})
@GetMapping(value = "/{netId}/transactions", produces = MediaTypes.HAL_JSON_VALUE)
public TransactionsResource getTransactions(@PathVariable("netId") String netId, Locale locale) {
PetriNet net = service.getPetriNet(decodeUrl(netId));
public TransactionsResource getTransactions(@PathVariable String netId, Locale locale) {
netId = decodeUrl(netId);
PetriNet net = service.getPetriNet(netId);
return new TransactionsResource(net.getTransactions().values(), netId, locale);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

@PreAuthorize("@authorizationService.hasAuthority('ADMIN')")
@Operation(summary = "Download process model", security = {@SecurityRequirement(name = "BasicAuth")})
@GetMapping(value = "/{netId}/file", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public FileSystemResource getNetFile(@PathVariable("netId") String netId, @RequestParam(value = "title", required = false) String title, Authentication auth, HttpServletResponse response) {
public FileSystemResource getNetFile(@PathVariable String netId, @RequestParam(value = "title", required = false) String title, Authentication auth, HttpServletResponse response) {
FileSystemResource fileResource = service.getFile(decodeUrl(netId), decodeUrl(title));
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileResource.getFilename() + Importer.FILE_EXTENSION + "\"");
Expand Down Expand Up @@ -227,7 +219,7 @@ PagedModel<PetriNetReferenceResource> searchElasticPetriNets(@RequestBody PetriN
public MessageResource deletePetriNet(@PathVariable("id") String processId, Authentication auth) {
String decodedProcessId = decodeUrl(processId);
if (Objects.equals(decodedProcessId, "")) {
log.error("Deleting Petri net [" + processId + "] failed: could not decode process ID from URL");
log.error("Deleting Petri net [{}] failed: could not decode process ID from URL", processId);
return MessageResource.errorMessage("Deleting Petri net " + processId + " failed!");
}
LoggedUser user = (LoggedUser) auth.getPrincipal();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.netgrif.application.engine.petrinet.web.responsebodies;


import com.netgrif.application.engine.auth.domain.Author;
import com.netgrif.application.engine.petrinet.domain.DeploymentState;
import com.netgrif.application.engine.petrinet.domain.PetriNet;
import com.netgrif.application.engine.workflow.web.responsebodies.DataFieldReference;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

@Data
@EqualsAndHashCode(callSuper = true)
public class PetriNetReference extends Reference {

private String identifier;
Expand All @@ -22,7 +24,7 @@ public class PetriNetReference extends Reference {
private LocalDateTime createdDate;
private Author author;
private List<DataFieldReference> immediateData;

private DeploymentState deploymentState;

public PetriNetReference() {
super();
Expand All @@ -37,10 +39,7 @@ public PetriNetReference(String stringId, String identifier, String version, Str
}

public PetriNetReference(String stringId, String title, String identifier, String version, String initials, String icon, LocalDateTime createdDate, Author author) {
super(stringId, title);
this.identifier = identifier;
this.version = version;
this.initials = initials;
this(stringId, identifier, version, title, initials, null);
this.icon = icon;
this.createdDate = createdDate;
this.author = author;
Expand All @@ -52,5 +51,6 @@ public PetriNetReference(PetriNet net, Locale locale) {
this.createdDate = net.getCreationDate();
this.author = net.getAuthor();
this.immediateData = net.getImmediateFields().stream().map(field -> new DataFieldReference(field, locale)).collect(Collectors.toList());
this.deploymentState = net.getDeploymentState();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public PetriNetReferenceResource(PetriNetReference content) {

private void buildLinks() {
add(WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder
.methodOn(PetriNetController.class).getOne(getContent().getStringId(), null, null))
.methodOn(PetriNetController.class).getOne(getContent().getStringId(), null))
.withSelfRel());

add(WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder
Expand Down
Loading