Api integration stage 3: Defined apis for application and platform.

feature/appm-store/pbac
Menaka Jayawardena 7 years ago
parent 2b6f9a9e2c
commit 4bbfa33534

@ -22,13 +22,11 @@ import AuthHandler from './authHandler';
import Constants from '../common/constants';
import Helper from './helpers/appMgtApiHelpers';
export default class Endpoint {
/* =================================================================
* Application related apis
/**
* Api definitions related to application management.
* TODO: Work to be done on Application release.
* */
export default class ApplicationMgtApi {
/**
* Api for create an application.
@ -38,19 +36,26 @@ export default class Endpoint {
* From applicationData, the proper application object will be created and send it to the api.
* */
static createApplication(applicationData) {
let app = Helper.buildApplication(applicationData).application;
let {application, images} = Helper.buildApplication(applicationData);
const headers = AuthHandler.createAuthenticationHeaders("application/json");
return Axios.post(Constants.appManagerEndpoints.CREATE_APP, app, {headers: headers});
console.log(application);
console.log(images);
Axios.post(Constants.appManagerEndpoints.CREATE_APP, application, {headers: headers});
}
/**
* Upload the image artifacts (banner, icon, screenshots) related to the application.
* @param appId: The application uuid of the application which the images should be uploaded to.
* @param images: The images object. This contains icon, banner and screenshots.
* */
static uploadImageArtifacts(appId) {
let user = AuthHandler.getUser();
static uploadImageArtifacts(appId, images) {
let formData = new FormData();
formData.append('icon', images.icon);
formData.append('banner', images.banner);
formData.append('screenshot', images.screenshots);
console.log("Image", formData);
const headers = AuthHandler.createAuthenticationHeaders("multipart/form-data");
return Axios.post(Constants.appManagerEndpoints.UPLOAD_IMAGES + appId, appId, {headers: headers});
return Axios.post(Constants.appManagerEndpoints.UPLOAD_IMAGE_ARTIFACTS + appId, formData, {headers: headers});
}
/**
@ -63,8 +68,11 @@ export default class Endpoint {
/**
* Promote the current life cycle state of the application.
* @param appId: The uuid of the application which the state should be updated.
* @param nextState: The next lifecycle state that the application can be updated to.
*
* URL Pattern : /application/1.0/
* */
static updateLifeCycleState(appId) {
static updateLifeCycleState(appId, nextState) {
}
@ -86,9 +94,19 @@ export default class Endpoint {
return Axios.put(Constants.appManagerEndpoints.CREATE_APP, app, {headers: headers});
}
static editApplicationArtofacts(appId) {
static getApplicationArtifacts(appId, artifactName) {
const headers = AuthHandler.createAuthenticationHeaders("image/png");
return Axios.get(Constants.appManagerEndpoints.GET_IMAGE_ARTIFACTS + appId + "?name=" + artifactName,
{headers: headers});
}
static editApplicationArtifacts(appId, images) {
let formData = new FormData();
formData.append('icon', images.icon);
formData.append('banner', images.banner);
formData.append('screenshot', images.screenshots);
const headers = AuthHandler.createAuthenticationHeaders("application/json");
return Axios.put(Constants.appManagerEndpoints.CREATE_APP, appId, {headers: headers});
return Axios.put(Constants.appManagerEndpoints.UPLOAD_IMAGE_ARTIFACTS + appId, formData, {headers: headers});
}
/**
@ -96,8 +114,6 @@ export default class Endpoint {
* @return Object: The response object from the axios post.
* */
static getApplications() {
let user = AuthHandler.getUser();
console.log("Get all applications", user.getAuthToken());
const headers = AuthHandler.createAuthenticationHeaders("application/json");
return Axios.get(Constants.appManagerEndpoints.GET_ALL_APPS, {headers: headers});
}
@ -107,8 +123,6 @@ export default class Endpoint {
* @param appId: The application Id.
* */
static getApplication(appId) {
let user = AuthHandler.getUser();
console.log("Get Application",appId, user.getAuthToken());
const headers = AuthHandler.createAuthenticationHeaders("application/json");
return Axios.get(Constants.appManagerEndpoints.GET_ALL_APPS + appId, {headers: headers});
}
@ -118,59 +132,7 @@ export default class Endpoint {
* @param appId: The id of the application which is to be deleted.
* */
static deleteApplication(appId) {
}
/*
* End of Application management apis.
* =================================================================
* =================================================================
* Platform related apis
* */
/**
* Create a new Platform
* @param platformData: The platform data object.
* */
static createPlatform(platformData) {
const headers = AuthHandler.createAuthenticationHeaders("application/json");
Axios.post(Constants.platformManagerEndpoints.CREATE_PLATFORM, platformData, {headers: headers}).then(
function (response) {
console.log(response);
return Axios.delete(Constants.appManagerEndpoints.GET_ALL_APPS + appId, {headers: headers});
}
).catch(function (err) {
console.log(err);
});
}
/**
* Get available platforms
* */
static getPlatforms() {
const headers = AuthHandler.createAuthenticationHeaders("application/json");
return Axios.get(Constants.platformManagerEndpoints.GET_ENABLED_PLATFORMS, {headers: headers});
}
/**
* Get the user specified platform
* @param platformId: The identifier of the platform
* */
static getPlatform(platformId) {
const headers = AuthHandler.createAuthenticationHeaders("application/json");
return Axios.get(Constants.platformManagerEndpoints.GET_PLATFORM + platformId, {headers: headers});
}
/**
* Delete specified platform
* @param platformId: The id of the platform which is to be deleted.
* */
static deletePlatform(platformId) {
const headers = AuthHandler.createAuthenticationHeaders("application/json");
return Axios.delete(Constants.platformManagerEndpoints.GET_PLATFORM + platformId, {headers: headers});
}
/*
* End of Platform management apis.
* =================================================================
* */
}

@ -0,0 +1,68 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.
*/
'use strict';
import Axios from 'axios';
import AuthHandler from './authHandler';
import Constants from '../common/constants';
/**
* Api definitions for Platform management.
* */
export default class PlatformMgtApi{
/**
* Create a new Platform
* @param platformData: The platform data object.
* */
static createPlatform(platformData) {
const headers = AuthHandler.createAuthenticationHeaders("application/json");
Axios.post(Constants.platformManagerEndpoints.CREATE_PLATFORM, platformData, {headers: headers}).then(
function (response) {
console.log(response);
}
).catch(function (err) {
console.log(err);
});
}
/**
* Get available platforms
* */
static getPlatforms() {
const headers = AuthHandler.createAuthenticationHeaders("application/json");
return Axios.get(Constants.platformManagerEndpoints.GET_ENABLED_PLATFORMS, {headers: headers});
}
/**
* Get the user specified platform
* @param platformId: The identifier of the platform
* */
static getPlatform(platformId) {
const headers = AuthHandler.createAuthenticationHeaders("application/json");
return Axios.get(Constants.platformManagerEndpoints.GET_PLATFORM + platformId, {headers: headers});
}
/**
* Delete specified platform
* @param platformId: The id of the platform which is to be deleted.
* */
static deletePlatform(platformId) {
const headers = AuthHandler.createAuthenticationHeaders("application/json");
return Axios.delete(Constants.platformManagerEndpoints.GET_PLATFORM + platformId, {headers: headers});
}
}

@ -17,6 +17,8 @@
*/
'use strict';
//TODO: Replace the server address with response from auth endpoint and remove hardcoded ids etc.
export default class Constants {
static scopes = 'perm:application:get perm:application:create perm:application:update perm:application-mgt:login' +
@ -25,7 +27,8 @@ export default class Constants {
static appManagerEndpoints = {
GET_ALL_APPS: 'https://localhost:8243/api/application-mgt/v1.0/applications/1.0.0/',
CREATE_APP: 'https://localhost:8243/api/application-mgt/v1.0/applications/1.0.0/',
UPLOAD_IMAGES: '/api/application-mgt/v1.0/applications/1.0.0/upload-artifacts/', //+appId
UPLOAD_IMAGE_ARTIFACTS: 'https://localhost:8243/api/application-mgt/v1.0/applications/1.0.0/upload-image-artifacts/', //+appId
GET_IMAGE_ARTIFACTS: "https://localhost:8243/api/application-mgt/v1.0/applications/1.0.0/image-artifacts/"
};
static platformManagerEndpoints = {

@ -18,7 +18,7 @@
import React, {Component} from 'react';
import Dialog from 'material-ui/Dialog';
import Endpoint from '../../api/endpoints';
import ApplicationMgtApi from '../../api/applicationMgtApi';
import {withRouter} from 'react-router-dom';
import FlatButton from 'material-ui/FlatButton';
import {Step1, Step2, Step3} from './CreateSteps';
@ -83,10 +83,8 @@ class ApplicationCreate extends Component {
* */
handleSubmit() {
let stepData = this.state.stepData;
let applicationCreationPromise = Endpoint.createApplication(stepData);
let applicationCreationPromise = ApplicationMgtApi.createApplication(stepData);
applicationCreationPromise.then( response => {
console.log(response);
let uploadArtifactsPromise = Endpoint.uploadImageArtifacts(response.data.uuid);
this.handleYes();
}
).catch(

@ -17,7 +17,7 @@
*/
import React, {Component} from 'react';
import EndPoint from '../../api/endpoints';
import ApplicationMgtApi from '../../api/applicationMgtApi';
import {withRouter} from 'react-router-dom';
import TextField from 'material-ui/TextField';
import DataTable from '../UIComponents/DataTable';
@ -49,8 +49,6 @@ class ApplicationListing extends Component {
this.scriptId = "application-listing";
}
data = [];
//
headers = [
{
data_id: "image",
@ -86,8 +84,6 @@ class ApplicationListing extends Component {
];
componentWillMount() {
//Fetch all the applications from backend and create application objects.
this.setState({data: this.data});
/**
*Loading the theme files based on the the user-preference.
@ -101,7 +97,7 @@ class ApplicationListing extends Component {
}
componentDidMount() {
let getApps = EndPoint.getApplications();
let getApps = ApplicationMgtApi.getApplications();
getApps.then(response => {
let apps = this.setData(response.data.applications);
console.log(apps);
@ -112,53 +108,10 @@ class ApplicationListing extends Component {
});
}
/**
* Extract application from application list and update the state.
* */
setData(applications) {
// {
// id: Math.random(),
// applicationName: "one",
// platform: 'Android',
// category: "Public",
// status: "Created"
// }
//
// "uuid":"f59ca462-7fa0-4cef-8536-96c17905e587",
// "name":"sdkfsdkf",
// "shortDescription":"shdkfhsd[f sfs;df dsf","description":"khsdkhfkjdss hfdsff\nsdf\ndsf",
// "tags":["dsfds","f","dsfs"],
// "platform":{
// "name":"jdslkjfljs",
// "description":"ljlksdjlfjdsljf",
// "identifier":"sdjflsjdfjlkj",
// "fileBased":false,
// "shared":false,
// "enabled":false,
// "defaultTenantMapping":false
// },
//
// "category":{
// "id":1
// },
//
// "createdAt":"Tue, 12 Sep 2017 18:53:54 IST",
// "modifiedAt":"Tue, 12 Sep 2017 18:53:54 IST",
// "currentLifecycle":{
// "lifecycleState":{
// "id":1,
// "name":"CREATED",
// "identifier":"CREATED",
// "description":"Application creation initial state"
// },
//
// "lifecycleStateModifiedAt":"Tue, 12 Sep 2017 18:53:54 IST",
// "getLifecycleStateModifiedBy":"admin"},
// "screenShotCount":0,
// "user":{
// "userName":"admin",
// "tenantId":-1234
// }
// }
let apps = [];
for (let app in applications) {
let application = {};
@ -212,7 +165,7 @@ class ApplicationListing extends Component {
}
onRowClick(id) {
EndPoint.getApplication(id).then(response => {
ApplicationMgtApi.getApplication(id).then(response => {
console.log(response);
}).catch(err => {
console.log(err)

@ -22,7 +22,7 @@ import MenuItem from 'material-ui/MenuItem';
import SelectField from 'material-ui/SelectField';
import RaisedButton from 'material-ui/RaisedButton';
import Theme from '../../../theme';
import Endpoint from "../../../api/endpoints";
import PlatformMgtApi from "../../../api/platformMgtApi";
import AuthHandler from "../../../api/authHandler";
/**
@ -69,7 +69,7 @@ class Step1 extends Component {
}
componentDidMount() {
//Get the list of available platforms and set to the state.
Endpoint.getPlatforms().then(response => {
PlatformMgtApi.getPlatforms().then(response => {
console.log(response);
this.setPlatforms(response.data);
}).catch(err => {
@ -95,7 +95,7 @@ class Step1 extends Component {
* Persist the current form data to the state.
* */
setStepData() {
console.log(this.state.platforms);
console.log("Platforms",this.state.platforms);
let step = {
store: this.state.store,
platform: this.state.platforms[this.state.platformSelectedIndex]

@ -27,13 +27,13 @@ import FlatButton from 'material-ui/FlatButton';
import IconButton from 'material-ui/IconButton';
import SelectField from 'material-ui/SelectField';
import RaisedButton from 'material-ui/RaisedButton';
import PlatformMgtApi from '../../api/platformMgtApi';
import Clear from 'material-ui/svg-icons/content/clear';
import {GridList, GridTile} from 'material-ui/GridList';
import Close from 'material-ui/svg-icons/navigation/close';
import {Card, CardActions, CardTitle} from 'material-ui/Card';
import AddCircleOutline from 'material-ui/svg-icons/content/add-circle-outline';
import Theme from '../../theme';
import Endpoint from '../../api/endpoints';
/**
* Platform Create component.
@ -221,6 +221,9 @@ class PlatformCreate extends Component {
}
};
/**
* Create platform object and call the create platform api.
* */
onCreatePlatform() {
//Call the platform create api.
let platform = {};
@ -234,8 +237,7 @@ class PlatformCreate extends Component {
platform.allTenants = this.state.allTenants;
platform.defaultTenantMapping = true;
Endpoint.createPlatform(platform);
PlatformMgtApi.createPlatform(platform);
}

Loading…
Cancel
Save