#20 -- Get business logic classes
This commit is contained in:
parent
b25a1dbab9
commit
9fcc14ae6f
@ -7,7 +7,8 @@ package ru.ulstu.extractor.heuristic.api;
|
|||||||
|
|
||||||
import ru.ulstu.extractor.heuristic.component.BuildTool;
|
import ru.ulstu.extractor.heuristic.component.BuildTool;
|
||||||
import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage;
|
import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage;
|
||||||
import ru.ulstu.extractor.heuristic.model.StructuralUnit;
|
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
||||||
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
||||||
import ru.ulstu.extractor.heuristic.service.DetectorService;
|
import ru.ulstu.extractor.heuristic.service.DetectorService;
|
||||||
import ru.ulstu.extractor.heuristic.service.ProgrammingLanguageService;
|
import ru.ulstu.extractor.heuristic.service.ProgrammingLanguageService;
|
||||||
import ru.ulstu.extractor.util.StringUtils;
|
import ru.ulstu.extractor.util.StringUtils;
|
||||||
@ -24,11 +25,16 @@ import static ru.ulstu.extractor.heuristic.service.DetectorService.LangDetectScr
|
|||||||
import static ru.ulstu.extractor.heuristic.service.DetectorService.LangDetectScrupulousness.LOW;
|
import static ru.ulstu.extractor.heuristic.service.DetectorService.LangDetectScrupulousness.LOW;
|
||||||
|
|
||||||
public abstract class StructuralUnitIdentifier {
|
public abstract class StructuralUnitIdentifier {
|
||||||
public List<StructuralUnit> getEntityClasses(String projectPath, List<File> projectFiles, List<File> rootProjectFiles) {
|
public List<EntityUnit> getEntityClasses(String projectPath, List<File> projectFiles, List<File> rootProjectFiles) {
|
||||||
String subDirectory = getSourceDirectory(rootProjectFiles);
|
String subDirectory = getSourceDirectory(rootProjectFiles);
|
||||||
return getEntityClasses(projectPath, subDirectory, projectFiles);
|
return getEntityClasses(projectPath, subDirectory, projectFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<BusinessLogicUnit> getBusinessLogicClasses(String projectPath, List<File> projectFiles, List<File> rootProjectFiles) {
|
||||||
|
String subDirectory = getSourceDirectory(rootProjectFiles);
|
||||||
|
return getBusinessLogicClasses(projectPath, subDirectory, projectFiles);
|
||||||
|
}
|
||||||
|
|
||||||
public abstract boolean canAppliedToCode(String sourceCode);
|
public abstract boolean canAppliedToCode(String sourceCode);
|
||||||
|
|
||||||
public abstract boolean canAppliedToFile(File projectFile);
|
public abstract boolean canAppliedToFile(File projectFile);
|
||||||
@ -41,13 +47,13 @@ public abstract class StructuralUnitIdentifier {
|
|||||||
|
|
||||||
protected abstract boolean isBusinessLogicClass(File file);
|
protected abstract boolean isBusinessLogicClass(File file);
|
||||||
|
|
||||||
public abstract List<StructuralUnit> getBusinessLogicClasses();
|
public abstract List<BusinessLogicUnit> getBusinessLogicClasses(String projectPath, String subDirectory, List<File> projectFiles);
|
||||||
|
|
||||||
public abstract boolean isMultiModuleProject();
|
public abstract boolean isMultiModuleProject();
|
||||||
|
|
||||||
public abstract Optional<BuildTool> getBuildTool(List<File> rootDirectoryFiles);
|
public abstract Optional<BuildTool> getBuildTool(List<File> rootDirectoryFiles);
|
||||||
|
|
||||||
protected abstract List<StructuralUnit> getEntityClasses(String projectPath, String subDirectory, List<File> projectFiles);
|
protected abstract List<EntityUnit> getEntityClasses(String projectPath, String subDirectory, List<File> projectFiles);
|
||||||
|
|
||||||
protected abstract String getSourceDirectory(List<File> rootProjectFiles);
|
protected abstract String getSourceDirectory(List<File> rootProjectFiles);
|
||||||
|
|
||||||
|
@ -8,7 +8,8 @@ package ru.ulstu.extractor.heuristic.controller;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import ru.ulstu.extractor.heuristic.model.StructuralUnit;
|
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
||||||
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
||||||
import ru.ulstu.extractor.heuristic.service.StructuralUnitService;
|
import ru.ulstu.extractor.heuristic.service.StructuralUnitService;
|
||||||
import ru.ulstu.extractor.service.GitRepositoryService;
|
import ru.ulstu.extractor.service.GitRepositoryService;
|
||||||
|
|
||||||
@ -29,8 +30,14 @@ public class StructuralUnitController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("get-entities")
|
@GetMapping("get-entities")
|
||||||
public List<StructuralUnit> getEntities(String repositoryUrl) throws IOException {
|
public List<EntityUnit> getEntities(String repositoryUrl) throws IOException {
|
||||||
File rootPath = gitRepositoryService.getProjectDirectoryFile(repositoryUrl);
|
File rootPath = gitRepositoryService.getProjectDirectoryFile(repositoryUrl);
|
||||||
return structuralUnitService.getEntities(rootPath);
|
return structuralUnitService.getEntities(rootPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("get-business-logic")
|
||||||
|
public List<BusinessLogicUnit> getBusinessLogic(String repositoryUrl) throws IOException {
|
||||||
|
File rootPath = gitRepositoryService.getProjectDirectoryFile(repositoryUrl);
|
||||||
|
return structuralUnitService.getBusinessLogic(rootPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
|
||||||
|
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ru.ulstu.extractor.heuristic.model;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class BusinessLogicUnit extends StructuralUnit {
|
||||||
|
|
||||||
|
public BusinessLogicUnit(String projectPath, File file) {
|
||||||
|
super(projectPath, file);
|
||||||
|
}
|
||||||
|
}
|
@ -13,8 +13,8 @@ import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier;
|
|||||||
import ru.ulstu.extractor.heuristic.component.BuildTool;
|
import ru.ulstu.extractor.heuristic.component.BuildTool;
|
||||||
import ru.ulstu.extractor.heuristic.component.JavaProgrammingLanguage;
|
import ru.ulstu.extractor.heuristic.component.JavaProgrammingLanguage;
|
||||||
import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage;
|
import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage;
|
||||||
|
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
||||||
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
||||||
import ru.ulstu.extractor.heuristic.model.StructuralUnit;
|
|
||||||
import ru.ulstu.extractor.util.StringUtils;
|
import ru.ulstu.extractor.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -29,6 +29,7 @@ import static ru.ulstu.extractor.heuristic.service.DetectorService.LangDetectScr
|
|||||||
@Service
|
@Service
|
||||||
public class JavaIdentifier extends StructuralUnitIdentifier {
|
public class JavaIdentifier extends StructuralUnitIdentifier {
|
||||||
private static final String ENTITY_ANNOTATION = "@Entity";
|
private static final String ENTITY_ANNOTATION = "@Entity";
|
||||||
|
private static final String SERVICE_ANNOTATION = "@Service";
|
||||||
private final DetectorService detectorService;
|
private final DetectorService detectorService;
|
||||||
private final BuildToolService buildToolService;
|
private final BuildToolService buildToolService;
|
||||||
private final ProgrammingLanguageService programmingLanguageService;
|
private final ProgrammingLanguageService programmingLanguageService;
|
||||||
@ -56,7 +57,7 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<StructuralUnit> getEntityClasses(String projectPath, String subDirectory, List<File> projectFiles) {
|
public List<EntityUnit> getEntityClasses(String projectPath, String subDirectory, List<File> projectFiles) {
|
||||||
return projectFiles.stream()
|
return projectFiles.stream()
|
||||||
.filter(file -> StringUtils.fileInSubdirectory(file.getPath(), projectPath, subDirectory))
|
.filter(file -> StringUtils.fileInSubdirectory(file.getPath(), projectPath, subDirectory))
|
||||||
.filter(this::isEntityClass)
|
.filter(this::isEntityClass)
|
||||||
@ -64,15 +65,14 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Optional<ProgrammingLanguage> getMainProgrammingLanguage(String sourceCode) {
|
|
||||||
return sourceCodeContainsClass(sourceCode)
|
|
||||||
? Optional.of(getProgrammingLanguage())
|
|
||||||
: Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<StructuralUnit> getBusinessLogicClasses() {
|
public List<BusinessLogicUnit> getBusinessLogicClasses(String projectPath, String subDirectory, List<File> projectFiles) {
|
||||||
return null;
|
return projectFiles.stream()
|
||||||
|
.filter(file -> StringUtils.fileInSubdirectory(file.getPath(), projectPath, subDirectory))
|
||||||
|
.filter(this::isBusinessLogicClass)
|
||||||
|
.map(file -> new BusinessLogicUnit(projectPath, file))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -85,6 +85,12 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
|||||||
return buildToolService.getProjectBuildTool(rootDirectoryFiles);
|
return buildToolService.getProjectBuildTool(rootDirectoryFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Optional<ProgrammingLanguage> getMainProgrammingLanguage(String sourceCode) {
|
||||||
|
return sourceCodeContainsClass(sourceCode)
|
||||||
|
? Optional.of(getProgrammingLanguage())
|
||||||
|
: Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DetectorService getDetectorService() {
|
protected DetectorService getDetectorService() {
|
||||||
return detectorService;
|
return detectorService;
|
||||||
@ -152,6 +158,11 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isBusinessLogicClass(File file) {
|
protected boolean isBusinessLogicClass(File file) {
|
||||||
|
try {
|
||||||
|
return file.getName().endsWith("java") && classContainsAnnotation(file, SERVICE_ANNOTATION);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,8 @@ package ru.ulstu.extractor.heuristic.service;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier;
|
import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier;
|
||||||
import ru.ulstu.extractor.heuristic.model.StructuralUnit;
|
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
||||||
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -26,7 +27,7 @@ public class StructuralUnitService {
|
|||||||
this.structuralUnitIdentifiers = structuralUnitIdentifiers;
|
this.structuralUnitIdentifiers = structuralUnitIdentifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StructuralUnit> getEntities(File rootPath) throws IOException {
|
public List<EntityUnit> getEntities(File rootPath) throws IOException {
|
||||||
List<File> projectFiles = directoryService.getFilesRecursively(rootPath);
|
List<File> projectFiles = directoryService.getFilesRecursively(rootPath);
|
||||||
List<File> rootProjectFiles = directoryService.getDirectoryFiles(rootPath.toPath());
|
List<File> rootProjectFiles = directoryService.getDirectoryFiles(rootPath.toPath());
|
||||||
return getStructuralUnitIdentifier(
|
return getStructuralUnitIdentifier(
|
||||||
@ -38,6 +39,18 @@ public class StructuralUnitService {
|
|||||||
.getEntityClasses(rootPath.getPath(), projectFiles, rootProjectFiles);
|
.getEntityClasses(rootPath.getPath(), projectFiles, rootProjectFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<BusinessLogicUnit> getBusinessLogic(File rootPath) throws IOException {
|
||||||
|
List<File> projectFiles = directoryService.getFilesRecursively(rootPath);
|
||||||
|
List<File> rootProjectFiles = directoryService.getDirectoryFiles(rootPath.toPath());
|
||||||
|
return getStructuralUnitIdentifier(
|
||||||
|
structuralUnitIdentifier -> structuralUnitIdentifier.canAppliedToProject(
|
||||||
|
rootPath.getPath(),
|
||||||
|
projectFiles,
|
||||||
|
rootProjectFiles))
|
||||||
|
.orElseThrow(() -> new RuntimeException("Identifier not found"))
|
||||||
|
.getBusinessLogicClasses(rootPath.getPath(), projectFiles, rootProjectFiles);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean containsEntity(File projectFile) {
|
public boolean containsEntity(File projectFile) {
|
||||||
return getStructuralUnitIdentifier(
|
return getStructuralUnitIdentifier(
|
||||||
structuralUnitIdentifier -> structuralUnitIdentifier.canAppliedToFile(projectFile))
|
structuralUnitIdentifier -> structuralUnitIdentifier.canAppliedToFile(projectFile))
|
||||||
|
Loading…
Reference in New Issue
Block a user