Skip to content

Commit

Permalink
Dokumenttien generoinnin auktorisointi.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhyoty committed Sep 15, 2014
1 parent 79a7638 commit e845921
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 261 deletions.
112 changes: 46 additions & 66 deletions eperusteet/eperusteet-app/yo/app/scripts/services/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,91 +20,69 @@
angular.module('eperusteApp')
.factory('Dokumentti', function($resource, SERVICE_LOC) {

// api:
//
// Generointi:
// /dokumentti/create/:id/:kieli
// /dokumentti/create/:id // oletuskieli
//
// Luonnin seuranta/tilakysely:
// /dokumentti/query/:token
//
// Valmiin dokumentin hakeminen:
// /dokumentti/get/:token
//
// Yksivaiheinen luominen
// /dokumentti/:id/:kieli
// /dokumentti/:id // oletuskieli

return $resource(SERVICE_LOC + '/dokumentti/create/:id/:kieli', {
id: '@id',
kieli: '@kieli'
});
})
.factory('DokumenttiHaku', function($resource, SERVICE_LOC) {
return $resource(SERVICE_LOC + '/dokumentti/:tapa/:token', {
tapa: '@tapa', // query | get
token: '@token'
},
{
hae: {method: 'GET', responseType: 'arraybuffer'}
});
})
.factory('DokumenttiKysely', function($resource, SERVICE_LOC) {

return $resource(SERVICE_LOC + '/dokumentti/uusin/:perusteId/:kieli', {
perusteId: '@id',
kieli: '@kieli'
// api:
//
// Generointi:
// POST /dokumentit?perusteId=<id>&kieli=fi
// GET /dokumentit/:token/tila
// Valmiin dokumentin hakeminen:
// GET /dokumentit/:token

var baseUrl = SERVICE_LOC+'/dokumentit/:id';
return $resource(baseUrl, {
id: '@id'
}, {
'tila': {
method: 'GET', url: baseUrl+'/tila'
}
});
})
.service('Pdf', function(Dokumentti, DokumenttiHaku, DokumenttiKysely, SERVICE_LOC) {
.service('Pdf', function(Dokumentti, SERVICE_LOC) {

function generoiPdf(perusteId, kieli, success, failure) {
success = success || angular.noop;
failure = failure || angular.noop;

Dokumentti.get({
id: perusteId,
kieli: kieli
}, success, failure);
Dokumentti.save({
'perusteId': perusteId,
'kieli': kieli
}, null, success, failure);
}

function haeTila(tokenId, success, failure) {
success = success || angular.noop;
failure = failure || angular.noop;

DokumenttiHaku.get({
tapa: 'query',
token: tokenId
Dokumentti.tila({
id: tokenId
}, success);
}

function haeDokumentti(tokenId, success, failure) {
success = success || angular.noop;
failure = failure || angular.noop;
success = success || angular.noop;
failure = failure || angular.noop;

return DokumenttiHaku.hae({
tapa: 'get',
token: tokenId
}, success);
return Dokumentti.get({
id: tokenId
}, success);
}

function haeLinkki(tokenId) {
// dis like, ewwww
return SERVICE_LOC + '/dokumentti/get/'+tokenId;
console.log(new Dokumentti({id:tokenId}));
// dis like, ewwww
return SERVICE_LOC + '/dokumentit/' + tokenId;
}

function haeUusin(perusteId, kieli, success, failure) {
success = success || angular.noop;
failure = failure || angular.noop;

return DokumenttiKysely.get({
return Dokumentti.get({
perusteId: perusteId,
kieli: kieli
}, success);

}

return {
generoiPdf: generoiPdf,
haeDokumentti: haeDokumentti,
Expand All @@ -114,21 +92,23 @@ angular.module('eperusteApp')
};
})

.factory('PdfCreation', function ($modal, YleinenData) {
.factory('PdfCreation', function($modal, YleinenData) {
var service = {};
var perusteId = null;

service.setPerusteId = function (id) {
service.setPerusteId = function(id) {
perusteId = id;
};

service.openModal = function () {
service.openModal = function() {
$modal.open({
templateUrl: 'views/modals/pdfcreation.html',
controller: 'PdfCreationController',
resolve: {
perusteId: function () { return perusteId; },
kielet: function () {
perusteId: function() {
return perusteId;
},
kielet: function() {
return {
lista: _.sortBy(YleinenData.kielet),
valittu: YleinenData.kieli
Expand All @@ -140,13 +120,13 @@ angular.module('eperusteApp')

return service;
})
.controller('PdfCreationController', function ($scope, kielet, Pdf, perusteId,
.controller('PdfCreationController', function($scope, kielet, Pdf, perusteId,
$timeout, Notifikaatiot, Kaanna) {
$scope.kielet = kielet;
$scope.docs = {};
var pdfToken = null;

$scope.hasPdf = function () {
$scope.hasPdf = function() {
return !!$scope.docs[$scope.kielet.valittu];
};

Expand All @@ -157,7 +137,7 @@ angular.module('eperusteApp')
} else {
kielet = kielet.lista;
}
_.each(kielet, function (kieli) {
_.each(kielet, function(kieli) {
Pdf.haeUusin(perusteId, kieli, function(res) {
if (kieli === $scope.kielet.valittu) {
$scope.tila = res.tila;
Expand All @@ -177,7 +157,7 @@ angular.module('eperusteApp')
function getStatus(id) {
Pdf.haeTila(id, function(res) {
$scope.tila = res.tila;
switch(res.tila) {
switch (res.tila) {
case 'luodaan':
case 'ei_ole':
startPolling(res.id);
Expand All @@ -198,7 +178,7 @@ angular.module('eperusteApp')
}

function startPolling(id) {
$scope.poller = $timeout(function () {
$scope.poller = $timeout(function() {
getStatus(id);
}, 3000);
}
Expand All @@ -207,7 +187,7 @@ angular.module('eperusteApp')
$timeout.cancel($scope.poller);
});

$scope.generate = function () {
$scope.generate = function() {
enableActions(false);
$scope.docs[$scope.kielet.valittu] = null;
$scope.tila = 'luodaan';
Expand All @@ -216,13 +196,13 @@ angular.module('eperusteApp')
pdfToken = res.id;
startPolling(res.id);
}
}, function () {
}, function() {
enableActions();
$scope.tila = 'ei_ole';
});
};

$scope.$watch('kielet.valittu', function (value) {
$scope.$watch('kielet.valittu', function(value) {
fetchLatest(value);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public abstract class PerusteenOsa
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private TekstiPalanen nimi;

@Getter
@Setter
@Enumerated(value = EnumType.STRING)
@NotNull
private PerusteTila tila = PerusteTila.LUONNOS;

public Long getId() {
return id;
}
Expand All @@ -75,12 +81,6 @@ public void setNimi(TekstiPalanen nimi) {
this.nimi = nimi;
}

@Getter
@Setter
@Enumerated(EnumType.STRING)
@NotNull
private PerusteTila tila;

@Override
public void mergeState(PerusteenOsa updated) {
if (this.getClass().isAssignableFrom(updated.getClass()) && getId() == null || !getId().equals(updated.getId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public class TutkinnonOsa extends PerusteenOsa implements Serializable {
@Column(name = "koodi_arvo")
private String koodiArvo;

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
//Hibernate bug: orphanRemoval ei toimi jos fetchMode = Lazy
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private Arviointi arviointi;

@Getter
Expand Down

0 comments on commit e845921

Please sign in to comment.