Commit ec6918c2 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '383-use-generated-models-and-services' into 'master'

Resolve "Use generated models and services"

Closes #383

See merge request !305
parents 2634437f fa8205b1
Pipeline #6892 passed with stages
in 5 minutes and 52 seconds
......@@ -18,6 +18,7 @@ import getDir from '../server/middleware/detectDirection';
// JSS & MUI
import { MuiThemeProvider } from '@material-ui/core/styles';
import theme from 'ui/theme';
import { configureBackendApi } from 'utilities/requestUtils';
declare const __PRELOADED_STATE__: any;
......@@ -33,6 +34,9 @@ const detectedLang = initialLanguage ? initialLanguage : detectLocaleFromPath(vi
const historyOptions = { basename: detectedLang !== 'en' ? `${virtualPath}/${detectedLang}` : `${virtualPath}` };
const history = createHistory(historyOptions);
// Configure axios for client
configureBackendApi({ apiUrl: `${virtualPath}/proxy` });
const initialState = __PRELOADED_STATE__ === undefined ? {} : __PRELOADED_STATE__;
const store = composeEnhancers(applyMiddleware(thunk, routerMiddleware(history)))(createStore)(rootReducer, initialState);
......
import { configureBackendApi } from 'utilities/requestUtils';
/**
* Start the frontend server
*/
let server = require('./server').default;
const server = require('./server').default;
const PORT = process.env.PORT || 3000;
// Configure axios for server
configureBackendApi({ apiUrl: `http://localhost:${PORT}/proxy` });
// start server on PORT
server.listen(PORT, () => {
console.log('HTTP server listening on: ' + PORT);
......
......@@ -11,7 +11,7 @@ const httpProxy = proxy(config.apiUrl, {
return true;
}
if (req.url.startsWith('/uploads')) {
req.url = req.url.replace(/^\/uploads/, '/api/v0/repository/download');
req.url = req.url.replace(/^\/uploads/, '/api/v1/repository/download');
}
if (req.url.startsWith('/api')) {
// If authorization header is not provided, use access_token from cookie
......
......@@ -17,7 +17,7 @@ import createGenerateClassName from '@material-ui/core/styles/createGenerateClas
import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider';
import theme from 'ui/theme';
import checkAuthToken from './checkAuthToken';
// import checkAuthToken from './checkAuthToken';
import routes from 'ui/routes';
import matchRoutes from 'ui/matchRoutes';
import renderRoutes from 'ui/renderRoutes';
......@@ -25,7 +25,8 @@ import fetchComponentData from './fetchComponentData';
import detectLocaleFromPath from './detectLocaleFromPath';
import getDir from './detectDirection';
import config from '../config';
import {configure} from 'actions/applicationConfig';
import checkAuthToken from './checkAuthToken';
import { configure } from 'actions/applicationConfig';
const prerenderer = (html) => (req, res) => {
console.log('Init prerenderer, request url:', req.url);
......@@ -51,13 +52,14 @@ const prerenderer = (html) => (req, res) => {
const generateClassName = createGenerateClassName();
const initialLanguage = req.i18n.language;
const initialI18nStore = {};
const defaultLanguage = 'en';
initialI18nStore[initialLanguage] = req.i18n.services.resourceStore.data[initialLanguage];
if (initialLanguage !== 'en') {
if (initialLanguage !== defaultLanguage) {
// So that we have missing translations
initialI18nStore['en'] = req.i18n.services.resourceStore.data['en'];
initialI18nStore[defaultLanguage] = req.i18n.services.resourceStore.data[defaultLanguage];
}
const basename = initialLanguage !== 'en' ? `${config.frontendPath}/${initialLanguage}` : `${config.frontendPath}`;
const pathWithoutLang = req.url.substr(initialLanguage !== 'en' ? 3 : 0, req.url.length);
const basename = initialLanguage !== defaultLanguage ? `${config.frontendPath}/${initialLanguage}` : `${config.frontendPath}`;
const pathWithoutLang = req.url.substr(initialLanguage !== defaultLanguage ? 3 : 0, req.url.length);
console.log(`<StaticRouter location="${pathWithoutLang}" basename="${basename}"`);
......@@ -105,6 +107,7 @@ const prerenderer = (html) => (req, res) => {
checkAuthToken(req, res, store.dispatch).then(() => {
const language = req.i18n.language;
const pathWithoutLang = pathname.substr(language !== 'en' ? 3 : 0, pathname.length);
console.log(`Rendering ${pathWithoutLang} for ${pathname}`);
const branch = matchRoutes(routes, pathWithoutLang);
fetchComponentData(store.dispatch, branch, search)
......
import {push} from 'react-router-redux';
import {Crop} from 'model/crop.model';
import {CropService} from 'service/CropService';
import Crop from 'model/genesys/Crop';
import CropService from 'service/CropService';
import {LIST_CROPS_CACHE_IDLE, CREATE_CROP, GET_CROP, RECEIVE_CROP, RECEIVE_CROPS} from 'constants/crop';
import {IReducerAction} from 'model/common.model';
import {log} from 'utilities/debug';
......@@ -21,11 +21,9 @@ const receiveCrops = (crops: Crop[]): IReducerAction => ({
});
export const loadCrop = (shortName: string) => (dispatch, getState) => {
const token = getState().login.access_token;
dispatch({type: GET_CROP, payload: shortName});
return CropService.getCrop(token, shortName)
return CropService.getCrop(shortName)
.then((crop) => {
return dispatch(receiveCrop(crop));
}).catch((error) => {
......@@ -49,7 +47,7 @@ export const listCrops = (forceReload: boolean = false) => (dispatch, getState)
const isDataStale = Date.now() - timeSinceLastFetch > LIST_CROPS_CACHE_IDLE;
if (isDataStale || forceReload) {
return CropService.listCrops(getState().login.access_token)
return CropService.listCrops()
.then((list) => {
dispatch(receiveCrops(list));
})
......@@ -61,7 +59,7 @@ export const listCrops = (forceReload: boolean = false) => (dispatch, getState)
export const saveCrop = (crop: Crop) => (dispatch, getState) => {
return CropService.saveCrop(getState().login.access_token, crop)
return CropService.saveCrop(crop)
.then((saved) => {
dispatch(receiveCrop(saved));
dispatch(listCrops(true));
......@@ -72,7 +70,7 @@ export const saveCrop = (crop: Crop) => (dispatch, getState) => {
};
export const deleteCrop = (crop: Crop) => (dispatch, getState) => {
return CropService.deleteCrop(getState().login.access_token, crop.shortName)
return CropService.deleteCrop(crop.shortName)
.then((crop) => {
dispatch(push('/crops'));
})
......
// constants
import {ADD_TO_EDIT_LIST, REMOVE_FROM_EDIT_LIST, RECEIVE_IS_EDIT_MODE, SELECT_ALL, UNSELECT_ALL} from 'constants/dashboard';
import { ADD_TO_EDIT_LIST, REMOVE_FROM_EDIT_LIST, RECEIVE_IS_EDIT_MODE, SELECT_ALL, UNSELECT_ALL } from 'constants/dashboard';
// Models
import {Dataset} from 'model/dataset.model';
import {Descriptor, DescriptorList} from 'model/descriptor.model';
import Dataset from 'model/catalog/Dataset';
import Descriptor from 'model/catalog/Descriptor';
import DescriptorList from 'model/catalog/DescriptorList';
export const setEditMode = (payload: boolean) => (dispatch) => {
......
......@@ -3,127 +3,123 @@ import * as Constants from 'constants/login';
import * as cookies from 'es-cookie';
import { clearCookies, saveCookies } from 'utilities';
import { ROLE_CLIENT } from 'constants/userRoles';
import {log} from 'utilities/debug';
import { log } from 'utilities/debug';
import { configureBackendApi } from 'utilities/requestUtils';
export function checkAccessTokens(dispatch) {
const cookieToken: string = typeof window !== 'undefined' && cookies.get('access_token');
const applicationLogin = () =>
LoginService.loginApp()
.then((data) => {
saveCookies({access_token: data.access_token, authorities: [ROLE_CLIENT]});
dispatch(loginApp(data));
})
.catch((error) => {
log('Something went wrong', error);
});
if (cookieToken) {
return LoginService.checkToken(cookieToken)
.then((data) => {
dispatch(loginUser({ access_token: cookieToken, ...data }));
return true;
})
.catch((error) => {
const cookieToken: string = typeof window !== 'undefined' && cookies.get('access_token');
const applicationLogin = () =>
LoginService.loginApp()
.then((data) => {
saveCookies({access_token: data.access_token, authorities: [ROLE_CLIENT]});
dispatch(loginApp(data));
})
.catch((error) => {
log('Something went wrong', error);
});
if (cookieToken) {
return LoginService.checkToken(cookieToken)
.then((data) => {
dispatch(loginUser({ access_token: cookieToken, ...data }));
return true;
})
.catch((error) => {
clearCookies();
return applicationLogin();
});
} else {
clearCookies();
return applicationLogin();
});
} else {
clearCookies();
return applicationLogin();
}
}
}
function loginRequest(username, password) {
return (dispatch) => {
return LoginService.login(username, password)
.then((data) => {
saveCookies(data);
return dispatch(loginUser(data));
});
};
export function loginAppRequest() {
return (dispatch) => {
return LoginService.loginApp()
.then((data) => {
return dispatch(loginApp(data));
});
};
}
function loginAppRequest() {
return (dispatch) => {
return LoginService.loginApp()
.then((data) => {
return dispatch(loginApp(data));
});
};
export function loginApp(d) {
// console.log('Login app', d);
configureBackendApi({ accessToken: d.access_token });
return {
type: Constants.LOGIN_APP,
authorities: [ROLE_CLIENT],
...d,
};
}
function logoutRequest() {
return (dispatch, getState) => {
const token = getState().login.access_token;
return LoginService.logout(token)
.then(() => {
clearCookies();
return dispatch(logout());
});
// Login
export const loginUser = (payload) => {
// console.log('loginUser', payload);
configureBackendApi({ accessToken: payload.access_token });
return {
type: Constants.LOGIN_USER,
...payload,
};
}
};
function checkTokenRequest(token) {
return (dispatch) => {
log('checkTokenRequest verifying ', token);
return LoginService.checkToken(token)
.then((data) => {
log('checkTokenRequest got', data);
return dispatch(checkToken({ access_token: token, ...data }));
});
const checkToken = (payload) => {
return {
type: Constants.CHECK_TOKEN,
...payload,
};
}
};
function verifyGoogleTokenRequest(accessToken, googleClientId) {
return (dispatch, getState) => {
const token = getState().login.access_token;
export const loginRequest = (username, password) => (dispatch) => {
return LoginService.verifyGoogleToken(token, accessToken, googleClientId)
.then((data) => {
saveCookies(data);
return dispatch(loginApp(data));
});
};
}
return LoginService.login(username, password)
.then((data) => {
saveCookies(data);
return dispatch(loginUser(data));
});
};
function loginUser(d) {
return {
type: Constants.LOGIN_USER,
...d,
};
}
export const checkTokenRequest = (token) => (dispatch) => {
log('checkTokenRequest verifying ', token);
return LoginService.checkToken(token)
.then((data) => {
log('checkTokenRequest got', data);
return dispatch(checkToken({access_token: token, ...data}));
});
};
function loginApp(d) {
// Google login
// TODO find usage
export const verifyGoogleToken = (payload) => {
return {
type: Constants.LOGIN_APP,
authorities: [ROLE_CLIENT],
...d,
type: Constants.VERIFY_GOOGLE_TOKEN,
...payload,
};
}
};
function logout() {
return {
type: Constants.LOGOUT,
};
}
export const verifyGoogleTokenRequest = (accessToken) => (dispatch, getState) => {
const token = getState().login.access_token;
function checkToken(d) {
return {
type: Constants.CHECK_TOKEN,
...d,
};
}
return LoginService.verifyGoogleToken(token, accessToken)
.then((data) => {
saveCookies(data);
return dispatch(loginApp(data));
});
};
function verifyGoogleToken(d) {
// Logout
const logout = () => {
return {
type: Constants.VERIFY_GOOGLE_TOKEN,
...d,
type: Constants.LOGOUT,
};
}
};
export {
loginRequest, loginUser, loginAppRequest, loginApp, logoutRequest, logout,
checkTokenRequest, checkToken, verifyGoogleTokenRequest, verifyGoogleToken,
export const logoutRequest = () => (dispatch, getState) => {
const token = getState().login.access_token;
return LoginService.logout(token)
.then(() => {
clearCookies();
return dispatch(logout());
});
};
import {PermissionService} from 'service/PermissionService';
import PermissionService from 'service/PermissionService';
import {log} from 'utilities/debug';
import {SidPermissions} from 'model/acl.model';
import SidPermissions from 'model/acl/SidPermissions';
export const permissions = (clazz: string, id: number) => (dispatch, getState) => {
return PermissionService.permissions(getState().login.access_token, clazz, id)
return PermissionService.permissions(clazz, id)
.catch((error) => {
log('Error', error);
});
......@@ -12,7 +12,7 @@ export const permissions = (clazz: string, id: number) => (dispatch, getState) =
export const addPermission = (clazz: string, id: number, sidPermissions: SidPermissions) => (dispatch, getState) => {
return PermissionService.addPermission(getState().login.access_token, clazz, id, sidPermissions)
return PermissionService.addPermission(clazz, id, sidPermissions)
.catch((error) => {
log('Error', error);
});
......@@ -20,7 +20,7 @@ export const addPermission = (clazz: string, id: number, sidPermissions: SidPerm
export const autocomplete = (term: string) => (dispatch, getState) => {
return PermissionService.autocomplete(getState().login.access_token, term)
return PermissionService.acSid(term)
.catch((error) => {
log('Error', error);
});
......
import { RepositoryFile } from 'model/repositoryFile.model';
import { RepositoryFileService } from 'service/RepositoryFileService';
import RepositoryFile from 'model/repository/RepositoryFile';
import RepositoryService from 'service/RepositoryService';
import {log} from 'utilities/debug';
import { log } from 'utilities/debug';
import * as UUIDv4 from 'uuid/v4';
export const uploadMarkdownAttachment = (file: File) => (dispatch, getState) => {
const token = getState().login.access_token;
return RepositoryFileService.uploadMarkdownAttachment(token, file)
const metadata: RepositoryFile = new RepositoryFile();
const dummy: string = UUIDv4().replace(/\-/g, '');
metadata.originalFilename = `${dummy}_${file.name}`;
metadata.contentType = file.type;
console.log(`Uploading Markdown`, metadata);
return RepositoryService.uploadFile('/content/markdown', file, metadata)
.then((repoFile: RepositoryFile) => {
return repoFile;
}).catch((error) => {
......
import { SearchService } from 'service/SearchService';
import {DescriptorService} from 'service/DescriptorService';
import {DatasetService} from 'service/DatasetService';
import {DescriptorListService} from 'service/DescriptorListService';
import {Descriptor, DescriptorList} from 'model/descriptor.model';
import {Page} from 'model/common.model';
import {Dataset} from 'model/dataset.model';
import SearchService from 'service/SearchService';
import DescriptorService from 'service/DescriptorService';
import DatasetService from 'service/DatasetService';
import DescriptorListService from 'service/DescriptorListService';
import DescriptorList from 'model/catalog/DescriptorList';
import Descriptor from 'model/catalog/Descriptor';
import { Page } from 'model/common.model';
import Dataset from 'model/catalog/Dataset';
import {
SEARCH_DATASET_PAGE,
SEARCH_DESCRIPTOR_PAGE,
......@@ -12,7 +14,7 @@ import {
NEW_SEARCH,
SEARCH_DATASET_SUGGESTIONS,
} from 'constants/search';
import {log} from 'utilities/debug';
import { log } from 'utilities/debug';
const search = (search: string) => ({
type: NEW_SEARCH,
......@@ -41,9 +43,9 @@ const searchDatasetsSuggestions = (suggestions: any) => ({
export function datasetSuggestions(searchQuery, filter?) {
return (dispatch, getState) => {
const token = getState().login.access_token;
if (searchQuery && searchQuery.trim() !== '') {
return SearchService.datasetSuggestions(token, searchQuery, filter)
return SearchService.datasets(searchQuery, filter)
.then((data) => {
return dispatch(searchDatasetsSuggestions(data));
})
......@@ -57,13 +59,13 @@ export function datasetSuggestions(searchQuery, filter?) {
};
}
export function searchDatasets(page?, results?, sortBy?, filter?, order?) {
export function searchDatasets(page?, results?, sortBy?: string[], filter?, order?) {
return (dispatch, getState) => {
const token = getState().login.access_token;
dispatch(search(filter._text));
return DatasetService.listDatasets(token, page, results, sortBy, filter, order)
return DatasetService.datasetList(filter, { page, size: results, properties: sortBy, direction: order })
.then((paged) => {
return dispatch(searchDatasetPage(paged));
})
......@@ -75,11 +77,10 @@ export function searchDatasets(page?, results?, sortBy?, filter?, order?) {
export function searchDescriptors(page?, results?, sortBy?, filter?, order?) {
return (dispatch, getState) => {
const token = getState().login.access_token;
dispatch(search(filter._text));
return DescriptorService.listDescriptors(token, page, results, sortBy, filter, order)
return DescriptorService.listDescriptors(filter, { page, size: results, properties: sortBy, direction: order })
.then((paged) => {
return dispatch(searchDescriptorPage(paged));
})
......@@ -89,13 +90,13 @@ export function searchDescriptors(page?, results?, sortBy?, filter?, order?) {
};
}
export function searchDescriptorLists(page?, results?, sortBy?, filter?, order?) {
export function searchDescriptorLists(page?, results?, sortBy?: string[], filter?, order?) {
return (dispatch, getState) => {
const token = getState().login.access_token;
dispatch(search(filter._text));
return DescriptorListService.listDescriptorLists(token, page, results, sortBy, filter, order)
return DescriptorListService.listDescriptorLists(filter, { page, size: results, properties: sortBy, direction: order })
.then((paged) => {
return dispatch(searchDescriptorListPage(paged));
})
......
import * as Constants from 'constants/serverInfo';
import {log} from 'utilities/debug';
import {InfoService} from 'service/InfoService';
import {ServerInfo} from 'model/serverinfo.model';
import { log } from 'utilities/debug';
import ApiInfoService from 'service/ApiInfoService';
import ServerApiInfo from 'model/ServerApiInfo';
export const serverInfoRequest = () => (dispatch, getState): Promise<ServerInfo> => {
const token = getState().login.access_token;
export const serverInfoRequest = () => (dispatch, getState): Promise<ServerApiInfo> => {
return InfoService.getServerInfo(token)
return ApiInfoService.apiInfo()
.then((data) => dispatch(getServerInfo(data)))
.catch((error) => log('Error', error));
};
const getServerInfo = (info: ServerInfo) => ({
const getServerInfo = (info: ServerApiInfo) => ({
type: Constants.GET_SERVER_INFO,
payload: { info },
});
import { UserProfileService } from 'service/UserProfileService';
import {log} from 'utilities/debug';
import { log } from 'utilities/debug';
import { SubmissionError } from 'redux-form';
import * as _ from 'lodash';
import { showSnackbar } from 'actions/snackbar';
import { RECEIVE_USER_PROFILE } from 'constants/userProfile';
import {User} from 'model/user.model';
import User from 'model/user/User';
import { IReducerAction } from 'model/common.model';
const receiveUserProfile = (user: User): IReducerAction => ({
......@@ -12,8 +12,7 @@ const receiveUserProfile = (user: User): IReducerAction => ({
});
export const loadUserProfile = () => (dispatch, getState) => {
const token = getState().login.access_token;
return UserProfileService.getProfile(token)
return UserProfileService.getProfile()
// receive the current user profile
.then((userProfile) => {
return dispatch(receiveUserProfile(userProfile));
......@@ -24,7 +23,7 @@ export const loadUserProfile = () => (dispatch, getState) => {
};
export const changePassword = (newPassword: string, oldPassword: string) => (dispatch, getState) => {
return UserProfileService.changePassword(getState().login.access_token, newPassword, oldPassword)
return UserProfileService.changePassword(newPassword, oldPassword)
.then(() => {
dispatch(showSnackbar('Password was changed successfully'));
}).catch((error) => {
......
import * as _ from 'lodash';
import {Partner} from 'model/partner.model';
import {DescriptorList} from 'model/descriptor.model';
import Partner from 'model/genesys/Partner';
import DescriptorList from 'model/catalog/DescriptorList';
import {RECEIVE_UUID_LABELS} from 'constants/uuidDecoder';
import { RECEIVE_UUID_LABELS } from 'constants/uuidDecoder';