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
13 changes: 13 additions & 0 deletions backend/src/main/java/ai/giskard/service/CallableService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ai.giskard.web.dto.TestFunctionArgumentDTO;
import ai.giskard.web.dto.mapper.GiskardMapper;
import lombok.RequiredArgsConstructor;
import org.apache.logging.log4j.util.Strings;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
Expand Down Expand Up @@ -83,4 +84,16 @@ protected E update(E existing, D dto) {

return existing;
}

protected void initializeCallable(E callable) {
if (callable.getArgs() != null) {
callable.getArgs().forEach(arg -> arg.setFunction(callable));
}

if (Strings.isBlank(callable.getDisplayName())) {
callable.setDisplayName(callable.getModule() + "." + callable.getName());
}

callable.setVersion(callableRepository.countByDisplayName(callable.getDisplayName()) + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import ai.giskard.web.dto.SlicingFunctionDTO;
import ai.giskard.web.dto.mapper.GiskardMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -43,16 +42,7 @@ public SlicingFunctionDTO save(SlicingFunctionDTO slicingFunction) {
protected SlicingFunction create(SlicingFunctionDTO dto) {
SlicingFunction function = giskardMapper.fromDTO(dto);
function.setProjectKey(dto.getProjectKey());

if (function.getArgs() != null) {
function.getArgs().forEach(arg -> arg.setFunction(function));
}

if (Strings.isBlank(function.getDisplayName())) {
function.setDisplayName(function.getModule() + "." + function.getName());
}

function.setVersion(slicingFunctionRepository.countByDisplayName(function.getDisplayName()) + 1);
initializeCallable(function);
return function;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ai.giskard.repository.ml.TestFunctionRepository;
import ai.giskard.web.dto.TestFunctionDTO;
import ai.giskard.web.dto.mapper.GiskardMapper;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -27,16 +26,7 @@ public TestFunctionDTO save(TestFunctionDTO testFunction) {

protected TestFunction create(TestFunctionDTO dto) {
TestFunction function = giskardMapper.fromDTO(dto);
if (function.getArgs() != null) {
function.getArgs().forEach(arg -> arg.setFunction(function));
}

if (Strings.isBlank(function.getDisplayName())) {
function.setDisplayName(function.getModule() + "." + function.getName());
}

function.setVersion(testFunctionRepository.countByDisplayName(function.getDisplayName()) + 1);

initializeCallable(function);
return function;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ai.giskard.repository.ml.TransformationFunctionRepository;
import ai.giskard.web.dto.TransformationFunctionDTO;
import ai.giskard.web.dto.mapper.GiskardMapper;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -27,16 +26,7 @@ public TransformationFunctionDTO save(TransformationFunctionDTO transformationFu

protected TransformationFunction create(TransformationFunctionDTO dto) {
TransformationFunction function = giskardMapper.fromDTO(dto);
if (function.getArgs() != null) {
function.getArgs().forEach(arg -> arg.setFunction(function));
}

if (Strings.isBlank(function.getDisplayName())) {
function.setDisplayName(function.getModule() + "." + function.getName());
}

function.setVersion(transformationFunctionRepository.countByDisplayName(function.getDisplayName()) + 1);

initializeCallable(function);
return function;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/stores/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface State {

function latestVersions<E extends CallableDTO>(data?: Array<E>): Array<E> {
return chain(data ?? [])
.groupBy(func => func.module ?? `${func.module}.${func.name}`)
.groupBy(func => func.displayName)
.mapValues(functions => chain(functions)
.maxBy(func => func.version ?? 1)
.value())
Expand Down