Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a4fefec4
authored
Aug 07, 2018
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed graphQL and viplist is now using it
1 parent
e53e5e2b
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
122 additions
and
82 deletions
code/moya-angular/angular.json
code/moya-angular/src/app/app.module.ts
code/moya-angular/src/app/components/moya-locale/locale.service.ts
code/moya-angular/src/app/modules/viplist/info/info-viplist-page.component.html
code/moya-angular/src/app/modules/viplist/models/vip-product-delivery.model.ts
code/moya-angular/src/app/modules/viplist/models/vip-product.model.ts
code/moya-angular/src/app/modules/viplist/models/vip.model.ts
code/moya-angular/src/app/modules/viplist/viplist.service.ts
code/moya-angular/src/app/shared/config/moya.config.ts
code/moya-angular/src/app/shared/models/event-user.model.ts
code/moya-angular/src/app/shared/models/user.model.ts
code/moya-angular/src/app/shared/services/user.service.ts
code/moya-beans/ejbModule/fi/codecrew/moya/beans/TestDataBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/facade/UserFacade.java
code/moya-database/src/main/java/fi/codecrew/moya/model/EventUser.java
code/moya-database/src/main/java/fi/codecrew/moya/model/IUser.java
code/moya-database/src/main/java/fi/codecrew/moya/model/User.java
code/moya-database/src/main/java/fi/codecrew/moya/model/VipProduct.java
code/moya-web/WebContent/resources/cditools/user/eventuserlist.xhtml
code/moya-web/src/main/java/fi/codecrew/moya/graphql/MoyaGraphQLServlet.java
code/pom.xml
code/moya-angular/angular.json
View file @
a4fefec
...
...
@@ -3,7 +3,7 @@
"version"
:
1
,
"newProjectRoot"
:
"projects"
,
"projects"
:
{
"
angular6testi
"
:
{
"
moya-angular
"
:
{
"root"
:
""
,
"sourceRoot"
:
"src"
,
"projectType"
:
"application"
,
...
...
@@ -48,18 +48,18 @@
"serve"
:
{
"builder"
:
"@angular-devkit/build-angular:dev-server"
,
"options"
:
{
"browserTarget"
:
"
angular6testi
:build"
"browserTarget"
:
"
moya-angular
:build"
},
"configurations"
:
{
"production"
:
{
"browserTarget"
:
"
angular6testi
:build:production"
"browserTarget"
:
"
moya-angular
:build:production"
}
}
},
"extract-i18n"
:
{
"builder"
:
"@angular-devkit/build-angular:extract-i18n"
,
"options"
:
{
"browserTarget"
:
"
angular6testi
:build"
"browserTarget"
:
"
moya-angular
:build"
}
},
"test"
:
{
...
...
@@ -93,7 +93,8 @@
}
}
},
"angular6testi-e2e"
:
{
"moya-angular-e2e"
:
{
"root"
:
"e2e"
,
"sourceRoot"
:
"e2e"
,
"projectType"
:
"application"
,
...
...
@@ -102,7 +103,7 @@
"builder"
:
"@angular-devkit/build-angular:protractor"
,
"options"
:
{
"protractorConfig"
:
"./protractor.conf.js"
,
"devServerTarget"
:
"
angular6testi
:serve"
"devServerTarget"
:
"
moya-angular
:serve"
}
},
"lint"
:
{
...
...
@@ -119,7 +120,7 @@
}
}
},
"defaultProject"
:
"
angular6testi
"
,
"defaultProject"
:
"
moya-angular
"
,
"schematics"
:
{
"@schematics/angular:component"
:
{
"prefix"
:
"moya"
,
...
...
@@ -129,4 +130,4 @@
"prefix"
:
"moya"
}
}
}
\ No newline at end of file
}
code/moya-angular/src/app/app.module.ts
View file @
a4fefec
...
...
@@ -16,9 +16,9 @@ import { NgModule } from '@angular/core';
import
{
LoginModule
}
from
'./modules/login/login.module'
;
import
{
LeftMenuModule
}
from
'./menu/left-menu/left-menu.module'
;
import
{
FrontpageComponent
}
from
'./components/frontpage/frontpage.component'
;
import
{
HttpLink
,
HttpLinkModule
}
from
"apollo-angular-link-http"
;
import
{
APOLLO_OPTIONS
,
ApolloModule
}
from
"apollo-angular"
;
import
{
createApollo
}
from
"./shared/config/moya.config"
;
import
{
HttpLink
,
HttpLinkModule
}
from
'apollo-angular-link-http'
;
import
{
APOLLO_OPTIONS
,
ApolloModule
}
from
'apollo-angular'
;
import
{
createApollo
}
from
'./shared/config/moya.config'
;
@
NgModule
({
declarations
:
[
...
...
code/moya-angular/src/app/components/moya-locale/locale.service.ts
View file @
a4fefec
...
...
@@ -6,7 +6,7 @@ import {MoyaLocale} from './moya-locale.model';
import
{
HttpClient
}
from
'@angular/common/http'
;
import
{
TranslateService
}
from
'@ngx-translate/core'
;
import
{
MOYA_REST_URL
}
from
"../../shared/config/moya.config"
;
import
{
MOYA_REST_URL
}
from
'../../shared/config/moya.config'
;
export
const
ENGLISH
=
'en'
;
...
...
code/moya-angular/src/app/modules/viplist/info/info-viplist-page.component.html
View file @
a4fefec
...
...
@@ -2,7 +2,7 @@
<mat-table
#
table
[
dataSource
]="
vips
|
async
"
>
<ng-container
matColumnDef=
"host"
>
<mat-header-cell
*
matHeaderCellDef
translate
>
vip.host
</mat-header-cell>
<mat-cell
*
matCellDef=
"let v"
>
{{v.host.
firstname}} {{ v.host
.lastname}}
</mat-cell>
<mat-cell
*
matCellDef=
"let v"
>
{{v.host.
user.firstname}} {{ v.host.user
.lastname}}
</mat-cell>
</ng-container>
<ng-container
matColumnDef=
"shortdescr"
>
...
...
code/moya-angular/src/app/modules/viplist/models/vip-product-delivery.model.ts
View file @
a4fefec
/**
* Created by tuukka on 04/02/17.
*/
import
gql
from
"graphql-tag"
;
import
gql
from
'graphql-tag'
;
export
class
VipProductDelivery
{
static
fragments
=
gql
`
fragment vipProductDeliveryPrimitives on VipProductDelivery {
fragment vipProductDeliveryPrimitives on VipProductDelivery {
deliverytime
id
notes
...
...
code/moya-angular/src/app/modules/viplist/models/vip-product.model.ts
View file @
a4fefec
import
{
VipProductDelivery
}
from
'./vip-product-delivery.model'
;
import
gql
from
"graphql-tag"
;
import
gql
from
'graphql-tag'
;
/**
* Created by tuukka on 04/02/17.
*/
...
...
@@ -12,10 +12,18 @@ export class VipProduct {
fragment vipProductPrimitives on VipProduct {
id
name
notes
quantity
}
`
;
/*
static fragmentsZ = gql`
fragment vipProductPrimitives on VipProduct {
id
name
notes
quantity
}
`;*/
id
:
number
;
name
:
string
;
...
...
code/moya-angular/src/app/modules/viplist/models/vip.model.ts
View file @
a4fefec
import
{
VipProduct
}
from
'./vip-product.model'
;
import
{
User
}
from
'../../../shared/models/user.model'
;
import
gql
from
"graphql-tag"
;
import
{
VipProductDelivery
}
from
"./vip-product-delivery.model"
;
import
gql
from
'graphql-tag'
;
import
{
VipProductDelivery
}
from
'./vip-product-delivery.model'
;
/**
* Created by tuukka on 04/02/17.
*/
...
...
code/moya-angular/src/app/modules/viplist/viplist.service.ts
View file @
a4fefec
...
...
@@ -10,17 +10,17 @@ import {UserService} from '../../shared/services/user.service';
import
{
HttpClient
}
from
'@angular/common/http'
;
import
{
MOYA_BASE_URL
,
MOYA_REST_URL
}
from
"../../shared/config/moya.config"
;
import
{
MOYA_BASE_URL
,
MOYA_REST_URL
}
from
'../../shared/config/moya.config'
;
import
gql
from
'graphql-tag'
;
import
{
EventUser
}
from
"../../shared/models/event-user.model"
;
import
{
Apollo
}
from
"apollo-angular"
;
import
"rxjs-compat/add/operator/map"
;
import
{
first
,
map
}
from
"rxjs/operators"
;
import
{
Error
}
from
"tslint/lib/error"
;
import
{
EventUser
}
from
'../../shared/models/event-user.model'
;
import
{
Apollo
}
from
'apollo-angular'
;
import
'rxjs-compat/add/operator/map'
;
import
{
first
,
map
}
from
'rxjs/operators'
;
import
{
Error
}
from
'tslint/lib/error'
;
export
const
Q_VIPS_N_DATA
=
gql
`
query Vips()
{
{
vips {
...vipPrimitives
products {
...
...
@@ -35,16 +35,24 @@ export const Q_VIPS_N_DATA = gql`
...userPrimitives
}
}
host {
...eventUserPrimitives
user {
...userPrimitives
}
}
}
}
${
VipFragmentsCombined
}
${
EventUser
.
fragments
}
${
User
.
fragments
}
`
;
class
VipsQueryRoot
{
vips
:
Array
<
Vip
>
;
}
@
Injectable
()
...
...
@@ -61,7 +69,8 @@ export class ViplistService {
* get vips
*/
public
get
():
Observable
<
Array
<
Vip
>>
{
return
this
.
apollo
.
watchQuery
<
Array
<
Vip
>>
({
query
:
Q_VIPS_N_DATA
}).
valueChanges
.
pipe
(
map
(
x
=>
x
.
data
));
return
this
.
apollo
.
watchQuery
<
VipsQueryRoot
>
({
query
:
Q_VIPS_N_DATA
}).
valueChanges
.
pipe
(
map
(
x
=>
{
console
.
log
(
x
.
data
.
vips
);
return
x
.
data
.
vips
}));
// return this.apollo.query<vipsQueryRoot>({query: Q_VIPS_N_DATA}).pipe(map(x => x.data.vips));
}
...
...
code/moya-angular/src/app/shared/config/moya.config.ts
View file @
a4fefec
import
{
InMemoryCache
}
from
"apollo-cache-inmemory"
;
import
{
HttpLink
}
from
"apollo-angular-link-http"
;
import
{
InMemoryCache
}
from
'apollo-cache-inmemory'
;
import
{
HttpLink
}
from
'apollo-angular-link-http'
;
export
const
MOYA_BASE_URL
=
'/MoyaWeb/'
;
export
const
MOYA_REST_URL
=
MOYA_BASE_URL
+
'rest/'
;
...
...
@@ -7,7 +7,7 @@ export const MOYA_REST_URL = MOYA_BASE_URL + 'rest/';
export
function
createApollo
(
httpLink
:
HttpLink
)
{
return
{
link
:
httpLink
.
create
({
uri
:
MOYA_
REST_URL
+
'/
graphql'
}),
link
:
httpLink
.
create
({
uri
:
MOYA_
BASE_URL
+
'
graphql'
}),
cache
:
new
InMemoryCache
(),
};
}
code/moya-angular/src/app/shared/models/event-user.model.ts
View file @
a4fefec
import
{
User
}
from
"./user.model"
;
import
gql
from
"graphql-tag"
;
import
{
User
}
from
'./user.model'
;
import
gql
from
'graphql-tag'
;
export
enum
UserGender
{
MALE
,
...
...
@@ -15,7 +15,7 @@ export class EventUser {
id
eventusercreated
}
`
;
id
:
number
;
...
...
code/moya-angular/src/app/shared/models/user.model.ts
View file @
a4fefec
...
...
@@ -4,7 +4,7 @@
// vim magic: %s/^\s*\w\+\s\+\(\w\+\)\s\+\(\w\+\)\s*.*;$/ \2: \L\1;/
import
gql
from
"graphql-tag"
;
import
gql
from
'graphql-tag'
;
export
enum
UserGender
{
MALE
,
...
...
@@ -18,12 +18,21 @@ export class User {
static
fragments
=
gql
`
fragment userPrimitives on User {
address
birthday
email
}
`
;
/*
static fragmentsZZ = gql`
fragment userPrimitives on User {
address
allergiesFreetext
birthday
email
firstnames
gender
id:
id:
lastname
login
nick
...
...
@@ -31,12 +40,12 @@ export class User {
town
shirtSize
town
zip
zip
}
`
;
`;
*/
nick
:
string
;
login
:
string
;
...
...
code/moya-angular/src/app/shared/services/user.service.ts
View file @
a4fefec
...
...
@@ -4,7 +4,7 @@ import {Injectable} from '@angular/core';
import
{
User
}
from
'../models/user.model'
;
import
{
CacheService
}
from
'./cache.service'
;
import
{
HttpClient
}
from
'@angular/common/http'
;
import
{
MOYA_REST_URL
}
from
"../config/moya.config"
;
import
{
MOYA_REST_URL
}
from
'../config/moya.config'
;
@
Injectable
()
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/beans/TestDataBean.java
View file @
a4fefec
...
...
@@ -131,7 +131,6 @@ public class TestDataBean implements TestDataBeanLocal {
u
.
resetPassword
(
"kavija"
);
u
.
setPhone
(
"123-45679854"
);
u
.
setTown
(
"Keikyän MLK"
);
u
.
setPostalTown
(
"Keykyä"
);
u
.
setZip
(
"393929"
);
userFacade
.
create
(
u
);
return
u
;
...
...
@@ -157,7 +156,6 @@ public class TestDataBean implements TestDataBeanLocal {
u
.
resetPassword
(
"admin"
);
u
.
setPhone
(
"1337"
);
u
.
setTown
(
"Adminila"
);
u
.
setPostalTown
(
"Adminila "
);
u
.
setZip
(
"6666"
);
// u.setSuperadmin(true);
userFacade
.
create
(
u
);
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/facade/UserFacade.java
View file @
a4fefec
...
...
@@ -194,9 +194,6 @@ public class UserFacade extends IntegerPkGenericFacade<User> {
case
"zip"
:
sort
=
User_
.
zip
;
break
;
case
"postalTown"
:
sort
=
User_
.
postalTown
;
break
;
case
"town"
:
sort
=
User_
.
town
;
break
;
...
...
code/moya-database/src/main/java/fi/codecrew/moya/model/EventUser.java
View file @
a4fefec
...
...
@@ -421,14 +421,6 @@ public class EventUser extends GenericEntity {
return
user
.
isSuperadmin
();
}
public
void
setPostalTown
(
String
postalTown
)
{
user
.
setPostalTown
(
postalTown
);
}
public
String
getPostalTown
()
{
return
user
.
getPostalTown
();
}
public
void
setGender
(
Gender
gender
)
{
user
.
setGender
(
gender
);
}
...
...
code/moya-database/src/main/java/fi/codecrew/moya/model/IUser.java
View file @
a4fefec
...
...
@@ -112,10 +112,6 @@ public interface IUser {
public
abstract
boolean
isSuperadmin
();
public
abstract
void
setPostalTown
(
String
postalTown
);
public
abstract
String
getPostalTown
();
public
abstract
void
setGender
(
Gender
gender
);
public
abstract
Gender
getGender
();
...
...
code/moya-database/src/main/java/fi/codecrew/moya/model/User.java
View file @
a4fefec
...
...
@@ -346,15 +346,6 @@ public class User extends GenericEntity implements IUser {
return
superadmin
;
}
@Override
public
void
setPostalTown
(
String
postalTown
)
{
this
.
postalTown
=
postalTown
;
}
@Override
public
String
getPostalTown
()
{
return
postalTown
;
}
@Override
public
void
setGender
(
Gender
gender
)
{
...
...
code/moya-database/src/main/java/fi/codecrew/moya/model/VipProduct.java
View file @
a4fefec
...
...
@@ -29,7 +29,7 @@ public class VipProduct extends GenericEntity {
/**
* If product is null this is used as the name of the product
*/
private
String
name
;
private
String
name
=
""
;
@ManyToOne
()
@JoinColumn
(
nullable
=
true
)
...
...
code/moya-web/WebContent/resources/cditools/user/eventuserlist.xhtml
View file @
a4fefec
...
...
@@ -28,7 +28,7 @@
<hr
/>
<h:outputText
value=
"#{user.address}"
/>
<br
/>
<h:outputText
value=
"#{user.zip} #{user.
postalT
own}"
/>
<h:outputText
value=
"#{user.zip} #{user.
t
own}"
/>
<br
/>
<br
/>
<h:outputText
value=
"#{user.phone}"
/>
...
...
code/moya-web/src/main/java/fi/codecrew/moya/graphql/MoyaGraphQLServlet.java
View file @
a4fefec
package
fi
.
codecrew
.
moya
.
graphql
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.internal.LinkedTreeMap
;
import
com.google.gson.reflect.TypeToken
;
import
fi.codecrew.moya.beans.*
;
import
fi.codecrew.moya.entitysearch.UserSearchQuery
;
import
fi.codecrew.moya.enums.apps.UserPermission
;
...
...
@@ -12,6 +15,7 @@ import fi.codecrew.moya.utilities.SearchResult;
import
graphql.*
;
import
graphql.schema.*
;
import
graphql.schema.idl.SchemaPrinter
;
import
org.primefaces.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -31,6 +35,7 @@ import java.io.IOException;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
static
graphql
.
Scalars
.*;
...
...
@@ -123,25 +128,61 @@ public class MoyaGraphQLServlet extends HttpServlet {
}
}
graphql
.
ExecutionInput
.
Builder
queryBuilder
=
new
graphql
.
ExecutionInput
.
Builder
();
String
query
=
request
.
getParameter
(
"query"
);
executeQuery
(
query
,
response
);
if
(
query
==
null
)
{
String
q
=
request
.
getReader
().
lines
().
collect
(
Collectors
.
joining
());
Map
<
String
,
Object
>
queryJson
=
new
Gson
()
.
fromJson
(
q
,
new
TypeToken
<
Map
<
String
,
Object
>>(){}
.
getType
());
query
=
queryJson
.
get
(
"query"
).
toString
();
//Map varJson = new Gson().fromJson(queryJson.get("variables"), Map.class);
//if (queryJson.get("variables") instanceof LinkedTreeMap)
queryBuilder
.
variables
((
LinkedTreeMap
)
queryJson
.
get
(
"variables"
));
}
queryBuilder
.
query
(
query
);
executeQuery
(
queryBuilder
,
response
);
}
private
void
executeQuery
(
String
query
,
HttpServletResponse
response
)
throws
IOException
{
private
void
executeQuery
(
ExecutionInput
.
Builder
query
,
HttpServletResponse
response
)
throws
IOException
{
GraphQL
graphql
=
GraphQL
.
newGraphQL
(
schema
).
build
();
response
.
setCharacterEncoding
(
"UTF-8"
);
PrintWriter
writer
=
response
.
getWriter
();
try
{
Gson
gson
=
new
Gson
();
Gson
gson
=
new
Gson
Builder
().
serializeNulls
().
create
();
ExecutionResult
exec
=
graphql
.
execute
(
query
);
logger
.
warn
(
"Executed stuff errors: {}"
,
exec
.
getErrors
());
if
(
exec
.
getErrors
()
!=
null
&&
!
exec
.
getErrors
().
isEmpty
())
{
writer
.
write
(
gson
.
toJson
(
new
ErrorContainer
(
exec
.
getErrors
())));
response
.
setStatus
(
HttpServletResponse
.
SC_BAD_REQUEST
);
Map
<
String
,
Object
>
returnMap
=
new
HashMap
<>();
if
(
exec
.
getData
()
!=
null
)
{
returnMap
.
put
(
"data"
,
exec
.
getData
());
}
else
{
returnMap
.
put
(
"data"
,
""
);
}
if
(
exec
.
getErrors
()
!=
null
)
{
returnMap
.
put
(
"errors"
,
exec
.
getErrors
());
}
else
{
Map
<
String
,
Object
>
data
=
exec
.
getData
();
writer
.
write
(
gson
.
toJson
(
data
));
returnMap
.
put
(
"errors"
,
""
);
}
writer
.
write
(
gson
.
toJson
(
returnMap
));
}
catch
(
Exception
e
)
{
logger
.
warn
(
"Got exception at graphql "
,
e
);
writer
.
write
(
"Error completing the query because of exception: "
+
e
.
getMessage
());
...
...
@@ -285,7 +326,6 @@ public class MoyaGraphQLServlet extends HttpServlet {
b
.
addField
(
EventUser_
.
user
);
b
.
addField
(
EventUser_
.
event
).
type
(
builder
.
typeFor
(
SIMPLE_EVENT_TYPE_NAME
));
b
.
addField
(
EventUser_
.
eventuserCreated
);
b
.
addField
(
EventUser_
.
id
);
b
.
addListField
(
Role
.
class
).
dataFetcher
(
environment
->
userbean
.
findUsersRoles
(
environment
.
getSource
()));
b
.
addListField
(
UsersEventUserproperty
.
class
).
dataFetcher
(
environment
->
eventUserPropertyBean
.
getUserPropertiesForUser
(
environment
.
getSource
()).
stream
().
sorted
(
ENTITY_ID_SORTER
).
collect
(
toList
()));
b
.
addField
(
EventUser_
.
currentPlaces
);
...
...
code/pom.xml
View file @
a4fefec
...
...
@@ -48,8 +48,8 @@
<rewriteservlet.version>
3.4.2.Final
</rewriteservlet.version>
<iudex.standalone>
1.0.23
</iudex.standalone>
<js.node.version>
v
8.11.3
</js.node.version>
<js.npm.version>
6.
3
.0
</js.npm.version>
<js.node.version>
v
10.8.0
</js.node.version>
<js.npm.version>
6.
2
.0
</js.npm.version>
<eirslett.frontend.version>
1.4
</eirslett.frontend.version>
<payara.version>
4.1.2.181
</payara.version>
</properties>
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment