Compare commits
66 Commits
Author | SHA1 | Date |
---|---|---|
Marcin Woźniak | cf4d8c05a2 | |
Filip Izydorczyk | 72f049b478 | |
Marcin Woźniak | bb7f1b6737 | |
Filip Izydorczyk | ad4984bdae | |
Marcin Woźniak | 63def650c9 | |
Filip Izydorczyk | a201bcc581 | |
Marcin Woźniak | e688f8b71d | |
Filip Izydorczyk | 389e557674 | |
Marcin Woźniak | dd82acc1de | |
Filip Izydorczyk | bfa8eb6e3e | |
Filip Izydorczyk | a910709798 | |
Filip Izydorczyk | 270e31f120 | |
Filip Izydorczyk | 6a0d425c37 | |
Filip Izydorczyk | 676070c8c7 | |
Filip Izydorczyk | 7045844653 | |
Marcin Woźniak | cd2665bd08 | |
Filip Izydorczyk | 0eccbfe9a3 | |
Filip Izydorczyk | a304e25629 | |
Filip Izydorczyk | af29d0a54a | |
Filip Izydorczyk | 20a6db61cc | |
Filip Izydorczyk | 20f52746b5 | |
Filip Izydorczyk | cf875889b9 | |
filipizydorczyk | 08a4bdde06 | |
filipizydorczyk | 548e39dc63 | |
filipizydorczyk | 65ea502619 | |
Marcin Woźniak | c177314419 | |
Filip Izydorczyk | 847dd76fc8 | |
Filip Izydorczyk | 265315b874 | |
Filip Izydorczyk | d1a54a93d6 | |
Filip Izydorczyk | 7f647f9b8a | |
Filip Izydorczyk | 7b9e334328 | |
Filip Izydorczyk | d217536f2c | |
Filip Izydorczyk | 6a4ea45900 | |
Filip Izydorczyk | 06fb41b5dd | |
filipizydorczyk | 5ec41fa5d0 | |
Marcin Woźniak | fa59845be8 | |
Marcin Woźniak | c89d629c61 | |
Filip Izydorczyk | 5ed445449c | |
Filip Izydorczyk | 0103a028b4 | |
Filip Izydorczyk | b740562e9d | |
Filip Izydorczyk | 4cf6cb58cb | |
Marcin Woźniak | 27b357fc86 | |
Marcin Woźniak | 3269a36239 | |
Filip Izydorczyk | 2d28abefea | |
Filip Izydorczyk | ad3d4e6900 | |
filipizydorczyk | 3222faeab2 | |
Filip Izydorczyk | c5f09a91ec | |
Filip Izydorczyk | 11ec43911e | |
Marcin Woźniak | c762d7fd4b | |
Marcin Woźniak | 77c3b9e3a5 | |
Filip Izydorczyk | d4514affcc | |
Marcin Woźniak | c4ec88e691 | |
Filip Izydorczyk | 98d6faf555 | |
Filip Izydorczyk | 2cfe0e7551 | |
Filip Izydorczyk | 707e26e082 | |
Filip Izydorczyk | 9372ea5562 | |
Filip Izydorczyk | e600e84ae2 | |
Filip Izydorczyk | f77213a01e | |
Filip Izydorczyk | 061c3a24fe | |
Filip Izydorczyk | bf7d0c7dbc | |
Filip Izydorczyk | 21983fe4f7 | |
Filip Izydorczyk | 8d007c259f | |
Filip Izydorczyk | 28e872ce3a | |
Filip Izydorczyk | fafd94f469 | |
Filip Izydorczyk | 423c6667a9 | |
Filip Izydorczyk | 334129cb70 |
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Provides the classes necessary to obtain usos authentication with Oauth1
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.api;
|
|
@ -12,16 +12,29 @@ import org.apache.poi.ss.usermodel.Row;
|
|||
import com.plannaplan.models.FileData;
|
||||
|
||||
/**
|
||||
* FileReader is used for reading xls file from input stream.
|
||||
* FileReader is used for reading xls file from input stream.
|
||||
*/
|
||||
public class FileReader {
|
||||
|
||||
private InputStream fileInputStream;
|
||||
|
||||
/**
|
||||
* @param fileInputStream stream of stadarized file contains courses and gropups
|
||||
* to import. File needs to be .xlsx file that has
|
||||
* fields: zaj_cyk_id, typ, sym, nazwa, gr_nr, Mc, dzien,
|
||||
* godz_od, sala, tytul, nazwisko, imie. Order doesn't
|
||||
* have impact on import. Any change name of given field
|
||||
* can be performed in FileToDatabaseMigrator class
|
||||
*/
|
||||
public FileReader(InputStream fileInputStream) {
|
||||
this.fileInputStream = fileInputStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* read data rom file
|
||||
*
|
||||
* @return instance of class FileData
|
||||
*/
|
||||
public FileData read() {
|
||||
|
||||
FileData result = null;
|
||||
|
|
|
@ -16,99 +16,119 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* FileToDatabaseMigrator is used for migrate data from file (it reads line by line) and push it into database
|
||||
* FileToDatabaseMigrator is used for migrate data from file (it reads line by
|
||||
* line) and push it into database
|
||||
*/
|
||||
@Component
|
||||
public class FileToDatabaseMigrator {
|
||||
|
||||
private static final String LECTURER_NAME_STRING = "imie";
|
||||
private static final String LECTURER_SURNAME_STRING = "nazwisko";
|
||||
private static final String LECTURER_TITLE_STRING = "tytul";
|
||||
private static final String LECTURER_NAME_STRING = "imie";
|
||||
private static final String LECTURER_SURNAME_STRING = "nazwisko";
|
||||
private static final String LECTURER_TITLE_STRING = "tytul";
|
||||
|
||||
private static final String COURSE_SYMBOL_STRING = "sym";
|
||||
private static final String COURSE_NAME_STRING = "nazwa";
|
||||
private static final String COURSE_SYMBOL_STRING = "sym";
|
||||
private static final String COURSE_NAME_STRING = "nazwa";
|
||||
|
||||
private static final String groupDay_STRING = "dzien";
|
||||
private static final String GROUP_TIME_STRING = "godz_od";
|
||||
private static final String ROOM_STRING = "sala";
|
||||
private static final String CAPACITY_STRING = "Mc";
|
||||
private static final String TYPE_GROUP= "typ";
|
||||
private static final String groupDay_STRING = "dzien";
|
||||
private static final String GROUP_TIME_STRING = "godz_od";
|
||||
private static final String ROOM_STRING = "sala";
|
||||
private static final String CAPACITY_STRING = "Mc";
|
||||
private static final String TYPE_GROUP = "typ";
|
||||
|
||||
private static final String ZAJ_CYK_ID = "zaj_cyk_id";
|
||||
private static final String GR_NR = "gr_nr";
|
||||
private static final String ZAJ_CYK_ID = "zaj_cyk_id";
|
||||
private static final String GR_NR = "gr_nr";
|
||||
|
||||
@Autowired
|
||||
private LecturerService lecturerService;
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
@Autowired
|
||||
private LecturerService lecturerService;
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
public FileToDatabaseMigrator() {
|
||||
}
|
||||
public FileToDatabaseMigrator() {
|
||||
}
|
||||
|
||||
public void migrate(FileData data) {
|
||||
Iterator<Row> rows = data.getRows();
|
||||
int courseNameIndex = data.getIndexOf(FileToDatabaseMigrator.COURSE_NAME_STRING);
|
||||
int symbolIndex = data.getIndexOf(FileToDatabaseMigrator.COURSE_SYMBOL_STRING);
|
||||
/**
|
||||
* insert data to database
|
||||
*
|
||||
* @param data FileData imported from file
|
||||
*/
|
||||
public void migrate(FileData data) {
|
||||
Iterator<Row> rows = data.getRows();
|
||||
int courseNameIndex = data.getIndexOf(FileToDatabaseMigrator.COURSE_NAME_STRING);
|
||||
int symbolIndex = data.getIndexOf(FileToDatabaseMigrator.COURSE_SYMBOL_STRING);
|
||||
|
||||
int titleIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_TITLE_STRING);
|
||||
int surnameIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
|
||||
int nameIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
|
||||
int titleIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_TITLE_STRING);
|
||||
int surnameIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
|
||||
int nameIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
|
||||
|
||||
int dayIndex = data.getIndexOf(FileToDatabaseMigrator.groupDay_STRING);
|
||||
int timeIndex = data.getIndexOf(FileToDatabaseMigrator.GROUP_TIME_STRING);
|
||||
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
||||
int capacityIndex = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
|
||||
int typeGroupIndex = data.getIndexOf(FileToDatabaseMigrator.TYPE_GROUP);
|
||||
int dayIndex = data.getIndexOf(FileToDatabaseMigrator.groupDay_STRING);
|
||||
int timeIndex = data.getIndexOf(FileToDatabaseMigrator.GROUP_TIME_STRING);
|
||||
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
||||
int capacityIndex = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
|
||||
int typeGroupIndex = data.getIndexOf(FileToDatabaseMigrator.TYPE_GROUP);
|
||||
|
||||
int zajCykIdIndex = data.getIndexOf(FileToDatabaseMigrator.ZAJ_CYK_ID);
|
||||
int grNrIndex = data.getIndexOf(FileToDatabaseMigrator.GR_NR);
|
||||
int zajCykIdIndex = data.getIndexOf(FileToDatabaseMigrator.ZAJ_CYK_ID);
|
||||
int grNrIndex = data.getIndexOf(FileToDatabaseMigrator.GR_NR);
|
||||
|
||||
while (rows.hasNext()) {
|
||||
Row row = rows.next();
|
||||
while (rows.hasNext()) {
|
||||
Row row = rows.next();
|
||||
|
||||
String courseName = row.getCell(courseNameIndex).toString().trim();
|
||||
String symbol = row.getCell(symbolIndex).toString().trim();
|
||||
String courseName = row.getCell(courseNameIndex).toString().trim();
|
||||
String symbol = row.getCell(symbolIndex).toString().trim();
|
||||
|
||||
String lecturerTitle = row.getCell(titleIndex) != null ? row.getCell(titleIndex).toString().trim() : "";
|
||||
String lecturerName = row.getCell(nameIndex) != null ? row.getCell(nameIndex).toString().trim() : "";
|
||||
String lecturerSurname = row.getCell(surnameIndex) != null ? row.getCell(surnameIndex).toString().trim()
|
||||
: "";
|
||||
String lecturerTitle = row.getCell(titleIndex) != null
|
||||
? row.getCell(titleIndex).toString().trim()
|
||||
: "";
|
||||
String lecturerName = row.getCell(nameIndex) != null ? row.getCell(nameIndex).toString().trim()
|
||||
: "";
|
||||
String lecturerSurname = row.getCell(surnameIndex) != null
|
||||
? row.getCell(surnameIndex).toString().trim()
|
||||
: "";
|
||||
|
||||
Integer zajCykId = row.getCell(zajCykIdIndex) != null ? (int) Double.parseDouble(row.getCell(zajCykIdIndex).toString().trim())
|
||||
: null;
|
||||
|
||||
Integer grNr = row.getCell(grNrIndex) != null ? (int) Double.parseDouble(row.getCell(grNrIndex).toString().trim())
|
||||
: null;
|
||||
Integer zajCykId = row.getCell(zajCykIdIndex) != null
|
||||
? (int) Double.parseDouble(row.getCell(zajCykIdIndex).toString().trim())
|
||||
: null;
|
||||
|
||||
int day = row.getCell(dayIndex) != null ? (int) Double.parseDouble(row.getCell(dayIndex).toString()) : 0;
|
||||
WeekDay groupDay = WeekDay.getDay(day - 1);
|
||||
int time = parseTimeToInt(row.getCell(timeIndex).toString());
|
||||
String room = row.getCell(roomIndex).toString().trim();
|
||||
int capacity = (int) Double.parseDouble(row.getCell(capacityIndex).toString());
|
||||
GroupType typeGroup = GroupType.getType(row.getCell(typeGroupIndex).toString());
|
||||
Integer grNr = row.getCell(grNrIndex) != null
|
||||
? (int) Double.parseDouble(row.getCell(grNrIndex).toString().trim())
|
||||
: null;
|
||||
|
||||
Course course = this.courseService.getCourseByName(courseName)
|
||||
.orElseGet(() -> this.courseService.save(new Course(courseName, symbol)));
|
||||
int day = row.getCell(dayIndex) != null
|
||||
? (int) Double.parseDouble(row.getCell(dayIndex).toString())
|
||||
: 0;
|
||||
WeekDay groupDay = WeekDay.getDay(day - 1);
|
||||
int time = parseTimeToInt(row.getCell(timeIndex).toString());
|
||||
String room = row.getCell(roomIndex).toString().trim();
|
||||
int capacity = (int) Double.parseDouble(row.getCell(capacityIndex).toString());
|
||||
GroupType typeGroup = GroupType.getType(row.getCell(typeGroupIndex).toString());
|
||||
|
||||
Lecturer lecturer = this.lecturerService.getLecturer(lecturerTitle, lecturerName, lecturerSurname)
|
||||
.orElseGet(() -> this.lecturerService
|
||||
.save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
|
||||
Course course = this.courseService.getCourseByName(courseName)
|
||||
.orElseGet(() -> this.courseService.save(new Course(courseName, symbol)));
|
||||
|
||||
Groups group = this.groupService.find(zajCykId, grNr).orElseGet(
|
||||
() -> new Groups(capacity, room, course, time, groupDay, lecturer, zajCykId, grNr, typeGroup));
|
||||
group.update(capacity, room, course, time, null, groupDay, lecturer, typeGroup);
|
||||
|
||||
this.groupService.save(group);
|
||||
Lecturer lecturer = this.lecturerService
|
||||
.getLecturer(lecturerTitle, lecturerName, lecturerSurname)
|
||||
.orElseGet(() -> this.lecturerService.save(
|
||||
new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
|
||||
|
||||
Groups group = this.groupService.find(zajCykId, grNr).orElseGet(() -> new Groups(capacity, room,
|
||||
course, time, groupDay, lecturer, zajCykId, grNr, typeGroup));
|
||||
group.update(capacity, room, course, time, null, groupDay, lecturer, typeGroup);
|
||||
|
||||
this.groupService.save(group);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param time time string in formaT hh:mm or hh.mm
|
||||
* @return int time witch is minutes from 00:00
|
||||
*/
|
||||
private static int parseTimeToInt(String time) {
|
||||
String times[] = time.split("\\.|\\:");
|
||||
return times.length == 2 ? Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]) : 0;
|
||||
|
||||
private static int parseTimeToInt(String time) {
|
||||
String times[] = time.split("\\.|\\:");
|
||||
return times.length == 2 ? Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]) : 0;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* Provides the classes necessary to to config and import related operations in
|
||||
* the app
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.configutils;
|
|
@ -38,6 +38,15 @@ public class Assignment {
|
|||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param oldAssignment old assignment that we want to move to new commision
|
||||
* @param newCommision commsion to move assiongment
|
||||
*/
|
||||
public static Assignment getNewFromAssignment(Assignment oldAssignment, Commision newCommision) {
|
||||
return new Assignment(oldAssignment.getGroup(), newCommision);
|
||||
}
|
||||
|
||||
/**
|
||||
* If it returns trues it mesans u are assigned to group accepted by algorythm
|
||||
*
|
||||
|
@ -49,9 +58,10 @@ public class Assignment {
|
|||
|
||||
/**
|
||||
* Getter of commision
|
||||
*
|
||||
* @return Commision Commision of given assignments
|
||||
*/
|
||||
public Commision getCommision(){
|
||||
public Commision getCommision() {
|
||||
return this.commision;
|
||||
}
|
||||
|
||||
|
@ -68,9 +78,13 @@ public class Assignment {
|
|||
public Assignment() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param commision commision to set
|
||||
*/
|
||||
public void setCommision(Commision commision) {
|
||||
this.commision = commision;
|
||||
this.commision = commision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Id getter
|
||||
*
|
||||
|
|
|
@ -48,8 +48,9 @@ public class User {
|
|||
}
|
||||
|
||||
public void removeGroup(Long id) {
|
||||
final Groups groupToDelete = this.studentRegisteredGrups.stream().filter(e -> e.getId().equals(id)).findFirst().get();
|
||||
this.studentRegisteredGrups.remove(groupToDelete);
|
||||
final Groups groupToDelete = this.studentRegisteredGrups.stream().filter(e -> e.getId().equals(id)).findFirst()
|
||||
.get();
|
||||
this.studentRegisteredGrups.remove(groupToDelete);
|
||||
}
|
||||
|
||||
public void claimGroup(Groups group) {
|
||||
|
@ -164,7 +165,7 @@ public class User {
|
|||
public void setToken(String token) {
|
||||
this.tokenUsageDate = new Timestamp(System.currentTimeMillis());
|
||||
this.token = token;
|
||||
this.refreshToken = UUID.randomUUID().toString();
|
||||
this.refreshToken = this.refreshToken == null ? UUID.randomUUID().toString() : this.refreshToken;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,6 +237,9 @@ public class User {
|
|||
* @return ranking points [100;500]
|
||||
*/
|
||||
public Integer getRanking() {
|
||||
if (ranking == null) {
|
||||
return 100;
|
||||
}
|
||||
return ranking;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Provides all entieites that are created in database by Hibernate
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.entities;
|
|
@ -1,9 +1,9 @@
|
|||
package com.plannaplan.exceptions;
|
||||
|
||||
/**
|
||||
* Excepction to be thrown when provided token is expired
|
||||
*/
|
||||
public class TokenExpiredException extends RuntimeException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public TokenExpiredException(String message) {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.plannaplan.exceptions;
|
||||
|
||||
/**
|
||||
* Exception to be thrown when provided user does not exist in database
|
||||
*/
|
||||
public class UserNotFoundException extends Exception {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserNotFoundException(String message) {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Provides custom for our app exceptions to get more accutrate errors info
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.exceptions;
|
|
@ -2,6 +2,9 @@ package com.plannaplan.models;
|
|||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Config data copntainer to keep tours dates and stream of dasta to import
|
||||
*/
|
||||
public class ConfigData {
|
||||
private TourData firstTour;
|
||||
private TourData secondTour;
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package com.plannaplan.models;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Container to keep data to export
|
||||
*/
|
||||
public class ExportData {
|
||||
|
||||
private static final String GROUP_FIELD = "gr_nr";
|
||||
private static final String USER_FIELD = "user_id";
|
||||
private static final String CYKL_FIELD = "zaj_cykl_id";
|
||||
|
||||
private String userId;
|
||||
private String zajCyklId;
|
||||
private String grNr;
|
||||
|
||||
/**
|
||||
* @param userId usosid
|
||||
* @param zajCyklId course cycle
|
||||
* @param grNr group number
|
||||
*/
|
||||
public ExportData(String userId, String zajCyklId, String grNr) {
|
||||
this.setUserId(userId);
|
||||
this.setZajCyklId(zajCyklId);
|
||||
this.setGrNr(grNr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return group number
|
||||
*/
|
||||
public String getGrNr() {
|
||||
return grNr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param grNr group number
|
||||
*/
|
||||
public void setGrNr(String grNr) {
|
||||
this.grNr = grNr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return course cycle
|
||||
*/
|
||||
public String getZajCyklId() {
|
||||
return zajCyklId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param zajCyklId course cycle
|
||||
*/
|
||||
public void setZajCyklId(String zajCyklId) {
|
||||
this.zajCyklId = zajCyklId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return usosid
|
||||
*/
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userId usosid
|
||||
*/
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return csv fromated line
|
||||
*/
|
||||
public String convertToCSVRecord() {
|
||||
return Stream.of(this.userId, this.zajCyklId, this.grNr).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return csv formated first line
|
||||
*/
|
||||
public static String getCSVHeader() {
|
||||
return USER_FIELD + ", " + CYKL_FIELD + ", " + GROUP_FIELD;
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,9 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
|
||||
/**
|
||||
* Wrapper for data readed from file
|
||||
*/
|
||||
public class FileData {
|
||||
|
||||
private HashMap<String, Integer> keys;
|
||||
|
@ -13,6 +16,7 @@ public class FileData {
|
|||
* FileData
|
||||
*
|
||||
* @param keys this is a hashmap of String and Integer
|
||||
*
|
||||
* @param rows this is a iterator of rows.
|
||||
*/
|
||||
public FileData(HashMap<String, Integer> keys, Iterator<Row> rows) {
|
||||
|
@ -31,6 +35,7 @@ public class FileData {
|
|||
|
||||
/*
|
||||
* setRows
|
||||
*
|
||||
* @param rows set the rows to given function
|
||||
*/
|
||||
public void setRows(Iterator<Row> rows) {
|
||||
|
@ -39,6 +44,7 @@ public class FileData {
|
|||
|
||||
/*
|
||||
* getKeys
|
||||
*
|
||||
* @return keys
|
||||
*/
|
||||
public HashMap<String, Integer> getKeys() {
|
||||
|
@ -47,6 +53,7 @@ public class FileData {
|
|||
|
||||
/*
|
||||
* setKeys
|
||||
*
|
||||
* @param keys set the key is being a struck of hashmap (String, Integer)
|
||||
*/
|
||||
public void setKeys(HashMap<String, Integer> keys) {
|
||||
|
@ -55,6 +62,7 @@ public class FileData {
|
|||
|
||||
/*
|
||||
* getIndexOf
|
||||
*
|
||||
* @return index
|
||||
*/
|
||||
public int getIndexOf(String key) {
|
||||
|
|
|
@ -3,64 +3,93 @@ package com.plannaplan.models;
|
|||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Exchange;
|
||||
|
||||
/**
|
||||
* Match of users Exchange's to be performed
|
||||
*/
|
||||
public class MatchData {
|
||||
private Exchange exchangeOne;
|
||||
private Exchange exchangeTwo;
|
||||
private Exchange exchangeOne;
|
||||
private Exchange exchangeTwo;
|
||||
|
||||
public MatchData(Exchange exchangeOne, Exchange exchangeTwo) {
|
||||
this.exchangeOne = exchangeOne;
|
||||
this.exchangeTwo = exchangeTwo;
|
||||
}
|
||||
|
||||
public Exchange getExchangeOne() {
|
||||
return this.exchangeOne;
|
||||
}
|
||||
|
||||
public Exchange getExchangeTwo() {
|
||||
return this.exchangeTwo;
|
||||
}
|
||||
|
||||
public Assignment getAssignmentTwo() {
|
||||
return this.exchangeTwo.getOwnedAssignment();
|
||||
}
|
||||
|
||||
public Assignment getAssignmentOne() {
|
||||
return this.exchangeOne.getOwnedAssignment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.getAssignmentOne().hashCode() + this.getAssignmentTwo().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
// If the object is compared with itself then return true
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if o is an instance of Complex or not "null instanceof [type]" also
|
||||
* returns false
|
||||
/**
|
||||
* create MatchData
|
||||
*
|
||||
* @param exchangeOne first Exchange of found match
|
||||
* @param exchangeTwo second Exchange of found match
|
||||
*/
|
||||
if (!(o instanceof MatchData)) {
|
||||
return false;
|
||||
public MatchData(Exchange exchangeOne, Exchange exchangeTwo) {
|
||||
this.exchangeOne = exchangeOne;
|
||||
this.exchangeTwo = exchangeTwo;
|
||||
}
|
||||
|
||||
// typecast o to Complex so that we can compare data members
|
||||
MatchData c = (MatchData) o;
|
||||
/**
|
||||
* @return first Exchange
|
||||
*/
|
||||
public Exchange getExchangeOne() {
|
||||
return this.exchangeOne;
|
||||
}
|
||||
|
||||
// Compare the data members and return accordingly
|
||||
return (this.getAssignmentOne().equals(c.getAssignmentOne()) && this.getAssignmentTwo().equals(c.getAssignmentTwo())) || (this.getAssignmentOne().equals(c.getAssignmentTwo()) && this.getAssignmentTwo().equals(c.getAssignmentOne()));
|
||||
}
|
||||
/**
|
||||
* @return second Exchange
|
||||
*/
|
||||
public Exchange getExchangeTwo() {
|
||||
return this.exchangeTwo;
|
||||
}
|
||||
|
||||
public int compare(MatchData m1) {
|
||||
return Long.compare(m1.getExchangesMsValue(), this.getExchangesMsValue());
|
||||
}
|
||||
/**
|
||||
* @return second Exchange's owned assignmetn
|
||||
*/
|
||||
public Assignment getAssignmentTwo() {
|
||||
return this.exchangeTwo.getOwnedAssignment();
|
||||
}
|
||||
|
||||
public long getExchangesMsValue(){
|
||||
return this.exchangeOne.getDataExchange().getTime() + this.exchangeTwo.getDataExchange().getTime();
|
||||
}
|
||||
/**
|
||||
* @return first Exchange's owned assignmetn
|
||||
*/
|
||||
public Assignment getAssignmentOne() {
|
||||
return this.exchangeOne.getOwnedAssignment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.getAssignmentOne().hashCode() + this.getAssignmentTwo().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof MatchData)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MatchData c = (MatchData) o;
|
||||
|
||||
return (this.getAssignmentOne().equals(c.getAssignmentOne())
|
||||
&& this.getAssignmentTwo().equals(c.getAssignmentTwo()))
|
||||
|| (this.getAssignmentOne().equals(c.getAssignmentTwo())
|
||||
&& this.getAssignmentTwo().equals(c.getAssignmentOne()));
|
||||
}
|
||||
|
||||
/**
|
||||
* comparator for MatchData. It compare it by sum of both exchange's times. For
|
||||
* example MatchData with Exchanges 11:00 and 12:00 will be less than with
|
||||
* Exchanges 12:00 and 12:00
|
||||
*
|
||||
* @param m1 MatchData instance to compare to
|
||||
* @return int less than 0 if m1 is "less than", 0 if it's equal and more than 0
|
||||
* otherwise
|
||||
*/
|
||||
public int compare(MatchData m1) {
|
||||
return Long.compare(m1.getExchangesMsValue(), this.getExchangesMsValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return sum of both exchanges java.sql.Timestanp::getTime"
|
||||
*/
|
||||
public long getExchangesMsValue() {
|
||||
return this.exchangeOne.getDataExchange().getTime() + this.exchangeTwo.getDataExchange().getTime();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package com.plannaplan.models;
|
|||
|
||||
import java.sql.Date;
|
||||
|
||||
/**
|
||||
* Container for Tours dates
|
||||
*/
|
||||
public class TourData {
|
||||
|
||||
private Date start;
|
||||
|
|
|
@ -11,18 +11,36 @@ public class UserApiResponse {
|
|||
public UserApiResponse() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return user's Surname
|
||||
*/
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for name. Reson to have setters for this class is for case if there
|
||||
* would be name and no surname or otherwise
|
||||
*
|
||||
* @param surname name to set that was obtained by api request
|
||||
*/
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return user's Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for surname. Reson to have setters for this class is for case if there
|
||||
* would be name and no surname or otherwise
|
||||
*
|
||||
* @param name name to set that was obtained by api request
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Provides readonly (mostly) classes to keep data for diffrent pourposes
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.models;
|
|
@ -4,5 +4,8 @@ import com.plannaplan.entities.AppConfig;
|
|||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* Repository for app config
|
||||
*/
|
||||
public interface AppConfigRepository extends JpaRepository<AppConfig, Long> {
|
||||
}
|
||||
|
|
|
@ -10,17 +10,15 @@ import org.springframework.data.repository.query.Param;
|
|||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* CommisionRepository.getUsers:
|
||||
* Return list of:
|
||||
* SELECT * FROM Commision WHERE owner_id = i .
|
||||
* CommisionRepository.getUsers: Return list of: SELECT * FROM Commision WHERE
|
||||
* owner_id = i .
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
* Where i, ?1 are equale to variables.
|
||||
*
|
||||
* CommisionRepository.getNewestCommision
|
||||
* Return list of:
|
||||
* SELECT * FROM Commision WHERE owner_id = i Order by commisionDate desc.
|
||||
* CommisionRepository.getNewestCommision Return list of: SELECT * FROM
|
||||
* Commision WHERE owner_id = i Order by commisionDate desc.
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
* Where i, ?1 are equale to variables.
|
||||
*/
|
||||
@Repository
|
||||
public interface CommisionRepository extends JpaRepository<Commision, Long> {
|
||||
|
@ -30,4 +28,10 @@ public interface CommisionRepository extends JpaRepository<Commision, Long> {
|
|||
@Query("FROM Commision WHERE owner_id = ?1 order by commisionDate desc")
|
||||
List<Commision> getNewestCommision(@Param("owner_id") Long id);
|
||||
|
||||
/**
|
||||
* @return ammount of uniqe users that have a commision placed on first array
|
||||
* element
|
||||
*/
|
||||
@Query("SELECT COUNT(DISTINCT owner_id) AS count FROM Commision")
|
||||
Object[] getUsersAssigned();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* Provides jpa repositories interfaces to comunicate with database. These are
|
||||
* used exclusively in services
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.repositories;
|
|
@ -91,12 +91,14 @@ public class AssignmentService {
|
|||
if (com.isPresent()) {
|
||||
final List<Assignment> assignments = this.getCommisionAssignments(com.get());
|
||||
assignments.forEach(a -> {
|
||||
final Groups group = a.getGroup();
|
||||
if (group.getCapacity() > group.getRegisteredStudents().size()) {
|
||||
e.claimGroup(group);
|
||||
accepted.add(group);
|
||||
} else {
|
||||
removed.add(group);
|
||||
if (a.isAccepted() == false) {
|
||||
final Groups group = a.getGroup();
|
||||
if (group.getCapacity() > group.getRegisteredStudents().size()) {
|
||||
e.claimGroup(group);
|
||||
accepted.add(group);
|
||||
} else {
|
||||
removed.add(group);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -104,4 +106,12 @@ public class AssignmentService {
|
|||
this.emailService.sendAcceptationResult(e, new EmailAcceptedData(accepted, removed));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param toSave list of entites to save to db
|
||||
* @return list of assignments entities with ids from db
|
||||
*/
|
||||
public List<Assignment> saveAll(List<Assignment> toSave) {
|
||||
return this.repo.saveAll(toSave);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package com.plannaplan.services;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.models.ExportData;
|
||||
import com.plannaplan.repositories.AssignmentRepository;
|
||||
import com.plannaplan.repositories.CommisionRepository;
|
||||
|
||||
|
@ -22,10 +24,19 @@ public class CommisionService {
|
|||
private CommisionRepository repo;
|
||||
@Autowired
|
||||
private AssignmentRepository aRepository;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
public CommisionService() {
|
||||
}
|
||||
|
||||
/**
|
||||
* save to database commision. It also checks for missing assignments from
|
||||
* previous commision (you can not get rid of accepted assignment)
|
||||
*
|
||||
* @param commision to save to db
|
||||
* @return Commision instance with id from database
|
||||
*/
|
||||
public Commision save(Commision commision) {
|
||||
Optional<Commision> lastCommision = this.getNewestCommision(commision.getCommisionOwner());
|
||||
if (lastCommision.isPresent()) {
|
||||
|
@ -34,6 +45,7 @@ public class CommisionService {
|
|||
assignment.setPastAssignment(true);
|
||||
this.aRepository.save(assignment);
|
||||
});
|
||||
|
||||
}
|
||||
this.repo.save(commision);
|
||||
return commision;
|
||||
|
@ -69,4 +81,21 @@ public class CommisionService {
|
|||
public long getCommisionsAmmount() {
|
||||
return this.repo.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of ExportData inmstancces keeping data to exprt to file
|
||||
*/
|
||||
public List<ExportData> getExportData() {
|
||||
final List<ExportData> response = new ArrayList<>();
|
||||
|
||||
this.userService.getAllStudents().forEach(student -> {
|
||||
student.getStudentRegisteredGrups().forEach(group -> {
|
||||
response.add(new ExportData(student.getUsosId(), Integer.toString(group.getZajCykId()),
|
||||
Integer.toString(group.getGrNr())));
|
||||
});
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Service of CourseService which can get(Course By Name, All Courses, Courses Ammount ), save, delete course.
|
||||
* Service of CourseService which can get(Course By Name, All Courses, Courses
|
||||
* Ammount ), save, delete course.
|
||||
*/
|
||||
|
||||
@Service
|
||||
|
@ -18,42 +19,46 @@ public class CourseService {
|
|||
@Autowired
|
||||
private CourseRepository repo;
|
||||
|
||||
/*
|
||||
/**
|
||||
* getCourseByName
|
||||
* Return Course By Name
|
||||
*
|
||||
* @param name name of course to be found
|
||||
* @return Course By Name
|
||||
*/
|
||||
public Optional<Course> getCourseByName(String name) {
|
||||
return this.repo.findByName(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* getAllCourses
|
||||
* Return List of get courses
|
||||
/**
|
||||
*
|
||||
* @return all courses from db
|
||||
*/
|
||||
public List<Course> getAllCourses() {
|
||||
return this.repo.findAll();
|
||||
}
|
||||
|
||||
/*
|
||||
* save
|
||||
/**
|
||||
* save to db
|
||||
*
|
||||
* @param course which course you would like to save
|
||||
* @return Course instance with id from db
|
||||
*/
|
||||
public Course save(Course course) {
|
||||
this.repo.save(course);
|
||||
return course;
|
||||
}
|
||||
|
||||
/*
|
||||
* delete
|
||||
/**
|
||||
* delete course from db
|
||||
*
|
||||
* @param course which course you would like to delete
|
||||
*/
|
||||
public void delete(Course course) {
|
||||
this.repo.delete(course);
|
||||
}
|
||||
|
||||
/*
|
||||
* getCoursesAmmount
|
||||
* Return a ammount of courses
|
||||
/**
|
||||
* @return ammount of courses in db
|
||||
*/
|
||||
public int getCoursesAmmount() {
|
||||
return (int) this.repo.count();
|
||||
|
|
|
@ -12,6 +12,9 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Service to manage app events
|
||||
*/
|
||||
@Service
|
||||
public class EventService {
|
||||
|
||||
|
@ -29,6 +32,9 @@ public class EventService {
|
|||
System.out.println("Checking for groups");
|
||||
}
|
||||
|
||||
/**
|
||||
* perfroms checks for matching exchanges daily
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 * * *")
|
||||
public void performExchangeService() {
|
||||
System.out.println("Performing Exchange");
|
||||
|
@ -53,6 +59,10 @@ public class EventService {
|
|||
jobsMap.put(taskId, scheduledTask);
|
||||
}
|
||||
|
||||
/**
|
||||
* init resources needed for dynamicly creating new tasks (needed to set tours
|
||||
* end events)
|
||||
*/
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
this.scheduler = new ThreadPoolTaskScheduler();
|
||||
|
|
|
@ -19,6 +19,9 @@ import com.plannaplan.repositories.ExchangeRepository;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Service to manage Exchanges
|
||||
*/
|
||||
@Service
|
||||
public class ExchangeService {
|
||||
|
||||
|
@ -50,6 +53,9 @@ public class ExchangeService {
|
|||
return this.repo.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of all exchanges in database
|
||||
*/
|
||||
public List<Exchange> getAllExchanges() {
|
||||
return this.repo.findAll();
|
||||
}
|
||||
|
@ -78,6 +84,12 @@ public class ExchangeService {
|
|||
return this.repo.checkForExchange(assignment, group);
|
||||
}
|
||||
|
||||
/**
|
||||
* method to perform Exchange algorythm. It search for matches and swap
|
||||
* assignments between latests user commisions if it can be performed. After
|
||||
* swap we block users matches that contains switched groups. After algorythm
|
||||
* email is being sent to all users with information about performed exchanges
|
||||
*/
|
||||
public void performExchange() {
|
||||
final List<MatchData> matchData = this.getMatches();
|
||||
final List<Long> performedAssignmentExchanges = new ArrayList<>();
|
||||
|
@ -127,6 +139,9 @@ public class ExchangeService {
|
|||
this.repo.deleteAll(exchangesToDelete);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of matches found in database
|
||||
*/
|
||||
public List<MatchData> getMatches() {
|
||||
final List<MatchData> matches = this.repo.getMatches().stream().map(m -> {
|
||||
final Exchange exchangeOne = (Exchange) m[0];
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.plannaplan.services;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
@ -18,7 +19,6 @@ import org.springframework.stereotype.Service;
|
|||
* Service of GroupService which can find(optional), get(By Course, Groups
|
||||
* Ammount, Group By Id, find Not Existing Group), save, delete group.
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class GroupService {
|
||||
@Autowired
|
||||
|
@ -27,34 +27,84 @@ public class GroupService {
|
|||
public GroupService() {
|
||||
}
|
||||
|
||||
/**
|
||||
* find group with given properties
|
||||
*
|
||||
* @param time scheduled time for group as int of minutes passed from 00:00
|
||||
* @param capacity capacity of group
|
||||
* @param room class room
|
||||
* @return optional with Groups instance if found
|
||||
*/
|
||||
public Optional<Groups> find(int time, int capacity, String room) {
|
||||
return this.repo.find(time, room, capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* find group with given properties
|
||||
*
|
||||
* @param zajCykId proteprty from usos
|
||||
* @param nrGr group number
|
||||
* @return optional with Groups instance if found
|
||||
*/
|
||||
public Optional<Groups> find(Integer zajCykId, Integer nrGr) {
|
||||
return this.repo.find(zajCykId, nrGr);
|
||||
}
|
||||
|
||||
/**
|
||||
* find group with given properties
|
||||
*
|
||||
* @param id course id of groups belogns to
|
||||
* @return list of found groups
|
||||
*/
|
||||
public List<Groups> getGroupsByCourse(Long id) {
|
||||
return this.repo.getByCourse(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* save group to database
|
||||
*
|
||||
* @param group insatnce to be saved
|
||||
* @return new instance that has id form database
|
||||
*/
|
||||
public Groups save(Groups group) {
|
||||
return this.repo.save(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete from database
|
||||
*
|
||||
* @param groups isntance to delete
|
||||
*/
|
||||
public void delete(Groups groups) {
|
||||
this.repo.delete(groups);
|
||||
}
|
||||
|
||||
/**
|
||||
* get hom manyh groups are in database in general
|
||||
*
|
||||
* @return int - groups ammount
|
||||
*/
|
||||
public int getGroupsAmmount() {
|
||||
return (int) this.repo.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* find group with given properties
|
||||
*
|
||||
* @param id group id
|
||||
* @return optional with group if found
|
||||
*/
|
||||
public Optional<Groups> getGroupById(Long id) {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* get wich of provided id is not existind groups
|
||||
*
|
||||
* @param ids list of ids to check
|
||||
* @return optional with id that is not group if found. If there is multiple
|
||||
* will be returned first found
|
||||
*/
|
||||
public Optional<Long> findNotExistingGroup(List<Long> ids) {
|
||||
for (Long oneId : ids) {
|
||||
if (this.repo.existsById(oneId) == false) {
|
||||
|
@ -104,4 +154,22 @@ public class GroupService {
|
|||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return amount of groups with full capacity taken
|
||||
*/
|
||||
public Integer getFullgroupsAmmount() {
|
||||
Integer response = 0;
|
||||
final Iterator<Groups> groups = this.repo.findAll().iterator();
|
||||
|
||||
while (groups.hasNext()) {
|
||||
final Groups group = groups.next();
|
||||
if (group.getCapacity() <= group.getRegisteredStudents().size()) {
|
||||
response += 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,16 @@
|
|||
package com.plannaplan.services;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.exceptions.UserNotFoundException;
|
||||
import com.plannaplan.models.UserApiResponse;
|
||||
import com.plannaplan.repositories.CommisionRepository;
|
||||
import com.plannaplan.repositories.UserRepository;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
|
@ -25,6 +28,12 @@ public class UserService {
|
|||
@Autowired
|
||||
private UsosApiService service;
|
||||
|
||||
@Autowired
|
||||
private CommisionRepository comRepo;
|
||||
|
||||
@Autowired
|
||||
private CommisionService comService;
|
||||
|
||||
public UserService() {
|
||||
super();
|
||||
}
|
||||
|
@ -169,4 +178,52 @@ public class UserService {
|
|||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ammount of how many users created an assignment
|
||||
*/
|
||||
public int getAmmountOfUsersWithAssignedGroups() {
|
||||
int response = 0;
|
||||
|
||||
final Object dbResponse = this.comRepo.getUsersAssigned()[0];
|
||||
if (dbResponse != null) {
|
||||
response = ((Long) dbResponse).intValue();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ammount of how many users haven't created an assignment yet
|
||||
*/
|
||||
public Integer getAmmountOfUsersWithNoAssignedGroups() {
|
||||
return this.getAllStudents().size() - this.getAmmountOfUsersWithAssignedGroups();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ammount of how many users have full schedule accepted
|
||||
*/
|
||||
public Integer getAmmountOfUsersWithAcceptedSchedules() {
|
||||
final List<User> students = this.getAllStudents();
|
||||
Integer accepted = 0;
|
||||
|
||||
final Iterator<User> it = students.iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
final User user = it.next();
|
||||
final Optional<Commision> com = this.comService.getNewestCommision(user);
|
||||
if (com.isPresent() && user.getStudentRegisteredGrups().size() == com.get().getAssignments().size()) {
|
||||
accepted += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return accepted;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ammount of how many users have partly or none schedule accepted
|
||||
*/
|
||||
public Integer getAmmountOfUsersWithNoAcceptedSchedules() {
|
||||
return this.getAllStudents().size() - this.getAmmountOfUsersWithAcceptedSchedules();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* Provides service classes to make operations with entities or comunicate with
|
||||
* external systems.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.services;
|
|
@ -1,23 +1,39 @@
|
|||
package com.plannaplan.types;
|
||||
|
||||
/**
|
||||
* GroupType contains types: LECTURE, CLASS, LAB, SEMINAR, CONSERVATORY, PRATICE
|
||||
* GroupType contains types: LECTURE, CLASS, LAB, SEMINAR, CONSERVATORY, PRATICE
|
||||
*/
|
||||
|
||||
public enum GroupType {
|
||||
LECTURE("Wykład"), CLASS("Ćwiczenia"), LAB("Laboratorium"), SEMINAR("Seminarium"),CONSERVATORY("Konwersatorium"), PRATICE("Praktyka");
|
||||
LECTURE("Wykład"), CLASS("Ćwiczenia"), LAB("Laboratorium"), SEMINAR("Seminarium"), CONSERVATORY("Konwersatorium"),
|
||||
PRATICE("Praktyka");
|
||||
|
||||
public final String type;
|
||||
|
||||
private GroupType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type as string
|
||||
* @return Enum converted from provided string
|
||||
*/
|
||||
public final static GroupType getType(String type) {
|
||||
for (GroupType d : values()) {
|
||||
if (d.type.equals(type)) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type group type to check
|
||||
* @return general convertion to bring down tours to two generals LECTURE and
|
||||
* CLASS. To class are included: CLASS, LAB, SEMINAR, CONSERVATORY,
|
||||
* PRATICE.
|
||||
*/
|
||||
public final static GroupType isLectureOrClass(GroupType type) {
|
||||
return type == GroupType.LECTURE ? GroupType.LECTURE : GroupType.CLASS;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package com.plannaplan.types;
|
||||
|
||||
/**
|
||||
* UserRoles contains types: STUDENT, DEANERY, ADMIN, TEST_USER
|
||||
* UserRoles contains types: STUDENT, DEANERY, ADMIN, TEST_USER
|
||||
*/
|
||||
|
||||
|
||||
public enum UserRoles {
|
||||
STUDENT, DEANERY, ADMIN, TEST_USER
|
||||
STUDENT, DEANERY, ADMIN, TEST_USER, DEVELOPER
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Provides enums for different goals.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.types;
|
|
@ -0,0 +1,14 @@
|
|||
package com.plannaplan.models;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExportDataTest {
|
||||
|
||||
@Test
|
||||
public void shouldConvertDataToCSVRecord() {
|
||||
final ExportData data = new ExportData("4234", "242352", "12");
|
||||
assertTrue(data.convertToCSVRecord().equals("4234,242352,12"));
|
||||
}
|
||||
}
|
|
@ -131,6 +131,34 @@ public class AssignmentServiceTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldAcceptTwoTours() throws InterruptedException {
|
||||
final Groups group = this.groupService.save(new Groups(5, null, null, 840, WeekDay.MONDAY, null));
|
||||
final Groups group2 = this.groupService.save(new Groups(5, null, null, 840, WeekDay.MONDAY, null));
|
||||
|
||||
User user = this.userService.save(new User(null, null,
|
||||
"shouldNotAcceptForOnePerson-" + UUID.randomUUID().toString() + "@AssignmentService.test", null,
|
||||
UserRoles.STUDENT, 234));
|
||||
|
||||
final Commision com = this.comServie.save(new Commision(user));
|
||||
|
||||
this.service.save(new Assignment(group, com));
|
||||
|
||||
this.service.callAcceptAlgorythm();
|
||||
|
||||
user = this.userService.getById(user.getId()).get();
|
||||
assertTrue(user.getStudentRegisteredGrups().size() == 1);
|
||||
|
||||
this.service.save(new Assignment(group2, com));
|
||||
|
||||
this.service.callAcceptAlgorythm();
|
||||
|
||||
user = this.userService.getById(user.getId()).get();
|
||||
assertTrue(user.getStudentRegisteredGrups().size() == 2);
|
||||
|
||||
}
|
||||
|
||||
private void addAssignmentToCommision(Commision com) {
|
||||
Assignment a = new Assignment(null, com);
|
||||
this.service.save(a);
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package com.plannaplan.types;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GroupTypeTest {
|
||||
@Test
|
||||
public void shouldBeLecture() {
|
||||
assertTrue(GroupType.isLectureOrClass(GroupType.LECTURE) == GroupType.LECTURE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBeClass1() {
|
||||
assertTrue(GroupType.isLectureOrClass(GroupType.CLASS) == GroupType.CLASS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBeClass2() {
|
||||
assertTrue(GroupType.isLectureOrClass(GroupType.CONSERVATORY) == GroupType.CLASS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBeClass3() {
|
||||
assertTrue(GroupType.isLectureOrClass(GroupType.LAB) == GroupType.CLASS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBeClass4() {
|
||||
assertTrue(GroupType.isLectureOrClass(GroupType.PRATICE) == GroupType.CLASS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBeClass5() {
|
||||
assertTrue(GroupType.isLectureOrClass(GroupType.SEMINAR) == GroupType.CLASS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCastFromString1() {
|
||||
assertTrue(GroupType.getType("Ćwiczenia") == GroupType.CLASS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCastFromString2() {
|
||||
assertTrue(GroupType.getType("Wykład") == GroupType.LECTURE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCastFromString3() {
|
||||
assertTrue(GroupType.getType("Laboratorium") == GroupType.LAB);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCastFromString4() {
|
||||
assertTrue(GroupType.getType("Seminarium") == GroupType.SEMINAR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCastFromString5() {
|
||||
assertTrue(GroupType.getType("Konwersatorium") == GroupType.CONSERVATORY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCastFromString6() {
|
||||
assertTrue(GroupType.getType("Praktyka") == GroupType.PRATICE);
|
||||
}
|
||||
|
||||
}
|
|
@ -62,6 +62,14 @@
|
|||
<version>4.5.10</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
|
|
|
@ -21,6 +21,9 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||
|
||||
import com.plannaplan.services.ConfiguratorService;
|
||||
|
||||
/**
|
||||
* Root class of Application.
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class App {
|
||||
|
@ -46,7 +49,9 @@ public class App {
|
|||
|
||||
/**
|
||||
* method to import mocked data to testing app after startz. It is called only
|
||||
* in dev profile
|
||||
* in dev profile. Note that tests are written to this app state so if you
|
||||
* change ConfigData it can have an impact to other tests like
|
||||
* CommisionControllerTest
|
||||
*/
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void importData() {
|
||||
|
|
|
@ -3,6 +3,9 @@ package com.plannaplan;
|
|||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* Class to generate logo string on start application and make logs info
|
||||
*/
|
||||
public class Logo {
|
||||
|
||||
public static final String ANSI_RESET = "\u001B[0m";
|
||||
|
@ -35,6 +38,11 @@ ANSI_RESET;
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* return init string to log
|
||||
* @param isDev is spring profile dev
|
||||
* @return string to print in log
|
||||
*/
|
||||
public static String getInitInfo(boolean isDev){
|
||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
@ -45,6 +53,11 @@ ANSI_RESET;
|
|||
return ANSI_BLACK + dtf.format(now) + ANSI_YELLOW + " plannaplan" + ANSI_RESET + " initializing [" +ANSI_BLUE + "prod" + ANSI_RESET +"]";
|
||||
}
|
||||
|
||||
/**
|
||||
* return start string to log
|
||||
* @param isDev is spring profile dev
|
||||
* @return string to print in log
|
||||
*/
|
||||
public static String getStartedInfo(boolean isDev){
|
||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
|
|
@ -18,6 +18,9 @@ import springfox.documentation.spi.DocumentationType;
|
|||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* Config class of Swagger to generate rest api documentation
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class Swagger2Config extends WebMvcConfigurationSupport {
|
||||
|
|
|
@ -12,19 +12,26 @@ import io.swagger.annotations.ApiParam;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.exceptions.UserNotFoundException;
|
||||
import com.plannaplan.models.ExportData;
|
||||
import com.plannaplan.responses.mappers.CommisionResponseMappers;
|
||||
import com.plannaplan.responses.models.CommisionResponse;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.CommisionService;
|
||||
import com.plannaplan.services.ConfiguratorService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.types.AppState;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -35,12 +42,20 @@ import org.springframework.util.Assert;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.plannaplan.responses.mappers.AssignmentResponseMappers;
|
||||
import com.plannaplan.responses.models.AssignmentDetailedResponse;
|
||||
import com.plannaplan.responses.models.AssignmentResponse;
|
||||
|
||||
/**
|
||||
* Rest controller to Commision and Assignment related endpoints. More detailed
|
||||
* api docs is available via swagger
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/commisions")
|
||||
|
@ -56,9 +71,17 @@ public class CommisionController extends TokenBasedController {
|
|||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
@Autowired
|
||||
private ConfiguratorService configuratorService;
|
||||
|
||||
public CommisionController() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groups to make assignmetns
|
||||
* @param userId user to assign to groups
|
||||
* @return was operations success
|
||||
*/
|
||||
@PostMapping(value = { "/user", "/user/{id}" })
|
||||
@ApiOperation(value = "Create commision with assignents to given groups. If group doesn't exist error will be thrown")
|
||||
public ResponseEntity<String> addCommision(
|
||||
|
@ -66,7 +89,7 @@ public class CommisionController extends TokenBasedController {
|
|||
@PathVariable(name = "id", required = false) Long userId) {
|
||||
|
||||
try {
|
||||
|
||||
final AppState appState = this.configuratorService.getCurrentConfig().getCurrentState();
|
||||
final User asker = this.getCurrentUser()
|
||||
.orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||
|
||||
|
@ -76,23 +99,51 @@ public class CommisionController extends TokenBasedController {
|
|||
: asker;
|
||||
|
||||
Assert.isTrue((asker.getRole() == UserRoles.DEANERY && user.getRole() == UserRoles.STUDENT
|
||||
|| (asker.getId().equals(user.getId()) && user.getRole() == UserRoles.STUDENT)),
|
||||
&& appState == AppState.NO_TOUR
|
||||
|| (asker.getId().equals(user.getId()) && user.getRole() == UserRoles.STUDENT
|
||||
&& appState != AppState.NO_TOUR)),
|
||||
"Incorrect attempt to change plan");
|
||||
|
||||
Optional<Long> notExistingGroup = this.groupServcicxe.findNotExistingGroup(groups);
|
||||
Assert.isTrue(!notExistingGroup.isPresent(), "Group "
|
||||
+ notExistingGroup.orElse(Long.MIN_VALUE).toString() + "doesn't exist");
|
||||
|
||||
final Optional<Commision> comPrev = this.commisionService.getNewestCommision(user);
|
||||
final Commision com = new Commision(user, asker);
|
||||
this.commisionService.save(com);
|
||||
|
||||
final List<Long> addedGroups = new ArrayList<>();
|
||||
final List<Assignment> addedAssignments = new ArrayList<>();
|
||||
|
||||
groups.stream().forEach((groupId) -> {
|
||||
Groups group = this.groupServcicxe.getGroupById(groupId)
|
||||
.orElseThrow(() -> new NullPointerException());
|
||||
Assignment a = new Assignment(group, com);
|
||||
this.assignmentService.save(a);
|
||||
addedAssignments.add(a);
|
||||
// this.assignmentService.save(a);
|
||||
addedGroups.add(groupId);
|
||||
});
|
||||
|
||||
boolean isBad = false;
|
||||
if (comPrev.isPresent()) {
|
||||
final Iterator<Assignment> it = comPrev.get().getAssignments().iterator();
|
||||
|
||||
while (it.hasNext() && !isBad) {
|
||||
final Assignment a = it.next();
|
||||
if (a.isAccepted() && !addedGroups.contains(a.getGroup().getId())) {
|
||||
isBad = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isBad) {
|
||||
return new ResponseEntity<>("Error. You can't delete accepted assignmet",
|
||||
HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
this.commisionService.save(com);
|
||||
this.assignmentService.saveAll(addedAssignments);
|
||||
|
||||
return new ResponseEntity<>("Succes", HttpStatus.OK);
|
||||
} catch (UserNotFoundException exception) {
|
||||
return new ResponseEntity<>(exception.getMessage(), HttpStatus.NOT_FOUND);
|
||||
|
@ -101,25 +152,62 @@ public class CommisionController extends TokenBasedController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groups should include groups list in response
|
||||
* @return list of user all commisions (history of schedules)
|
||||
* @throws UserNotFoundException if user was found
|
||||
*/
|
||||
@GetMapping("/user")
|
||||
@ApiOperation("Return list of user all commisions (history of schedules)")
|
||||
public ResponseEntity<List<? extends CommisionResponse>> getAlCommisions(
|
||||
@RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if we want to display wiht commision's group ids") Boolean groups)
|
||||
@RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if we want to display wiht commision's group ids") Boolean groups,
|
||||
@RequestParam(name = "extraInfo", defaultValue = "false") @ApiParam(value = "Boolean if we want to display extra info about listed groups. Works only if we have groups set top true") Boolean extraInfo)
|
||||
throws UserNotFoundException {
|
||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
|
||||
|
||||
List<? extends CommisionResponse> result;
|
||||
|
||||
final List<Commision> commisions = this.commisionService.getUsersCommisions(user);
|
||||
if (!groups) {
|
||||
result = CommisionResponseMappers.mapToResponse(this.commisionService.getUsersCommisions(user));
|
||||
result = CommisionResponseMappers.mapToResponse(commisions);
|
||||
} else {
|
||||
result = CommisionResponseMappers
|
||||
.mapToResponseWithGroups(this.commisionService.getUsersCommisions(user));
|
||||
if (extraInfo) {
|
||||
result = CommisionResponseMappers.mapToResponseWithExtraInforGroups(commisions);
|
||||
} else {
|
||||
result = CommisionResponseMappers.mapToResponseWithGroups(commisions);
|
||||
}
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of user latests assignmets
|
||||
* @throws UserNotFoundException if user was not found bny token
|
||||
*/
|
||||
@GetMapping("/user/assignments")
|
||||
@ApiOperation("Return list of latest user commision assignments. User is recognized via token")
|
||||
public ResponseEntity<List<AssignmentDetailedResponse>> getAllAssignmets() throws UserNotFoundException {
|
||||
final User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
|
||||
|
||||
final Optional<Commision> latestCommision = this.commisionService.getNewestCommision(user);
|
||||
|
||||
if (latestCommision.isEmpty()) {
|
||||
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
final List<AssignmentDetailedResponse> response = AssignmentResponseMappers
|
||||
.mapAssignmetnToDetialedResponse(latestCommision.get().getAssignments());
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return current schedule of user indenified via token
|
||||
* @throws Exception if incorrect role was trying to see self schedule (for
|
||||
* example DEANERY don't have a schedule)
|
||||
*/
|
||||
@GetMapping("/user/schedule")
|
||||
@ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.")
|
||||
public ResponseEntity<List<AssignmentResponse>> getCurrentAssignments() throws Exception {
|
||||
|
@ -137,6 +225,12 @@ public class CommisionController extends TokenBasedController {
|
|||
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userId user id in db
|
||||
* @param groups should commision include assigned groups list
|
||||
* @return list of commisions for given user
|
||||
* @throws UserNotFoundException
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@GetMapping("/user/{id}")
|
||||
@ApiOperation("Return list of commisions for given user. To be able to access this data u need to provide DEANERY token")
|
||||
|
@ -156,6 +250,11 @@ public class CommisionController extends TokenBasedController {
|
|||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userId schedule to display owner
|
||||
* @return user's schedule
|
||||
* @throws Exception if incorrect access atempt occured
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@GetMapping("/user/{id}/schedule")
|
||||
@ApiOperation(value = "Return given user current assignemts (from newest commision). DEANERY Token needs to be provided.")
|
||||
|
@ -177,4 +276,32 @@ public class CommisionController extends TokenBasedController {
|
|||
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param response spring response to set headers
|
||||
*/
|
||||
@GetMapping("/export/csv")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@ApiOperation(value = "Export acceptes assignmetns as csv file to import to usos. You need to provide ADMIN token in order to get access to this data.")
|
||||
public void getFile(HttpServletResponse response) {
|
||||
try {
|
||||
String csvString = ExportData.getCSVHeader() + "\n";
|
||||
final Iterator<ExportData> it = this.commisionService.getExportData().iterator();
|
||||
while (it.hasNext()) {
|
||||
final ExportData data = it.next();
|
||||
csvString += (data.convertToCSVRecord() + "\n");
|
||||
}
|
||||
|
||||
final InputStream is = IOUtils.toInputStream(csvString, "UTF-8");
|
||||
|
||||
IOUtils.copy(is, response.getOutputStream());
|
||||
response.setContentType("application/csv");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"export.csv\"");
|
||||
response.flushBuffer();
|
||||
} catch (IOException ex) {
|
||||
|
||||
throw new RuntimeException("IOError writing file to output stream");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.plannaplan.App;
|
|||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.models.ConfigData;
|
||||
import com.plannaplan.models.TourData;
|
||||
import com.plannaplan.responses.models.ConfigTourResponse;
|
||||
import com.plannaplan.security.cas.CasUserIdentity;
|
||||
import com.plannaplan.security.cas.CasValidationExcepiton;
|
||||
import com.plannaplan.security.cas.CasValidator;
|
||||
|
@ -34,7 +35,12 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* Rest controller to Config related endpoints. More detailed api docs is
|
||||
* available via swagger
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/configurator")
|
||||
|
@ -47,14 +53,22 @@ public class ConfigController {
|
|||
|
||||
@Value("${plannaplan.dev}")
|
||||
private boolean isDev;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ConfiguratorService contrl;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* @param file file .xlsx that contains courses and groups with
|
||||
* apoinnted rules
|
||||
* @param firstTourBegin formated string dd.MM.yyyy
|
||||
* @param firstTourEnd formated string dd.MM.yyyy
|
||||
* @param secondTourBegin formated string dd.MM.yyyy
|
||||
* @param secondTourEnd formated string dd.MM.yyyy
|
||||
* @return was config success
|
||||
*/
|
||||
@PostMapping(path = "/config", consumes = { "multipart/form-data" })
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@ApiOperation("Imports data to system. To call you need to provide ADMIN token")
|
||||
|
@ -82,7 +96,13 @@ public class ConfigController {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param firstTourBegin formated string dd.MM.yyyy
|
||||
* @param firstTourEnd formated string dd.MM.yyyy
|
||||
* @param secondTourBegin formated string dd.MM.yyyy
|
||||
* @param secondTourEnd formated string dd.MM.yyyy
|
||||
* @return was operation successful
|
||||
*/
|
||||
@PostMapping(path = "/config/tours")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@ApiOperation("Set tours dates. To call you need to provide ADMIN token")
|
||||
|
@ -104,12 +124,15 @@ public class ConfigController {
|
|||
return new ResponseEntity<>("Sucess", HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file file .xlsx that contains courses and groups with
|
||||
* @return was operation successfull
|
||||
*/
|
||||
@PostMapping(path = "/config/courses", consumes = { "multipart/form-data" })
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@ApiOperation("Imports data to system. To call you need to provide ADMIN token")
|
||||
public ResponseEntity<String> configAppChangeCources(
|
||||
@RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file)
|
||||
{
|
||||
@RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file) {
|
||||
try {
|
||||
this.contrl.importCoursesStream(file.getInputStream());
|
||||
return new ResponseEntity<>("Sucess", HttpStatus.OK);
|
||||
|
@ -118,15 +141,20 @@ public class ConfigController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ticket CAS ticket to get user wuthority
|
||||
* @return was admin created
|
||||
*/
|
||||
@PostMapping(path = "/admin/init")
|
||||
@ApiOperation("It can be run only in the initialization of the application. It will create admin user to manage the application.")
|
||||
public ResponseEntity<String> initAdmin(@RequestParam("ticket") @ApiParam(value = "Ticket for validation.") String ticket){
|
||||
if (this.userService.adminExists()){
|
||||
public ResponseEntity<String> initAdmin(
|
||||
@RequestParam("ticket") @ApiParam(value = "Ticket for validation.") String ticket) {
|
||||
if (this.userService.adminExists()) {
|
||||
return new ResponseEntity<>("Admin had been already created.", HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
|
||||
final CasValidator validator = isDev ? new DefaultUAMCasValidator(serviceUrl, ticket)
|
||||
: new CustomUAMCasValidator(serviceUrl, ticket);
|
||||
: new CustomUAMCasValidator(serviceUrl, ticket);
|
||||
|
||||
try {
|
||||
final CasUserIdentity casUserIdentity = validator.validate();
|
||||
|
@ -140,5 +168,28 @@ public class ConfigController {
|
|||
} catch (Exception e) {
|
||||
return new ResponseEntity<>("Internal Server Error", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return api response entity
|
||||
*/
|
||||
@GetMapping(path = "/config/tour")
|
||||
@ApiOperation("It will return what tour is currently on.")
|
||||
public ResponseEntity<ConfigTourResponse> getCurrentTourDate() {
|
||||
final ConfigTourResponse response = new ConfigTourResponse(this.contrl.getCurrentConfig().getCurrentState());
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return api response entity
|
||||
*/
|
||||
@Deprecated
|
||||
@GetMapping(path = "/admin/tour")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@ApiOperation("It will return what tour is currently on. You need to provide admin token. It is depreaceted use /configurator/config/tour isntead.")
|
||||
public ResponseEntity<ConfigTourResponse> getTourDate() {
|
||||
final ConfigTourResponse response = new ConfigTourResponse(this.contrl.getCurrentConfig().getCurrentState());
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
|
@ -29,6 +29,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import com.plannaplan.responses.models.abstracts.CoursesResponse;
|
||||
|
||||
/**
|
||||
* Rest controller to Courses related endpoints. More detailed api docs is
|
||||
* available via swagger
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/courses")
|
||||
|
@ -41,6 +45,11 @@ public class CoursesController {
|
|||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
/**
|
||||
* @param groups should include groups in response
|
||||
* @param takenPlaces should include groups in response
|
||||
* @return list of all courses in system
|
||||
*/
|
||||
@GetMapping("/all")
|
||||
@ApiOperation(value = "Return all courses")
|
||||
public ResponseEntity<List<? extends CoursesResponse>> getMethodName(
|
||||
|
@ -59,7 +68,7 @@ public class CoursesController {
|
|||
final HashMap<Long, Integer> ammounts = this.groupService.getTakenPlaces(course.getGroups());
|
||||
|
||||
course.getGroups().stream().forEach(group -> {
|
||||
if (group.getType() == GroupType.CLASS) {
|
||||
if (GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS) {
|
||||
classes.add(new GroupWithCapacityResponse(group, ammounts.get(group.getId())));
|
||||
} else {
|
||||
lectures.add(new GroupWithCapacityResponse(group, ammounts.get(group.getId())));
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
package com.plannaplan.controllers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.models.TourData;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.ConfiguratorService;
|
||||
import com.plannaplan.services.ExchangeService;
|
||||
|
||||
/**
|
||||
* Rest controller to enpoint that help deveopler test the app
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/developer")
|
||||
@Api(tags = {
|
||||
"DeveloperController" }, value = "DeveloperController", description = "All endpoints to use in development time to help app testing")
|
||||
public class DeveloperController {
|
||||
|
||||
private static final long ONE_DAY = 86400000;
|
||||
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
@Autowired
|
||||
private ExchangeService exchangeService;
|
||||
|
||||
@Autowired
|
||||
private ConfiguratorService configurationController;
|
||||
|
||||
/**
|
||||
* @return if accept algorythm was perfomed
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
||||
@PostMapping(path = "/algorythm/accept")
|
||||
public ResponseEntity<String> performAcceptAlgorythm() {
|
||||
this.assignmentService.callAcceptAlgorythm();
|
||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if exchange algorythm was perfomed
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
||||
@PostMapping(path = "/algorythm/exchange")
|
||||
public ResponseEntity<String> performExchangeAlgorythm() {
|
||||
this.exchangeService.performExchange();
|
||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if tour was set
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
||||
@PostMapping(path = "/tours/first")
|
||||
public ResponseEntity<String> setFirstTour() {
|
||||
this.configurationController.saveTours(
|
||||
new TourData(new Date(System.currentTimeMillis() - ONE_DAY),
|
||||
new Date(System.currentTimeMillis() + ONE_DAY)),
|
||||
new TourData(new Date(System.currentTimeMillis() + 2 * ONE_DAY),
|
||||
new Date(System.currentTimeMillis() + 3 * ONE_DAY)));
|
||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if tour was set
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
||||
@PostMapping(path = "/tours/second")
|
||||
public ResponseEntity<String> setSecondTour() {
|
||||
this.configurationController.saveTours(
|
||||
new TourData(new Date(System.currentTimeMillis() - 3 * ONE_DAY),
|
||||
new Date(System.currentTimeMillis() - 2 * ONE_DAY)),
|
||||
new TourData(new Date(System.currentTimeMillis() - ONE_DAY),
|
||||
new Date(System.currentTimeMillis() + ONE_DAY)));
|
||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if tour was set
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
||||
@PostMapping(path = "/tours/no")
|
||||
public ResponseEntity<String> setNoTour() {
|
||||
this.configurationController.saveTours(
|
||||
new TourData(new Date(System.currentTimeMillis() - ONE_DAY), new Date(System.currentTimeMillis())),
|
||||
new TourData(new Date(System.currentTimeMillis() + ONE_DAY),
|
||||
new Date(System.currentTimeMillis() + 2 * ONE_DAY)));
|
||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ import com.plannaplan.responses.models.ExchangeResponse;
|
|||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.ExchangeService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -33,11 +34,15 @@ import io.swagger.annotations.Api;
|
|||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
||||
/**
|
||||
* Rest controller to Exchange related endpoints. More detailed api docs is
|
||||
* available via swagger
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/exchanges")
|
||||
@Api(tags = { "Exchange" }, value = "Exchange", description = "Endpoint to exchange with accepted assignments.")
|
||||
public class ExchangeController extends TokenBasedController{
|
||||
public class ExchangeController extends TokenBasedController {
|
||||
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
@ -48,40 +53,59 @@ public class ExchangeController extends TokenBasedController{
|
|||
@Autowired
|
||||
private ExchangeService exchangeService;
|
||||
|
||||
/**
|
||||
* @param exchangeRequest mapped json body with requierd paramas (groupid and
|
||||
* assignment)
|
||||
* @return was job successfull
|
||||
* @throws UserNotFoundException if user was not found
|
||||
*/
|
||||
@PostMapping("/exchange")
|
||||
@ApiOperation(value = "Creates exchange offer.")
|
||||
public ResponseEntity<String> createExchange(
|
||||
@ApiParam( value = "Json object that contains assignment to trade and desired group")
|
||||
@RequestBody
|
||||
Map<String, Long> exchangeRequest)
|
||||
@ApiParam(value = "Json object that contains assignment to trade and desired group. For example: { \"assignment\": 3, \"group\":32 }") @RequestBody Map<String, Long> exchangeRequest)
|
||||
throws UserNotFoundException {
|
||||
|
||||
final User asker = this.getCurrentUser()
|
||||
.orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||
final User asker = this.getCurrentUser().orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||
final Long assignmentId = exchangeRequest.get("assignment");
|
||||
final Long groupId = exchangeRequest.get("group");
|
||||
final List<Long> ownedGroups = asker.getStudentRegisteredGrups().stream().map(Groups::getId).collect(Collectors.toList());
|
||||
final List<Long> ownedGroups = asker.getStudentRegisteredGrups().stream().map(Groups::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if(ownedGroups.contains(groupId)){
|
||||
if (ownedGroups.contains(groupId)) {
|
||||
return new ResponseEntity<>("User has already got this group.", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if(assignmentId == null || groupId == null ){
|
||||
if (assignmentId == null || groupId == null) {
|
||||
return new ResponseEntity<>("Some of values are missing", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
final Optional<Assignment> assignment = this.assignmentService.getById(assignmentId);
|
||||
final Optional<Groups> group = this.groupService.getGroupById(groupId);
|
||||
|
||||
if(assignment.isEmpty() || group.isEmpty()){
|
||||
if (assignment.isEmpty() || group.isEmpty()) {
|
||||
return new ResponseEntity<>("Some of provided value does not exist.", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
final Assignment assignmentInstance = assignment.get();
|
||||
final Groups groupInstance = group.get();
|
||||
|
||||
if(!(assignmentInstance.getCommision().getCommisionOwner().getId().equals(asker.getId()) && assignmentInstance.isAccepted())){
|
||||
return new ResponseEntity<>("Some of problems appeared. Check if you have access to given assignment and if it is accepted or the exchange has not been already added.", HttpStatus.BAD_REQUEST);
|
||||
if (assignmentInstance.getGroup().getCourseId() != null
|
||||
&& !assignmentInstance.getGroup().getCourseId().getId().equals(groupInstance.getCourseId().getId())) {
|
||||
System.out.println(assignmentInstance.getGroup().getCourseId().getId());
|
||||
System.out.println(groupInstance.getCourseId().getId());
|
||||
return new ResponseEntity<>("You can performe exchange only within one course.", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (GroupType.isLectureOrClass(assignmentInstance.getGroup().getType()) != GroupType
|
||||
.isLectureOrClass(groupInstance.getType())) {
|
||||
return new ResponseEntity<>("You can't exchange lecture to class and otherwise.", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (!(assignmentInstance.getCommision().getCommisionOwner().getId().equals(asker.getId())
|
||||
&& assignmentInstance.isAccepted())) {
|
||||
return new ResponseEntity<>(
|
||||
"Some of problems appeared. Check if you have access to given assignment and if it is accepted or the exchange has not been already added.",
|
||||
HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
this.exchangeService.save(new Exchange(assignmentInstance, groupInstance));
|
||||
|
@ -89,37 +113,43 @@ public class ExchangeController extends TokenBasedController{
|
|||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offerId id to delwete from db
|
||||
* @return was jub successful
|
||||
* @throws UserNotFoundException if user was not found
|
||||
*/
|
||||
@DeleteMapping("/exchange/{id}")
|
||||
@ApiOperation(value = "Delete exchange offer")
|
||||
public ResponseEntity<String> deleteExchange(@PathVariable(name = "id", required = false) Long offerId)
|
||||
throws UserNotFoundException {
|
||||
|
||||
final User asker = this.getCurrentUser()
|
||||
.orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||
final User asker = this.getCurrentUser().orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||
|
||||
final Optional<Exchange> exchange = this.exchangeService.getById(offerId);
|
||||
|
||||
if(exchange.isEmpty()){
|
||||
return new ResponseEntity<>("Given offer does not exist.", HttpStatus.BAD_REQUEST);
|
||||
if (exchange.isEmpty()) {
|
||||
return new ResponseEntity<>("Given offer does not exist.", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
final Exchange exchangeToDelete = exchange.get();
|
||||
|
||||
if(!(exchangeToDelete.getOwnedAssignment().getCommision().getCommisionOwner().getId().equals(asker.getId()))){
|
||||
return new ResponseEntity<>("You have not permission for that action.", HttpStatus.BAD_REQUEST);
|
||||
if (!(exchangeToDelete.getOwnedAssignment().getCommision().getCommisionOwner().getId().equals(asker.getId()))) {
|
||||
return new ResponseEntity<>("You have not permission for that action.", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
this.exchangeService.deleteExchange(exchangeToDelete);
|
||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return return all user's exchange offers
|
||||
* @throws UserNotFoundException iF user was not found
|
||||
*/
|
||||
@GetMapping("/exchange/all")
|
||||
@ApiOperation(value = "Get exchange offers")
|
||||
public ResponseEntity<List<ExchangeResponse>> getExchange()
|
||||
throws UserNotFoundException {
|
||||
public ResponseEntity<List<ExchangeResponse>> getExchange() throws UserNotFoundException {
|
||||
|
||||
final User asker = this.getCurrentUser()
|
||||
.orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||
final User asker = this.getCurrentUser().orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||
|
||||
final List<Exchange> response = exchangeService.getByUserId(asker.getId());
|
||||
final List<ExchangeResponse> listOfResponses = ExchangeResponseMappers.mapToDefaultResponse(response);
|
||||
|
@ -127,23 +157,27 @@ public class ExchangeController extends TokenBasedController{
|
|||
return new ResponseEntity<>(listOfResponses, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offerId id of exchange in db
|
||||
* @return Exchage response
|
||||
* @throws UserNotFoundException if user was not found
|
||||
*/
|
||||
@GetMapping("/exchange/{id}")
|
||||
@ApiOperation(value = "Get exchange offers")
|
||||
@ApiOperation(value = "Get exchange offer")
|
||||
public ResponseEntity<ExchangeResponse> getExchangeById(@PathVariable(name = "id", required = false) Long offerId)
|
||||
throws UserNotFoundException {
|
||||
|
||||
final User asker = this.getCurrentUser()
|
||||
.orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||
final User asker = this.getCurrentUser().orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||
|
||||
final Optional<Exchange> exchange = this.exchangeService.getById(offerId);
|
||||
|
||||
if(exchange.isEmpty()){
|
||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
if (exchange.isEmpty()) {
|
||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
final Exchange exchangeInstance = exchange.get();
|
||||
if(!exchangeInstance.getOwnerId().equals(asker.getId())){
|
||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
if (!exchangeInstance.getOwnerId().equals(asker.getId())) {
|
||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(new ExchangeResponse(exchangeInstance), HttpStatus.OK);
|
||||
|
|
|
@ -27,9 +27,12 @@ import io.swagger.annotations.Api;
|
|||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
||||
/**
|
||||
* Rest controller to Groups related endpoints. More detailed api docs is
|
||||
* available via swagger
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/groups")
|
||||
@Api(tags = {
|
||||
"Group" }, value = "Group", description = "Enpoints to deal with gorups. Group is related directly to course and can be either class and lecture")
|
||||
|
@ -37,6 +40,12 @@ public class GroupController {
|
|||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
/**
|
||||
* @param id course to display with groups
|
||||
* @param capacity should include capaticty in response
|
||||
* @param takenPlaces should include takenPlaces in response
|
||||
* @return CourseWithGroupsResponse
|
||||
*/
|
||||
@GetMapping("/course/{id}")
|
||||
@ApiOperation(value = "Return list of lectures and classes (if present) given course")
|
||||
public ResponseEntity<CourseWithGroupsResponse<? extends GroupDefaultResponse>> getCourses(
|
||||
|
@ -61,6 +70,11 @@ public class GroupController {
|
|||
return new ResponseEntity<>(GroupsMappers.mapToGetCourseGroupsDefaultResponse(groups), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id group id to change capacity
|
||||
* @param newcapacity new capacity to insert
|
||||
* @return ResponseEntity was action success
|
||||
*/
|
||||
@PutMapping("/{id}/capacity")
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@ApiOperation(value = "Change capacity of given group. You need to provide DEANERY token to be ale to change capacity")
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
package com.plannaplan.controllers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.responses.models.StatisticSimpleNumberResponse;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.services.UserService;
|
||||
|
||||
/**
|
||||
* Rest controller to enpoint that help deveopler test the app
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/statistics")
|
||||
@Api(tags = {
|
||||
"StatisticsController" }, value = "StatisticsController", description = "Statistics are meant to be used by deanery only so in every endpoint you need to provide DEANERY token.")
|
||||
|
||||
public class StatisticsController {
|
||||
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* @return if tour was set
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@GetMapping(path = "/groups/created")
|
||||
public ResponseEntity<StatisticSimpleNumberResponse> getGroupsAmmounts() {
|
||||
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
|
||||
this.groupService.getGroupsAmmount());
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if tour was set
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@GetMapping(path = "/groups/full")
|
||||
public ResponseEntity<StatisticSimpleNumberResponse> getGroupsFullAmmounts() {
|
||||
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
|
||||
this.groupService.getFullgroupsAmmount());
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return amount of registered to some groups
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@GetMapping(path = "/users/registered")
|
||||
public ResponseEntity<StatisticSimpleNumberResponse> getCommisionsAmmounts() {
|
||||
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
|
||||
this.userService.getAmmountOfUsersWithAssignedGroups());
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return amount of students not registered to any groups
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@GetMapping(path = "/users/noregistered")
|
||||
public ResponseEntity<StatisticSimpleNumberResponse> getNonCommisionsAmmounts() {
|
||||
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
|
||||
this.userService.getAmmountOfUsersWithNoAssignedGroups());
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return amount of students that have fully accepted schedules
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@GetMapping(path = "/users/accepted")
|
||||
public ResponseEntity<StatisticSimpleNumberResponse> getAcceptedAmmounts() {
|
||||
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
|
||||
this.userService.getAmmountOfUsersWithAcceptedSchedules());
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return amount of students that have purtly accepted schedules
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@GetMapping(path = "/users/accepted/partly")
|
||||
public ResponseEntity<StatisticSimpleNumberResponse> getAcceptedPartlyAmmounts() {
|
||||
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
|
||||
this.userService.getAmmountOfUsersWithNoAcceptedSchedules());
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
|
@ -11,6 +11,10 @@ import org.springframework.security.core.Authentication;
|
|||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
|
||||
/**
|
||||
* Abstract class for controllers that requires token to extra authorize action
|
||||
* beyond spring security
|
||||
*/
|
||||
public abstract class TokenBasedController {
|
||||
@Autowired
|
||||
protected UserService userService;
|
||||
|
@ -18,6 +22,10 @@ public abstract class TokenBasedController {
|
|||
public TokenBasedController() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return get currect user based no current spring context
|
||||
* @throws UserNotFoundException if user was not fount
|
||||
*/
|
||||
protected Optional<User> getCurrentUser() throws UserNotFoundException {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
|
|
|
@ -26,6 +26,10 @@ import io.swagger.annotations.Api;
|
|||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
||||
/**
|
||||
* Rest controller to Token related endpoints. More detailed api docs is
|
||||
* available via swagger
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@Api(tags = { "Token" }, value = "Token", description = "Enpoints to get authorization.")
|
||||
|
@ -40,6 +44,10 @@ public class TokenController {
|
|||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* @param ticket via CAS obtained ticket - it's base to auth user
|
||||
* @return TokenResponse if operation was success
|
||||
*/
|
||||
@GetMapping("/token")
|
||||
@ApiOperation(value = "Endpoint to access token required to call secured endpoints. In order to access token we need to provide access token comming from unviersity CAS system")
|
||||
public ResponseEntity<TokenResponse> getToken(
|
||||
|
@ -64,6 +72,11 @@ public class TokenController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param refreshToken refresh token obtained via /token endpoint
|
||||
* @return TokenResponse if operation was success
|
||||
* @throws NullPointerException is thrown if user was not found by refrshtoken
|
||||
*/
|
||||
@GetMapping("/token/refresh")
|
||||
@ApiOperation(value = "Endpoint to access new token based on refresh token. It's needed when request with provided token fail with code 403")
|
||||
public ResponseEntity<TokenResponse> getRefreshToken(
|
||||
|
|
|
@ -27,6 +27,10 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* Rest controller to assignments related endpoints. More detailed api docs is
|
||||
* available via swagger
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/users")
|
||||
|
@ -36,6 +40,10 @@ public class UsersController {
|
|||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* @param query to filrer userst with STUDENT role
|
||||
* @return list found
|
||||
*/
|
||||
@GetMapping("/student/search")
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@ApiOperation(value = "Serch for user by providing query. If query is empty it will return all students. You need token with DEANERY role to call this")
|
||||
|
@ -46,6 +54,9 @@ public class UsersController {
|
|||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of all studnents
|
||||
*/
|
||||
@GetMapping("/students")
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@ApiOperation(value = "Gets all students. You need token with DEANERY role to call this")
|
||||
|
@ -55,10 +66,16 @@ public class UsersController {
|
|||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authority USOS ID or E-mail. If user does not exist it should be USOS
|
||||
* ID
|
||||
* @return response entity was operation with succcesss
|
||||
*/
|
||||
@PostMapping(path = "/admin")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@ApiOperation(value = "Adds new admin user.")
|
||||
public ResponseEntity<String> addAdmin(@RequestParam("authority") @ApiParam(value = "USOS ID or E-mail. If user does not exist it should be USOS ID") String authority) {
|
||||
public ResponseEntity<String> addAdmin(
|
||||
@RequestParam("authority") @ApiParam(value = "USOS ID or E-mail. If user does not exist it should be USOS ID") String authority) {
|
||||
final Optional<User> userResponse = this.userService.getByAuthority(authority);
|
||||
final User user = userResponse.orElseGet(() -> new User(null, null, null, authority, UserRoles.ADMIN));
|
||||
user.setRole(UserRoles.ADMIN);
|
||||
|
@ -66,10 +83,16 @@ public class UsersController {
|
|||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authority USOS ID or E-mail. If user does not exist it should be USOS
|
||||
* ID
|
||||
* @return response entity was operation with succcesss
|
||||
*/
|
||||
@PostMapping(path = "/deanery")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@ApiOperation(value = "Adds new deanery user.")
|
||||
public ResponseEntity<String> addDeanery(@RequestParam("authority") @ApiParam(value = "USOS ID or E-mail. If user does not exist it should be USOS ID") String authority) {
|
||||
public ResponseEntity<String> addDeanery(
|
||||
@RequestParam("authority") @ApiParam(value = "USOS ID or E-mail. If user does not exist it should be USOS ID") String authority) {
|
||||
final Optional<User> userResponse = this.userService.getByAuthority(authority);
|
||||
final User user = userResponse.orElseGet(() -> new User(null, null, null, authority, UserRoles.DEANERY));
|
||||
user.setRole(UserRoles.DEANERY);
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Provides rest controllers that defines endpoints and their accessibility
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.controllers;
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Root package of project
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan;
|
|
@ -4,35 +4,51 @@ import java.util.List;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.responses.models.AssignmentDetailedResponse;
|
||||
import com.plannaplan.responses.models.AssignmentResponse;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
/**
|
||||
* Mappers for Assingnmetns to api responses
|
||||
*/
|
||||
public class AssignmentResponseMappers {
|
||||
|
||||
/**
|
||||
* @param assignments lsit of assignments to be maped
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static final List<AssignmentResponse> mapToResponse(List<Assignment> assignments) {
|
||||
return mapToResponse(assignments, null);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param assignments lsit of assignments to be maped
|
||||
* @param ammounts ammounts to be take into account
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static final List<AssignmentResponse> mapToResponse(List<Assignment> assignments,
|
||||
HashMap<Long, Integer> ammounts) {
|
||||
List<AssignmentResponse> response = new ArrayList<>();
|
||||
HashMap<Course, List<Groups>> courses = new HashMap<>();
|
||||
HashMap<Course, List<Assignment>> courses = new HashMap<>();
|
||||
assignments.stream().forEach((Assignment assignment) -> {
|
||||
final Groups group = assignment.getGroup();
|
||||
final Course course = group.getCourseId();
|
||||
if (courses.get(course) == null) {
|
||||
courses.put(course, new ArrayList<>());
|
||||
}
|
||||
courses.get(course).add(group);
|
||||
courses.get(course).add(assignment);
|
||||
});
|
||||
|
||||
for (Map.Entry<Course, List<Groups>> entry : courses.entrySet()) {
|
||||
for (Map.Entry<Course, List<Assignment>> entry : courses.entrySet()) {
|
||||
final Course course = entry.getKey();
|
||||
final List<Groups> courseGroups = entry.getValue();
|
||||
final List<Assignment> courseGroups = entry.getValue();
|
||||
if (courseGroups.size() == 1) {
|
||||
if (ammounts != null) {
|
||||
response.add(new AssignmentResponse(course, courseGroups.get(0), ammounts));
|
||||
|
@ -41,9 +57,11 @@ public class AssignmentResponseMappers {
|
|||
}
|
||||
}
|
||||
if (courseGroups.size() == 2) {
|
||||
final Groups lecture = courseGroups.stream().filter(o -> o.getType() == GroupType.LECTURE).findFirst()
|
||||
.get();
|
||||
final Groups classes = courseGroups.stream().filter(o -> o.getType() == GroupType.CLASS).findFirst()
|
||||
final Assignment lecture = courseGroups.stream()
|
||||
.filter(o -> GroupType.isLectureOrClass(o.getGroup().getType()) == GroupType.LECTURE)
|
||||
.findFirst().get();
|
||||
final Assignment classes = courseGroups.stream()
|
||||
.filter(o -> GroupType.isLectureOrClass(o.getGroup().getType()) == GroupType.CLASS).findFirst()
|
||||
.get();
|
||||
|
||||
if (ammounts != null) {
|
||||
|
@ -56,4 +74,15 @@ public class AssignmentResponseMappers {
|
|||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* map assignmetn to detailed response
|
||||
*
|
||||
* @param assignments list of assignments to map
|
||||
* @return list of responses
|
||||
*/
|
||||
public static final List<AssignmentDetailedResponse> mapAssignmetnToDetialedResponse(List<Assignment> assignments) {
|
||||
return assignments.stream().filter(Objects::nonNull).map(AssignmentDetailedResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,15 +6,37 @@ import java.util.stream.Collectors;
|
|||
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.responses.models.CommisionResponse;
|
||||
import com.plannaplan.responses.models.CommisionWithAcceptedGroupsResponse;
|
||||
import com.plannaplan.responses.models.CommisionWithGroupsResponse;
|
||||
|
||||
/**
|
||||
* Mappers for Commisions to api responses
|
||||
*/
|
||||
public class CommisionResponseMappers {
|
||||
/**
|
||||
* @param commisions list of commisions to be mapped
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static final List<CommisionResponse> mapToResponse(List<Commision> commisions) {
|
||||
return commisions.stream().filter(Objects::nonNull).map(CommisionResponse::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param commisions list of commisions to be mapped
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static final List<CommisionWithGroupsResponse> mapToResponseWithGroups(List<Commision> commisions) {
|
||||
return commisions.stream().filter(Objects::nonNull).map(CommisionWithGroupsResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param commisions list of commisions to be mapped
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static final List<CommisionWithAcceptedGroupsResponse> mapToResponseWithExtraInforGroups(
|
||||
List<Commision> commisions) {
|
||||
return commisions.stream().filter(Objects::nonNull).map(CommisionWithAcceptedGroupsResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,22 @@ import com.plannaplan.entities.Course;
|
|||
import com.plannaplan.responses.models.CoursesDefaultResponse;
|
||||
import com.plannaplan.responses.models.CoursesWithGroupsResponse;
|
||||
|
||||
/**
|
||||
* Mappers for Courses to api responses
|
||||
*/
|
||||
public class CoursesResponseMappers {
|
||||
/**
|
||||
* @param courses list of courses to be mapped
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static final List<CoursesDefaultResponse> mapToGetCoursesResponse(List<Course> courses) {
|
||||
return courses.stream().filter(Objects::nonNull).map(CoursesDefaultResponse::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param courses list of courses to be mapped
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static final List<CoursesWithGroupsResponse> mapToGetCoursesWithGroupsResponse(List<Course> courses) {
|
||||
return courses.stream().filter(Objects::nonNull).map(CoursesWithGroupsResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
|
|
|
@ -7,7 +7,14 @@ import java.util.stream.Collectors;
|
|||
import com.plannaplan.entities.Exchange;
|
||||
import com.plannaplan.responses.models.ExchangeResponse;
|
||||
|
||||
/**
|
||||
* Mappers for Exchange to api responses
|
||||
*/
|
||||
public class ExchangeResponseMappers {
|
||||
/**
|
||||
* @param exchanges lsit of exchanges to be mapped
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static final List<ExchangeResponse> mapToDefaultResponse(List<Exchange> exchanges) {
|
||||
return exchanges.stream().filter(Objects::nonNull).map(ExchangeResponse::new).collect(Collectors.toList());
|
||||
}
|
||||
|
|
|
@ -13,7 +13,15 @@ import com.plannaplan.responses.models.CourseWithGroupsResponse;
|
|||
import com.plannaplan.responses.models.GroupWithCapacityResponse;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
/**
|
||||
* Mappers for Groups to api responses
|
||||
*/
|
||||
public class GroupsMappers {
|
||||
/**
|
||||
* @param groups list of groups to be mapped
|
||||
* @param taken ammoints to be take into account
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static List<GroupDefaultResponse> mapToDefaultResponse(List<Groups> groups, HashMap<Long, Integer> taken) {
|
||||
return groups.stream().filter(Objects::nonNull).map(new Function<Groups, GroupDefaultResponse>() {
|
||||
@Override
|
||||
|
@ -27,10 +35,20 @@ public class GroupsMappers {
|
|||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groups list of groups to be mapped
|
||||
* @return ammoints to be take into account
|
||||
*/
|
||||
public static List<GroupDefaultResponse> mapToDefaultResponse(List<Groups> groups) {
|
||||
return GroupsMappers.mapToDefaultResponse(groups, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groups list of groups to be mapped
|
||||
* @param taken ammoints to be take into account
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static List<GroupWithCapacityResponse> mapToCapacityResponse(List<Groups> groups,
|
||||
HashMap<Long, Integer> taken) {
|
||||
return groups.stream().filter(Objects::nonNull).map(new Function<Groups, GroupWithCapacityResponse>() {
|
||||
|
@ -45,10 +63,19 @@ public class GroupsMappers {
|
|||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groups list of groups to be mapped
|
||||
* @return ammoints to be take into account
|
||||
*/
|
||||
public static List<GroupWithCapacityResponse> mapToCapacityResponse(List<Groups> groups) {
|
||||
return GroupsMappers.mapToCapacityResponse(groups, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groups list of groups to be mapped
|
||||
* @param taken ammoints to be take into account
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static CourseWithGroupsResponse<GroupDefaultResponse> mapToGetCourseGroupsDefaultResponse(
|
||||
List<Groups> groups, HashMap<Long, Integer> taken) {
|
||||
|
||||
|
@ -56,7 +83,7 @@ public class GroupsMappers {
|
|||
List<GroupDefaultResponse> classes = new ArrayList<>();
|
||||
|
||||
groups.stream().forEach(group -> {
|
||||
if (group.getType() == GroupType.CLASS) {
|
||||
if (GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS) {
|
||||
if (taken != null) {
|
||||
classes.add(new GroupDefaultResponse(group, taken.get(group.getId())));
|
||||
} else {
|
||||
|
@ -74,11 +101,20 @@ public class GroupsMappers {
|
|||
return new CourseWithGroupsResponse<>(classes, lectures);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groups list of groups to be mapped
|
||||
* @return ammoints to be take into account
|
||||
*/
|
||||
public static CourseWithGroupsResponse<GroupDefaultResponse> mapToGetCourseGroupsDefaultResponse(
|
||||
List<Groups> groups) {
|
||||
return GroupsMappers.mapToGetCourseGroupsDefaultResponse(groups, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groups list of groups to be mapped
|
||||
* @param taken ammoints to be take into account
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static CourseWithGroupsResponse<GroupWithCapacityResponse> mapToGetCourseGroupsWithCapacityResponse(
|
||||
List<Groups> groups, HashMap<Long, Integer> taken) {
|
||||
|
||||
|
@ -86,7 +122,7 @@ public class GroupsMappers {
|
|||
List<GroupWithCapacityResponse> classes = new ArrayList<>();
|
||||
|
||||
groups.stream().forEach(group -> {
|
||||
if (group.getType() == GroupType.CLASS) {
|
||||
if (GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS) {
|
||||
if (taken != null) {
|
||||
classes.add(new GroupWithCapacityResponse(group, taken.get(group.getId())));
|
||||
} else {
|
||||
|
@ -105,6 +141,10 @@ public class GroupsMappers {
|
|||
return new CourseWithGroupsResponse<>(classes, lectures);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groups list of groups to be mapped
|
||||
* @return ammoints to be take into account
|
||||
*/
|
||||
public static CourseWithGroupsResponse<GroupWithCapacityResponse> mapToGetCourseGroupsWithCapacityResponse(
|
||||
List<Groups> groups) {
|
||||
return GroupsMappers.mapToGetCourseGroupsWithCapacityResponse(groups, null);
|
||||
|
|
|
@ -7,9 +7,15 @@ import java.util.stream.Collectors;
|
|||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.responses.models.UserResponse;
|
||||
|
||||
/**
|
||||
* Mappers for Users to api responses
|
||||
*/
|
||||
public class UserResponseMappers {
|
||||
/**
|
||||
* @param groups list of groups to be mapped
|
||||
* @return list of api responses
|
||||
*/
|
||||
public static List<UserResponse> mapToDefaultResponse(List<User> groups) {
|
||||
return groups.stream().filter(Objects::nonNull).map(UserResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
return groups.stream().filter(Objects::nonNull).map(UserResponse::new).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Provides mappers to map mutiple entites from db to single api response
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.responses.mappers;
|
|
@ -0,0 +1,81 @@
|
|||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
/**
|
||||
* Assignment detailed response for api
|
||||
*/
|
||||
public class AssignmentDetailedResponse {
|
||||
public Long id;
|
||||
public String name;
|
||||
private int day;
|
||||
private String time;
|
||||
private String endTime;
|
||||
private String lecturer;
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* @param assignment Assignment instance to map
|
||||
*/
|
||||
public AssignmentDetailedResponse(Assignment assignment) {
|
||||
final Groups group = assignment.getGroup();
|
||||
this.id = assignment.getId();
|
||||
this.name = group.getCourseId().getName();
|
||||
this.day = group.getDay().label;
|
||||
this.time = group.getTimeString();
|
||||
this.endTime = group.getEndTimeString();
|
||||
this.lecturer = group.getLecturer().toString();
|
||||
this.type = GroupType.isLectureOrClass(group.getType()).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return type of the lecture
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return day as a value from 0-6
|
||||
*/
|
||||
public int getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return lecturer string fromated
|
||||
*/
|
||||
public String getLecturer() {
|
||||
return lecturer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return time formated string
|
||||
*/
|
||||
public String getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return time formated string
|
||||
*/
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return name of course that group belongs to
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return db id of assignment
|
||||
*/
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
|
@ -2,55 +2,157 @@ package com.plannaplan.responses.models;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
/**
|
||||
* Assignment entity api response
|
||||
*/
|
||||
@ApiModel(description = "Response shows information about given assigment to course.", value = "AssignmentResponse")
|
||||
public class AssignmentResponse {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String symbol;
|
||||
private GroupWithCapacityResponse classes;
|
||||
private GroupWithCapacityResponse lecture;
|
||||
|
||||
/**
|
||||
* @param course course entity
|
||||
* @param lecture lecture Groups entity
|
||||
* @param classes class Groups entity
|
||||
*/
|
||||
public AssignmentResponse(Course course, Groups lecture, Groups classes) {
|
||||
this.id = course.getId();
|
||||
this.name = course.getName();
|
||||
this.symbol = course.getSymbol();
|
||||
this.lecture = lecture == null ? null : new GroupWithCapacityResponse(lecture);
|
||||
this.classes = classes == null ? null : new GroupWithCapacityResponse(classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return returns symbol of assigned course
|
||||
*/
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param course course entity
|
||||
* @param lecture lecture Groups entity
|
||||
* @param classes class Groups entity
|
||||
* @param ammounts map with ammounts key - group id, value - ammounts of taken
|
||||
* places
|
||||
*/
|
||||
public AssignmentResponse(Course course, Groups lecture, Groups classes, HashMap<Long, Integer> ammounts) {
|
||||
this.id = course.getId();
|
||||
this.name = course.getName();
|
||||
this.symbol = course.getSymbol();
|
||||
this.lecture = lecture == null ? null : new GroupWithCapacityResponse(lecture, ammounts.get(lecture.getId()));
|
||||
this.classes = classes == null ? null : new GroupWithCapacityResponse(classes, ammounts.get(classes.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param course course entity
|
||||
* @param group class/lecture entity
|
||||
*/
|
||||
public AssignmentResponse(Course course, Groups group) {
|
||||
this(course, group.getType() == GroupType.LECTURE ? group : null,
|
||||
group.getType() == GroupType.CLASS ? group : null);
|
||||
this(course, GroupType.isLectureOrClass(group.getType()) == GroupType.LECTURE ? group : null,
|
||||
GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS ? group : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param course course entity
|
||||
* @param group class/lecture entity
|
||||
* @param ammounts map with ammounts key - group id, value - ammounts of taken
|
||||
* places
|
||||
*/
|
||||
public AssignmentResponse(Course course, Groups group, HashMap<Long, Integer> ammounts) {
|
||||
this(course, group.getType() == GroupType.LECTURE ? group : null,
|
||||
group.getType() == GroupType.CLASS ? group : null, ammounts);
|
||||
this(course, GroupType.isLectureOrClass(group.getType()) == GroupType.LECTURE ? group : null,
|
||||
GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS ? group : null, ammounts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param course course entity
|
||||
* @param group class/lecture entity
|
||||
* @param ammounts map with ammounts key - group id, value - ammounts of taken
|
||||
* places
|
||||
*/
|
||||
public AssignmentResponse(Course course, Assignment group, HashMap<Long, Integer> ammounts) {
|
||||
this(course, GroupType.isLectureOrClass(group.getGroup().getType()) == GroupType.LECTURE ? group : null,
|
||||
GroupType.isLectureOrClass(group.getGroup().getType()) == GroupType.CLASS ? group : null, ammounts);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param course course entity
|
||||
* @param group class/lecture entity
|
||||
*/
|
||||
public AssignmentResponse(Course course, Assignment group) {
|
||||
this(course, GroupType.isLectureOrClass(group.getGroup().getType()) == GroupType.LECTURE ? group : null,
|
||||
GroupType.isLectureOrClass(group.getGroup().getType()) == GroupType.CLASS ? group : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param course course entity
|
||||
* @param lecture lecture Groups entity
|
||||
* @param classes class Groups entity
|
||||
* @param ammounts map with ammounts key - group id, value - ammounts of taken
|
||||
* places
|
||||
*/
|
||||
public AssignmentResponse(Course course, Assignment lecture, Assignment classes, HashMap<Long, Integer> ammounts) {
|
||||
this.id = course.getId();
|
||||
this.name = course.getName();
|
||||
this.symbol = course.getSymbol();
|
||||
this.classes = classes != null
|
||||
? new GroupWithCapacityResponse(classes, ammounts.get(classes.getGroup().getId()))
|
||||
: null;
|
||||
this.lecture = lecture != null
|
||||
? new GroupWithCapacityResponse(lecture, ammounts.get(lecture.getGroup().getId()))
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param course course entity
|
||||
* @param lecture lecture Groups entity
|
||||
* @param classes class Groups entity
|
||||
*/
|
||||
public AssignmentResponse(Course course, Assignment lecture, Assignment classes) {
|
||||
this.id = course.getId();
|
||||
this.name = course.getName();
|
||||
this.symbol = course.getSymbol();
|
||||
this.classes = classes != null ? new GroupWithCapacityResponse(classes) : null;
|
||||
this.lecture = lecture != null ? new GroupWithCapacityResponse(lecture) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Lecture in api response forms
|
||||
*/
|
||||
public GroupWithCapacityResponse getLecture() {
|
||||
return this.lecture;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Class in api response forms
|
||||
*/
|
||||
public GroupWithCapacityResponse getClasses() {
|
||||
return this.classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String course name
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return db assignment id
|
||||
*/
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
|
||||
/**
|
||||
* Repsonse for single assignment to use in commision repsonse
|
||||
*/
|
||||
public class AssignmentsSingleResponse {
|
||||
private Long id;
|
||||
private boolean isAccepted;
|
||||
|
||||
/**
|
||||
* @param assignment to map to response
|
||||
*/
|
||||
public AssignmentsSingleResponse(Assignment assignment) {
|
||||
this.id = assignment.getGroup().getId();
|
||||
this.isAccepted = assignment.isAccepted();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return id of assigned group
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return is group already accepted or not
|
||||
*/
|
||||
public boolean isAccepted() {
|
||||
return isAccepted;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,9 @@ import com.plannaplan.entities.Commision;
|
|||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Commision api response
|
||||
*/
|
||||
@ApiModel(description = "Response shows information about commision.", value = "CommisionResponse")
|
||||
public class CommisionResponse {
|
||||
@ApiModelProperty(value = "ID created by database")
|
||||
|
@ -19,6 +22,9 @@ public class CommisionResponse {
|
|||
@ApiModelProperty(value = "Timestamp where the user commit the commision")
|
||||
private String commisionDate;
|
||||
|
||||
/**
|
||||
* @param commision commision to map to api response
|
||||
*/
|
||||
public CommisionResponse(Commision commision) {
|
||||
this.id = commision.getId();
|
||||
this.commisionDate = commision.getCommisionDate().toString();
|
||||
|
@ -27,18 +33,30 @@ public class CommisionResponse {
|
|||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return get Commiter user as api response
|
||||
*/
|
||||
public UserResponse getCommiter() {
|
||||
return commiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return get Owner user as api response
|
||||
*/
|
||||
public UserResponse getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return when commision was created string formated
|
||||
*/
|
||||
public String getCommisionDate() {
|
||||
return commisionDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return db id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package com.plannaplan.responses.models;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
/**
|
||||
* Commision With Groups api Response. It extends CommisionResponse repsone
|
||||
*/
|
||||
@ApiModel(description = "Response shows information about commision and its groups. It also has info about group state (is accepted or not)", value = "CommisionWithGroupsResponse")
|
||||
public class CommisionWithAcceptedGroupsResponse extends CommisionResponse {
|
||||
|
||||
private List<AssignmentsSingleResponse> groups;
|
||||
|
||||
/**
|
||||
* @param commision commision to map to api response
|
||||
*/
|
||||
public CommisionWithAcceptedGroupsResponse(Commision commision) {
|
||||
super(commision);
|
||||
this.groups = commision.getAssignments().stream().filter(Objects::nonNull)
|
||||
.map(new Function<Assignment, AssignmentsSingleResponse>() {
|
||||
|
||||
@Override
|
||||
public AssignmentsSingleResponse apply(Assignment arg0) {
|
||||
return new AssignmentsSingleResponse(arg0);
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return lsit of fetured groups informations
|
||||
*/
|
||||
public List<AssignmentsSingleResponse> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
}
|
|
@ -11,12 +11,18 @@ import com.plannaplan.entities.Commision;
|
|||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Commision With Groups api Response. It extends CommisionResponse repsone
|
||||
*/
|
||||
@ApiModel(description = "Response shows information about commision and its groups.", value = "CommisionWithGroupsResponse")
|
||||
public class CommisionWithGroupsResponse extends CommisionResponse {
|
||||
|
||||
@ApiModelProperty(value = "List of groups ids in databse that belongs to commision")
|
||||
private List<Long> groups;
|
||||
|
||||
/**
|
||||
* @param commision commision to map to api response
|
||||
*/
|
||||
public CommisionWithGroupsResponse(Commision commision) {
|
||||
super(commision);
|
||||
this.groups = commision.getAssignments().stream().filter(Objects::nonNull)
|
||||
|
@ -29,6 +35,9 @@ public class CommisionWithGroupsResponse extends CommisionResponse {
|
|||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return lsit of fetured groups ids
|
||||
*/
|
||||
public List<Long> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.types.AppState;
|
||||
|
||||
/**
|
||||
* Api response for config tours entpoint
|
||||
*/
|
||||
public class ConfigTourResponse {
|
||||
|
||||
private String currentTour;
|
||||
|
||||
/**
|
||||
* @param appState to send as a response
|
||||
*/
|
||||
public ConfigTourResponse(AppState appState) {
|
||||
this.currentTour = appState.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return current app state as string
|
||||
*/
|
||||
public String getCurrentTour() {
|
||||
return currentTour;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,21 +5,36 @@ import java.util.List;
|
|||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
/**
|
||||
* Course respose with all realted groups as api response. Alse needs to specify
|
||||
* what type of Groups api response will be kept here. For excmaple it can be
|
||||
* <b> GroupDefaultRespnse </b>
|
||||
*/
|
||||
@ApiModel(description = "Response shows information about groups to given course.", value = "CourseWithGroupsResponse")
|
||||
public class CourseWithGroupsResponse <T> {
|
||||
public class CourseWithGroupsResponse<T> {
|
||||
|
||||
private List<T> lectures = new ArrayList<>();
|
||||
private List<T> classes = new ArrayList<>();
|
||||
|
||||
public CourseWithGroupsResponse(List<T> classes, List<T> lectures ){
|
||||
/**
|
||||
* @param classes realted classes Groups instance
|
||||
* @param lectures realted lectures Groups instance
|
||||
*/
|
||||
public CourseWithGroupsResponse(List<T> classes, List<T> lectures) {
|
||||
this.lectures = lectures;
|
||||
this.classes = classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return realted classes Groups instance
|
||||
*/
|
||||
public List<T> getClasses() {
|
||||
return this.classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return realted lectures Groups instance
|
||||
*/
|
||||
public List<T> getLectures() {
|
||||
return this.lectures;
|
||||
}
|
||||
|
|
|
@ -5,9 +5,21 @@ import com.plannaplan.responses.models.abstracts.CoursesResponse;
|
|||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
/**
|
||||
* Courses Default Api Response. It extends abstract response - CoursesResponse.
|
||||
* It was one of first repsones created in system. Later we resigned from
|
||||
* asbstract and used settig
|
||||
* <code>spring.jackson.default-property-inclusion = NON_NULL</code> in
|
||||
* properties instead.
|
||||
*/
|
||||
@ApiModel(description = "Response shows information about course.", value = "CoursesDefaultResponse")
|
||||
public class CoursesDefaultResponse extends CoursesResponse {
|
||||
|
||||
/**
|
||||
* create new instance
|
||||
*
|
||||
* @param course course to map to api response
|
||||
*/
|
||||
public CoursesDefaultResponse(Course course) {
|
||||
super(course);
|
||||
}
|
||||
|
|
|
@ -9,16 +9,28 @@ import com.plannaplan.types.GroupType;
|
|||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
/**
|
||||
* Courses With Groups Api Response . It extends abstract response -
|
||||
* CoursesResponse. It was one of first repsones created in system. Later we
|
||||
* resigned from asbstract and used settig
|
||||
* <code>spring.jackson.default-property-inclusion = NON_NULL</code> in
|
||||
* properties instead.
|
||||
*/
|
||||
@ApiModel(description = "Response shows information about groups to given course.", value = "CoursesWithGroupsResponse")
|
||||
public class CoursesWithGroupsResponse extends CoursesResponse {
|
||||
|
||||
private List<GroupWithCapacityResponse> lectures = new ArrayList<>();
|
||||
private List<GroupWithCapacityResponse> classes = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* create new instance
|
||||
*
|
||||
* @param course course to map to api response
|
||||
*/
|
||||
public CoursesWithGroupsResponse(Course course) {
|
||||
super(course);
|
||||
course.getGroups().stream().forEach(group -> {
|
||||
if (group.getType() == GroupType.CLASS) {
|
||||
if (GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS) {
|
||||
this.classes.add(new GroupWithCapacityResponse(group));
|
||||
} else {
|
||||
this.lectures.add(new GroupWithCapacityResponse(group));
|
||||
|
@ -26,6 +38,12 @@ public class CoursesWithGroupsResponse extends CoursesResponse {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param course course to map to api response
|
||||
* @param lectures list of api resposnes of lectures
|
||||
* @param classes list of api resposnes of classes
|
||||
*/
|
||||
public CoursesWithGroupsResponse(Course course, List<GroupWithCapacityResponse> lectures,
|
||||
List<GroupWithCapacityResponse> classes) {
|
||||
super(course);
|
||||
|
@ -33,10 +51,16 @@ public class CoursesWithGroupsResponse extends CoursesResponse {
|
|||
this.classes = classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of api resposnes of classes
|
||||
*/
|
||||
public List<GroupWithCapacityResponse> getClasses() {
|
||||
return this.classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of api resposnes of lectures
|
||||
*/
|
||||
public List<GroupWithCapacityResponse> getLectures() {
|
||||
return this.lectures;
|
||||
}
|
||||
|
|
|
@ -2,35 +2,83 @@ package com.plannaplan.responses.models;
|
|||
|
||||
import com.plannaplan.entities.Exchange;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Exchange proposal api repsonse
|
||||
*/
|
||||
@ApiModel(description = "Response shows information about user exchanges", value = "CourseWithGroupsResponse")
|
||||
public class ExchangeResponse {
|
||||
private Long id;
|
||||
private GroupDefaultResponse ownedAssignment;
|
||||
private GroupDefaultResponse desiredGroup;
|
||||
@ApiModelProperty(value = "Database id")
|
||||
private Long id;
|
||||
@ApiModelProperty(value = "Assignmetn that user want to trade")
|
||||
private GroupDefaultResponse ownedAssignment;
|
||||
@ApiModelProperty(value = "Group that user want to get")
|
||||
private GroupDefaultResponse desiredGroup;
|
||||
private String courseName;
|
||||
|
||||
public ExchangeResponse(Exchange exchange){
|
||||
this.id = exchange.getId();
|
||||
this.ownedAssignment = new GroupDefaultResponse(exchange.getOwnedAssignment().getGroup());
|
||||
this.desiredGroup = new GroupDefaultResponse(exchange.getDesiredAssignment());
|
||||
}
|
||||
/**
|
||||
* creat new instance
|
||||
*
|
||||
* @param exchange entity to map to api repsone
|
||||
*/
|
||||
public ExchangeResponse(Exchange exchange) {
|
||||
this.id = exchange.getId();
|
||||
this.ownedAssignment = new GroupDefaultResponse(exchange.getOwnedAssignment().getGroup());
|
||||
this.desiredGroup = new GroupDefaultResponse(exchange.getDesiredAssignment());
|
||||
this.courseName = exchange.getOwnedAssignment().getGroup().getCourseId() != null
|
||||
? exchange.getOwnedAssignment().getGroup().getCourseId().getName()
|
||||
: "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return name of course related to exchange
|
||||
*/
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return get api respondse of wanted byt user group
|
||||
*/
|
||||
public GroupDefaultResponse getDesiredGroup() {
|
||||
return desiredGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param desiredGroup set api respondse of wanted byt user group
|
||||
*/
|
||||
public void setDesiredGroup(GroupDefaultResponse desiredGroup) {
|
||||
this.desiredGroup = desiredGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return get api respondse of owned user group
|
||||
*/
|
||||
public GroupDefaultResponse getOwnedAssignment() {
|
||||
return ownedAssignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ownedAssignment set api respondse of owned user group
|
||||
*/
|
||||
public void setOwnedAssignment(GroupDefaultResponse ownedAssignment) {
|
||||
this.ownedAssignment = ownedAssignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return database id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id set database id
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@ import com.plannaplan.types.GroupType;
|
|||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Default api response for Groups entity
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ApiModel(description = "Response shows information about given group.", value = "GroupDefaultResponse")
|
||||
public class GroupDefaultResponse {
|
||||
|
@ -36,6 +39,16 @@ public class GroupDefaultResponse {
|
|||
@ApiModelProperty(value = "Value shows how many places is already taken by other students.")
|
||||
private Integer takenPlaces;
|
||||
|
||||
@ApiModelProperty(value = "Used only in resposnes realted to user assignments. For example in /api/v1/users/schedule.")
|
||||
private Boolean isAccepted;
|
||||
|
||||
private Integer grNr;
|
||||
|
||||
/**
|
||||
* creat new entity
|
||||
*
|
||||
* @param group entity to map to api response
|
||||
*/
|
||||
public GroupDefaultResponse(Groups group) {
|
||||
this.id = group.getId() != null ? group.getId() : null;
|
||||
this.day = group.getDay() != null ? group.getDay().label : -1;
|
||||
|
@ -43,46 +56,105 @@ public class GroupDefaultResponse {
|
|||
this.endTime = group.getEndTimeString() != null ? group.getEndTimeString() : "";
|
||||
this.lecturer = group.getLecturer() != null ? group.getLecturer().toString() : "";
|
||||
this.room = group.getRoom() != null ? group.getRoom() : "";
|
||||
this.type = group.getType() != null ? group.getType() : null;
|
||||
this.type = group.getType() != null ? GroupType.isLectureOrClass(group.getType()) : null;
|
||||
this.grNr = group.getGrNr() != null ? group.getGrNr() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return group number
|
||||
*/
|
||||
public Integer getGrNr() {
|
||||
return grNr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return is group accepted if its related to assignmetn
|
||||
*/
|
||||
public Boolean getIsAccepted() {
|
||||
return isAccepted;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param group entity to map to api response
|
||||
* @param takenPlaces ammount of taken places for group by other users
|
||||
*/
|
||||
public GroupDefaultResponse(Groups group, int takenPlaces) {
|
||||
this(group);
|
||||
this.takenPlaces = takenPlaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* creat new entity
|
||||
*
|
||||
* @param assignment entity to map to api response
|
||||
*/
|
||||
public GroupDefaultResponse(Assignment assignment) {
|
||||
this(assignment.getGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param assignment entity to map to api response
|
||||
* @param takenPlaces map with ammounts of taken places
|
||||
*/
|
||||
public GroupDefaultResponse(Assignment assignment, int takenPlaces) {
|
||||
this(assignment.getGroup(), takenPlaces);
|
||||
this.isAccepted = assignment.isAccepted();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return what typew of group is this (lecture or class)
|
||||
*/
|
||||
public GroupType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return room where classes will take place
|
||||
*/
|
||||
public String getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return name of group lecturer
|
||||
*/
|
||||
public String getLecturer() {
|
||||
return lecturer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return time when group is scheduled on
|
||||
*/
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return time when class ends
|
||||
*/
|
||||
public String getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int what day is it. 0-6 (Monday - Sunday)
|
||||
*/
|
||||
public int getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return db id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ammount of taken places for group by other users
|
||||
*/
|
||||
public Integer getTakenPlaces() {
|
||||
return this.takenPlaces;
|
||||
}
|
||||
|
|
|
@ -4,29 +4,58 @@ import com.plannaplan.entities.Assignment;
|
|||
import com.plannaplan.entities.Groups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
/**
|
||||
* Group api response featuring group capacity
|
||||
*/
|
||||
@ApiModel(description = "Response shows information about group with included capacity.", value = "GroupWithCapacityResponse")
|
||||
public class GroupWithCapacityResponse extends GroupDefaultResponse {
|
||||
|
||||
private int capacity;
|
||||
|
||||
/**
|
||||
* create new instance
|
||||
*
|
||||
* @param group entity to map to api response
|
||||
*/
|
||||
public GroupWithCapacityResponse(Groups group) {
|
||||
super(group);
|
||||
this.capacity = group.getCapacity();
|
||||
}
|
||||
|
||||
/**
|
||||
* create new instance
|
||||
*
|
||||
* @param group entity to map to api response
|
||||
* @param takenPlaces group taken places
|
||||
*/
|
||||
public GroupWithCapacityResponse(Groups group, int takenPlaces) {
|
||||
super(group, takenPlaces);
|
||||
this.capacity = group.getCapacity();
|
||||
}
|
||||
|
||||
/**
|
||||
* create new instance
|
||||
*
|
||||
* @param assignment entity to map to api response
|
||||
*/
|
||||
public GroupWithCapacityResponse(Assignment assignment) {
|
||||
this(assignment.getGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
* create new instance
|
||||
*
|
||||
* @param assignment entity to map to api response
|
||||
* @param takenPlaces group taken places
|
||||
*/
|
||||
public GroupWithCapacityResponse(Assignment assignment, int takenPlaces) {
|
||||
this(assignment.getGroup(), takenPlaces);
|
||||
super(assignment, takenPlaces);
|
||||
this.capacity = assignment.getGroup().getCapacity();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return group taken places
|
||||
*/
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package com.plannaplan.responses.models;
|
||||
|
||||
/**
|
||||
* Simple api response for number statistics
|
||||
*/
|
||||
public class StatisticSimpleNumberResponse {
|
||||
private Integer ammount;
|
||||
|
||||
/**
|
||||
* @param ammount to return as api response
|
||||
*/
|
||||
public StatisticSimpleNumberResponse(Integer ammount) {
|
||||
this.ammount = ammount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ammount
|
||||
*/
|
||||
public Integer getAmmount() {
|
||||
return ammount;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,9 @@ import com.plannaplan.entities.User;
|
|||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Response to show after successfully login cation
|
||||
*/
|
||||
@ApiModel(description = "Response shows information about logged user.", value = "TokenResponse")
|
||||
public class TokenResponse {
|
||||
@ApiModelProperty(value = "user token used to verify requests")
|
||||
|
@ -18,6 +21,9 @@ public class TokenResponse {
|
|||
@ApiModelProperty(value = "user unviersity email")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* @param user user to be mapped to api response
|
||||
*/
|
||||
public TokenResponse(User user) {
|
||||
this.id = user.getId();
|
||||
this.authorityRole = user.getRole().toString();
|
||||
|
@ -26,22 +32,37 @@ public class TokenResponse {
|
|||
this.refreshToken = user.getRefreshToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return user email
|
||||
*/
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return user role in system
|
||||
*/
|
||||
public String getAuthorityRole() {
|
||||
return authorityRole;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return db id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return user token to authorize other requests
|
||||
*/
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return user refresh token
|
||||
*/
|
||||
public String getRefreshToken() {
|
||||
return this.refreshToken;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@ import com.plannaplan.entities.User;
|
|||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
/**
|
||||
* Model for api response for user serach results.
|
||||
*/
|
||||
@ApiModel(description = "Response shows information about user.", value = "UserResponse")
|
||||
public class UserResponse {
|
||||
|
||||
|
@ -12,6 +15,9 @@ public class UserResponse {
|
|||
private String surname;
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* @param user entity to be mapped to api response
|
||||
*/
|
||||
public UserResponse(User user) {
|
||||
this.id = user.getId();
|
||||
this.name = user.getName() != null ? user.getName() : "";
|
||||
|
@ -19,18 +25,30 @@ public class UserResponse {
|
|||
this.email = user.getEmail();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return user email
|
||||
*/
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return user surname
|
||||
*/
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return user name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return db id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -2,20 +2,43 @@ package com.plannaplan.responses.models.abstracts;
|
|||
|
||||
import com.plannaplan.entities.Course;
|
||||
|
||||
/**
|
||||
* Course entity api response
|
||||
*/
|
||||
public abstract class CoursesResponse {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String symbol;
|
||||
|
||||
/**
|
||||
* create instance
|
||||
*
|
||||
* @param course entity to map to api response
|
||||
*/
|
||||
public CoursesResponse(Course course) {
|
||||
this.id = course.getId() != null ? course.getId() : null;
|
||||
this.name = course.getName() != null ? course.getName() : "";
|
||||
this.symbol = course.getSymbol() != null ? course.getSymbol() : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return course name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return course symbol
|
||||
*/
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return db id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Abstract api responses
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.responses.models.abstracts;
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* Provides models of all possible api responses. Convention for naming this
|
||||
* class is EntityModifierRepsone. For Example CourseDefaultResponse
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.responses.models;
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Contains packeges realted to creating api responses
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.responses;
|
|
@ -17,6 +17,9 @@ import org.springframework.security.web.util.matcher.RequestMatcher;
|
|||
|
||||
import static org.springframework.http.HttpHeaders.AUTHORIZATION;
|
||||
|
||||
/**
|
||||
* Spring authentication filter class
|
||||
*/
|
||||
public class AuthenticationFilter extends AbstractAuthenticationProcessingFilter {
|
||||
|
||||
AuthenticationFilter(final RequestMatcher requiresAuth) {
|
||||
|
|
|
@ -16,6 +16,9 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Spring authentication provider
|
||||
*/
|
||||
@Component
|
||||
public class AuthenticationProvider extends AbstractUserDetailsAuthenticationProvider {
|
||||
|
||||
|
@ -25,8 +28,6 @@ public class AuthenticationProvider extends AbstractUserDetailsAuthenticationPro
|
|||
@Override
|
||||
protected void additionalAuthenticationChecks(UserDetails userDetails,
|
||||
UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
|
||||
// is being done in other task
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,8 +6,12 @@ import com.plannaplan.types.UserRoles;
|
|||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
/**
|
||||
* Users Roles for spring app
|
||||
*/
|
||||
public enum AuthorityRoles implements GrantedAuthority {
|
||||
STUDENT("ROLE_STUDENT"), DEANERY("ROLE_DEANERY"), ADMIN("ROLE_ADMIN"), TEST_USER("ROLE_TESTUSER");
|
||||
STUDENT("ROLE_STUDENT"), DEANERY("ROLE_DEANERY"), ADMIN("ROLE_ADMIN"), TEST_USER("ROLE_TESTUSER"),
|
||||
DEVELOPER("ROLE_DEVELOPER");
|
||||
|
||||
private String role;
|
||||
|
||||
|
@ -20,6 +24,12 @@ public enum AuthorityRoles implements GrantedAuthority {
|
|||
return this.role;
|
||||
}
|
||||
|
||||
/**
|
||||
* map buisness logic UserRoles enum to spring enum
|
||||
*
|
||||
* @param role buisness logic enum
|
||||
* @return restservice AuthorityRoles enum
|
||||
*/
|
||||
public static final Optional<AuthorityRoles> getAuthorityRole(UserRoles role) {
|
||||
switch (role) {
|
||||
case ADMIN:
|
||||
|
@ -30,6 +40,8 @@ public enum AuthorityRoles implements GrantedAuthority {
|
|||
return Optional.of(AuthorityRoles.STUDENT);
|
||||
case TEST_USER:
|
||||
return Optional.of(AuthorityRoles.TEST_USER);
|
||||
case DEVELOPER:
|
||||
return Optional.of(AuthorityRoles.DEVELOPER);
|
||||
default:
|
||||
return Optional.empty();
|
||||
}
|
||||
|
|
|
@ -16,9 +16,11 @@ import org.springframework.http.HttpStatus;
|
|||
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
|
||||
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
|
||||
|
||||
/**
|
||||
* Spring config class for security
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
private static final RequestMatcher PROTECTED_URLS = new OrRequestMatcher(new AntPathRequestMatcher("/api/**"));
|
||||
|
@ -38,7 +40,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||
@Override
|
||||
public void configure(final WebSecurity webSecurity) {
|
||||
webSecurity.ignoring().antMatchers("/token**").antMatchers("/token/refresh**")
|
||||
.antMatchers("/api/v1/courses/all").antMatchers("/api/v1/groups/course/{id}")
|
||||
.antMatchers("/api/v1/courses/all")
|
||||
.antMatchers("/api/v1/groups/course/{id}", "/api/v1/configurator/config/tour")
|
||||
.antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources/**", "/configuration/security",
|
||||
"/swagger-ui.html", "/webjars/**");
|
||||
}
|
||||
|
|
|
@ -1,19 +1,36 @@
|
|||
package com.plannaplan.security.cas;
|
||||
|
||||
/**
|
||||
* Model to keep data from Cas response. It's important to remember that wee
|
||||
* need to register our domain name in CAS in order to get this data. Otherwise
|
||||
* CAS will retuned what user typed as login.
|
||||
*/
|
||||
public class CasUserIdentity {
|
||||
private String usosId;
|
||||
private String email;
|
||||
|
||||
public CasUserIdentity(String usosId, String email){
|
||||
|
||||
/**
|
||||
* creates new instance
|
||||
*
|
||||
* @param usosId usosId retured from CAS
|
||||
* @param email emial returned from CAS
|
||||
*/
|
||||
public CasUserIdentity(String usosId, String email) {
|
||||
this.usosId = usosId;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string with usosid
|
||||
*/
|
||||
public String getUsosId() {
|
||||
return usosId;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string with email
|
||||
*/
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package com.plannaplan.security.cas;
|
||||
|
||||
/**
|
||||
* Exception to throw when cas didn't validate provided ticket
|
||||
*/
|
||||
public class CasValidationExcepiton extends RuntimeException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CasValidationExcepiton(String s) {
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
package com.plannaplan.security.cas;
|
||||
|
||||
/**
|
||||
* We can authorize in different contexts. For example if we rgister our domain
|
||||
* we will get more info than on localhost. This abstraction let's us handle
|
||||
* both cases based on spring profile
|
||||
*/
|
||||
public interface CasValidator {
|
||||
|
||||
|
||||
/**
|
||||
* validate ticket (should be provided in costructor or by setter)
|
||||
*
|
||||
* @return CasUserIdentity instance with values from response or null if
|
||||
* validation failed
|
||||
*/
|
||||
CasUserIdentity validate();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,10 @@ import org.jasig.cas.client.validation.Assertion;
|
|||
import org.jasig.cas.client.validation.Cas20ServiceTicketValidator;
|
||||
import org.jasig.cas.client.validation.TicketValidationException;
|
||||
|
||||
/**
|
||||
* Cas Validator for UAM with domain registered for email and usosid as a
|
||||
* repsonse
|
||||
*/
|
||||
public class CustomUAMCasValidator implements CasValidator {
|
||||
private static String CAS_URL = "https://cas.amu.edu.pl/cas";
|
||||
private static String EMAIL_FIELD = "mail";
|
||||
|
@ -11,31 +15,36 @@ public class CustomUAMCasValidator implements CasValidator {
|
|||
private String service;
|
||||
private String ticket;
|
||||
|
||||
public CustomUAMCasValidator(String service, String ticket){
|
||||
/**
|
||||
* craste new instance
|
||||
*
|
||||
* @param service string with url of our service from where request began
|
||||
* @param ticket ticket returned after user provided creeds on cas page
|
||||
*/
|
||||
public CustomUAMCasValidator(String service, String ticket) {
|
||||
this.service = service;
|
||||
this.ticket = ticket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CasUserIdentity validate() {
|
||||
/*
|
||||
* TO DO
|
||||
* Dodać case z CAS10/CAS20/CAS30
|
||||
*/
|
||||
final Cas20ServiceTicketValidator validator = new Cas20ServiceTicketValidator(CustomUAMCasValidator.CAS_URL);
|
||||
|
||||
try {
|
||||
final Assertion assertion = validator.validate(this.ticket, this.service);
|
||||
|
||||
|
||||
if (assertion == null) {
|
||||
throw new CasValidationExcepiton("Validation failed. Assertion could not be retrieved for ticket " + "");
|
||||
throw new CasValidationExcepiton(
|
||||
"Validation failed. Assertion could not be retrieved for ticket " + "");
|
||||
}
|
||||
|
||||
final String usosid = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.USOS_ID).toString();
|
||||
|
||||
final String mail = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.EMAIL_FIELD).toString();
|
||||
final String usosid = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.USOS_ID)
|
||||
.toString();
|
||||
|
||||
return new CasUserIdentity(usosid,mail);
|
||||
final String mail = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.EMAIL_FIELD)
|
||||
.toString();
|
||||
|
||||
return new CasUserIdentity(usosid, mail);
|
||||
|
||||
} catch (TicketValidationException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -9,12 +9,21 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
/**
|
||||
* Cas Validator for localhost and not registered dopmains
|
||||
*/
|
||||
public class DefaultUAMCasValidator implements CasValidator {
|
||||
private static String CAS_URL = "https://cas.amu.edu.pl/cas";
|
||||
private final CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
private String service;
|
||||
private String ticket;
|
||||
|
||||
/**
|
||||
* craste new instance
|
||||
*
|
||||
* @param service string with url of our service from where request began
|
||||
* @param ticket ticket returned after user provided creeds on cas page
|
||||
*/
|
||||
public DefaultUAMCasValidator(String service, String ticket) {
|
||||
this.service = service;
|
||||
this.ticket = ticket;
|
||||
|
@ -39,13 +48,13 @@ public class DefaultUAMCasValidator implements CasValidator {
|
|||
}
|
||||
|
||||
String res = result.substring(result.indexOf('\n') + 1);
|
||||
return new CasUserIdentity(null,res);
|
||||
return new CasUserIdentity(null, res);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
throw new CasValidationExcepiton("Cas Validation has failed.");
|
||||
throw new CasValidationExcepiton("Cas Validation has failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* All calsses realted to authorizing user with CAS system.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.security.cas;
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* All classes realted to seciuirty includin spring secuirty and cas
|
||||
* authentication
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.plannaplan.security;
|
|
@ -14,6 +14,21 @@
|
|||
"name": "plannaplan.email",
|
||||
"type": "java.lang.String",
|
||||
"description": "Email from which app sends message"
|
||||
},
|
||||
{
|
||||
"name": "plannaplan.apiurl",
|
||||
"type": "java.lang.String",
|
||||
"description": "Url to usos api endpoints"
|
||||
},
|
||||
{
|
||||
"name": "plannaplan.apikey",
|
||||
"type": "java.lang.String",
|
||||
"description": "Api consumer key"
|
||||
},
|
||||
{
|
||||
"name": "plannaplan.apisecret",
|
||||
"type": "java.lang.String",
|
||||
"description": "Api consumer secret"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.plannaplan.entities.User;
|
|||
import com.plannaplan.services.UserService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
|
@ -31,11 +32,13 @@ public class CommisionControllerTest extends AbstractControllerTest {
|
|||
private UserService service;
|
||||
|
||||
private static User user;
|
||||
private static User admin;
|
||||
private static User otherUser;
|
||||
private static User asker;
|
||||
private static User otherAsker;
|
||||
|
||||
private static final String TEST_COMMISIONS_STUDENT_EMAIL = "commisions.student@notexisting.domain";
|
||||
private static final String TEST_COMMISIONS_ADMIN_EMAIL = "commisions.admin@notexisiting,domain";
|
||||
private static final String TEST_COMMISIONS_OTHER_STUDENT_EMAIL = "commisions.student2@notexisting.domain";
|
||||
private static final String TEST_COMMISIONS_DEANERY_EMAIL = "commisions.deanery@notexisting.domain";
|
||||
private static final String TEST_COMMISIONS_OTHER_DEANERY_EMAIL = "commisions.deanery2@notexisting.domain";
|
||||
|
@ -44,6 +47,9 @@ public class CommisionControllerTest extends AbstractControllerTest {
|
|||
private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
||||
private static final String GET_SOMEONE_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
||||
private static final String GET_USER_SCHEDULE_ENDPOINT = "/api/v1/commisions/user/schedule";
|
||||
private static final String GET_ASSIGNMENTS_ENDPOINT = "/api/v1/commisions/user/assignments";
|
||||
|
||||
private static final String EXPORT_DATA = "/api/v1/commisions/export/csv";
|
||||
|
||||
private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
|
||||
MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
|
||||
|
@ -67,14 +73,14 @@ public class CommisionControllerTest extends AbstractControllerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnOkAddingCommision() throws Exception {
|
||||
public void shouldFailAddingCommisionDueToWrongTour() throws Exception {
|
||||
this.checkUsers();
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token)
|
||||
.contentType(APPLICATION_JSON_UTF8).content("[]")).andExpect(status().isOk());
|
||||
.contentType(APPLICATION_JSON_UTF8).content("[]")).andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -95,15 +101,16 @@ public class CommisionControllerTest extends AbstractControllerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldAddCommisionWithSelfIdPrivided() throws Exception {
|
||||
public void shouldFailAddingCommisionWithSelfIdPrividedDueToWrongTour() throws Exception {
|
||||
this.checkUsers();
|
||||
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.user.getId().toString())
|
||||
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
||||
.andExpect(status().isOk());
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -253,6 +260,10 @@ public class CommisionControllerTest extends AbstractControllerTest {
|
|||
UserRoles.STUDENT);
|
||||
this.service.save(otherUser);
|
||||
}
|
||||
if (CommisionControllerTest.admin == null) {
|
||||
CommisionControllerTest.admin = new User(null, null, TEST_COMMISIONS_ADMIN_EMAIL, UserRoles.ADMIN);
|
||||
this.service.save(admin);
|
||||
}
|
||||
if (CommisionControllerTest.asker == null) {
|
||||
CommisionControllerTest.asker = new User(null, null, TEST_COMMISIONS_DEANERY_EMAIL, UserRoles.DEANERY);
|
||||
this.service.save(asker);
|
||||
|
@ -263,4 +274,50 @@ public class CommisionControllerTest extends AbstractControllerTest {
|
|||
this.service.save(otherAsker);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExportData() throws Exception {
|
||||
this.checkUsers();
|
||||
final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null);
|
||||
final String token = this.service.login(admin).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotExportDataDueToWrongPermision() throws Exception {
|
||||
this.checkUsers();
|
||||
final User student = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
||||
final String token = this.service.login(student).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExportDataBeCsvFile() throws Exception {
|
||||
this.checkUsers();
|
||||
final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null);
|
||||
final String token = this.service.login(admin).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
|
||||
assertTrue(
|
||||
mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().isOk())
|
||||
.andReturn().getResponse().getContentAsString().contains("user_id, zaj_cykl_id, gr_nr"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRetrunOkForAssignmentEnpoint() throws Exception {
|
||||
this.checkUsers();
|
||||
final User admin = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
||||
final String token = this.service.login(admin).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
|
||||
mockMvc.perform(get(GET_ASSIGNMENTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
|||
private static final String COURSE_ENDPOINT = "/api/v1/configurator/config/courses";
|
||||
private static final String TOURS_ENDPOINT = "/api/v1/configurator/config/tours";
|
||||
private static final String ADMIN_INIT_ENDPOINT = "/api/v1/configurator/admin/init";
|
||||
private static final String TOUR_GET_ENDPOINT = "/api/v1/configurator/admin/tour";
|
||||
private static final String FIRST_TOUR_START = "firstTourBegin";
|
||||
private static final String FIRST_TOUR_END = "firstTourEnd";
|
||||
private static final String SECOND_TOUR_START = "secondTourBegin";
|
||||
|
@ -230,19 +231,19 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
|||
@Test
|
||||
@Ignore
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldCreateAdminBecouseOfEmptyDatabase() throws Exception{
|
||||
public void shouldCreateAdminBecouseOfEmptyDatabase() throws Exception {
|
||||
// have no idea how to make this test independent from user that run this
|
||||
final String ticket = "";
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||
mockMvc.perform(get(ADMIN_INIT_ENDPOINT).param("ticket", ticket)).andExpect(status().isOk());
|
||||
mockMvc.perform(get(ADMIN_INIT_ENDPOINT).param("ticket", ticket)).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailDueToExistingAdmin() throws Exception{
|
||||
public void shouldFailDueToExistingAdmin() throws Exception {
|
||||
this.service.save(new User(null, null, "shouldFailDueToExistingAdmin@ConfigController.Test", UserRoles.ADMIN));
|
||||
final String ticket = "hfewlhfjlewhipfqwehipqwef";
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||
mockMvc.perform(get(ADMIN_INIT_ENDPOINT).param("ticket", ticket)).andExpect(status().is4xxClientError());
|
||||
mockMvc.perform(get(ADMIN_INIT_ENDPOINT).param("ticket", ticket)).andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -282,10 +283,9 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
|||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020").param(FIRST_TOUR_END, "14.12.2020")
|
||||
.param(SECOND_TOUR_START, "16.12.2020").param(SECOND_TOUR_END, "20.12.2020")
|
||||
.header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -295,10 +295,9 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
|||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||
.param(SECOND_TOUR_END, "13.12.2020").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020").param(FIRST_TOUR_END, "14.12.2020")
|
||||
.param(SECOND_TOUR_START, "16.12.2020").param(SECOND_TOUR_END, "13.12.2020")
|
||||
.header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
|
@ -309,10 +308,9 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
|||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||
.param(FIRST_TOUR_END, "10.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020").param(FIRST_TOUR_END, "10.12.2020")
|
||||
.param(SECOND_TOUR_START, "16.12.2020").param(SECOND_TOUR_END, "20.12.2020")
|
||||
.header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
|
@ -323,10 +321,9 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
|||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "13.12.2020")
|
||||
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020").param(FIRST_TOUR_END, "14.12.2020")
|
||||
.param(SECOND_TOUR_START, "13.12.2020").param(SECOND_TOUR_END, "20.12.2020")
|
||||
.header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
|
@ -337,10 +334,41 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
|||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020").param(FIRST_TOUR_END, "14.12.2020")
|
||||
.param(SECOND_TOUR_START, "16.12.2020").param(SECOND_TOUR_END, "20.12.2020")
|
||||
.header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnOKAuthorizedForGetTours() throws Exception {
|
||||
final String mail = "shouldReturnOKAuthorizedForGetTours@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||
|
||||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(TOUR_GET_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDenyForGetTours() throws Exception {
|
||||
final String mail = "shouldDenyForGetTours@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(TOUR_GET_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDenyWithNoToken() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(TOUR_GET_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,205 @@
|
|||
package com.plannaplan.controllers;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.services.UserService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class DeveloperControllerTest extends AbstractControllerTest {
|
||||
private static final String ACCEPT_ENDPOINT = "/api/v1/developer/algorythm/accept";
|
||||
private static final String EXCHANGE_ENDPOINT = "/api/v1/developer/algorythm/exchange";
|
||||
private static final String FIRST_TOUR_ENDPOINT = "/api/v1/developer/tours/first";
|
||||
private static final String NO_TOUR_ENDPOINT = "/api/v1/developer/tours/no";
|
||||
private static final String SECOND_TOUR_ENDPOINT = "/api/v1/developer/tours/second";
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/* ACCEPT TESTS */
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongAcces() throws Exception {
|
||||
final String mail = "shouldFailWithWrongAcces@DeveloperController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ACCEPT_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkPerformingAcceptAlgotyrhm() throws Exception {
|
||||
final String mail = "shouldOkPerformingAcceptAlgotyrhm@DeveloperController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ACCEPT_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWithNoToken() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ACCEPT_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
/* EXCHANGE TESTS */
|
||||
|
||||
@Test
|
||||
public void shouldFailExchangeWithWrongAcces() throws Exception {
|
||||
final String mail = "shouldFailExchangeWithWrongAcces@DeveloperController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkExchangeAlgotyrhm() throws Exception {
|
||||
final String mail = "shouldOkExchangeAlgotyrhm@DeveloperController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailExchaneWithNoToken() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
/* FIRST TOUR */
|
||||
|
||||
@Test
|
||||
public void shouldFailFirstTourWithWrongAcces() throws Exception {
|
||||
final String mail = "shouldFailFirstTourWithWrongAcces@DeveloperController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(FIRST_TOUR_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkFirstTourAlgotyrhm() throws Exception {
|
||||
final String mail = "shouldOkFirstTourAlgotyrhm@DeveloperController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(FIRST_TOUR_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFirstTourWithNoToken() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(FIRST_TOUR_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
/* SECOND TOUR */
|
||||
|
||||
@Test
|
||||
public void shouldFailSecondTourWithWrongAcces() throws Exception {
|
||||
final String mail = "shouldFailSecondTourWithWrongAcces@DeveloperController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(SECOND_TOUR_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkSecondTourAlgotyrhm() throws Exception {
|
||||
final String mail = "shouldOkSecondTourAlgotyrhm@DeveloperController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(SECOND_TOUR_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailSecondTourWithNoToken() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(SECOND_TOUR_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
/* NO TOUR */
|
||||
|
||||
@Test
|
||||
public void shouldNoTourWithWrongAcces() throws Exception {
|
||||
final String mail = "shouldNoTourWithWrongAcces@DeveloperController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(NO_TOUR_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkNoAlgotyrhm() throws Exception {
|
||||
final String mail = "shouldOkNoAlgotyrhm@DeveloperController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(NO_TOUR_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailNoTourWithNoToken() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(NO_TOUR_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -22,11 +22,13 @@ import java.nio.charset.Charset;
|
|||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Exchange;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.CommisionService;
|
||||
import com.plannaplan.services.CourseService;
|
||||
import com.plannaplan.services.ExchangeService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.services.UserService;
|
||||
|
@ -57,11 +59,14 @@ public class ExchangeControllerTest extends AbstractControllerTest {
|
|||
@Autowired
|
||||
private ExchangeService exchangeService;
|
||||
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldGetAllUsersExchanges() throws Exception {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldGetAllUsersExchanges@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
"shouldGetAllUsersExchanges@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
||||
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
||||
|
@ -70,26 +75,27 @@ public class ExchangeControllerTest extends AbstractControllerTest {
|
|||
this.exchangeService.save(new Exchange(assignment, groupDesired));
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(EXCHANGE_ENDPOINT + "/all").header("Authorization", "Bearer " +
|
||||
token)).andExpect(status().isOk());
|
||||
mockMvc.perform(get(EXCHANGE_ENDPOINT + "/all").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailGettingNotExistingExchange() throws Exception {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldFailGettingNotExistingExchange@ExchangeController.test", UserRoles.STUDENT));
|
||||
"shouldFailGettingNotExistingExchange@ExchangeController.test", UserRoles.STUDENT));
|
||||
|
||||
final String token = this.userService.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + user.getId()).header("Authorization", "Bearer " + token)).andExpect(status().isBadRequest());
|
||||
mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + user.getId()).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldGetSingleExchange() throws Exception{
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldGetSingleExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
public void shouldGetSingleExchange() throws Exception {
|
||||
final User user = this.userService.save(new User(null, null, "shouldGetSingleExchange@ExchangeController.test",
|
||||
"11111", UserRoles.STUDENT, 320));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
||||
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
||||
|
@ -98,14 +104,14 @@ public class ExchangeControllerTest extends AbstractControllerTest {
|
|||
final Exchange exchange = this.exchangeService.save(new Exchange(assignment, groupDesired));
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " +
|
||||
token)).andExpect(status().isOk());
|
||||
mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailGettingExchangeDueToPermission() throws Exception{
|
||||
public void shouldFailGettingExchangeDueToPermission() throws Exception {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldFailGettingExchangeDueToPermission@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
"shouldFailGettingExchangeDueToPermission@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
||||
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
|
@ -113,32 +119,33 @@ public class ExchangeControllerTest extends AbstractControllerTest {
|
|||
final Exchange exchange = this.exchangeService.save(new Exchange(assignment, groupDesired));
|
||||
|
||||
final User user2 = this.userService.save(new User(null, null,
|
||||
"shouldFailGettingExchangeDueToPermission2@ExchangeController.test", "11112", UserRoles.STUDENT, 321));
|
||||
"shouldFailGettingExchangeDueToPermission2@ExchangeController.test", "11112", UserRoles.STUDENT, 321));
|
||||
final String token2 = this.userService.login(user2).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " +
|
||||
token2)).andExpect(status().is4xxClientError());
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + token2))
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailPostDueToAssignmentNotFound() throws Exception{
|
||||
public void shouldFailPostDueToAssignmentNotFound() throws Exception {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldFailPostDueToAssignmentNotFound@ExchangeController.test", UserRoles.STUDENT));
|
||||
"shouldFailPostDueToAssignmentNotFound@ExchangeController.test", UserRoles.STUDENT));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
final Groups group = this.groupService.save(new Groups(212, "A2-1", null, 420, WeekDay.WEDNESDAY, null));
|
||||
|
||||
MockMvc mockMvc =
|
||||
MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " +
|
||||
token).contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": "+ user.getId() +", \"group\": "+ group.getId() +" }")).andExpect(status().isBadRequest());
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(
|
||||
post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8)
|
||||
.content("{\"assignment\": " + user.getId() + ", \"group\": " + group.getId() + " }"))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldInsertExchange() throws Exception{
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldInsertExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
public void shouldInsertExchange() throws Exception {
|
||||
final User user = this.userService.save(
|
||||
new User(null, null, "shouldInsertExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
||||
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
||||
|
@ -148,49 +155,55 @@ public class ExchangeControllerTest extends AbstractControllerTest {
|
|||
this.assignmentService.callAcceptAlgorythm();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " +
|
||||
token).contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": "+ assignment.getId() +", \"group\": "+ groupDesired.getId() +" }")).andExpect(status().isOk());
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)
|
||||
.contentType(APPLICATION_JSON_UTF8)
|
||||
.content("{\"assignment\": " + assignment.getId() + ", \"group\": " + groupDesired.getId() + " }"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailInsertExchangeDueToMissingGroup() throws Exception{
|
||||
public void shouldFailInsertExchangeDueToMissingGroup() throws Exception {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldFailInsertExchangeDueToMissingGroup@ExchangeController.test", UserRoles.STUDENT));
|
||||
"shouldFailInsertExchangeDueToMissingGroup@ExchangeController.test", UserRoles.STUDENT));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " +
|
||||
token).contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": "+ user.getId() +" }")).andExpect(status().isBadRequest());
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)
|
||||
.contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": " + user.getId() + " }"))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailInsertExchangeDueToMissingAssignment() throws Exception{
|
||||
public void shouldFailInsertExchangeDueToMissingAssignment() throws Exception {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldFailInsertExchangeDueToMissingAssignment@ExchangeController.test", UserRoles.STUDENT));
|
||||
"shouldFailInsertExchangeDueToMissingAssignment@ExchangeController.test", UserRoles.STUDENT));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
final Groups group = this.groupService.save(new Groups(212, "A2-1", null, 420, WeekDay.WEDNESDAY, null));
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " +
|
||||
token).contentType(APPLICATION_JSON_UTF8).content("{\"group\": "+ group.getId() +" }")).andExpect(status().isBadRequest());
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)
|
||||
.contentType(APPLICATION_JSON_UTF8).content("{\"group\": " + group.getId() + " }"))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailInsertExchangeDueToMissingParam() throws Exception{
|
||||
public void shouldFailInsertExchangeDueToMissingParam() throws Exception {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldFailInsertExchangeDueToMissingParam@ExchangeController.test", UserRoles.STUDENT));
|
||||
"shouldFailInsertExchangeDueToMissingParam@ExchangeController.test", UserRoles.STUDENT));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " +
|
||||
token).contentType(APPLICATION_JSON_UTF8)).andExpect(status().isBadRequest());
|
||||
mockMvc.perform(
|
||||
post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldDenyExchangeDueToAssigmentOverlapping() throws Exception{
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldDenyExchangeDueToAssigmentOverlapping@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
public void shouldDenyExchangeDueToAssigmentOverlapping() throws Exception {
|
||||
final User user = this.userService
|
||||
.save(new User(null, null, "shouldDenyExchangeDueToAssigmentOverlapping@ExchangeController.test",
|
||||
"11111", UserRoles.STUDENT, 320));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
|
@ -198,30 +211,34 @@ public class ExchangeControllerTest extends AbstractControllerTest {
|
|||
this.exchangeService.save(new Exchange(assignment, group));
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " +
|
||||
token).contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": "+ user.getId() +", \"group\": "+ group.getId() +" }")).andExpect(status().isBadRequest());
|
||||
mockMvc.perform(
|
||||
post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8)
|
||||
.content("{\"assignment\": " + user.getId() + ", \"group\": " + group.getId() + " }"))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDenyPostDueToAssignmentNotAccepted() throws Exception{
|
||||
public void shouldDenyPostDueToAssignmentNotAccepted() throws Exception {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldDenyPostDueToAssignmentNotAccepted@ExchangeController.test", UserRoles.STUDENT));
|
||||
"shouldDenyPostDueToAssignmentNotAccepted@ExchangeController.test", UserRoles.STUDENT));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
final Groups group = this.groupService.save(new Groups(212, "A2-1", null, 420, WeekDay.WEDNESDAY, null));
|
||||
final Groups group2 = this.groupService.save(new Groups(213, "A2-2", null, 420, WeekDay.MONDAY, null));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
final Assignment assignment = this.assignmentService.save(new Assignment(group,commision));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " +
|
||||
token).contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": "+ assignment.getId() +", \"group\": "+ group2.getId() +" }")).andExpect(status().isBadRequest());
|
||||
mockMvc.perform(
|
||||
post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8)
|
||||
.content("{\"assignment\": " + assignment.getId() + ", \"group\": " + group2.getId() + " }"))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldDeleteExchange() throws Exception{
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldDeleteExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
public void shouldDeleteExchange() throws Exception {
|
||||
final User user = this.userService.save(
|
||||
new User(null, null, "shouldDeleteExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
||||
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
||||
|
@ -230,14 +247,14 @@ public class ExchangeControllerTest extends AbstractControllerTest {
|
|||
final Exchange exchange = this.exchangeService.save(new Exchange(assignment, groupDesired));
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(delete(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " +
|
||||
token)).andExpect(status().isOk());
|
||||
mockMvc.perform(delete(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailDeleteDueToWrongPermissions() throws Exception{
|
||||
public void shouldFailDeleteDueToWrongPermissions() throws Exception {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldFailDeleteDueToWrongPermissions@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
"shouldFailDeleteDueToWrongPermissions@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
||||
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
|
@ -245,39 +262,41 @@ public class ExchangeControllerTest extends AbstractControllerTest {
|
|||
final Exchange exchange = this.exchangeService.save(new Exchange(assignment, groupDesired));
|
||||
|
||||
final User user2 = this.userService.save(new User(null, null,
|
||||
"shouldFailDeleteDueToWrongPermissions@ExchangeController2.test", "11112", UserRoles.STUDENT, 322));
|
||||
"shouldFailDeleteDueToWrongPermissions@ExchangeController2.test", "11112", UserRoles.STUDENT, 322));
|
||||
final String token2 = this.userService.login(user2).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " +
|
||||
token2)).andExpect(status().isBadRequest());
|
||||
mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + token2))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailDeleteDueToMissingParam() throws Exception{
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldFailDeleteDueToMissingParam@ExchangeController.test", UserRoles.STUDENT));
|
||||
public void shouldFailDeleteDueToMissingParam() throws Exception {
|
||||
final User user = this.userService.save(
|
||||
new User(null, null, "shouldFailDeleteDueToMissingParam@ExchangeController.test", UserRoles.STUDENT));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(delete(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError());
|
||||
mockMvc.perform(delete(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailDeleteDueToExchangeNotFound() throws Exception{
|
||||
public void shouldFailDeleteDueToExchangeNotFound() throws Exception {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldFailDeleteDueToExchangeNotFound@ExchangeController.test", UserRoles.STUDENT));
|
||||
"shouldFailDeleteDueToExchangeNotFound@ExchangeController.test", UserRoles.STUDENT));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(delete(EXCHANGE_ENDPOINT + "/" + user.getId()).header("Authorization", "Bearer " +
|
||||
token)).andExpect(status().isBadRequest());
|
||||
mockMvc.perform(delete(EXCHANGE_ENDPOINT + "/" + user.getId()).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldFailPostDueToGroupAlreadyAccepted() throws Exception{
|
||||
final User user = this.userService.save(new User(null, null, "shouldFailPostDueToGroupAlreadyAccepted@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
public void shouldFailPostDueToGroupAlreadyAccepted() throws Exception {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldFailPostDueToGroupAlreadyAccepted@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
||||
final Groups group2 = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
||||
|
@ -288,7 +307,55 @@ public class ExchangeControllerTest extends AbstractControllerTest {
|
|||
this.exchangeService.save(new Exchange(assignment, group2));
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " +
|
||||
token).contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": "+ assignment.getId() +", \"group\": "+ group2.getId() +" }")).andExpect(status().isBadRequest());
|
||||
mockMvc.perform(
|
||||
post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8)
|
||||
.content("{\"assignment\": " + assignment.getId() + ", \"group\": " + group2.getId() + " }"))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldFailForDiffrentCoursesExchange() throws Exception {
|
||||
final User user = this.userService.save(
|
||||
new User(null, null, "shouldInsertExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
final Course course = this.courseService
|
||||
.save(new Course("shouldFailForDiffrentCoursesExchangeCourse", "SFFDCEC"));
|
||||
final Course course2 = this.courseService
|
||||
.save(new Course("shouldFailForDiffrentCoursesExchangeCourse2", "SFFDCEC-2"));
|
||||
final Groups group = this.groupService.save(new Groups(215, "A2-2", course, 520, WeekDay.TUESDAY, null));
|
||||
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", course2, 530, WeekDay.MONDAY, null));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
||||
|
||||
this.assignmentService.callAcceptAlgorythm();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)
|
||||
.contentType(APPLICATION_JSON_UTF8)
|
||||
.content("{\"assignment\": " + assignment.getId() + ", \"group\": " + groupDesired.getId() + " }"))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldFailForDiffrentGroupTypesExchange() throws Exception {
|
||||
final User user = this.userService.save(
|
||||
new User(null, null, "shouldInsertExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
||||
final String token = this.userService.login(user).getToken();
|
||||
final Course course = this.courseService
|
||||
.save(new Course("shouldFailForDiffrentCoursesExchangeCourse", "SFFDCEC"));
|
||||
final Groups group = this.groupService.save(new Groups(12, "A2-2", course, 520, WeekDay.TUESDAY, null));
|
||||
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", course, 530, WeekDay.MONDAY, null));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
||||
|
||||
this.assignmentService.callAcceptAlgorythm();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)
|
||||
.contentType(APPLICATION_JSON_UTF8)
|
||||
.content("{\"assignment\": " + assignment.getId() + ", \"group\": " + groupDesired.getId() + " }"))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,244 @@
|
|||
package com.plannaplan.controllers;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.services.UserService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class StatisticsControllerTest extends AbstractControllerTest {
|
||||
|
||||
private static final String GROUP_AMMOUNTS_ENDPOINT = "/api/v1/statistics/groups/created";
|
||||
private static final String GROUP_FULL_AMMOUNTS_ENDPOINT = "/api/v1/statistics/groups/full";
|
||||
private static final String USER_ASSIGNED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/registered";
|
||||
private static final String USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/noregistered";
|
||||
private static final String USER_ACCEPTED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/accepted";
|
||||
private static final String USER_PARTLY_ACCEPTED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/accepted/partly";
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/* GROUP AMMOUNTS TESTS */
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongAccesGroupsAmmounts() throws Exception {
|
||||
final String mail = "shouldFailWithWrongAccesGroupsAmmounts@StatisticsController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(GROUP_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkGettingGroupsAmmounts() throws Exception {
|
||||
final String mail = "shouldOkGettingGroupsAmmounts@StatisticsController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(GROUP_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWithNoTokenGroupsAmmounts() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(GROUP_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
/* USERS ASSIGNED TESTS */
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongAccesRegisteredStudentsAmmount() throws Exception {
|
||||
final String mail = "shouldFailWithWrongAccesRegisteredStudentsAmmount@StatisticsController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkGettingRegisteredStudentsAmmount() throws Exception {
|
||||
final String mail = "shouldOkGettingRegisteredStudentsAmmount@StatisticsController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWithNoTokenRegisteredStudentsAmmount() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_ASSIGNED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
/* USERS NO ASSIGNED TESTS */
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongAccesNoRegisteredStudentsAmmount() throws Exception {
|
||||
final String mail = "shouldFailWithWrongAccesNoRegisteredStudentsAmmount@StatisticsController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkGettingNoRegisteredStudentsAmmount() throws Exception {
|
||||
final String mail = "shouldOkGettingNoRegisteredStudentsAmmount@StatisticsController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWithNoTokenNoRegisteredStudentsAmmount() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
/* USERS FULL ACCPTED TESTS */
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongAccessAcceptedStudentsAmmount() throws Exception {
|
||||
final String mail = "shouldFailWithWrongAccessAcceptedStudentsAmmount@StatisticsController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_ACCEPTED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkGettingAcceptedStudentsAmmount() throws Exception {
|
||||
final String mail = "shouldOkGettingAcceptedStudentsAmmount@StatisticsController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_ACCEPTED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWithNoTokenAcceptedStudentsAmmount() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_ACCEPTED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
/* USERS PARTLY ACCPTED TESTS */
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongAccessPartlyAcceptedStudentsAmmount() throws Exception {
|
||||
final String mail = "shouldFailWithWrongAccessPartlyAcceptedStudentsAmmount@StatisticsController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_PARTLY_ACCEPTED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkGettingPartlyAcceptedStudentsAmmount() throws Exception {
|
||||
final String mail = "shouldOkGettingPartlyAcceptedStudentsAmmount@StatisticsController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_PARTLY_ACCEPTED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWithNoTokenPartlyAcceptedStudentsAmmount() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_PARTLY_ACCEPTED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
/* USERS FULL TAKEN GROUPS TESTS */
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongAccessFullGroupsAmmount() throws Exception {
|
||||
final String mail = "shouldFailWithWrongAccessFullGroupsAmmount@StatisticsController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(GROUP_FULL_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkGettingFullGroupsAmmount() throws Exception {
|
||||
final String mail = "shouldOkGettingFullGroupsAmmount@StatisticsController.test";
|
||||
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
|
||||
|
||||
final String token = this.userService.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(GROUP_FULL_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWithNoTokenFullGroupsAmmount() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(GROUP_FULL_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue