mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-8025] Add new service and API for predictions (#9714)
* [ACS-8025] Add new service and API for predictions * [ACS-8025] Fix update type
This commit is contained in:
18
lib/content-services/src/lib/prediction/index.ts
Normal file
18
lib/content-services/src/lib/prediction/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './public-api';
|
18
lib/content-services/src/lib/prediction/public-api.ts
Normal file
18
lib/content-services/src/lib/prediction/public-api.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './services';
|
18
lib/content-services/src/lib/prediction/services/index.ts
Normal file
18
lib/content-services/src/lib/prediction/services/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './prediction.service';
|
@@ -0,0 +1,47 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PredictionService } from './prediction.service';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||
import { Prediction, PredictionEntry, PredictionPaging, PredictionPagingList } from '@alfresco/js-api';
|
||||
|
||||
describe('PredictionService', () => {
|
||||
let service: PredictionService;
|
||||
|
||||
const mockPredictionPaging = (): PredictionPaging => {
|
||||
const prediction = new Prediction();
|
||||
prediction.id = 'test id';
|
||||
const predictionEntry = new PredictionEntry({ entry: prediction });
|
||||
const predictionPagingList = new PredictionPagingList({ entries: [predictionEntry] });
|
||||
return new PredictionPaging({ list: predictionPagingList });
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ContentTestingModule]
|
||||
});
|
||||
service = TestBed.inject(PredictionService);
|
||||
});
|
||||
|
||||
it('should call getPredictions on PredictionsApi with nodeId', () => {
|
||||
spyOn(service.predictionsApi, 'getPredictions').and.returnValue(Promise.resolve(mockPredictionPaging()));
|
||||
|
||||
service.getPredictions('test id');
|
||||
expect(service.predictionsApi.getPredictions).toHaveBeenCalledWith('test id');
|
||||
});
|
||||
});
|
@@ -0,0 +1,43 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AlfrescoApiService } from '@alfresco/adf-core';
|
||||
import { PredictionsApi, PredictionPaging } from '@alfresco/js-api';
|
||||
import { from, Observable } from 'rxjs';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PredictionService {
|
||||
private _predictionsApi: PredictionsApi;
|
||||
|
||||
get predictionsApi(): PredictionsApi {
|
||||
this._predictionsApi = this._predictionsApi ?? new PredictionsApi(this.apiService.getInstance());
|
||||
return this._predictionsApi;
|
||||
}
|
||||
|
||||
constructor(private apiService: AlfrescoApiService) {}
|
||||
|
||||
/**
|
||||
* Get predictions for a given node
|
||||
*
|
||||
* @param nodeId The identifier of node.
|
||||
* @returns Observable<PredictionPaging>
|
||||
*/
|
||||
getPredictions(nodeId: string): Observable<PredictionPaging> {
|
||||
return from(this.predictionsApi.getPredictions(nodeId));
|
||||
}
|
||||
}
|
@@ -44,5 +44,6 @@ export * from './lib/category/index';
|
||||
export * from './lib/viewer/index';
|
||||
export * from './lib/security/index';
|
||||
export * from './lib/infinite-scroll-datasource';
|
||||
export * from './lib/prediction/index';
|
||||
|
||||
export * from './lib/content.module';
|
||||
|
Reference in New Issue
Block a user