Resolve "Определять классы, содержащие бизнес-логику" #46

Merged
romanov73 merged 1 commits from 20-detect-bl into master 2021-04-19 13:47:07 +04:00
6 changed files with 45 additions and 0 deletions
Showing only changes of commit 37839920c0 - Show all commits

View File

@ -45,6 +45,8 @@ public abstract class StructuralUnitIdentifier {
public abstract boolean isEntityClass(String sourceCode); public abstract boolean isEntityClass(String sourceCode);
public abstract boolean isBusinessLogicClass(String sourceCode);
protected abstract boolean isBusinessLogicClass(File file); protected abstract boolean isBusinessLogicClass(File file);
public abstract List<BusinessLogicUnit> getBusinessLogicClasses(String projectPath, String subDirectory, List<File> projectFiles); public abstract List<BusinessLogicUnit> getBusinessLogicClasses(String projectPath, String subDirectory, List<File> projectFiles);

View File

@ -126,6 +126,16 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
return false; return false;
} }
@Override
public boolean isBusinessLogicClass(String sourceCode) {
try {
return classContainsAnnotation(sourceCode, SERVICE_ANNOTATION);
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
private boolean classContainsAnnotation(File file, String annotationDeclaration) throws IOException { private boolean classContainsAnnotation(File file, String annotationDeclaration) throws IOException {
return classContainsAnnotation(new String(Files.readAllBytes(file.toPath())), annotationDeclaration); return classContainsAnnotation(new String(Files.readAllBytes(file.toPath())), annotationDeclaration);
} }

View File

@ -70,4 +70,11 @@ public class StructuralUnitService {
.filter(predicate) .filter(predicate)
.findAny(); .findAny();
} }
public boolean containsBusinessLogic(String sourceCode) {
return getStructuralUnitIdentifier(
structuralUnitIdentifier -> structuralUnitIdentifier.canAppliedToCode(sourceCode))
.map(identifier -> identifier.isBusinessLogicClass(sourceCode))
.orElse(false);
}
} }

View File

@ -27,6 +27,8 @@ public class FileChange extends BaseEntity {
private Boolean containsEntity; private Boolean containsEntity;
private Boolean containsBusinessLogic;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "file_change_id", unique = true) @JoinColumn(name = "file_change_id", unique = true)
@Fetch(FetchMode.SUBSELECT) @Fetch(FetchMode.SUBSELECT)
@ -86,4 +88,20 @@ public class FileChange extends BaseEntity {
public void setContainsEntity(boolean containsEntity) { public void setContainsEntity(boolean containsEntity) {
this.containsEntity = containsEntity; this.containsEntity = containsEntity;
} }
public Boolean getContainsEntity() {
return containsEntity;
}
public void setContainsEntity(Boolean containsEntity) {
this.containsEntity = containsEntity;
}
public Boolean getContainsBusinessLogic() {
return containsBusinessLogic;
}
public void setContainsBusinessLogic(Boolean containsBusinessLogic) {
this.containsBusinessLogic = containsBusinessLogic;
}
} }

View File

@ -206,6 +206,9 @@ public class GitRepositoryService {
fileChange.setContainsEntity( fileChange.setContainsEntity(
structuralUnitService.containsEntity(getContent(repository, commit, maybeFileName.get())) structuralUnitService.containsEntity(getContent(repository, commit, maybeFileName.get()))
); );
fileChange.setContainsBusinessLogic(
structuralUnitService.containsBusinessLogic(getContent(repository, commit, maybeFileName.get()))
);
/// вытащить другие изменения из коммита /// вытащить другие изменения из коммита
changes.add(fileChange); changes.add(fileChange);
} }

View File

@ -12,4 +12,9 @@
<column name="contains_entity" type="boolean"/> <column name="contains_entity" type="boolean"/>
</addColumn> </addColumn>
</changeSet> </changeSet>
<changeSet author="orion" id="20210419-100000-1">
<addColumn tableName="file_change">
<column name="contains_business_logic" type="boolean"/>
</addColumn>
</changeSet>
</databaseChangeLog> </databaseChangeLog>