Skip to content

Commit

Permalink
【fix】数据查询遗漏判断iportaldata是否发布服务, 不支持未发布服务的数据; review by songym
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiaojiao committed Nov 20, 2024
1 parent 3aefe29 commit ecabd56
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/common/_utils/get-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default function getFeatures(dataset) {
orderBy,
returnFeaturesOnly,
bounds,
keyWord
keyWord,
onlyService
} = dataset;
if (dataset && (url || geoJSON) && type) {
let queryInfo = {
Expand Down Expand Up @@ -62,6 +63,9 @@ export default function getFeatures(dataset) {
params = [datasetInfo, queryInfo];
} else if (type === 'iPortal') {
queryInfo.withCredentials = withCredentials;
if (onlyService !== undefined) {
queryInfo.onlyService = onlyService;
}
superMapService = new iPortalDataService(url, withCredentials, {
epsgCode,
resourceId: dataset.id,
Expand Down
15 changes: 13 additions & 2 deletions src/common/_utils/iPortalDataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FetchRequest, Util } from 'vue-iclient/static/libs/iclient-common/iclie
import iServerRestService, { vertifyEpsgCode, transformFeatures } from 'vue-iclient/src/common/_utils/iServerRestService';
import { isXField, isYField, handleWithCredentials, handleDataParentRes } from 'vue-iclient/src/common/_utils/util';
import { Events } from 'vue-iclient/src/common/_types/event/Events';
import { geti18n } from 'vue-iclient/src/common/_lang/index';

/**
* @class iPortalDataService
Expand Down Expand Up @@ -78,10 +79,12 @@ export default class iPortalDataService extends Events {
}
let datasetUrl = this.url;

if (preferContent) {
const onlyService = queryInfo.onlyService;
if (preferContent && !onlyService) {
this._getDatafromContent(datasetUrl, queryInfo);
return;
}
delete queryInfo.onlyService;
FetchRequest.get(datasetUrl, null, {
withCredentials: this.withCredentials
})
Expand All @@ -100,8 +103,16 @@ export default class iPortalDataService extends Events {
this._getStructureDatafromContent();
return;
}
const hasService = data.dataItemServices && data.dataItemServices.length > 0;
if (onlyService && !hasService) {
this.triggerEvent('getdatafailed', {
error: { message: geti18n().t('query.seviceNotSupport') },
onlyService
});
return;
}
// 是否有rest服务
if (data.dataItemServices && data.dataItemServices.length > 0) {
if (hasService) {
let dataItemServices = data.dataItemServices;
let resultData = dataItemServices.find(
item =>
Expand Down
6 changes: 5 additions & 1 deletion src/mapboxgl/query/QueryViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export default class QueryViewModel extends mapboxgl.Evented {
keyWord: queryParameter.queryMode === 'KEYWORD' ? queryParameter.attributeFilter : '',
bounds: this.bounds
};
if (queryParameter.type === 'iPortal') {
queryOptions.onlyService = true;
}
const res = await getFeatures({ ...queryParameter, ...queryOptions });
if (res.type === 'featureisempty') {
this.fire('queryfailed', { message: geti18n().t('query.noResults') });
Expand All @@ -90,7 +93,8 @@ export default class QueryViewModel extends mapboxgl.Evented {
this._addResultLayer(this.queryResult);
this.fire('querysucceeded', { result: this.queryResult, layers: [this.layerID, this.strokeLayerID].filter(item => !!item) });
} catch (error) {
this.fire('queryfailed', { message: geti18n().t('query.queryFailed') });
const message = error.onlyService ? geti18n().t('query.seviceNotSupport') : geti18n().t('query.queryFailed');
this.fire('queryfailed', { message });
}
}
}
Expand Down
47 changes: 47 additions & 0 deletions src/mapboxgl/query/__tests__/Query.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ describe('query', () => {
if (url.indexOf('/123') > -1) {
return Promise.resolve(new Response(JSON.stringify(datas)));
}
if (url.indexOf('/1763883342') > -1) {
return Promise.resolve(new Response(JSON.stringify({ ...datas, dataItemServices: [] })));
}
if (url.includes('/content')) {
return Promise.resolve(new Response(JSON.stringify(iportal_content)));
}
Expand Down Expand Up @@ -103,6 +106,50 @@ describe('query', () => {
});
});

it('iPortal unpublished Data', async done => {
wrapper = mount(SmQuery, {
localVue,
propsData: {
mapTarget: 'map',
iportalData: [
{
name: '四川省电站发电-四川发电站上月发电量',
displayName: '分段&-四川省电站发电-四川发电站上月发电量',
mapTarget: 'map_1731901870198',
type: 'iPortal',
id: '1763883342',
url: 'http://lcoalhost:8190/iportal/web/datas/1763883342',
dataType: 'GEOJSON',
updateTime: '2024-10-25 11:38:12',
serviceStatus: 'PUBLISHED',
dataItemServices: null,
withCredentials: false,
preferContent: true,
maxFeatures: 8,
queryMode: 'SQL',
fields: [],
attributeFilter: 'SmID>0'
}
]
}
});
await mapSubComponentLoaded(wrapper);
expect(wrapper.vm.mapTarget).toBe('map');
const queryErrorTip = jest.spyOn(Message, 'warning');
wrapper.vm.$on('query-failed', (e) => {
expect(queryErrorTip).toHaveBeenCalledTimes(1);
expect(queryErrorTip).toHaveBeenCalledWith(e.message);
expect(e.message).toBe('query.seviceNotSupport');
expect(wrapper.vm.isQuery).toBe(false);
expect(wrapper.vm.activeTab).toBe('job');
expect(wrapper.vm.activeResultIndexList).toEqual([]);
expect(wrapper.vm.queryResult).toBeNull();
expect(wrapper.vm.activeQueryJob).toBeNull();
done();
})
wrapper.find(SmButton).find('.sm-component-query__a-button').trigger('click');
});

it('restData Service', async done => {
wrapper = mount(SmQuery, {
localVue,
Expand Down

0 comments on commit ecabd56

Please sign in to comment.