Add service consumers

parent e4221793
ws_endpoint: 'https://the.url'
ws_username: 'username'
ws_password: 'password'
verbose: true
NO_SAFE_CURL: false
......@@ -278,3 +278,27 @@ epal.applicant.creationpdf:
_controller: '\Drupal\epal\Controller\PdfCreator::createApplicantPDF'
requirements:
_user_is_logged_in: 'TRUE'
epal.svc.getdidacticyears:
path: '/epal/get-didactic-years'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\WSConsumer::getAllDidactiYear'
requirements:
_user_is_logged_in: 'TRUE'
epal.svc.getstudentpromotion:
path: '/epal/get-student-promotion/{didactic_year_id}/{lastname}/{firstname}/{father_firstname}/{mother_firstname}/{birthdate}/{registry_no}/{level_name}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\WSConsumer::getStudentEpalPromotion'
requirements:
_user_is_logged_in: 'TRUE'
epal.svc.getstudentcertification:
path: '/epal/get-student-certification/{didactic_year_id}/{lastname}/{firstname}/{father_firstname}/{mother_firstname}/{birthdate}/{registry_no}/{level_name}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\WSConsumer::getStudentEpalCertification'
requirements:
_user_is_logged_in: 'TRUE'
This diff is collapsed.
<?php
namespace Drupal\epal\Controller;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Database\Connection;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\epal\Client;
class WSConsumer extends ControllerBase
{
protected $entityTypeManager;
protected $logger;
protected $client;
protected $settings;
public function __construct(EntityTypeManagerInterface $entityTypeManager, LoggerChannelFactoryInterface $loggerChannel)
{
$config = $this->config('epal.settings');
foreach (['ws_endpoint', 'ws_username', 'ws_password', 'verbose', 'NO_SAFE_CURL'] as $setting) {
$this->settings[$setting] = $config->get($setting);
}
$this->entityTypeManager = $entityTypeManager;
$this->logger = $loggerChannel->get('epal-school');
$this->client = new Client($this->settings, $this->logger);
}
public static function create(ContainerInterface $container)
{
return new static(
$container->get('entity_type.manager'), $container->get('logger.factory')
);
}
public function getPing(Request $request)
{
return (new JsonResponse(['message' => 'Ping!!!']))
->setStatusCode(Response::HTTP_OK);
}
public function getAllDidactiYear()
{
$ts_start = microtime(true);
try {
$catalog = $this->client->getAllDidactiYear();
} catch (\Exception $e) {
return (new JsonResponse(['message' => $e->getMessage()]))
->setStatusCode(($code = $e->getCode()) == 0 ? Response::HTTP_INTERNAL_SERVER_ERROR : $code);
}
$duration = microtime(true) - $ts_start;
$this->logger->info(__METHOD__ . " :: timed [{$duration}]");
return (new JsonResponse([
'message' => 'Επιτυχία',
'data' => $catalog
]))
->setStatusCode(Response::HTTP_OK);
}
public function getStudentEpalPromotion($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name)
{
$ts_start = microtime(true);
try {
$result = $this->client->getStudentEpalPromotion($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name);
} catch (\Exception $e) {
return (new JsonResponse(['message' => $e->getMessage()]))
->setStatusCode(($code = $e->getCode()) == 0 ? Response::HTTP_INTERNAL_SERVER_ERROR : $code);
}
$duration = microtime(true) - $ts_start;
$this->logger->info(__METHOD__ . " :: timed [{$duration}]");
return (new JsonResponse([
'message' => 'Επιτυχία',
'data' => $result
]))
->setStatusCode(Response::HTTP_OK);
}
public function getStudentEpalCertification($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name)
{
$ts_start = microtime(true);
try {
$result = $this->client->getStudentEpalCertification($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name);
} catch (\Exception $e) {
return (new JsonResponse(['message' => $e->getMessage()]))
->setStatusCode(($code = $e->getCode()) == 0 ? Response::HTTP_INTERNAL_SERVER_ERROR : $code);
}
$duration = microtime(true) - $ts_start;
$this->logger->info(__METHOD__ . " :: timed [{$duration}]");
return (new JsonResponse([
'message' => 'Επιτυχία',
'data' => $result
]))
->setStatusCode(Response::HTTP_OK);
}
private function generateRandomString($length)
{
$characters = ['Α','Β','Γ','Δ','Ε','Ζ','Η','Θ','Ι','Κ','Λ','Μ','Ν','Ξ','Ο','Π','Ρ','Σ','Τ','Υ','Φ','Χ','Ψ','Ω'];
$charactersLength = count($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
// private function respondWithStatus($arr, $s)
// {
// $res = new JsonResponse($arr);
// $res->setStatusCode($s);
// return $res;
// }
}
<div class = "loading" *ngIf="(showLoader$ | async) === true"></div>
<div class="loading" *ngIf="(showLoader$ | async) === true"></div>
<div id="headerNotice" (onHidden)="onHidden()" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header {{modalHeader | async}}" >
<h3 class="modal-title pull-left"><i class="fa fa-check-square-o"></i>&nbsp;&nbsp;{{ modalTitle | async }}</h3>
<div class="modal-header {{modalHeader | async}}">
<h3 class="modal-title pull-left"><i class="fa fa-check-square-o"></i>&nbsp;&nbsp;{{ modalTitle | async }}</h3>
<button type="button" class="close pull-right" aria-label="Close" (click)="hideModal()">
<span aria-hidden="true"><i class="fa fa-times"></i></span>
</button>
</div>
<div class="modal-body">
<p>{{ modalText | async }}</p>
<p>{{ modalText | async }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Κλείσιμο</button>
......@@ -18,20 +18,19 @@
</div>
</div>
<div class="header-wrapper">
<header id="navbar" role="banner" class="navbar navbar-default">
<header id="navbar" role="banner" class="navbar navbar-default">
<div *ngIf="(loginInfo$ | async).size > 0">
<ul class="navbar-nav">
<div *ngIf="(loginInfo$ | async).cu_name !== ''">
<div class="row">
<div class="offset-md-8 col-md-4 pull-right">
<span class="username">{{ cuName }}&nbsp;&nbsp;&nbsp;&nbsp;</span>
<span class="signout isclickable" (click)="signOut()" style="color:#CC3300;">Αποσύνδεση&nbsp;&nbsp;</span>
<i class="fa fa-sign-out isclickable" (click)="signOut()"></i>
</div>
<ul class="navbar-nav">
<div *ngIf="(loginInfo$ | async).cu_name !== ''">
<div class="row">
<div class="offset-md-8 col-md-4 pull-right">
<span class="username">{{ cuName }}&nbsp;&nbsp;&nbsp;&nbsp;</span>
<span class="signout isclickable" (click)="signOut()" style="color:#CC3300;">Αποσύνδεση&nbsp;&nbsp;</span>
<i class="fa fa-sign-out isclickable" (click)="signOut()"></i>
</div>
</div>
</div>
</ul>
</div>
</header>
</div>
</ul>
</div>
</header>
</div>
\ No newline at end of file
import {Component, OnInit, OnDestroy} from '@angular/core';
import {Router} from '@angular/router';
import {Component, OnInit, OnDestroy} from "@angular/core";
import {Router} from "@angular/router";
import { Injectable } from "@angular/core";
import { BehaviorSubject } from 'rxjs/Rx';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import { ILoginInfo, ILoginInfoToken } from '../../store/logininfo/logininfo.types';
import { HelperDataService } from '../../services/helper-data-service';
import { LoginInfoActions } from '../../actions/logininfo.actions';
import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial-state';
import { SCHOOL_ROLE, STUDENT_ROLE, PDE_ROLE, DIDE_ROLE, MINISTRY_ROLE } from '../../constants';
import { EpalClassesActions } from '../../actions/epalclass.actions';
import { SectorFieldsActions } from '../../actions/sectorfields.actions';
import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import { SectorCoursesActions } from '../../actions/sectorcourses.actions';
import { CriteriaActions } from '../../actions/criteria.actions';
import { StudentDataFieldsActions } from '../../actions/studentdatafields.actions';
import { BehaviorSubject } from "rxjs/Rx";
import { NgRedux, select } from "ng2-redux";
import { IAppState } from "../../store/store";
import { ILoginInfo, ILoginInfoToken } from "../../store/logininfo/logininfo.types";
import { HelperDataService } from "../../services/helper-data-service";
import { LoginInfoActions } from "../../actions/logininfo.actions";
import { LOGININFO_INITIAL_STATE } from "../../store/logininfo/logininfo.initial-state";
import { SCHOOL_ROLE, STUDENT_ROLE, PDE_ROLE, DIDE_ROLE, MINISTRY_ROLE } from "../../constants";
import { EpalClassesActions } from "../../actions/epalclass.actions";
import { SectorFieldsActions } from "../../actions/sectorfields.actions";
import { RegionSchoolsActions } from "../../actions/regionschools.actions";
import { SectorCoursesActions } from "../../actions/sectorcourses.actions";
import { CriteriaActions } from "../../actions/criteria.actions";
import { StudentDataFieldsActions } from "../../actions/studentdatafields.actions";
@Component({
selector: 'reg-header',
templateUrl: 'header.component.html'
selector: "reg-header",
templateUrl: "header.component.html"
})
export default class HeaderComponent implements OnInit, OnDestroy {
private authToken: string;
private authRole: string;
private cuName: string;
private loginInfo$: BehaviorSubject<ILoginInfo>;
public cuser :any;
public cuser: any;
private showLoader$: BehaviorSubject<boolean>;
private modalTitle: BehaviorSubject<string>;
private modalText: BehaviorSubject<string>;
......@@ -44,9 +44,9 @@ export default class HeaderComponent implements OnInit, OnDestroy {
private router: Router
) {
this.authToken = '';
this.authRole = '';
this.cuName = '';
this.authToken = "";
this.authRole = "";
this.cuName = "";
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
this.showLoader$ = new BehaviorSubject(false);
this.modalTitle = new BehaviorSubject("");
......@@ -56,7 +56,7 @@ export default class HeaderComponent implements OnInit, OnDestroy {
};
ngOnInit() {
(<any>$('#headerNotice')).appendTo("body");
(<any>$("#headerNotice")).appendTo("body");
this._ngRedux.select(state => {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {
......@@ -64,7 +64,7 @@ export default class HeaderComponent implements OnInit, OnDestroy {
this.authRole = loginInfoToken.auth_role;
this.cuName = loginInfoToken.cu_name;
return loginInfoToken;
}, {})
}, {});
}
return state.loginInfo;
......@@ -73,7 +73,7 @@ export default class HeaderComponent implements OnInit, OnDestroy {
}
ngOnDestroy() {
(<any>$('#headerNotice')).remove();
(<any>$("#headerNotice")).remove();
this.loginInfo$.unsubscribe();
}
......@@ -84,20 +84,20 @@ export default class HeaderComponent implements OnInit, OnDestroy {
this._ata.initLoginInfo();
if (this.authRole === SCHOOL_ROLE) {
// this.router.navigate(['/school']);
this.authToken = '';
this.authRole = '';
this.authToken = "";
this.authRole = "";
window.location.assign((<any> data).next);
}
else if (this.authRole === PDE_ROLE) {
// this.router.navigate(['/school']);
this.authToken = '';
this.authRole = '';
// this.router.navigate(["/school"]);
this.authToken = "";
this.authRole = "";
window.location.assign((<any> data).next);
}
else if (this.authRole === DIDE_ROLE) {
// this.router.navigate(['/school']);
this.authToken = '';
this.authRole = '';
// this.router.navigate(["/school"]);
this.authToken = "";
this.authRole = "";
window.location.assign((<any> data).next);
}
else if (this.authRole === STUDENT_ROLE) {
......@@ -107,26 +107,26 @@ export default class HeaderComponent implements OnInit, OnDestroy {
this._csa.initSectorCourses();
this._sdfa.initStudentDataFields();
this._cria.initCriteria();
this.router.navigate(['']);
this.router.navigate([""]);
}
else if (this.authRole === MINISTRY_ROLE) {
this.router.navigate(['/ministry']);
this.router.navigate(["/ministry"]);
}
this.authToken = '';
this.authRole = '';
this.authToken = "";
this.authRole = "";
this.showLoader$.next(false);
}).catch(err => {
this.showLoader$.next(false);
console.log(err)
console.log(err);
});
}
public showModal():void {
(<any>$('#headerNotice')).modal('show');
public showModal(): void {
(<any>$("#headerNotice")).modal("show");
}
public hideModal():void {
(<any>$('#headerNotice')).modal('hide');
public hideModal(): void {
(<any>$("#headerNotice")).modal("hide");
}
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment