Skip to content

Commit

Permalink
Bugfix: update the column type to adapt to SqlServer (#642)
Browse files Browse the repository at this point in the history
<!-- Please provide brief information about the PR, what it contains &
its purpose, new behaviors after the change. And let us know here if you
need any help: https://github.com/microsoft/HydraLab/issues/new -->

## Description

<!-- A few words to explain your changes -->

### Linked GitHub issue ID: #  

## Pull Request Checklist
<!-- Put an x in the boxes that apply. This is simply a reminder of what
we are going to look for before merging your code. -->

- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Code compiles correctly with all tests are passed.
- [ ] I've read the [contributing
guide](https://github.com/microsoft/HydraLab/blob/main/CONTRIBUTING.md#making-changes-to-the-code)
and followed the recommended practices.
- [ ] [Wikis](https://github.com/microsoft/HydraLab/wiki) or
[README](https://github.com/microsoft/HydraLab/blob/main/README.md) have
been reviewed and added / updated if needed (for bug fixes / features)

### Does this introduce a breaking change?
*If this introduces a breaking change for Hydra Lab users, please
describe the impact and migration path.*

- [x] Yes
- [ ] No

## How you tested it
*Please make sure the change is tested, you can test it by adding UTs,
do local test and share the screenshots, etc.*


Please check the type of change your PR introduces:
- [x] Bugfix
- [ ] Feature
- [ ] Technical design
- [ ] Build related changes
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Code style update (formatting, renaming) or Documentation content
changes
- [ ] Other (please describe): 

### Feature UI screenshots or Technical design diagrams
*If this is a relatively large or complex change, kick it off by drawing
the tech design with PlantUML and explaining why you chose the solution
you did and what alternatives you considered, etc...*
  • Loading branch information
zhou9584 committed Jan 19, 2024
1 parent 280a711 commit 100ca07
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public void initWithAgentUser(AgentUser agentUser) {
agentVersionCode = agentUser.getVersionCode();
functionAvailabilities = agentUser.getFunctionAvailabilities();
for (AgentFunctionAvailability functionAvailability : functionAvailabilities) {
if (AgentFunctionAvailability.AgentFunctionType.ANALYSIS_RUNNER.equals(functionAvailability.getFunctionType()) && functionAvailability.isEnabled() &&
functionAvailability.isAvailable()) {
if (AgentFunctionAvailability.AgentFunctionType.ANALYSIS_RUNNER.equals(functionAvailability.getFunctionType()) && functionAvailability.isEnabled()) {
availableAnalysisTaskCount.put(functionAvailability.getFunctionName(), 3);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

package com.microsoft.hydralab.common.entity.common;

import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import javax.persistence.AttributeConverter;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import java.io.Serializable;
import java.util.HashMap;
Expand All @@ -24,11 +24,10 @@
@Entity
@Data
@EqualsAndHashCode(callSuper = true)
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
public class AnalysisTask extends Task implements Serializable {

@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
@Convert(converter = AnalysisConfig.Converter.class)
@Column(columnDefinition = "text")
private List<AnalysisConfig> analysisConfigs;

public AnalysisTask() {
Expand All @@ -52,6 +51,18 @@ public static class AnalysisConfig implements Serializable {
String analysisType;
String executor;
Map<String, String> analysisConfig = new HashMap<>();

public static class Converter implements AttributeConverter<List<AnalysisConfig>, String> {
@Override
public String convertToDatabaseColumn(List<AnalysisConfig> attribute) {
return JSONObject.toJSONString(attribute);
}

@Override
public List<AnalysisConfig> convertToEntityAttribute(String dbData) {
return JSONObject.parseArray(dbData, AnalysisConfig.class);
}
}
}

public enum AnalysisType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

package com.microsoft.hydralab.common.entity.common;

import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import javax.persistence.AttributeConverter;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
Expand All @@ -25,7 +25,6 @@
*/
@Data
@Entity
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
@Inheritance(strategy = InheritanceType.JOINED)
public class TaskResult implements Serializable {
@Id
Expand All @@ -35,10 +34,21 @@ public class TaskResult implements Serializable {
private String state;
private Date ingestTime;

@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
@Convert(converter = Converter.class)
@Column(columnDefinition = "text")
private List<String> reportFiles = new ArrayList<>();

public static class Converter implements AttributeConverter<List<String>, String> {
@Override
public String convertToDatabaseColumn(List<String> attribute) {
return JSONObject.toJSONString(attribute);
}

@Override
public List<String> convertToEntityAttribute(String dbData) {
return JSONObject.parseArray(dbData, String.class);
}
}

public TaskResult() {
this.id = UUID.randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.microsoft.hydralab.common.entity.common.scanner;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

import javax.persistence.AttributeConverter;
import java.io.Serializable;

@Data
Expand All @@ -11,4 +13,16 @@ public class ApkManifest implements Serializable {
private int versionCode;
private int targetSDKVersion;
private int minSDKVersion;

public static class Converter implements AttributeConverter<ApkManifest, String> {
@Override
public String convertToDatabaseColumn(ApkManifest attribute) {
return JSONObject.toJSONString(attribute);
}

@Override
public ApkManifest convertToEntityAttribute(String dbData) {
return JSONObject.parseObject(dbData, ApkManifest.class);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.microsoft.hydralab.common.entity.common.scanner;

import com.microsoft.hydralab.common.entity.common.TaskResult;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import java.io.Serializable;
import java.util.ArrayList;
Expand All @@ -16,21 +14,21 @@
@Data
@Entity
@EqualsAndHashCode(callSuper=true)
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
public class ApkReport extends TaskResult implements Serializable {
private String packageName;
private String buildFlavor;
@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")

@Convert(converter = ApkSizeReport.Converter.class)
@Column(columnDefinition = "text")
private ApkSizeReport apkSizeReport = new ApkSizeReport();
@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
@Convert(converter = ApkManifest.Converter.class)
@Column(columnDefinition = "text")
private ApkManifest apkManifest = new ApkManifest();
@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
@Convert(converter = BuildInfo.Converter.class)
@Column(columnDefinition = "text")
private BuildInfo buildInfo = new BuildInfo();
@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
@Convert(converter = LeakInfo.Converter.class)
@Column(columnDefinition = "text")
private List<LeakInfo> leakInfoList = new ArrayList<>();

public ApkReport(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.microsoft.hydralab.common.entity.common.scanner;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

import javax.persistence.AttributeConverter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -33,4 +35,16 @@ public static class FileItem implements Serializable {
public long size;
public String fileName;
}

public static class Converter implements AttributeConverter<ApkSizeReport, String> {
@Override
public String convertToDatabaseColumn(ApkSizeReport attribute) {
return JSONObject.toJSONString(attribute);
}

@Override
public ApkSizeReport convertToEntityAttribute(String dbData) {
return JSONObject.parseObject(dbData, ApkSizeReport.class);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.microsoft.hydralab.common.entity.common.scanner;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

import javax.persistence.AttributeConverter;
import java.io.Serializable;

@Data
Expand All @@ -10,4 +12,16 @@ public class BuildInfo implements Serializable {
private String buildFlavor;
private String buildType;
private int commitIndex;

public static class Converter implements AttributeConverter<BuildInfo, String> {
@Override
public String convertToDatabaseColumn(BuildInfo attribute) {
return JSONObject.toJSONString(attribute);
}

@Override
public BuildInfo convertToEntityAttribute(String dbData) {
return JSONObject.parseObject(dbData, BuildInfo.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

package com.microsoft.hydralab.common.entity.common.scanner;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

import javax.persistence.AttributeConverter;
import java.io.Serializable;
import java.util.List;

Expand All @@ -24,4 +26,16 @@ public LeakInfo(String keyword, List<String> LeakWordList) {
this.keyword = keyword;
this.LeakWordList = LeakWordList;
}

public static class Converter implements AttributeConverter<List<LeakInfo>, String> {
@Override
public String convertToDatabaseColumn(List<LeakInfo> attribute) {
return JSONObject.toJSONString(attribute);
}

@Override
public List<LeakInfo> convertToEntityAttribute(String dbData) {
return JSONObject.parseArray(dbData, LeakInfo.class);
}
}
}

0 comments on commit 100ca07

Please sign in to comment.