Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dataset fields conflict with pir sys field caused publish service failure #108

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -92,6 +92,9 @@ public void setServiceAuthInfos(List<ServiceAuthInfo> serviceAuthInfos) {
}

public void appendServiceAuthInfo(ServiceAuthInfo serviceAuthInfo) {
if (this.serviceAuthInfos.contains(serviceAuthInfo)) {
return;
}
this.serviceAuthInfos.add(serviceAuthInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,20 @@ public List<PublishedServiceInfo> query(
serviceAuthCondition.setAccessKeyId(accessKeyID);
// query the auth info
List<ServiceAuthInfo> serviceAuthInfos =
this.serviceAuthMapper.queryServiceAuth(null, selectedServiceList);
new ArrayList<>(
this.serviceAuthMapper.queryServiceAuth(
serviceAuthCondition, selectedServiceList));
// query all recorders for the owner
List<String> publishedServices = new ArrayList<>();
for (PublishedServiceInfo serviceInfo : result) {
if (serviceInfo.getOwner().equals(user) && serviceInfo.getAgency().equals(agency)) {
publishedServices.add(serviceInfo.getServiceId());
}
}
if (!publishedServices.isEmpty()) {
serviceAuthInfos.addAll(
this.serviceAuthMapper.queryServiceAuth(null, publishedServices));
}
// merge the result
for (ServiceAuthInfo serviceAuthInfo : serviceAuthInfos) {
if (publishedServiceInfoMap.containsKey(serviceAuthInfo.getServiceId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.webank.wedpr.common.utils.Constant;
import com.webank.wedpr.common.utils.TimeRange;
import com.webank.wedpr.components.uuid.generator.WeDPRUuidGenerator;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -46,4 +47,17 @@ public ServiceAuthInfo(String id) {
public boolean expired() {
return Common.isDateExpired(Constant.DEFAULT_TIMESTAMP_FORMAT, expireTime);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ServiceAuthInfo)) return false;
ServiceAuthInfo that = (ServiceAuthInfo) o;
return Objects.equals(id, that.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ private void constructFromCSV(Dataset dataset, String idField) throws Exception
Arrays.stream(dataset.getDatasetFields().trim().split(","))
.map(String::trim)
.toArray(String[]::new);

List<String> datasetFieldsList = Arrays.asList(datasetFields);
if (datasetFieldsList.contains(Constant.ID_FIELD_NAME)) {
throw new WeDPRException("Conflict with sys field " + Constant.ID_FIELD_NAME);
}
if (datasetFieldsList.contains(Constant.ID_HASH_FIELD_NAME)) {
throw new WeDPRException("Conflict with sys field " + Constant.ID_HASH_FIELD_NAME);
}
List<List<String>> sqlValues =
CSVFileParser.processCsv2SqlMap(datasetFields, localFilePath);
if (sqlValues.size() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
public class Constant {
public static String PIR_TEMP_TABLE_PREFIX = "wedpr_pir_";

public static final String ID_FIELD_NAME = "id";
public static final String ID_HASH_FIELD_NAME = "id_hash";
public static final String ID_FIELD_NAME = "pir_sys_id";
public static final String ID_HASH_FIELD_NAME = "pir_sys_id_hash";

public static String datasetId2tableId(String datasetId) {
return PIR_TEMP_TABLE_PREFIX + datasetId.substring(2);
Expand Down
Loading