diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..81aa2479a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*.class + +# Package Files # +*.jar +*.war +*.ear + +/target/ \ No newline at end of file diff --git a/JacksonReplacement/JsonAnySetter.java b/JacksonReplacement/JsonAnySetter.java new file mode 100644 index 000000000..2bee382de --- /dev/null +++ b/JacksonReplacement/JsonAnySetter.java @@ -0,0 +1,12 @@ +package com.darylbeattie.movies.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(value=ElementType.METHOD) +@Retention(value=RetentionPolicy.RUNTIME) +public @interface JsonAnySetter { + +} diff --git a/JacksonReplacement/JsonProperty.java b/JacksonReplacement/JsonProperty.java new file mode 100644 index 000000000..77be4f498 --- /dev/null +++ b/JacksonReplacement/JsonProperty.java @@ -0,0 +1,12 @@ +package com.darylbeattie.movies.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface JsonProperty { + String value() default ""; +} diff --git a/JacksonReplacement/JsonRootName.java b/JacksonReplacement/JsonRootName.java new file mode 100644 index 000000000..4f5450dfa --- /dev/null +++ b/JacksonReplacement/JsonRootName.java @@ -0,0 +1,12 @@ +package com.darylbeattie.movies.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface JsonRootName { + String value() default ""; +} diff --git a/JacksonReplacement/ObjectMapper.java b/JacksonReplacement/ObjectMapper.java new file mode 100644 index 000000000..2150c721d --- /dev/null +++ b/JacksonReplacement/ObjectMapper.java @@ -0,0 +1,69 @@ +package com.darylbeattie.movies.util; + +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONObject; + +public class ObjectMapper { + + /** + * This takes a JSON string and creates (and populates) an object of the given class + * with the data from that JSON string. It mimics the method signature of the jackson + * JSON API, so that we don't have to import the jackson library into this application. + * + * @param jsonString The JSON string to parse. + * @param objClass The class of object we want to create. + * @return The instantiation of that class, populated with data from the JSON object. + * @throws IOException If there was any kind of issue. + */ + public T readValue(String jsonString, Class objClass) throws IOException { + try { + return readValue(new JSONObject(jsonString), objClass); + } + catch (IOException ioe) { + throw ioe; + } + catch (Exception e) { + e.printStackTrace(); + throw new IOException(e); + } + } + + @SuppressWarnings("unchecked") + public T readValue(JSONObject json, Class objClass) throws IOException { + try { + //TODO Iterate through json object values and call the JsonAnySetter method on the unknown ones. + T obj = objClass.newInstance(); + for (Field f : objClass.getFields()) { + Annotation a = f.getAnnotation(JsonProperty.class); + if (List.class.equals(f.getType()) && (json.optJSONArray(((JsonProperty) a).value()) != null)) { // It's a list. + JSONArray jsonArray = json.optJSONArray(((JsonProperty) a).value()); + ParameterizedType listType = (ParameterizedType) f.getGenericType(); + Class subObj = (Class) listType.getActualTypeArguments()[0]; + List subObjList = ((Class>) f.getType()).newInstance(); + for (int i = 0; i < jsonArray.length(); i++) { + subObjList.add((R) readValue(jsonArray.getJSONObject(i), subObj)); + } + f.set(obj, subObjList); + } + else if (a != null) { + f.set(obj, json.opt(((JsonProperty) a).value())); + } + } + return obj; + } + catch (IOException ioe) { + throw ioe; + } + catch (Exception e) { + e.printStackTrace(); + throw new IOException(e); + } + } + +} \ No newline at end of file diff --git a/JacksonReplacement/README.md b/JacksonReplacement/README.md new file mode 100644 index 000000000..71bdb8a7d --- /dev/null +++ b/JacksonReplacement/README.md @@ -0,0 +1,6 @@ +Jackson Library Replacement +=========================== + +These files are provided by Darren Beattie as an example of how to replace the Jackson libraries with native libraries inside Android. + +They are provided without warrantee and if you modify them or find them useful, please let me know. diff --git a/LICENCE.txt b/LICENCE.txt new file mode 100644 index 000000000..5ec82a48a --- /dev/null +++ b/LICENCE.txt @@ -0,0 +1,648 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + 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. + + + Copyright (C) + + 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 . diff --git a/README.md b/README.md new file mode 100644 index 000000000..56c5ec377 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +The Movie DB API +================ + +Author: Stuart Boston (Omertron AT Gmail DOT com) + +This API uses the TheMovieDB.org API as specified here http://api.themoviedb.org/ + +Originally written for use by YetAnotherMovieJukebox (YAMJ) http://code.google.com/p/moviejukebox/ +But anyone can feel free to use it for other projects as well. + +TheMovieDB.org is an excellent open database for movie and film content. I encourage you to check it out and contribute to keep it growing. +http://www.themoviedb.org + +Project Logging +--------------- +This project uses SLF4J (http://www.slf4j.org) to abstract the logging in the project. +To use the logging in your own project you should add one of the bindings listed [HERE](http://www.slf4j.org/manual.html#swapping) + +Project Documentation +--------------------- +The automatically generated documentation can be found [HERE](http://omertron.github.com/api-themoviedb/) diff --git a/pom.xml b/pom.xml new file mode 100644 index 000000000..e4a00f5e5 --- /dev/null +++ b/pom.xml @@ -0,0 +1,337 @@ + + 4.0.0 + + + org.sonatype.oss + oss-parent + 7 + + + + 3.0.3 + + + com.omertron + themoviedbapi + 3.5-SNAPSHOT + jar + + API-The MovieDB + API for the TheMovieDb.org website + https://github.com/Omertron/api-themoviedb + 2012 + + + + Stuart Boston + omertron@gmail.com + omertron + http://omertron.com + 0 + + developer + + + + + + + GNU General Public License v3+ + http://www.gnu.org/licenses/gpl-3.0-standalone.html + repo + + + + + scm:git:git@github.com:Omertron/api-themoviedb.git + scm:git:git@github.com:Omertron/api-themoviedb.git + scm:git:git@github.com:Omertron/api-themoviedb.git + + + + + github-project-site + GitHub Project Pages + gitsite:git@github.com/Omertron/api-themoviedb.git + + + + + GitHub + https://github.com/Omertron/api-themoviedb/issues + + + + Hudson CI + http://jenkins.omertron.com/job/API-TheMovieDb/ + + + + false + UTF-8 + UTF-8 + zip + + + + + junit + junit + 4.11 + test + + + com.fasterxml.jackson.core + jackson-core + 2.1.4 + + + com.fasterxml.jackson.core + jackson-annotations + 2.1.4 + + + com.fasterxml.jackson.core + jackson-databind + 2.1.4 + + + commons-codec + commons-codec + 1.7 + + + org.apache.commons + commons-lang3 + 3.1 + + + org.slf4j + slf4j-api + 1.7.3 + + + org.slf4j + slf4j-jdk14 + 1.7.3 + test + + + + + ${project.artifactId}-${project.version}-r${buildNumber} + + + + org.codehaus.mojo + buildnumber-maven-plugin + 1.2 + + true + 0000 + {0,date,yyyy-MM-dd HH:mm:ss} + + + + validate + + create + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + 1.6 + 1.6 + true + true + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + ${project.name} + ${project.version} + ${buildNumber} + ${timestamp} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.13 + + + ${skipTests} + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.7 + + + create-version-txt + generate-resources + + + + + + + + Writing version file: ${version_file} + ${header_line} + ${build_date_line} + ${version_line} + + + + + run + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.4 + + + distro-assembly + package + + single + + + + src/main/resources/bin.xml + + + + + + + org.codehaus.mojo + versions-maven-plugin + 2.0 + + + org.apache.maven.plugins + maven-site-plugin + 3.2 + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.2 + + index + scm + issue-tracking + help + dependency-convergence + summary + dependency-management + dependencies + license + modules + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9 + + + + + + org.apache.maven.plugins + maven-clean-plugin + 2.5 + + + org.apache.maven.plugins + maven-deploy-plugin + 2.7 + + + org.apache.maven.plugins + maven-gpg-plugin + 1.4 + + + org.apache.maven.plugins + maven-install-plugin + 2.4 + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + + + + + org.apache.maven.scm + maven-scm-provider-gitexe + 1.4 + + + org.apache.maven.scm + maven-scm-manager-plexus + 1.4 + + + org.kathrynhuxtable.maven.wagon + wagon-gitsite + 0.3.1 + + + + + + + + release-sign-artifacts + + + performRelease + true + + + + + + maven-gpg-plugin + + + sign-artifacts + verify + + sign + + + + + + + + + + diff --git a/src/main/java/com/omertron/themoviedbapi/MovieDbException.java b/src/main/java/com/omertron/themoviedbapi/MovieDbException.java new file mode 100644 index 000000000..f781b5112 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/MovieDbException.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi; + +public class MovieDbException extends Exception { + + private static final long serialVersionUID = 1L; + + public enum MovieDbExceptionType { + /* + * Unknown error occured + */ + UNKNOWN_CAUSE, + /* + * URL is invalid + */ + INVALID_URL, + /* + * Page not found + */ + HTTP_404_ERROR, + /* + * The movie id was not found + */ + MOVIE_ID_NOT_FOUND, + /* + * Mapping failed from target to internal onbjects + */ + MAPPING_FAILED, + /* + * Error connecting to the service + */ + CONNECTION_ERROR, + /* + * Image was invalid + */ + INVALID_IMAGE, + /* + * Autorisation rejected + */ + AUTHORISATION_FAILURE; + } + + private final MovieDbExceptionType exceptionType; + private final String response; + + public MovieDbException(final MovieDbExceptionType exceptionType, final String response) { + super(); + this.exceptionType = exceptionType; + this.response = response; + } + + public MovieDbException(final MovieDbExceptionType exceptionType, final String response, final Throwable cause) { + super(cause); + this.exceptionType = exceptionType; + this.response = response; + } + + public MovieDbExceptionType getExceptionType() { + return exceptionType; + } + + public String getResponse() { + return response; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java new file mode 100644 index 000000000..4c75f5c67 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -0,0 +1,1522 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.omertron.themoviedbapi.MovieDbException.MovieDbExceptionType; +import com.omertron.themoviedbapi.model.*; +import com.omertron.themoviedbapi.tools.ApiUrl; +import static com.omertron.themoviedbapi.tools.ApiUrl.*; +import com.omertron.themoviedbapi.tools.WebBrowser; +import com.omertron.themoviedbapi.wrapper.*; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The MovieDb API

This is for version 3 of the API as specified here: http://help.themoviedb.org/kb/api/about-3 + * + * @author stuart.boston + */ +public class TheMovieDbApi { + + private static final Logger LOG = LoggerFactory.getLogger(TheMovieDbApi.class); + private String apiKey; + private TmdbConfiguration tmdbConfig; + /* + * API Methods + * + * These are not set to static so that multiple instances of + * the API can co-exist + */ + private static final String BASE_MOVIE = "movie/"; + private static final String BASE_PERSON = "person/"; + private static final String BASE_COMPANY = "company/"; + private static final String BASE_GENRE = "genre/"; + private static final String BASE_AUTH = "authentication/"; + private static final String BASE_COLLECTION = "collection/"; +// private static final String BASE_ACCOUNT = "account/"; + private static final String BASE_SEARCH = "search/"; + private static final String BASE_LIST = "list/"; + private static final String BASE_KEYWORD = "keyword/"; + // Account + /* + private final ApiUrl tmdbAccount = new ApiUrl(this, BASE_ACCOUNT); + private final ApiUrl tmdbFavouriteMovies = new ApiUrl(this, BASE_ACCOUNT, "/favorite_movies"); + private final ApiUrl tmdbPostFavourite = new ApiUrl(this, BASE_ACCOUNT, "/favorite"); + private final ApiUrl tmdbRatedMovies = new ApiUrl(this, BASE_ACCOUNT, "/rated_movies"); + private final ApiUrl tmdbMovieWatchList = new ApiUrl(this, BASE_ACCOUNT, "/movie_watchlist"); + private final ApiUrl tmdbPostMovieWatchList = new ApiUrl(this, BASE_ACCOUNT, "/movie_watchlist"); + */ + /* + * Jackson JSON configuration + */ + private static ObjectMapper mapper = new ObjectMapper(); + + /** + * API for The Movie Db. + * + * @param apiKey + * @throws MovieDbException + */ + public TheMovieDbApi(String apiKey) throws MovieDbException { + this.apiKey = apiKey; + ApiUrl apiUrl = new ApiUrl(this, "configuration"); + URL configUrl = apiUrl.buildUrl(); + String webpage = WebBrowser.request(configUrl); + + try { + WrapperConfig wc = mapper.readValue(webpage, WrapperConfig.class); + tmdbConfig = wc.getTmdbConfiguration(); + } catch (IOException ex) { + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, "Failed to read configuration", ex); + } + } + + /** + * Get the API key that is to be used + * + */ + public String getApiKey() { + return apiKey; + } + + /** + * Set the proxy information + * + * @param host + * @param port + * @param username + * @param password + */ + public void setProxy(String host, String port, String username, String password) { + WebBrowser.setProxyHost(host); + WebBrowser.setProxyPort(port); + WebBrowser.setProxyUsername(username); + WebBrowser.setProxyPassword(password); + } + + /** + * Set the connection and read time out values + * + * @param connect + * @param read + */ + public void setTimeout(int connect, int read) { + WebBrowser.setWebTimeoutConnect(connect); + WebBrowser.setWebTimeoutRead(read); + } + + /** + * Compare the MovieDB object with a title & year + * + * @param moviedb The moviedb object to compare too + * @param title The title of the movie to compare + * @param year The year of the movie to compare exact match + * @return True if there is a match, False otherwise. + */ + public static boolean compareMovies(MovieDb moviedb, String title, String year) { + return compareMovies(moviedb, title, year, 0); + } + + /** + * Compare the MovieDB object with a title & year + * + * @param moviedb The moviedb object to compare too + * @param title The title of the movie to compare + * @param year The year of the movie to compare + * @param maxDistance The Levenshtein Distance between the two titles. 0 = exact match + * @return True if there is a match, False otherwise. + */ + public static boolean compareMovies(MovieDb moviedb, String title, String year, int maxDistance) { + if ((moviedb == null) || (StringUtils.isBlank(title))) { + return Boolean.FALSE; + } + + if (isValidYear(year) && isValidYear(moviedb.getReleaseDate())) { + // Compare with year + String movieYear = moviedb.getReleaseDate().substring(0, 4); + if (movieYear.equals(year)) { + if (compareDistance(moviedb.getOriginalTitle(), title, maxDistance)) { + return Boolean.TRUE; + } + + if (compareDistance(moviedb.getTitle(), title, maxDistance)) { + return Boolean.TRUE; + } + } + } + + // Compare without year + if (compareDistance(moviedb.getOriginalTitle(), title, maxDistance)) { + return Boolean.TRUE; + } + + if (compareDistance(moviedb.getTitle(), title, maxDistance)) { + return Boolean.TRUE; + } + + return Boolean.FALSE; + } + + /** + * Compare the Levenshtein Distance between the two strings + * + * @param title1 + * @param title2 + * @param distance + */ + private static boolean compareDistance(String title1, String title2, int distance) { + return (StringUtils.getLevenshteinDistance(title1, title2) <= distance); + } + + /** + * Check the year is not blank or UNKNOWN + * + * @param year + */ + private static boolean isValidYear(String year) { + return (StringUtils.isNotBlank(year) && !year.equals("UNKNOWN")); + } + + // + /** + * Get the configuration information + */ + public TmdbConfiguration getConfiguration() { + return tmdbConfig; + } + + /** + * Generate the full image URL from the size and image path + * + * @param imagePath + * @param requiredSize + * @throws MovieDbException + */ + public URL createImageUrl(String imagePath, String requiredSize) throws MovieDbException { + if (!tmdbConfig.isValidSize(requiredSize)) { + throw new MovieDbException(MovieDbExceptionType.INVALID_IMAGE, requiredSize); + } + + StringBuilder sb = new StringBuilder(tmdbConfig.getBaseUrl()); + sb.append(requiredSize); + sb.append(imagePath); + try { + return (new URL(sb.toString())); + } catch (MalformedURLException ex) { + LOG.warn("Failed to create image URL: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.INVALID_URL, sb.toString(), ex); + } + } + + // + // + // + /** + * This method is used to generate a valid request token for user based authentication. + * + * A request token is required in order to request a session id. + * + * You can generate any number of request tokens but they will expire after 60 minutes. + * + * As soon as a valid session id has been created the token will be destroyed. + * + * @throws MovieDbException + */ + public TokenAuthorisation getAuthorisationToken() throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_AUTH, "token/new"); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + return mapper.readValue(webpage, TokenAuthorisation.class); + } catch (IOException ex) { + LOG.warn("Failed to get Authorisation Token: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.AUTHORISATION_FAILURE, webpage, ex); + } + } + + /** + * This method is used to generate a session id for user based authentication. + * + * A session id is required in order to use any of the write methods. + * + * @param token + * @throws MovieDbException + */ + public TokenSession getSessionToken(TokenAuthorisation token) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_AUTH, "session/new"); + + if (!token.getSuccess()) { + LOG.warn("Authorisation token was not successful!"); + throw new MovieDbException(MovieDbExceptionType.AUTHORISATION_FAILURE, "Authorisation token was not successful!"); + } + + apiUrl.addArgument(PARAM_TOKEN, token.getRequestToken()); + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + return mapper.readValue(webpage, TokenSession.class); + } catch (IOException ex) { + LOG.warn("Failed to get Session Token: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method is used to generate a guest session id. + * + * A guest session can be used to rate movies without having a registered TMDb user account. + * + * You should only generate a single guest session per user (or device) as you will be able to attach the ratings to a TMDb user + * account in the future. + * + * There are also IP limits in place so you should always make sure it's the end user doing the guest session actions. + * + * If a guest session is not used for the first time within 24 hours, it will be automatically discarded. + * + * @throws MovieDbException + */ + public TokenSession getGuestSessionToken() throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_AUTH, "guest_session/new"); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + return mapper.readValue(webpage, TokenSession.class); + } catch (IOException ex) { + LOG.warn("Failed to get Session Token: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + // + // + // + // + // + // + /** + * This method is used to retrieve all of the basic movie information. + * + * It will return the single highest rated poster and backdrop. + * + * @param movieId + * @param language + * @throws MovieDbException + */ + public MovieDb getMovieInfo(int movieId, String language) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE); + + apiUrl.addArgument(PARAM_ID, movieId); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + try { + return mapper.readValue(webpage, MovieDb.class); + } catch (IOException ex) { + LOG.warn("Failed to get movie info: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method is used to retrieve all of the basic movie information. + * + * It will return the single highest rated poster and backdrop. + * + * @param imdbId + * @param language + * @throws MovieDbException + */ + public MovieDb getMovieInfoImdb(String imdbId, String language) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE); + + apiUrl.addArgument(PARAM_ID, imdbId); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + try { + return mapper.readValue(webpage, MovieDb.class); + } catch (IOException ex) { + LOG.warn("Failed to get movie info: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method is used to retrieve all of the alternative titles we have for a particular movie. + * + * @param movieId + * @param country + * @throws MovieDbException + */ + public List getMovieAlternativeTitles(int movieId, String country) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "/alternative_titles"); + apiUrl.addArgument(PARAM_ID, movieId); + + if (StringUtils.isNotBlank(country)) { + apiUrl.addArgument(PARAM_COUNTRY, country); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + try { + WrapperAlternativeTitles wrapper = mapper.readValue(webpage, WrapperAlternativeTitles.class); + return wrapper.getTitles(); + } catch (IOException ex) { + LOG.warn("Failed to get movie alternative titles: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * Get the cast information for a specific movie id. + * + * TODO: Add a function to enrich the data with the people methods + * + * @param movieId + * @throws MovieDbException + */ + public List getMovieCasts(int movieId) throws MovieDbException { + List people = new ArrayList(); + + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "/casts"); + apiUrl.addArgument(PARAM_ID, movieId); + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperMovieCasts wrapper = mapper.readValue(webpage, WrapperMovieCasts.class); + + // Add a cast member + for (PersonCast cast : wrapper.getCast()) { + Person person = new Person(); + person.addCast(cast.getId(), cast.getName(), cast.getProfilePath(), cast.getCharacter(), cast.getOrder()); + people.add(person); + } + + // Add a crew member + for (PersonCrew crew : wrapper.getCrew()) { + Person person = new Person(); + person.addCrew(crew.getId(), crew.getName(), crew.getProfilePath(), crew.getDepartment(), crew.getJob()); + people.add(person); + } + + return people; + } catch (IOException ex) { + LOG.warn("Failed to get movie casts: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method should be used when you’re wanting to retrieve all of the images for a particular movie. + * + * @param movieId + * @param language + * @throws MovieDbException + */ + public List getMovieImages(int movieId, String language) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "/images"); + apiUrl.addArgument(PARAM_ID, movieId); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + List artwork = new ArrayList(); + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + try { + WrapperImages wrapper = mapper.readValue(webpage, WrapperImages.class); + + // Add all the posters to the list + for (Artwork poster : wrapper.getPosters()) { + poster.setArtworkType(ArtworkType.POSTER); + artwork.add(poster); + } + + // Add all the backdrops to the list + for (Artwork backdrop : wrapper.getBackdrops()) { + backdrop.setArtworkType(ArtworkType.BACKDROP); + artwork.add(backdrop); + } + + return artwork; + } catch (IOException ex) { + LOG.warn("Failed to get movie images: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method is used to retrieve all of the keywords that have been added to a particular movie. + * + * Currently, only English keywords exist. + * + * @param movieId + * @throws MovieDbException + */ + public List getMovieKeywords(int movieId) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "/keywords"); + apiUrl.addArgument(PARAM_ID, movieId); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperMovieKeywords wrapper = mapper.readValue(webpage, WrapperMovieKeywords.class); + return wrapper.getKeywords(); + } catch (IOException ex) { + LOG.warn("Failed to get movie keywords: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method is used to retrieve all of the release and certification data we have for a specific movie. + * + * @param movieId + * @param language + * @throws MovieDbException + */ + public List getMovieReleaseInfo(int movieId, String language) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "/releases"); + apiUrl.addArgument(PARAM_ID, movieId); + apiUrl.addArgument(PARAM_LANGUAGE, language); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperReleaseInfo wrapper = mapper.readValue(webpage, WrapperReleaseInfo.class); + return wrapper.getCountries(); + } catch (IOException ex) { + LOG.warn("Failed to get movie release information: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method is used to retrieve all of the trailers for a particular movie. + * + * Supported sites are YouTube and QuickTime. + * + * @param movieId + * @param language + * @throws MovieDbException + */ + public List getMovieTrailers(int movieId, String language) throws MovieDbException { + List trailers = new ArrayList(); + + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "/trailers"); + apiUrl.addArgument(PARAM_ID, movieId); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperTrailers wrapper = mapper.readValue(webpage, WrapperTrailers.class); + + // Add the trailer to the return list along with it's source + for (Trailer trailer : wrapper.getQuicktime()) { + trailer.setWebsite(Trailer.WEBSITE_QUICKTIME); + trailers.add(trailer); + } + // Add the trailer to the return list along with it's source + for (Trailer trailer : wrapper.getYoutube()) { + trailer.setWebsite(Trailer.WEBSITE_YOUTUBE); + trailers.add(trailer); + } + return trailers; + } catch (IOException ex) { + LOG.warn("Failed to get movie trailers: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method is used to retrieve a list of the available translations for a specific movie. + * + * @param movieId + * @throws MovieDbException + */ + public List getMovieTranslations(int movieId) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "/translations"); + apiUrl.addArgument(PARAM_ID, movieId); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperTranslations wrapper = mapper.readValue(webpage, WrapperTranslations.class); + return wrapper.getTranslations(); + } catch (IOException ex) { + LOG.warn("Failed to get movie tranlations: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * The similar movies method will let you retrieve the similar movies for a particular movie. + * + * This data is created dynamically but with the help of users votes on TMDb. + * + * The data is much better with movies that have more keywords + * + * @param movieId + * @param language + * @param page + * @throws MovieDbException + */ + public List getSimilarMovies(int movieId, String language, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "/similar_movies"); + apiUrl.addArgument(PARAM_ID, movieId); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperMovie wrapper = mapper.readValue(webpage, WrapperMovie.class); + return wrapper.getMovies(); + } catch (IOException ex) { + LOG.warn("Failed to get similar movies: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * Get the lists that the movie belongs to + * + * @param movieId + * @param language + * @param page + * @throws MovieDbException + */ + public List getMovieLists(int movieId, String language, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "/lists"); + apiUrl.addArgument(PARAM_ID, movieId); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperMovieList wrapper = mapper.readValue(webpage, WrapperMovieList.class); + return wrapper.getMovieList(); + } catch (IOException ex) { + LOG.warn("Failed to get movie lists: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * Get the changes for a specific movie id. + * + * Changes are grouped by key, and ordered by date in descending order. + * + * By default, only the last 24 hours of changes are returned. + * + * The maximum number of days that can be returned in a single request is 14. + * + * The language is present on fields that are translatable. + * + * TODO: DOES NOT WORK AT THE MOMENT. This is due to the "value" item changing type in the ChangeItem + * + * @param movieId + * @param startDate the start date of the changes, optional + * @param endDate the end date of the changes, optional + * @throws MovieDbException + */ + @Deprecated + public List getMovieChanges(int movieId, String startDate, String endDate) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "/changes"); + apiUrl.addArgument(PARAM_ID, movieId); + + if (StringUtils.isNotBlank(startDate)) { + apiUrl.addArgument("start_date", startDate); + } + + if (StringUtils.isNotBlank(endDate)) { + apiUrl.addArgument("end_date", endDate); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperChanges wrapper = mapper.readValue(webpage, WrapperChanges.class); + return wrapper.getChanges(); + } catch (IOException ex) { + LOG.warn("Failed to get movie changes: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + + } + + /** + * This method is used to retrieve the newest movie that was added to TMDb. + * + */ + public MovieDb getLatestMovie() throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "/latest"); + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + return mapper.readValue(webpage, MovieDb.class); + } catch (IOException ex) { + LOG.warn("Failed to get latest movie: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * Get the list of upcoming movies. + * + * This list refreshes every day. + * + * The maximum number of items this list will include is 100. + * + * @throws MovieDbException + */ + public List getUpcoming(String language, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "upcoming"); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperMovie wrapper = mapper.readValue(webpage, WrapperMovie.class); + return wrapper.getMovies(); + } catch (IOException ex) { + LOG.warn("Failed to get upcoming movies: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + + } + + /** + * This method is used to retrieve the movies currently in theatres. + * + * This is a curated list that will normally contain 100 movies. The default response will return 20 movies. + * + * TODO: Implement more than 20 movies + * + * @param language + * @param page + * @throws MovieDbException + */ + public List getNowPlayingMovies(String language, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "now-playing"); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperMovie wrapper = mapper.readValue(webpage, WrapperMovie.class); + return wrapper.getMovies(); + } catch (IOException ex) { + LOG.warn("Failed to get now playing movies: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method is used to retrieve the daily movie popularity list. + * + * This list is updated daily. The default response will return 20 movies. + * + * TODO: Implement more than 20 movies + * + * @param language + * @param page + * @throws MovieDbException + */ + public List getPopularMovieList(String language, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "popular"); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperMovie wrapper = mapper.readValue(webpage, WrapperMovie.class); + return wrapper.getMovies(); + } catch (IOException ex) { + LOG.warn("Failed to get popular movie list: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method is used to retrieve the top rated movies that have over 10 votes on TMDb. + * + * The default response will return 20 movies. + * + * TODO: Implement more than 20 movies + * + * @param language + * @param page + * @throws MovieDbException + */ + public List getTopRatedMovies(String language, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "top-rated"); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperMovie wrapper = mapper.readValue(webpage, WrapperMovie.class); + return wrapper.getMovies(); + } catch (IOException ex) { + LOG.warn("Failed to get top rated movies: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method lets users rate a movie. + * + * A valid session id is required. + * + * @param sessionId + * @param rating + * @throws MovieDbException + */ + public boolean postMovieRating(String sessionId, String rating) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_MOVIE, "/rating"); + + apiUrl.addArgument(PARAM_SESSION, sessionId); + apiUrl.addArgument(PARAM_VALUE, rating); + + throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + } + + // + // + // + /** + * This method is used to retrieve all of the basic information about a movie collection. + * + * You can get the ID needed for this method by making a getMovieInfo request for the belongs_to_collection. + * + * @param collectionId + * @param language + * @throws MovieDbException + */ + public CollectionInfo getCollectionInfo(int collectionId, String language) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_COLLECTION); + apiUrl.addArgument(PARAM_ID, collectionId); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + return mapper.readValue(webpage, CollectionInfo.class); + } catch (IOException ex) { + LOG.warn("Failed to get collection information: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * Get all of the images for a particular collection by collection id. + * + * @param collectionId + * @param language + * @throws MovieDbException + */ + public List getCollectionImages(int collectionId, String language) throws MovieDbException { + List artwork = new ArrayList(); + ApiUrl apiUrl = new ApiUrl(this, BASE_COLLECTION, "/images"); + apiUrl.addArgument(PARAM_ID, collectionId); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperImages wrapper = mapper.readValue(webpage, WrapperImages.class); + + // Add all the posters to the list + for (Artwork poster : wrapper.getPosters()) { + poster.setArtworkType(ArtworkType.POSTER); + artwork.add(poster); + } + + // Add all the backdrops to the list + for (Artwork backdrop : wrapper.getBackdrops()) { + backdrop.setArtworkType(ArtworkType.BACKDROP); + artwork.add(backdrop); + } + + return artwork; + } catch (IOException ex) { + LOG.warn("Failed to get collection images: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + + } + + // + // + // + /** + * This method is used to retrieve all of the basic person information. + * + * It will return the single highest rated profile image. + * + * @param personId + * @throws MovieDbException + */ + public Person getPersonInfo(int personId) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_PERSON); + + apiUrl.addArgument(PARAM_ID, personId); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + return mapper.readValue(webpage, Person.class); + } catch (IOException ex) { + LOG.warn("Failed to get movie info: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method is used to retrieve all of the cast & crew information for the person. + * + * It will return the single highest rated poster for each movie record. + * + * @param personId + * @throws MovieDbException + */ + public List getPersonCredits(int personId) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_PERSON, "/credits"); + + List personCredits = new ArrayList(); + + apiUrl.addArgument(PARAM_ID, personId); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperPersonCredits wrapper = mapper.readValue(webpage, WrapperPersonCredits.class); + + // Add a cast member + for (PersonCredit cast : wrapper.getCast()) { + cast.setPersonType(PersonType.CAST); + personCredits.add(cast); + } + // Add a crew member + for (PersonCredit crew : wrapper.getCrew()) { + crew.setPersonType(PersonType.CREW); + personCredits.add(crew); + } + return personCredits; + } catch (IOException ex) { + LOG.warn("Failed to get person credits: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method is used to retrieve all of the profile images for a person. + * + * @param personId + * @throws MovieDbException + */ + public List getPersonImages(int personId) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_PERSON, "/images"); + + List personImages = new ArrayList(); + + apiUrl.addArgument(PARAM_ID, personId); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperImages wrapper = mapper.readValue(webpage, WrapperImages.class); + + // Update the image type + for (Artwork artwork : wrapper.getProfiles()) { + artwork.setArtworkType(ArtworkType.PROFILE); + personImages.add(artwork); + } + return personImages; + } catch (IOException ex) { + LOG.warn("Failed to get person images: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * Get the changes for a specific person id. + * + * Changes are grouped by key, and ordered by date in descending order. + * + * By default, only the last 24 hours of changes are returned. + * + * The maximum number of days that can be returned in a single request is 14. + * + * The language is present on fields that are translatable. + * + * @param personId + * @param startDate + * @param endDate + * @throws MovieDbException + */ + public void getPersonChanges(int personId, String startDate, String endDate) throws MovieDbException { + throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + } + + /** + * Get the latest person id. + * + * @throws MovieDbException + */ + public Person getPersonLatest() throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_PERSON, "/latest"); + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + return mapper.readValue(webpage, Person.class); + } catch (IOException ex) { + LOG.warn("Failed to get latest person: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + // + // + // + /** + * This method is used to retrieve the basic information about a production company on TMDb. + * + * @param companyId + * @throws MovieDbException + */ + public Company getCompanyInfo(int companyId) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_COMPANY); + + apiUrl.addArgument(PARAM_ID, companyId); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + return mapper.readValue(webpage, Company.class); + } catch (IOException ex) { + LOG.warn("Failed to get company information: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This method is used to retrieve the movies associated with a company. + * + * These movies are returned in order of most recently released to oldest. The default response will return 20 movies per page. + * + * TODO: Implement more than 20 movies + * + * @param companyId + * @param language + * @param page + * @throws MovieDbException + */ + public List getCompanyMovies(int companyId, String language, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_COMPANY, "/movies"); + + apiUrl.addArgument(PARAM_ID, companyId); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperCompanyMovies wrapper = mapper.readValue(webpage, WrapperCompanyMovies.class); + return wrapper.getResults(); + } catch (IOException ex) { + LOG.warn("Failed to get company movies: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + // + // + // + /** + * You can use this method to retrieve the list of genres used on TMDb. + * + * These IDs will correspond to those found in movie calls. + * + * @param language + */ + public List getGenreList(String language) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_GENRE, "/list"); + apiUrl.addArgument(PARAM_LANGUAGE, language); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperGenres wrapper = mapper.readValue(webpage, WrapperGenres.class); + return wrapper.getGenres(); + } catch (IOException ex) { + LOG.warn("Failed to get genre list: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + @Deprecated + public List getGenreMovies(int genreId, String language, int page) throws MovieDbException { + return getGenreMovies(genreId, language, page, Boolean.TRUE); + } + + /** + * Get a list of movies per genre. + * + * It is important to understand that only movies with more than 10 votes get listed. + * + * This prevents movies from 1 10/10 rating from being listed first and for the first 5 pages. + * + * @param genreId + * @param language + * @param page + */ + public List getGenreMovies(int genreId, String language, int page, boolean includeAllMovies) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_GENRE, "/movies"); + apiUrl.addArgument(PARAM_ID, genreId); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + apiUrl.addArgument(PARAM_INCLUDE_ALL_MOVIES, includeAllMovies); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperMovie wrapper = mapper.readValue(webpage, WrapperMovie.class); + return wrapper.getMovies(); + } catch (IOException ex) { + LOG.warn("Failed to get genre movie list: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + // + // + // + + /** + * Search Movies This is a good starting point to start finding movies on TMDb. + * + * @param movieName + * @param searchYear Limit the search to the provided year. Zero (0) will get all years + * @param language The language to include. Can be blank/null. + * @param includeAdult true or false to include adult titles in the search + * @param page The page of results to return. 0 to get the default (first page) + * @throws MovieDbException + */ + public List searchMovie(String movieName, int searchYear, String language, boolean includeAdult, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "movie"); + if (StringUtils.isNotBlank(movieName)) { + apiUrl.addArgument(PARAM_QUERY, movieName); + } + + if (searchYear > 0) { + apiUrl.addArgument(PARAM_YEAR, Integer.toString(searchYear)); + } + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + apiUrl.addArgument(PARAM_ADULT, Boolean.toString(includeAdult)); + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, Integer.toString(page)); + } + + URL url = apiUrl.buildUrl(); + + String webpage = WebBrowser.request(url); + try { + WrapperMovie wrapper = mapper.readValue(webpage, WrapperMovie.class); + return wrapper.getMovies(); + } catch (IOException ex) { + LOG.warn("Failed to find movie: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + + } + + /** + * Search for collections by name. + * + * @param query + * @param language + * @param page + * @throws MovieDbException + */ + public List searchCollection(String query, String language, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "collections"); + + if (StringUtils.isNotBlank(query)) { + apiUrl.addArgument(PARAM_QUERY, query); + } + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, Integer.toString(page)); + } + + URL url = apiUrl.buildUrl(); + + String webpage = WebBrowser.request(url); + try { + WrapperCollection wrapper = mapper.readValue(webpage, WrapperCollection.class); + return wrapper.getResults(); + } catch (IOException ex) { + LOG.warn("Failed to find collection: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * This is a good starting point to start finding people on TMDb. + * + * The idea is to be a quick and light method so you can iterate through people quickly. + * + * @param personName + * @param includeAdult + * @param page + * @throws MovieDbException + */ + public List searchPeople(String personName, boolean includeAdult, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "person"); + apiUrl.addArgument(PARAM_QUERY, personName); + apiUrl.addArgument(PARAM_ADULT, includeAdult); + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperPerson wrapper = mapper.readValue(webpage, WrapperPerson.class); + return wrapper.getResults(); + } catch (IOException ex) { + LOG.warn("Failed to find person: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * Search for lists by name and description. + * + * @param query + * @param language + * @param page + * @throws MovieDbException + */ + public List searchList(String query, String language, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "list"); + + if (StringUtils.isNotBlank(query)) { + apiUrl.addArgument(PARAM_QUERY, query); + } + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, Integer.toString(page)); + } + + URL url = apiUrl.buildUrl(); + + String webpage = WebBrowser.request(url); + try { + WrapperMovieList wrapper = mapper.readValue(webpage, WrapperMovieList.class); + return wrapper.getMovieList(); + } catch (IOException ex) { + LOG.warn("Failed to find list: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * Search Companies. + * + * You can use this method to search for production companies that are part of TMDb. The company IDs will map to those returned + * on movie calls. + * + * http://help.themoviedb.org/kb/api/search-companies + * + * @param companyName + * @param page + * @throws MovieDbException + */ + public List searchCompanies(String companyName, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "company"); + apiUrl.addArgument(PARAM_QUERY, companyName); + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + try { + WrapperCompany wrapper = mapper.readValue(webpage, WrapperCompany.class); + return wrapper.getResults(); + } catch (IOException ex) { + LOG.warn("Failed to find company: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + /** + * Search for keywords by name + * + * @param query + * @param page + * @throws MovieDbException + */ + public List searchKeyword(String query, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "keyword"); + + if (StringUtils.isNotBlank(query)) { + apiUrl.addArgument(PARAM_QUERY, query); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, Integer.toString(page)); + } + + URL url = apiUrl.buildUrl(); + + String webpage = WebBrowser.request(url); + try { + WrapperKeywords wrapper = mapper.readValue(webpage, WrapperKeywords.class); + return wrapper.getResults(); + } catch (IOException ex) { + LOG.warn("Failed to find keyword: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + // + // + // + + /** + * Get a list by its ID + * + * @param listId + * @return The list and its items + * @throws MovieDbException + */ + public MovieDbList getList(String listId) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_LIST); + apiUrl.addArgument(PARAM_ID, listId); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + return mapper.readValue(webpage, MovieDbList.class); + } catch (IOException ex) { + LOG.warn("Failed to get list: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + // + // + // + + /** + * Get the basic information for a specific keyword id. + * + * @param keywordId + * @return + * @throws MovieDbException + */ + public Keyword getKeyword(String keywordId) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_KEYWORD); + apiUrl.addArgument(PARAM_ID, keywordId); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + return mapper.readValue(webpage, Keyword.class); + } catch (IOException ex) { + LOG.warn("Failed to get keyword: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + + } + + /** + * Get the list of movies for a particular keyword by id. + * + * @param keywordId + * @param language + * @param page + * @return List of movies with the keyword + * @throws MovieDbException + */ + public List getKeywordMovies(String keywordId, String language, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_KEYWORD, "/movies"); + apiUrl.addArgument(PARAM_ID, keywordId); + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperKeywordMovies wrapper = mapper.readValue(webpage, WrapperKeywordMovies.class); + return wrapper.getResults(); + } catch (IOException ex) { + LOG.warn("Failed to get top rated movies: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + + } + // + // + // + + public void getMovieChangesList(int page, String startDate, String endDate) throws MovieDbException { + throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + } + + public void getPersonChangesList(int page, String startDate, String endDate) throws MovieDbException { + throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + } + // +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/AlternativeTitle.java b/src/main/java/com/omertron/themoviedbapi/model/AlternativeTitle.java new file mode 100644 index 000000000..fc390e926 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/AlternativeTitle.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class AlternativeTitle implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(AlternativeTitle.class); + /* + * Properties + */ + @JsonProperty("iso_3166_1") + private String country; + @JsonProperty("title") + private String title; + + // + public String getCountry() { + return country; + } + + public String getTitle() { + return title; + } + // + + // + public void setCountry(String country) { + this.country = country; + } + + public void setTitle(String title) { + this.title = title; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final AlternativeTitle other = (AlternativeTitle) obj; + if ((this.country == null) ? (other.country != null) : !this.country.equals(other.country)) { + return false; + } + if ((this.title == null) ? (other.title != null) : !this.title.equals(other.title)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 89 * hash + (this.country != null ? this.country.hashCode() : 0); + hash = 89 * hash + (this.title != null ? this.title.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[AlternativeTitle="); + sb.append("[country=").append(country); + sb.append("],[title=").append(title); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/Artwork.java b/src/main/java/com/omertron/themoviedbapi/model/Artwork.java new file mode 100644 index 000000000..0c689a577 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/Artwork.java @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The artwork type information + * + * @author Stuart + */ +public class Artwork implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(Artwork.class); + /* + * Properties + */ + @JsonProperty("aspect_ratio") + private float aspectRatio; + @JsonProperty("file_path") + private String filePath; + @JsonProperty("height") + private int height; + @JsonProperty("iso_639_1") + private String language; + @JsonProperty("width") + private int width; + @JsonProperty("vote_average") + private float voteAverage; + @JsonProperty("vote_count") + private int voteCount; + @JsonProperty("flag") + private String flag; + private ArtworkType artworkType = ArtworkType.POSTER; + + // + public ArtworkType getArtworkType() { + return artworkType; + } + + public float getAspectRatio() { + return aspectRatio; + } + + public String getFilePath() { + return filePath; + } + + public int getHeight() { + return height; + } + + public String getLanguage() { + return language; + } + + public int getWidth() { + return width; + } + + public float getVoteAverage() { + return voteAverage; + } + + public int getVoteCount() { + return voteCount; + } + + public String getFlag() { + return flag; + } + + // + + // + public void setArtworkType(ArtworkType artworkType) { + this.artworkType = artworkType; + } + + public void setAspectRatio(float aspectRatio) { + this.aspectRatio = aspectRatio; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public void setHeight(int height) { + this.height = height; + } + + public void setLanguage(String language) { + this.language = language; + } + + public void setWidth(int width) { + this.width = width; + } + + public void setVoteAverage(float voteAverage) { + this.voteAverage = voteAverage; + } + + public void setVoteCount(int voteCount) { + this.voteCount = voteCount; + } + + public void setFlag(String flag) { + this.flag = flag; + } + + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Artwork other = (Artwork) obj; + if (Float.floatToIntBits(this.aspectRatio) != Float.floatToIntBits(other.aspectRatio)) { + return false; + } + if ((this.filePath == null) ? (other.filePath != null) : !this.filePath.equals(other.filePath)) { + return false; + } + if (this.height != other.height) { + return false; + } + if ((this.language == null) ? (other.language != null) : !this.language.equals(other.language)) { + return false; + } + if (this.width != other.width) { + return false; + } + if (this.artworkType != other.artworkType) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 71 * hash + Float.floatToIntBits(this.aspectRatio); + hash = 71 * hash + (this.filePath != null ? this.filePath.hashCode() : 0); + hash = 71 * hash + this.height; + hash = 71 * hash + (this.language != null ? this.language.hashCode() : 0); + hash = 71 * hash + this.width; + hash = 71 * hash + (this.artworkType != null ? this.artworkType.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[Artwork="); + sb.append("[aspectRatio=").append(aspectRatio); + sb.append("],[filePath=").append(filePath); + sb.append("],[height=").append(height); + sb.append("],[language=").append(language); + sb.append("],[width=").append(width); + sb.append("],[artworkType=").append(artworkType); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/ArtworkType.java b/src/main/java/com/omertron/themoviedbapi/model/ArtworkType.java new file mode 100644 index 000000000..383c35a33 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/ArtworkType.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +/** + * ArtworkType enum List of the artwork types that are available + */ +public enum ArtworkType { + + POSTER, // Poster artwork + BACKDROP, // Fanart/backdrop + PROFILE // Person image +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/ChangeItem.java b/src/main/java/com/omertron/themoviedbapi/model/ChangeItem.java new file mode 100644 index 000000000..a064a7712 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/ChangeItem.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ChangeItem { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(MovieChanges.class); + /* + * Properties + */ + @JsonProperty("id") + private String id; + @JsonProperty("action") + private String action; + @JsonProperty("time") + private String time; + @JsonProperty("value") + private ChangeValue value; + @JsonProperty("original_value") + private ChangeValue originalValue; + @JsonProperty("iso_639_1") + private String language; + + // + public String getId() { + return id; + } + + public String getAction() { + return action; + } + + public String getTime() { + return time; + } + + public ChangeValue getValue() { + return value; + } + + public ChangeValue getOriginalValue() { + return originalValue; + } + + public String getLanguage() { + return language; + } + // + + // + public void setId(String id) { + this.id = id; + } + + public void setAction(String action) { + this.action = action; + } + + public void setTime(String time) { + this.time = time; + } + + public void setValue(ChangeValue value) { + this.value = value; + } + + public void setOriginalValue(ChangeValue originalValue) { + this.originalValue = originalValue; + } + + public void setLanguage(String language) { + this.language = language; + } + + // + + @Override + public String toString() { + return "ChangeItem{" + "id=" + id + ", action=" + action + ", time=" + time + ", value=" + value + '}'; + } + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/ChangeValue.java b/src/main/java/com/omertron/themoviedbapi/model/ChangeValue.java new file mode 100644 index 000000000..b3cd2ff90 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/ChangeValue.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ChangeValue { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(MovieChanges.class); + /* + * Properties + */ + @JsonProperty("poster") + private Artwork poster; + @JsonProperty("backdrop") + private Artwork backdrop; + @JsonProperty("title") + private String title; + @JsonProperty("iso_3166_1") + private String language; + @JsonProperty("site") + private String site; + @JsonProperty("name") + private String name; + @JsonProperty("id") + private int id; + + // + public Artwork getPoster() { + return poster; + } + + public Artwork getBackdrop() { + return backdrop; + } + + public String getTitle() { + return title; + } + + public String getLanguage() { + return language; + } + + public String getSite() { + return site; + } + + public String getName() { + return name; + } + + public int getId() { + return id; + } + // + + // + public void setPoster(Artwork poster) { + this.poster = poster; + } + + public void setBackdrop(Artwork backdrop) { + this.backdrop = backdrop; + backdrop.setArtworkType(ArtworkType.BACKDROP); + } + + public void setTitle(String title) { + this.title = title; + } + + public void setLanguage(String language) { + this.language = language; + } + + public void setSite(String site) { + this.site = site; + } + + public void setName(String name) { + this.name = name; + } + + public void setId(int id) { + this.id = id; + } + + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/Collection.java b/src/main/java/com/omertron/themoviedbapi/model/Collection.java new file mode 100644 index 000000000..7df3b9647 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/Collection.java @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; +import java.io.Serializable; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +@JsonRootName("collection") +public class Collection implements Serializable { + + private static final long serialVersionUID = 1L; + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(Collection.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("title") + private String title; + @JsonProperty("name") + private String name; + @JsonProperty("poster_path") + private String posterPath; + @JsonProperty("backdrop_path") + private String backdropPath; + @JsonProperty("release_date") + private String releaseDate; + + // + public String getBackdropPath() { + return backdropPath; + } + + public int getId() { + return id; + } + + public String getPosterPath() { + return posterPath; + } + + public String getReleaseDate() { + return releaseDate; + } + + public String getTitle() { + if (StringUtils.isBlank(title)) { + return name; + } + return title; + } + + public String getName() { + if (StringUtils.isBlank(name)) { + return title; + } + return name; + } + // + + // + public void setBackdropPath(String backdropPath) { + this.backdropPath = backdropPath; + } + + public void setId(int id) { + this.id = id; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setName(String name) { + this.name = name; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Collection other = (Collection) obj; + if ((this.backdropPath == null) ? (other.backdropPath != null) : !this.backdropPath.equals(other.backdropPath)) { + return false; + } + if (this.id != other.id) { + return false; + } + if ((this.title == null) ? (other.title != null) : !this.title.equals(other.title)) { + return false; + } + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 19 * hash + (this.backdropPath != null ? this.backdropPath.hashCode() : 0); + hash = 19 * hash + this.id; + hash = 19 * hash + (this.title != null ? this.title.hashCode() : 0); + hash = 19 * hash + (this.name != null ? this.name.hashCode() : 0); + hash = 19 * hash + (this.posterPath != null ? this.posterPath.hashCode() : 0); + hash = 19 * hash + (this.releaseDate != null ? this.releaseDate.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[Collection="); + sb.append("[id=").append(id); + sb.append("],[title=").append(title); + sb.append("],[name=").append(name); + sb.append("],[posterPath=").append(posterPath); + sb.append("],[backdropPath=").append(backdropPath); + sb.append("],[releaseDate=").append(releaseDate); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/CollectionInfo.java b/src/main/java/com/omertron/themoviedbapi/model/CollectionInfo.java new file mode 100644 index 000000000..91a1fd475 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/CollectionInfo.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class CollectionInfo implements Serializable { + + private static final long serialVersionUID = 1L; + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(CollectionInfo.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("name") + private String name; + @JsonProperty("poster_path") + private String posterPath; + @JsonProperty("backdrop_path") + private String backdropPath; + @JsonProperty("parts") + private List parts = new ArrayList(); + + // + public String getBackdropPath() { + return backdropPath; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public List getParts() { + return parts; + } + + public String getPosterPath() { + return posterPath; + } + // + + // + public void setBackdropPath(String backdropPath) { + this.backdropPath = backdropPath; + } + + public void setId(int id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setParts(List parts) { + this.parts = parts; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[CollectionInfo="); + sb.append("[id=").append(id); + sb.append("],[name=").append(name); + sb.append("],[posterPath=").append(posterPath); + sb.append("],[backdropPath=").append(backdropPath); + sb.append("],[# of parts=").append(parts.size()); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/Company.java b/src/main/java/com/omertron/themoviedbapi/model/Company.java new file mode 100644 index 000000000..47d9ccce2 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/Company.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Company information + * + * @author Stuart + */ +public class Company implements Serializable { + + private static final long serialVersionUID = 1L; + // Logger + private static final Logger LOG = LoggerFactory.getLogger(Company.class); + private static final String DEFAULT_STRING = ""; + // Properties + @JsonProperty("id") + private int companyId = 0; + @JsonProperty("name") + private String name = DEFAULT_STRING; + @JsonProperty("description") + private String description = DEFAULT_STRING; + @JsonProperty("headquarters") + private String headquarters = DEFAULT_STRING; + @JsonProperty("homepage") + private String homepage = DEFAULT_STRING; + @JsonProperty("logo_path") + private String logoPath = DEFAULT_STRING; + @JsonProperty("parent_company") + private String parentCompany = DEFAULT_STRING; + + // + public int getCompanyId() { + return companyId; + } + + public String getDescription() { + return description; + } + + public String getHeadquarters() { + return headquarters; + } + + public String getHomepage() { + return homepage; + } + + public String getLogoPath() { + return logoPath; + } + + public String getName() { + return name; + } + + public String getParentCompany() { + return parentCompany; + } + // + + // + public void setCompanyId(int companyId) { + this.companyId = companyId; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setHeadquarters(String headquarters) { + this.headquarters = headquarters; + } + + public void setHomepage(String homepage) { + this.homepage = homepage; + } + + public void setLogoPath(String logoPath) { + this.logoPath = logoPath; + } + + public void setName(String name) { + this.name = name; + } + + public void setParentCompany(String parentCompany) { + this.parentCompany = parentCompany; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public String toString() { + return "Company{" + "companyId=" + companyId + ", name=" + name + ", description=" + description + ", headquarters=" + headquarters + ", homepage=" + homepage + ", logoPath=" + logoPath + ", parentCompany=" + parentCompany + '}'; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/Genre.java b/src/main/java/com/omertron/themoviedbapi/model/Genre.java new file mode 100644 index 000000000..2679c65c5 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/Genre.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +@JsonRootName("genre") +public class Genre implements Serializable { + + private static final long serialVersionUID = 1L; + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(Genre.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("name") + private String name; + + // + public int getId() { + return id; + } + + public String getName() { + return name; + } + // + + // + public void setId(int id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Genre other = (Genre) obj; + if (this.id != other.id) { + return false; + } + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 53 * hash + this.id; + hash = 53 * hash + (this.name != null ? this.name.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[Genre="); + sb.append("[id=").append(id); + sb.append("],[name=").append(name); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/Keyword.java b/src/main/java/com/omertron/themoviedbapi/model/Keyword.java new file mode 100644 index 000000000..f5169c85c --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/Keyword.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +@JsonRootName("keyword") +public class Keyword implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(Keyword.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("name") + private String name; + + // + public int getId() { + return id; + } + + public String getName() { + return name; + } + // + + // + public void setId(int id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Keyword other = (Keyword) obj; + if (this.id != other.id) { + return false; + } + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 83 * hash + this.id; + hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[Keyword="); + sb.append("[id=").append(id); + sb.append("],[name=").append(name); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/KeywordMovie.java b/src/main/java/com/omertron/themoviedbapi/model/KeywordMovie.java new file mode 100644 index 000000000..bb97e0509 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/KeywordMovie.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class KeywordMovie implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(KeywordMovie.class); + /* + * Properties + */ + @JsonProperty("id") + private String id; + @JsonProperty("backdrop_path") + private String backdropPath; + @JsonProperty("original_title") + private String originalTitle; + @JsonProperty("release_date") + private String releaseDate; + @JsonProperty("poster_path") + private String posterPath; + @JsonProperty("title") + private String title; + @JsonProperty("vote_average") + private float voteAverage; + @JsonProperty("vote_count") + private double voteCount; + + // + public static long getSerialVersionUID() { + return serialVersionUID; + } + + public String getBackdropPath() { + return backdropPath; + } + + public String getId() { + return id; + } + + public String getOriginalTitle() { + return originalTitle; + } + + public String getReleaseDate() { + return releaseDate; + } + + public String getPosterPath() { + return posterPath; + } + + public String getTitle() { + return title; + } + + public float getVoteAverage() { + return voteAverage; + } + + public double getVoteCount() { + return voteCount; + } + // + + // + public void setBackdropPath(String backdropPath) { + this.backdropPath = backdropPath; + } + + public void setId(String id) { + this.id = id; + } + + public void setOriginalTitle(String originalTitle) { + this.originalTitle = originalTitle; + } + + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setVoteAverage(float voteAverage) { + this.voteAverage = voteAverage; + } + + public void setVoteCount(double voteCount) { + this.voteCount = voteCount; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/Language.java b/src/main/java/com/omertron/themoviedbapi/model/Language.java new file mode 100644 index 000000000..71bd87720 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/Language.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +@JsonRootName("spoken_language") +public class Language implements Serializable { + + private static final long serialVersionUID = 1L; + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(Language.class); + /* + * Properties + */ + @JsonProperty("iso_639_1") + private String isoCode; + @JsonProperty("name") + private String name; + + // + public String getIsoCode() { + return isoCode; + } + + public String getName() { + return name; + } + // + + // + public void setIsoCode(String isoCode) { + this.isoCode = isoCode; + } + + public void setName(String name) { + this.name = name; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Language other = (Language) obj; + if ((this.isoCode == null) ? (other.isoCode != null) : !this.isoCode.equals(other.isoCode)) { + return false; + } + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 71 * hash + (this.isoCode != null ? this.isoCode.hashCode() : 0); + hash = 71 * hash + (this.name != null ? this.name.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[Language="); + sb.append("isoCode=").append(isoCode); + sb.append(", name=").append(name); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieChanges.java b/src/main/java/com/omertron/themoviedbapi/model/MovieChanges.java new file mode 100644 index 000000000..b6e13f14b --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieChanges.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class MovieChanges implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(MovieChanges.class); + /* + * Properties + */ + @JsonProperty("key") + private String key; + @JsonProperty("items") + private List items; + + // + public String getKey() { + return key; + } + + public List getItems() { + return items; + } + // + + // + public void setKey(String key) { + this.key = key; + } + + public void setItems(List items) { + this.items = items; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java new file mode 100644 index 000000000..e61d05a97 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java @@ -0,0 +1,354 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Movie Bean + * + * @author stuart.boston + */ +public class MovieDb implements Serializable { + + private static final long serialVersionUID = 1L; + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(MovieDb.class); + /* + * Properties + */ + @JsonProperty("backdrop_path") + private String backdropPath; + @JsonProperty("id") + private int id; + @JsonProperty("original_title") + private String originalTitle; + @JsonProperty("popularity") + private float popularity; + @JsonProperty("poster_path") + private String posterPath; + @JsonProperty("release_date") + private String releaseDate; + @JsonProperty("title") + private String title; + @JsonProperty("adult") + private boolean adult; + @JsonProperty("belongs_to_collection") + private Collection belongsToCollection; + @JsonProperty("budget") + private long budget; + @JsonProperty("genres") + private List genres; + @JsonProperty("homepage") + private String homepage; + @JsonProperty("imdb_id") + private String imdbID; + @JsonProperty("overview") + private String overview; + @JsonProperty("production_companies") + private List productionCompanies; + @JsonProperty("production_countries") + private List productionCountries; + @JsonProperty("revenue") + private long revenue; + @JsonProperty("runtime") + private int runtime; + @JsonProperty("spoken_languages") + private List spokenLanguages; + @JsonProperty("tagline") + private String tagline; + @JsonProperty("vote_average") + private float voteAverage; + @JsonProperty("vote_count") + private int voteCount; + @JsonProperty("status") + private String status; + + // + public String getBackdropPath() { + return backdropPath; + } + + public int getId() { + return id; + } + + public String getOriginalTitle() { + return originalTitle; + } + + public float getPopularity() { + return popularity; + } + + public String getPosterPath() { + return posterPath; + } + + public String getReleaseDate() { + return releaseDate; + } + + public String getTitle() { + return title; + } + + public boolean isAdult() { + return adult; + } + + public Collection getBelongsToCollection() { + return belongsToCollection; + } + + public long getBudget() { + return budget; + } + + public List getGenres() { + return genres; + } + + public String getHomepage() { + return homepage; + } + + public String getImdbID() { + return imdbID; + } + + public String getOverview() { + return overview; + } + + public List getProductionCompanies() { + return productionCompanies; + } + + public List getProductionCountries() { + return productionCountries; + } + + public long getRevenue() { + return revenue; + } + + public int getRuntime() { + return runtime; + } + + public List getSpokenLanguages() { + return spokenLanguages; + } + + public String getTagline() { + return tagline; + } + + public float getVoteAverage() { + return voteAverage; + } + + public int getVoteCount() { + return voteCount; + } + + public String getStatus() { + return status; + } + // + + // + public void setBackdropPath(String backdropPath) { + this.backdropPath = backdropPath; + } + + public void setId(int id) { + this.id = id; + } + + public void setOriginalTitle(String originalTitle) { + this.originalTitle = originalTitle; + } + + public void setPopularity(float popularity) { + this.popularity = popularity; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setAdult(boolean adult) { + this.adult = adult; + } + + public void setBelongsToCollection(Collection belongsToCollection) { + this.belongsToCollection = belongsToCollection; + } + + public void setBudget(long budget) { + this.budget = budget; + } + + public void setGenres(List genres) { + this.genres = genres; + } + + public void setHomepage(String homepage) { + this.homepage = homepage; + } + + public void setImdbID(String imdbID) { + this.imdbID = imdbID; + } + + public void setOverview(String overview) { + this.overview = overview; + } + + public void setProductionCompanies(List productionCompanies) { + this.productionCompanies = productionCompanies; + } + + public void setProductionCountries(List productionCountries) { + this.productionCountries = productionCountries; + } + + public void setRevenue(long revenue) { + this.revenue = revenue; + } + + public void setRuntime(int runtime) { + this.runtime = runtime; + } + + public void setSpokenLanguages(List spokenLanguages) { + this.spokenLanguages = spokenLanguages; + } + + public void setTagline(String tagline) { + this.tagline = tagline; + } + + public void setVoteAverage(float voteAverage) { + this.voteAverage = voteAverage; + } + + public void setVoteCount(int voteCount) { + this.voteCount = voteCount; + } + + public void setStatus(String status) { + this.status = status; + } + + // + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + // + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final MovieDb other = (MovieDb) obj; + if (this.id != other.id) { + return false; + } + if ((this.imdbID == null) ? (other.imdbID != null) : !this.imdbID.equals(other.imdbID)) { + return false; + } + if (this.runtime != other.runtime) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 89 * hash + this.id; + hash = 89 * hash + (this.imdbID != null ? this.imdbID.hashCode() : 0); + hash = 89 * hash + this.runtime; + return hash; + } + // + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[MovieDB="); + sb.append("[backdropPath=").append(backdropPath); + sb.append("],[id=").append(id); + sb.append("],[originalTitle=").append(originalTitle); + sb.append("],[popularity=").append(popularity); + sb.append("],[posterPath=").append(posterPath); + sb.append("],[releaseDate=").append(releaseDate); + sb.append("],[title=").append(title); + sb.append("],[adult=").append(adult); + sb.append("],[belongsToCollection=").append(belongsToCollection); + sb.append("],[budget=").append(budget); + sb.append("],[genres=").append(genres); + sb.append("],[homepage=").append(homepage); + sb.append("],[imdbID=").append(imdbID); + sb.append("],[overview=").append(overview); + sb.append("],[productionCompanies=").append(productionCompanies); + sb.append("],[productionCountries=").append(productionCountries); + sb.append("],[revenue=").append(revenue); + sb.append("],[runtime=").append(runtime); + sb.append("],[spokenLanguages=").append(spokenLanguages); + sb.append("],[tagline=").append(tagline); + sb.append("],[voteAverage=").append(voteAverage); + sb.append("],[voteCount=").append(voteCount); + sb.append("],[status=").append(status); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieDbList.java b/src/main/java/com/omertron/themoviedbapi/model/MovieDbList.java new file mode 100644 index 000000000..d3c51c1b4 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieDbList.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Collections; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Wrapper for the MovieDbList function + * @author stuart.boston + */ +public class MovieDbList { + /* + * Logger + */ + + private static final Logger LOG = LoggerFactory.getLogger(MovieDbList.class); + /* + * Properties + */ + @JsonProperty("id") + private String id; + @JsonProperty("created_by") + private String createdBy; + @JsonProperty("description") + private String description; + @JsonProperty("favorite_count") + private int favoriteCount; + @JsonProperty("items") + private List items = Collections.EMPTY_LIST; + @JsonProperty("item_count") + private int itemCount; + @JsonProperty("iso_639_1") + private String language; + @JsonProperty("name") + private String name; + @JsonProperty("poster_path") + private String posterPath; + + // + public String getId() { + return id; + } + + public String getCreatedBy() { + return createdBy; + } + + public String getDescription() { + return description; + } + + public int getFavoriteCount() { + return favoriteCount; + } + + public List getItems() { + return items; + } + + public int getItemCount() { + return itemCount; + } + + public String getLanguage() { + return language; + } + + public String getName() { + return name; + } + + public String getPosterPath() { + return posterPath; + } + // + + // + public void setId(String id) { + this.id = id; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setFavoriteCount(int favoriteCount) { + this.favoriteCount = favoriteCount; + } + + public void setItems(List items) { + this.items = items; + } + + public void setItemCount(int itemCount) { + this.itemCount = itemCount; + } + + public void setLanguage(String language) { + this.language = language; + } + + public void setName(String name) { + this.name = name; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieList.java b/src/main/java/com/omertron/themoviedbapi/model/MovieList.java new file mode 100644 index 000000000..747cbe020 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieList.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class MovieList implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(MovieList.class); + /* + * Properties + */ + @JsonProperty("description") + private String description; + @JsonProperty("favorite_count") + private int favoriteCount; + @JsonProperty("id") + private String id; + @JsonProperty("item_count") + private int itemCount; + @JsonProperty("iso_639_1") + private String language; + @JsonProperty("name") + private String name; + @JsonProperty("poster_path") + private String posterPath; + @JsonProperty("list_type") + private String listType; + + // + public String getDescription() { + return description; + } + + public int getFavoriteCount() { + return favoriteCount; + } + + public String getId() { + return id; + } + + public int getItemCount() { + return itemCount; + } + + public String getLanguage() { + return language; + } + + public String getName() { + return name; + } + + public String getPosterPath() { + return posterPath; + } + + public String getListType() { + return listType; + } + // + + // + public void setDescription(String description) { + this.description = description; + } + + public void setFavoriteCount(int favoriteCount) { + this.favoriteCount = favoriteCount; + } + + public void setId(String id) { + this.id = id; + } + + public void setItemCount(int itemCount) { + this.itemCount = itemCount; + } + + public void setLanguage(String language) { + this.language = language; + } + + public void setName(String name) { + this.name = name; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public void setListType(String listType) { + this.listType = listType; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public String toString() { + return "MovieList{" + "description=" + description + ", favoriteCount=" + favoriteCount + ", id=" + id + ", itemCount=" + itemCount + ", language=" + language + ", name=" + name + ", posterPath=" + posterPath + '}'; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/Person.java b/src/main/java/com/omertron/themoviedbapi/model/Person.java new file mode 100644 index 000000000..a80bd4b8b --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/Person.java @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +public class Person implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(Person.class); + + /* + * Static fields for default cast information + */ + private static final String CAST_DEPARTMENT = "acting"; + private static final String CAST_JOB = "actor"; + private static final String DEFAULT_STRING = ""; + /* + * Properties + */ + @JsonProperty("id") + private int id = -1; + @JsonProperty("name") + private String name = ""; + @JsonProperty("profile_path") + private String profilePath = DEFAULT_STRING; + private PersonType personType = PersonType.PERSON; + private String department = DEFAULT_STRING; // Crew + private String job = DEFAULT_STRING; // Crew + private String character = DEFAULT_STRING; // Cast + private int order = -1; // Cast + @JsonProperty("adult") + private boolean adult = false; // Person info + @JsonProperty("also_known_as") + private List aka = new ArrayList(); + @JsonProperty("biography") + private String biography = DEFAULT_STRING; + @JsonProperty("birthday") + private String birthday = DEFAULT_STRING; + @JsonProperty("deathday") + private String deathday = DEFAULT_STRING; + @JsonProperty("homepage") + private String homepage = DEFAULT_STRING; + @JsonProperty("place_of_birth") + private String birthplace = DEFAULT_STRING; + @JsonProperty("imdb_id") + private String imdbId = DEFAULT_STRING; + @JsonProperty("popularity") + private float popularity = 0.0f; + + /** + * Add a crew member + * + * @param id + * @param name + * @param profilePath + * @param department + * @param job + */ + public void addCrew(int id, String name, String profilePath, String department, String job) { + this.personType = PersonType.CREW; + this.id = id; + this.name = name; + this.profilePath = profilePath; + this.department = department; + this.job = job; + this.character = ""; + this.order = -1; + } + + /** + * Add a cast member + * + * @param id + * @param name + * @param profilePath + * @param character + * @param order + */ + public void addCast(int id, String name, String profilePath, String character, int order) { + this.personType = PersonType.CAST; + this.id = id; + this.name = name; + this.profilePath = profilePath; + this.character = character; + this.order = order; + this.department = CAST_DEPARTMENT; + this.job = CAST_JOB; + } + + // + public String getCharacter() { + return character; + } + + public String getDepartment() { + return department; + } + + public int getId() { + return id; + } + + public String getJob() { + return job; + } + + public String getName() { + return name; + } + + public int getOrder() { + return order; + } + + public PersonType getPersonType() { + return personType; + } + + public String getProfilePath() { + return profilePath; + } + + public boolean isAdult() { + return adult; + } + + public List getAka() { + return aka; + } + + public String getBiography() { + return biography; + } + + public String getBirthday() { + return birthday; + } + + public String getBirthplace() { + return birthplace; + } + + public String getDeathday() { + return deathday; + } + + public String getHomepage() { + return homepage; + } + + public String getImdbId() { + return imdbId; + } + + public float getPopularity() { + return popularity; + } + // + + // + public void setCharacter(String character) { + this.character = character; + } + + public void setDepartment(String department) { + this.department = department; + } + + public void setId(int id) { + this.id = id; + } + + public void setJob(String job) { + this.job = job; + } + + public void setName(String name) { + this.name = name; + } + + public void setOrder(int order) { + this.order = order; + } + + public void setPersonType(PersonType personType) { + this.personType = personType; + } + + public void setProfilePath(String profilePath) { + this.profilePath = profilePath; + } + + public void setAdult(boolean adult) { + this.adult = adult; + } + + public void setAka(List aka) { + this.aka = aka; + } + + public void setBiography(String biography) { + this.biography = biography; + } + + public void setBirthday(String birthday) { + this.birthday = birthday; + } + + public void setBirthplace(String birthplace) { + this.birthplace = birthplace; + } + + public void setDeathday(String deathday) { + this.deathday = deathday; + } + + public void setHomepage(String homepage) { + this.homepage = homepage; + } + + public void setImdbId(String imdbId) { + this.imdbId = imdbId; + } + + public void setPopularity(float popularity) { + this.popularity = popularity; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Person other = (Person) obj; + if (this.id != other.id) { + return false; + } + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + if ((this.profilePath == null) ? (other.profilePath != null) : !this.profilePath.equals(other.profilePath)) { + return false; + } + if (this.personType != other.personType) { + return false; + } + if ((this.department == null) ? (other.department != null) : !this.department.equals(other.department)) { + return false; + } + if ((this.job == null) ? (other.job != null) : !this.job.equals(other.job)) { + return false; + } + if ((this.character == null) ? (other.character != null) : !this.character.equals(other.character)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 37 * hash + this.id; + hash = 37 * hash + (this.name != null ? this.name.hashCode() : 0); + hash = 37 * hash + (this.profilePath != null ? this.profilePath.hashCode() : 0); + hash = 37 * hash + (this.personType != null ? this.personType.hashCode() : 0); + hash = 37 * hash + (this.department != null ? this.department.hashCode() : 0); + hash = 37 * hash + (this.job != null ? this.job.hashCode() : 0); + hash = 37 * hash + (this.character != null ? this.character.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[Person="); + sb.append("[id=").append(id); + sb.append("],[name=").append(name); + sb.append("],[profilePath=").append(profilePath); + sb.append("],[personType=").append(personType); + sb.append("],[department=").append(department); + sb.append("],[job=").append(job); + sb.append("],[character=").append(character); + sb.append("],[order=").append(order); + sb.append("],[adult=").append(adult); + sb.append("],[=aka").append(aka.toString()); + sb.append("],[biography=").append(biography); + sb.append("],[birthday=").append(birthday); + sb.append("],[deathday=").append(deathday); + sb.append("],[homepage=").append(homepage); + sb.append("],[birthplace=").append(birthplace); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/PersonCast.java b/src/main/java/com/omertron/themoviedbapi/model/PersonCast.java new file mode 100644 index 000000000..0f26edaa2 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/PersonCast.java @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class PersonCast implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(PersonCast.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("character") + private String character; + @JsonProperty("name") + private String name; + @JsonProperty("order") + private int order; + @JsonProperty("profile_path") + private String profilePath; + @JsonProperty("cast_id") + private int castId; + + // + public String getCharacter() { + return character; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public int getOrder() { + return order; + } + + public String getProfilePath() { + return profilePath; + } + + public int getCastId() { + return castId; + } + + // + + // + public void setCharacter(String character) { + this.character = character; + } + + public void setId(int id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setOrder(int order) { + this.order = order; + } + + public void setProfilePath(String profilePath) { + this.profilePath = profilePath; + } + + public void setCastId(int castId) { + this.castId = castId; + } + + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final PersonCast other = (PersonCast) obj; + if (this.id != other.id) { + return false; + } + if ((this.character == null) ? (other.character != null) : !this.character.equals(other.character)) { + return false; + } + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + if (this.order != other.order) { + return false; + } + if ((this.profilePath == null) ? (other.profilePath != null) : !this.profilePath.equals(other.profilePath)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 41 * hash + this.id; + hash = 41 * hash + (this.character != null ? this.character.hashCode() : 0); + hash = 41 * hash + (this.name != null ? this.name.hashCode() : 0); + hash = 41 * hash + this.order; + hash = 41 * hash + (this.profilePath != null ? this.profilePath.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[PersonCast="); + sb.append("id=").append(id); + sb.append("],[character=").append(character); + sb.append("],[name=").append(name); + sb.append("],[order=").append(order); + sb.append("],[profilePath=").append(profilePath); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/PersonCredit.java b/src/main/java/com/omertron/themoviedbapi/model/PersonCredit.java new file mode 100644 index 000000000..a17c6551c --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/PersonCredit.java @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +public class PersonCredit implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(PersonCredit.class); + private static final String DEFAULT_STRING = ""; + /* + * Properties + */ + @JsonProperty("id") + private int movieId = 0; + @JsonProperty("character") + private String character = DEFAULT_STRING; + @JsonProperty("original_title") + private String movieOriginalTitle = DEFAULT_STRING; + @JsonProperty("poster_path") + private String posterPath = DEFAULT_STRING; + @JsonProperty("release_date") + private String releaseDate = DEFAULT_STRING; + @JsonProperty("title") + private String movieTitle = DEFAULT_STRING; + @JsonProperty("department") + private String department = DEFAULT_STRING; + @JsonProperty("job") + private String job = DEFAULT_STRING; + @JsonProperty("adult") + private String adult = DEFAULT_STRING; + private PersonType personType = PersonType.PERSON; + + // + public String getCharacter() { + return character; + } + + public String getDepartment() { + return department; + } + + public String getJob() { + return job; + } + + public int getMovieId() { + return movieId; + } + + public String getMovieOriginalTitle() { + return movieOriginalTitle; + } + + public String getMovieTitle() { + return movieTitle; + } + + public PersonType getPersonType() { + return personType; + } + + public String getPosterPath() { + return posterPath; + } + + public String getReleaseDate() { + return releaseDate; + } + + public String getAdult() { + return adult; + } + // + + // + public void setCharacter(String character) { + this.character = character; + } + + public void setDepartment(String department) { + this.department = department; + } + + public void setJob(String job) { + this.job = job; + } + + public void setMovieId(int movieId) { + this.movieId = movieId; + } + + public void setMovieOriginalTitle(String movieOriginalTitle) { + this.movieOriginalTitle = movieOriginalTitle; + } + + public void setMovieTitle(String movieTitle) { + this.movieTitle = movieTitle; + } + + public void setPersonType(PersonType personType) { + this.personType = personType; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + public void setAdult(String adult) { + this.adult = adult; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[PersonCredit="); + sb.append("[movieId=").append(movieId); + sb.append("],[personType=").append(personType); + sb.append("],[originalTitle=").append(movieOriginalTitle); + sb.append("],[movieTitle=").append(movieTitle); + sb.append("],[posterPath=").append(posterPath); + sb.append("],[releaseDate=").append(releaseDate); + sb.append("],[character=").append(character); + sb.append("],[department=").append(department); + sb.append("],[job=").append(job); + sb.append("],[adult=").append(adult); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/PersonCrew.java b/src/main/java/com/omertron/themoviedbapi/model/PersonCrew.java new file mode 100644 index 000000000..f69c27166 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/PersonCrew.java @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class PersonCrew implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(PersonCrew.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("department") + private String department; + @JsonProperty("job") + private String job; + @JsonProperty("name") + private String name; + @JsonProperty("profile_path") + private String profilePath; + + // + public String getDepartment() { + return department; + } + + public int getId() { + return id; + } + + public String getJob() { + return job; + } + + public String getName() { + return name; + } + + public String getProfilePath() { + return profilePath; + } + // + + // + public void setDepartment(String department) { + this.department = department; + } + + public void setId(int id) { + this.id = id; + } + + public void setJob(String job) { + this.job = job; + } + + public void setName(String name) { + this.name = name; + } + + public void setProfilePath(String profilePath) { + this.profilePath = profilePath; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final PersonCrew other = (PersonCrew) obj; + if (this.id != other.id) { + return false; + } + if ((this.department == null) ? (other.department != null) : !this.department.equals(other.department)) { + return false; + } + if ((this.job == null) ? (other.job != null) : !this.job.equals(other.job)) { + return false; + } + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 59 * hash + this.id; + hash = 59 * hash + (this.department != null ? this.department.hashCode() : 0); + hash = 59 * hash + (this.job != null ? this.job.hashCode() : 0); + hash = 59 * hash + (this.name != null ? this.name.hashCode() : 0); + hash = 59 * hash + (this.profilePath != null ? this.profilePath.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[PersonCrew="); + sb.append("id=").append(id); + sb.append("],[department=").append(department); + sb.append("],[job=").append(job); + sb.append("],[name=").append(name); + sb.append("],[profilePath=").append(profilePath); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/PersonType.java b/src/main/java/com/omertron/themoviedbapi/model/PersonType.java new file mode 100644 index 000000000..1145578f8 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/PersonType.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +/** + * + * @author stuart.boston + */ +public enum PersonType { + + CAST, // A member of the cast + CREW, // A member of the crew + PERSON // No specific type +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/ProductionCompany.java b/src/main/java/com/omertron/themoviedbapi/model/ProductionCompany.java new file mode 100644 index 000000000..15f62ee55 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/ProductionCompany.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +@JsonRootName("production_company") +public class ProductionCompany implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(ProductionCompany.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("name") + private String name; + + // + public int getId() { + return id; + } + + public String getName() { + return name; + } + // + + // + public void setId(int id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ProductionCompany other = (ProductionCompany) obj; + if (this.id != other.id) { + return false; + } + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 37 * hash + this.id; + hash = 37 * hash + (this.name != null ? this.name.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[ProductionCompany="); + sb.append("[id=").append(id); + sb.append("],[name=").append(name); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/ProductionCountry.java b/src/main/java/com/omertron/themoviedbapi/model/ProductionCountry.java new file mode 100644 index 000000000..cc1063f16 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/ProductionCountry.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +@JsonRootName("production_country") +public class ProductionCountry implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(ProductionCountry.class); + /* + * Properties + */ + @JsonProperty("iso_3166_1") + private String isoCode; + @JsonProperty("name") + private String name; + + // + public String getIsoCode() { + return isoCode; + } + + public String getName() { + return name; + } + // + + // + public void setIsoCode(String isoCode) { + this.isoCode = isoCode; + } + + public void setName(String name) { + this.name = name; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ProductionCountry other = (ProductionCountry) obj; + if ((this.isoCode == null) ? (other.isoCode != null) : !this.isoCode.equals(other.isoCode)) { + return false; + } + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 47 * hash + (this.isoCode != null ? this.isoCode.hashCode() : 0); + hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[ProductionCountry="); + sb.append("[isoCode=").append(isoCode); + sb.append("],[name=").append(name); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/ReleaseInfo.java b/src/main/java/com/omertron/themoviedbapi/model/ReleaseInfo.java new file mode 100644 index 000000000..22a91c4bc --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/ReleaseInfo.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class ReleaseInfo implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(ReleaseInfo.class); + /* + * Properties + */ + @JsonProperty("iso_3166_1") + private String country; + @JsonProperty("certification") + private String certification; + @JsonProperty("release_date") + private String releaseDate; + + // + public String getCertification() { + return certification; + } + + public String getCountry() { + return country; + } + + public String getReleaseDate() { + return releaseDate; + } + // + + // + public void setCertification(String certification) { + this.certification = certification; + } + + public void setCountry(String country) { + this.country = country; + } + + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ReleaseInfo other = (ReleaseInfo) obj; + if ((this.country == null) ? (other.country != null) : !this.country.equals(other.country)) { + return false; + } + if ((this.certification == null) ? (other.certification != null) : !this.certification.equals(other.certification)) { + return false; + } + if ((this.releaseDate == null) ? (other.releaseDate != null) : !this.releaseDate.equals(other.releaseDate)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 89 * hash + (this.country != null ? this.country.hashCode() : 0); + hash = 89 * hash + (this.certification != null ? this.certification.hashCode() : 0); + hash = 89 * hash + (this.releaseDate != null ? this.releaseDate.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[ReleaseInfo="); + sb.append("[country=").append(country); + sb.append("],[certification=").append(certification); + sb.append("],[releaseDate=").append(releaseDate); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/StatusCode.java b/src/main/java/com/omertron/themoviedbapi/model/StatusCode.java new file mode 100644 index 000000000..9a0f3423b --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/StatusCode.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class StatusCode implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(StatusCode.class); + /* + * Properties + */ + @JsonProperty("status_code") + private int statusCode; + @JsonProperty("status_message") + private String statusMessage; + + // + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + // + + // + public String getStatusMessage() { + return statusMessage; + } + + public void setStatusMessage(String statusMessage) { + this.statusMessage = statusMessage; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Status Code: ").append(statusCode); + sb.append(", Message: ").append(statusMessage); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/TmdbConfiguration.java b/src/main/java/com/omertron/themoviedbapi/model/TmdbConfiguration.java new file mode 100644 index 000000000..469f9f1a0 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/TmdbConfiguration.java @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +public class TmdbConfiguration implements Serializable { + + private static final long serialVersionUID = 1L; + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(TmdbConfiguration.class); + /* + * Properties + */ + @JsonProperty("base_url") + private String baseUrl; + @JsonProperty("secure_base_url") + private String secureBaseUrl; + @JsonProperty("poster_sizes") + private List posterSizes; + @JsonProperty("backdrop_sizes") + private List backdropSizes; + @JsonProperty("profile_sizes") + private List profileSizes; + @JsonProperty("logo_sizes") + private List logoSizes; + + // //GEN-BEGIN:getterMethods + public List getBackdropSizes() { + return backdropSizes; + } + + public String getBaseUrl() { + return baseUrl; + } + + public List getPosterSizes() { + return posterSizes; + } + + public List getProfileSizes() { + return profileSizes; + } + + public List getLogoSizes() { + return logoSizes; + } + + public String getSecureBaseUrl() { + return secureBaseUrl; + } + + // + // //GEN-BEGIN:setterMethods + public void setBackdropSizes(List backdropSizes) { + this.backdropSizes = backdropSizes; + } + + public void setBaseUrl(String baseUrl) { + this.baseUrl = baseUrl; + } + + public void setPosterSizes(List posterSizes) { + this.posterSizes = posterSizes; + } + + public void setProfileSizes(List profileSizes) { + this.profileSizes = profileSizes; + } + + public void setLogoSizes(List logoSizes) { + this.logoSizes = logoSizes; + } + + public void setSecureBaseUrl(String secureBaseUrl) { + this.secureBaseUrl = secureBaseUrl; + } + // + + /** + * Copy the data from the passed object to this one + * + * @param config + */ + public void clone(TmdbConfiguration config) { + backdropSizes = config.getBackdropSizes(); + baseUrl = config.getBaseUrl(); + posterSizes = config.getPosterSizes(); + profileSizes = config.getProfileSizes(); + logoSizes = config.getLogoSizes(); + } + + /** + * Check that the poster size is valid + * + * @param posterSize + */ + public boolean isValidPosterSize(String posterSize) { + if (StringUtils.isBlank(posterSize) || posterSizes.isEmpty()) { + return false; + } + return posterSizes.contains(posterSize); + } + + /** + * Check that the backdrop size is valid + * + * @param backdropSize + */ + public boolean isValidBackdropSize(String backdropSize) { + if (StringUtils.isBlank(backdropSize) || backdropSizes.isEmpty()) { + return false; + } + return backdropSizes.contains(backdropSize); + } + + /** + * Check that the profile size is valid + * + * @param profileSize + */ + public boolean isValidProfileSize(String profileSize) { + if (StringUtils.isBlank(profileSize) || profileSizes.isEmpty()) { + return false; + } + return profileSizes.contains(profileSize); + } + + /** + * Check that the logo size is valid + * + * @param logoSize + */ + public boolean isValidLogoSize(String logoSize) { + if (StringUtils.isBlank(logoSize) || logoSizes.isEmpty()) { + return false; + } + return logoSizes.contains(logoSize); + } + + /** + * Check to see if the size is valid for any of the images types + * + * @param sizeToCheck + */ + public boolean isValidSize(String sizeToCheck) { + return (isValidPosterSize(sizeToCheck) + || isValidBackdropSize(sizeToCheck) + || isValidProfileSize(sizeToCheck) + || isValidLogoSize(sizeToCheck)); + } + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[ImageConfiguration="); + sb.append("[baseUrl=").append(baseUrl); + sb.append("],[posterSizes=").append(posterSizes.toString()); + sb.append("],[backdropSizes=").append(backdropSizes.toString()); + sb.append("],[profileSizes=").append(profileSizes.toString()); + sb.append("],[logoSizes=").append(logoSizes.toString()); + sb.append(("]]")); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/TokenAuthorisation.java b/src/main/java/com/omertron/themoviedbapi/model/TokenAuthorisation.java new file mode 100644 index 000000000..cebbd2d4d --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/TokenAuthorisation.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TokenAuthorisation { + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(TokenAuthorisation.class); + /* + * Properties + */ + @JsonProperty("expires_at") + private String expires; + @JsonProperty("request_token") + private String requestToken; + @JsonProperty("success") + private Boolean success; + + // + public String getExpires() { + return expires; + } + + public String getRequestToken() { + return requestToken; + } + + public Boolean getSuccess() { + return success; + } + // + + // + public void setExpires(String expires) { + this.expires = expires; + } + + public void setRequestToken(String requestToken) { + this.requestToken = requestToken; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public String toString() { + return "TokenAuthorisation{" + "expires=" + expires + ", requestToken=" + requestToken + ", success=" + success + '}'; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/TokenSession.java b/src/main/java/com/omertron/themoviedbapi/model/TokenSession.java new file mode 100644 index 000000000..5ba745392 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/TokenSession.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TokenSession { + /* + * Logger + */ + + private static final Logger LOG = LoggerFactory.getLogger(TokenSession.class); + /* + * Properties + */ + @JsonProperty("session_id") + private String sessionId; + @JsonProperty("success") + private Boolean success; + @JsonProperty("status_code") + private String statusCode; + @JsonProperty("status_message") + private String statusMessage; + @JsonProperty("guest_session_id") + private String guestSessionId; + @JsonProperty("expires_at") + private String expiresAt; + + // + public String getSessionId() { + return sessionId; + } + + public Boolean getSuccess() { + return success; + } + + public String getStatusCode() { + return statusCode; + } + + public String getStatusMessage() { + return statusMessage; + } + + public String getGuestSessionId() { + return guestSessionId; + } + + public String getExpiresAt() { + return expiresAt; + } + // + + // + public void setSessionId(String sessionId) { + this.sessionId = sessionId; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public void setStatusCode(String statusCode) { + this.statusCode = statusCode; + } + + public void setStatusMessage(String statusMessage) { + this.statusMessage = statusMessage; + } + + public void setGuestSessionId(String guestSessionId) { + this.guestSessionId = guestSessionId; + } + + public void setExpiresAt(String expiresAt) { + this.expiresAt = expiresAt; + } + + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public String toString() { + return "TokenSession{" + "sessionId=" + sessionId + ", success=" + success + ", statusCode=" + statusCode + ", statusMessage=" + statusMessage + ", guestSessionId=" + guestSessionId + ", expiresAt=" + expiresAt + '}'; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/Trailer.java b/src/main/java/com/omertron/themoviedbapi/model/Trailer.java new file mode 100644 index 000000000..e38112d7a --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/Trailer.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class Trailer implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(Trailer.class); + /* + * Website sources + */ + public static final String WEBSITE_YOUTUBE = "youtube"; + public static final String WEBSITE_QUICKTIME = "quicktime"; + /* + * Properties + */ + private String name; + private String size; + private String source; + private String website; // The website of the trailer + + // + public String getName() { + return name; + } + + public String getSize() { + return size; + } + + public String getSource() { + return source; + } + + public String getWebsite() { + return website; + } + // + + // + public void setName(String name) { + this.name = name; + } + + public void setSize(String size) { + this.size = size; + } + + public void setSource(String source) { + this.source = source; + } + + public void setWebsite(String website) { + this.website = website; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Trailer other = (Trailer) obj; + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + if ((this.size == null) ? (other.size != null) : !this.size.equals(other.size)) { + return false; + } + if ((this.source == null) ? (other.source != null) : !this.source.equals(other.source)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 61 * hash + (this.name != null ? this.name.hashCode() : 0); + hash = 61 * hash + (this.size != null ? this.size.hashCode() : 0); + hash = 61 * hash + (this.source != null ? this.source.hashCode() : 0); + hash = 61 * hash + (this.website != null ? this.website.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[Trailer="); + sb.append("name=").append(name); + sb.append("],[size=").append(size); + sb.append("],[source=").append(source); + sb.append("],[website=").append(website); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/Translation.java b/src/main/java/com/omertron/themoviedbapi/model/Translation.java new file mode 100644 index 000000000..315c069cd --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/Translation.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class Translation implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(Translation.class); + /* + * Properties + */ + @JsonProperty("english_name") + private String englishName; + @JsonProperty("iso_639_1") + private String isoCode; + @JsonProperty("name") + private String name; + + // + public String getEnglishName() { + return englishName; + } + + public String getIsoCode() { + return isoCode; + } + + public String getName() { + return name; + } + // + + // + public void setEnglishName(String englishName) { + this.englishName = englishName; + } + + public void setIsoCode(String isoCode) { + this.isoCode = isoCode; + } + + public void setName(String name) { + this.name = name; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Translation other = (Translation) obj; + if ((this.englishName == null) ? (other.englishName != null) : !this.englishName.equals(other.englishName)) { + return false; + } + if ((this.isoCode == null) ? (other.isoCode != null) : !this.isoCode.equals(other.isoCode)) { + return false; + } + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 29 * hash + (this.englishName != null ? this.englishName.hashCode() : 0); + hash = 29 * hash + (this.isoCode != null ? this.isoCode.hashCode() : 0); + hash = 29 * hash + (this.name != null ? this.name.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[Translation="); + sb.append("[englishName=").append(englishName); + sb.append("],[isoCode=").append(isoCode); + sb.append("],[name=").append(name); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/tools/ApiUrl.java b/src/main/java/com/omertron/themoviedbapi/tools/ApiUrl.java new file mode 100644 index 000000000..b443ff122 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/tools/ApiUrl.java @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.tools; + +import com.omertron.themoviedbapi.TheMovieDbApi; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLEncoder; +import java.util.HashMap; +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The API URL that is used to construct the API call + * + * @author Stuart + */ +public class ApiUrl { + + /* + * Logger + */ + private static final Logger LOG = LoggerFactory.getLogger(ApiUrl.class); + /* + * TheMovieDbApi API Base URL + */ + private static final String TMDB_API_BASE = "http://api.themoviedb.org/3/"; + /* + * Parameter configuration + */ + private static final String DELIMITER_FIRST = "?"; + private static final String DELIMITER_SUBSEQUENT = "&"; + private static final String DEFAULT_STRING = ""; + /* + * Properties + */ + private TheMovieDbApi tmdb; + private String method; + private String submethod; + private Map arguments = new HashMap(); + /* + * API Parameters + */ + public static final String PARAM_ADULT = "include_adult="; + public static final String PARAM_API_KEY = "api_key="; + public static final String PARAM_COUNTRY = "country="; + public static final String PARAM_FAVORITE = "favorite="; + public static final String PARAM_ID = "id="; + public static final String PARAM_LANGUAGE = "language="; + public static final String PARAM_INCLUDE_ALL_MOVIES = "include_all_movies="; +// public static final String PARAM_MOVIE_ID = "movie_id="; + public static final String PARAM_MOVIE_WATCHLIST = "movie_watchlist="; + public static final String PARAM_PAGE = "page="; + public static final String PARAM_QUERY = "query="; + public static final String PARAM_SESSION = "session_id="; + public static final String PARAM_TOKEN = "request_token="; + public static final String PARAM_VALUE = "value="; + public static final String PARAM_YEAR = "year="; + + // + /** + * Constructor for the simple API URL method without a sub-method + * + * @param method + */ + public ApiUrl(TheMovieDbApi tmdb, String method) { + this.tmdb = tmdb; + this.method = method; + this.submethod = DEFAULT_STRING; + } + + /** + * Constructor for the API URL with a sub-method + * + * @param method + * @param submethod + */ + public ApiUrl(TheMovieDbApi tmdb, String method, String submethod) { + this.tmdb = tmdb; + this.method = method; + this.submethod = submethod; + } + // + + /** + * Build the URL from the pre-created arguments. + */ + public URL buildUrl() { + StringBuilder urlString = new StringBuilder(TMDB_API_BASE); + + // Get the start of the URL + urlString.append(method); + + // We have either a queury, or a direct request + if (arguments.containsKey(PARAM_QUERY)) { + // Append the suffix of the API URL + urlString.append(submethod); + + // Append the key information + urlString.append(DELIMITER_FIRST).append(PARAM_API_KEY); + urlString.append(tmdb.getApiKey()); + + // Append the search term + urlString.append(DELIMITER_SUBSEQUENT); + urlString.append(PARAM_QUERY); + + String query = arguments.get(PARAM_QUERY); + + try { + urlString.append(URLEncoder.encode(query, "UTF-8")); + } catch (UnsupportedEncodingException ex) { + LOG.trace("Unable to encode query: '" + query + "' trying raw."); + // If we can't encode it, try it raw + urlString.append(query); + } + + arguments.remove(PARAM_QUERY); + } else { + // Append the ID if provided + if (arguments.containsKey(PARAM_ID)) { + urlString.append(arguments.get(PARAM_ID)); + arguments.remove(PARAM_ID); + } + + // Append the suffix of the API URL + urlString.append(submethod); + + // Append the key information + urlString.append(DELIMITER_FIRST).append(PARAM_API_KEY); + urlString.append(tmdb.getApiKey()); + } + + for (Map.Entry argEntry : arguments.entrySet()) { + urlString.append(DELIMITER_SUBSEQUENT).append(argEntry.getKey()); + urlString.append(argEntry.getValue()); + } + + try { + LOG.trace("URL: {}", urlString.toString()); + return new URL(urlString.toString()); + } catch (MalformedURLException ex) { + LOG.warn("Failed to create URL {} - {}", urlString.toString(), ex.toString()); + return null; + } finally { + arguments.clear(); + } + } + + /** + * Add arguments individually + * + * @param key + * @param value + */ + public void addArgument(String key, String value) { + arguments.put(key, value); + } + + /** + * Add arguments individually + * + * @param key + * @param value + */ + public void addArgument(String key, int value) { + arguments.put(key, Integer.toString(value)); + } + + /** + * Add arguments individually + * + * @param key + * @param value + */ + public void addArgument(String key, boolean value) { + arguments.put(key, Boolean.toString(value)); + } + + /** + * Clear the arguments + */ + public void clearArguments() { + arguments.clear(); + } + + /** + * Set the arguments directly + * + * @param args + */ + public void setArguments(Map args) { + arguments.putAll(args); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/tools/WebBrowser.java b/src/main/java/com/omertron/themoviedbapi/tools/WebBrowser.java new file mode 100644 index 000000000..0f0cfa52f --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/tools/WebBrowser.java @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.tools; + +import com.omertron.themoviedbapi.MovieDbException; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.StringWriter; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.Charset; +import java.nio.charset.UnsupportedCharsetException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Web browser with simple cookies support + */ +public final class WebBrowser { + + private static final Logger LOG = LoggerFactory.getLogger(WebBrowser.class); + private static Map browserProperties = new HashMap(); + private static Map> cookies = new HashMap>(); + private static String proxyHost = null; + private static String proxyPort = null; + private static String proxyUsername = null; + private static String proxyPassword = null; + private static String proxyEncodedPassword = null; + private static int webTimeoutConnect = 25000; // 25 second timeout + private static int webTimeoutRead = 90000; // 90 second timeout + + // Hide the constructor + protected WebBrowser() { + // prevents calls from subclass + throw new UnsupportedOperationException(); + } + + /** + * Populate the browser properties + */ + private static void populateBrowserProperties() { + if (browserProperties.isEmpty()) { + browserProperties.put("User-Agent", "Mozilla/5.25 Netscape/5.0 (Windows; I; Win95)"); + browserProperties.put("Accept", "application/json"); + } + } + + public static String request(String url) throws MovieDbException { + try { + return request(new URL(url)); + } catch (MalformedURLException ex) { + throw new MovieDbException(MovieDbException.MovieDbExceptionType.INVALID_URL, null, ex); + } + } + + public static URLConnection openProxiedConnection(URL url) throws MovieDbException { + try { + if (proxyHost != null) { + System.getProperties().put("proxySet", "true"); + System.getProperties().put("proxyHost", proxyHost); + System.getProperties().put("proxyPort", proxyPort); + } + + URLConnection cnx = url.openConnection(); + + if (proxyUsername != null) { + cnx.setRequestProperty("Proxy-Authorization", proxyEncodedPassword); + } + + return cnx; + } catch (IOException ex) { + throw new MovieDbException(MovieDbException.MovieDbExceptionType.INVALID_URL, null, ex); + } + } + + public static String request(URL url) throws MovieDbException { + StringWriter content = null; + + try { + content = new StringWriter(); + + BufferedReader in = null; + URLConnection cnx = null; + try { + cnx = openProxiedConnection(url); + + sendHeader(cnx); + readHeader(cnx); + + in = new BufferedReader(new InputStreamReader(cnx.getInputStream(), getCharset(cnx))); + String line; + while ((line = in.readLine()) != null) { + content.write(line); + } + } finally { + if (in != null) { + in.close(); + } + + if (cnx instanceof HttpURLConnection) { + ((HttpURLConnection) cnx).disconnect(); + } + } + return content.toString(); + } catch (IOException ex) { + throw new MovieDbException(MovieDbException.MovieDbExceptionType.CONNECTION_ERROR, null, ex); + } finally { + if (content != null) { + try { + content.close(); + } catch (IOException ex) { + LOG.debug("Failed to close connection: " + ex.getMessage()); + } + } + } + } + + private static void sendHeader(URLConnection cnx) { + populateBrowserProperties(); + + // send browser properties + for (Map.Entry browserProperty : browserProperties.entrySet()) { + cnx.setRequestProperty(browserProperty.getKey(), browserProperty.getValue()); + } + // send cookies + String cookieHeader = createCookieHeader(cnx); + if (!cookieHeader.isEmpty()) { + cnx.setRequestProperty("Cookie", cookieHeader); + } + } + + private static String createCookieHeader(URLConnection cnx) { + String host = cnx.getURL().getHost(); + StringBuilder cookiesHeader = new StringBuilder(); + for (Map.Entry> domainCookies : cookies.entrySet()) { + if (host.endsWith(domainCookies.getKey())) { + for (Map.Entry cookie : domainCookies.getValue().entrySet()) { + cookiesHeader.append(cookie.getKey()); + cookiesHeader.append("="); + cookiesHeader.append(cookie.getValue()); + cookiesHeader.append(";"); + } + } + } + if (cookiesHeader.length() > 0) { + // remove last ; char + cookiesHeader.deleteCharAt(cookiesHeader.length() - 1); + } + return cookiesHeader.toString(); + } + + private static void readHeader(URLConnection cnx) { + // read new cookies and update our cookies + for (Map.Entry> header : cnx.getHeaderFields().entrySet()) { + if ("Set-Cookie".equals(header.getKey())) { + for (String cookieHeader : header.getValue()) { + String[] cookieElements = cookieHeader.split(" *; *"); + if (cookieElements.length >= 1) { + String[] firstElem = cookieElements[0].split(" *= *"); + String cookieName = firstElem[0]; + String cookieValue = firstElem.length > 1 ? firstElem[1] : null; + String cookieDomain = null; + // find cookie domain + for (int i = 1; i < cookieElements.length; i++) { + String[] cookieElement = cookieElements[i].split(" *= *"); + if ("domain".equals(cookieElement[0])) { + cookieDomain = cookieElement.length > 1 ? cookieElement[1] : null; + break; + } + } + if (cookieDomain == null) { + // if domain isn't set take current host + cookieDomain = cnx.getURL().getHost(); + } + Map domainCookies = cookies.get(cookieDomain); + if (domainCookies == null) { + domainCookies = new HashMap(); + cookies.put(cookieDomain, domainCookies); + } + // add or replace cookie + domainCookies.put(cookieName, cookieValue); + } + } + } + } + } + + private static Charset getCharset(URLConnection cnx) { + Charset charset = null; + // content type will be string like "text/html; charset=UTF-8" or "text/html" + String contentType = cnx.getContentType(); + if (contentType != null) { + // changed 'charset' to 'harset' in regexp because some sites send 'Charset' + Matcher m = Pattern.compile("harset *=[ '\"]*([^ ;'\"]+)[ ;'\"]*").matcher(contentType); + if (m.find()) { + String encoding = m.group(1); + try { + charset = Charset.forName(encoding); + } catch (UnsupportedCharsetException e) { + // there will be used default charset + } + } + } + if (charset == null) { + charset = Charset.defaultCharset(); + } + + return charset; + } + + public static String getProxyHost() { + return proxyHost; + } + + public static void setProxyHost(String myProxyHost) { + WebBrowser.proxyHost = myProxyHost; + } + + public static String getProxyPort() { + return proxyPort; + } + + public static void setProxyPort(String myProxyPort) { + WebBrowser.proxyPort = myProxyPort; + } + + public static String getProxyUsername() { + return proxyUsername; + } + + public static void setProxyUsername(String myProxyUsername) { + WebBrowser.proxyUsername = myProxyUsername; + } + + public static String getProxyPassword() { + return proxyPassword; + } + + public static void setProxyPassword(String myProxyPassword) { + WebBrowser.proxyPassword = myProxyPassword; + + if (proxyUsername != null) { + proxyEncodedPassword = proxyUsername + ":" + proxyPassword; + proxyEncodedPassword = "Basic " + new String(Base64.encodeBase64((proxyUsername + ":" + proxyPassword).getBytes())); + } + } + + public static int getWebTimeoutConnect() { + return webTimeoutConnect; + } + + public static int getWebTimeoutRead() { + return webTimeoutRead; + } + + public static void setWebTimeoutConnect(int webTimeoutConnect) { + WebBrowser.webTimeoutConnect = webTimeoutConnect; + } + + public static void setWebTimeoutRead(int webTimeoutRead) { + WebBrowser.webTimeoutRead = webTimeoutRead; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperAlternativeTitles.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperAlternativeTitles.java new file mode 100644 index 000000000..d615e39f1 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperAlternativeTitles.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.AlternativeTitle; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class WrapperAlternativeTitles { + /* + * Logger + */ + + private static final Logger LOG = LoggerFactory.getLogger(WrapperAlternativeTitles.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("titles") + private List titles; + + public int getId() { + return id; + } + + public List getTitles() { + return titles; + } + + public void setId(int id) { + this.id = id; + } + + public void setTitles(List titles) { + this.titles = titles; + } + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperBase.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperBase.java new file mode 100644 index 000000000..196dd7efa --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperBase.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.slf4j.Logger; + +/** + * Base class for the wrappers + * + * @author Stuart + */ +public class WrapperBase { + /* + * Logger - set by the sub-classes + */ + + private Logger log; + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("page") + private int page; + @JsonProperty("total_pages") + private int totalPages; + @JsonProperty("total_results") + private int totalResults; + + public WrapperBase(Logger logger) { + this.log = logger; + } + + // + public int getId() { + return id; + } + + public int getPage() { + return page; + } + + public int getTotalPages() { + return totalPages; + } + + public int getTotalResults() { + return totalResults; + } + // + + // + public void setId(int id) { + this.id = id; + } + + public void setPage(int page) { + this.page = page; + } + + public void setTotalPages(int totalPages) { + this.totalPages = totalPages; + } + + public void setTotalResults(int totalResults) { + this.totalResults = totalResults; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + log.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperChanges.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperChanges.java new file mode 100644 index 000000000..6ee334390 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperChanges.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.MovieChanges; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +public class WrapperChanges { + /* + * Logger + */ + + private static final Logger LOG = LoggerFactory.getLogger(WrapperChanges.class); + /* + * Properties + */ + @JsonProperty("changes") + private List changes; + + // + public List getChanges() { + return changes; + } + // + + // + public void setChanges(List changes) { + this.changes = changes; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java new file mode 100644 index 000000000..dfc95042e --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.Collection; +import java.util.List; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +public class WrapperCollection extends WrapperBase { + /* + * Properties + */ + + @JsonProperty("results") + private List results; + + public WrapperCollection() { + super(LoggerFactory.getLogger(WrapperCollection.class)); + } + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompany.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompany.java new file mode 100644 index 000000000..0b56611d4 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompany.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.Company; +import java.util.List; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +public class WrapperCompany extends WrapperBase { + /* + * Properties + */ + + @JsonProperty("results") + private List results; + + public WrapperCompany() { + super(LoggerFactory.getLogger(WrapperCompany.class)); + } + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java new file mode 100644 index 000000000..9f7e8f0a4 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.MovieDb; +import java.util.List; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +public class WrapperCompanyMovies extends WrapperBase { + /* + * Properties + */ + + @JsonProperty("results") + private List results; + + public WrapperCompanyMovies() { + super(LoggerFactory.getLogger(WrapperCompanyMovies.class)); + } + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[ResultList=["); + sb.append("[companyId=").append(getId()); + sb.append("],[page=").append(getPage()); + sb.append("],[pageResults=").append(getResults().size()); + sb.append("],[totalPages=").append(getTotalPages()); + sb.append("],[totalResults=").append(getTotalResults()); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperConfig.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperConfig.java new file mode 100644 index 000000000..25bceede1 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperConfig.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.TmdbConfiguration; +import java.util.Collections; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class WrapperConfig { + /* + * Logger + */ + + private static final Logger LOG = LoggerFactory.getLogger(WrapperConfig.class); + /* + * Properties + */ + @JsonProperty("images") + private TmdbConfiguration tmdbConfiguration; + @JsonProperty("change_keys") + private List changeKeys = Collections.EMPTY_LIST; + + public TmdbConfiguration getTmdbConfiguration() { + return tmdbConfiguration; + } + + public void setTmdbConfiguration(TmdbConfiguration tmdbConfiguration) { + this.tmdbConfiguration = tmdbConfiguration; + } + + public List getChangeKeys() { + return changeKeys; + } + + public void setChangeKeys(List changeKeys) { + this.changeKeys = changeKeys; + } + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenres.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenres.java new file mode 100644 index 000000000..fba87f307 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenres.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.Genre; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Wrapper class for the Genres searches + * + * @author Stuart + */ +public class WrapperGenres { + /* + * Logger + */ + + private static final Logger LOG = LoggerFactory.getLogger(WrapperGenres.class); + /* + * Properties + */ + @JsonProperty("genres") + private List genres; + + public List getGenres() { + return genres; + } + + public void setGenres(List genres) { + this.genres = genres; + } + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperImages.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperImages.java new file mode 100644 index 000000000..a6fbaa172 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperImages.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.Artwork; +import java.util.List; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class WrapperImages extends WrapperBase { + /* + * Properties + */ + + @JsonProperty("backdrops") + private List backdrops; + @JsonProperty("posters") + private List posters; + @JsonProperty("profiles") + private List profiles; + + public WrapperImages() { + super(LoggerFactory.getLogger(WrapperImages.class)); + } + + // + public List getBackdrops() { + return backdrops; + } + + public List getPosters() { + return posters; + } + + public List getProfiles() { + return profiles; + } + // + + // + public void setBackdrops(List backdrops) { + this.backdrops = backdrops; + } + + public void setPosters(List posters) { + this.posters = posters; + } + + public void setProfiles(List profiles) { + this.profiles = profiles; + } + // +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywordMovies.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywordMovies.java new file mode 100644 index 000000000..f116b11da --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywordMovies.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.KeywordMovie; +import java.util.List; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +public class WrapperKeywordMovies extends WrapperBase { + /* + * Properties + */ + + @JsonProperty("results") + private List results; + + public WrapperKeywordMovies() { + super(LoggerFactory.getLogger(WrapperKeywordMovies.class)); + } + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywords.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywords.java new file mode 100644 index 000000000..85016c045 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywords.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.Keyword; +import java.util.List; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +public class WrapperKeywords extends WrapperBase { + /* + * Properties + */ + + @JsonProperty("results") + private List results; + + public WrapperKeywords() { + super(LoggerFactory.getLogger(WrapperKeywords.class)); + } + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovie.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovie.java new file mode 100644 index 000000000..94f2abbb7 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovie.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.MovieDb; +import java.util.List; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +public class WrapperMovie extends WrapperBase { + /* + * Properties + */ + + @JsonProperty("results") + private List movies; + + public WrapperMovie() { + super(LoggerFactory.getLogger(WrapperMovie.class)); + } + + public List getMovies() { + return movies; + } + + public void setMovies(List movies) { + this.movies = movies; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("[ResultList=["); + sb.append("[page=").append(getPage()); + sb.append("],[pageResults=").append(getMovies().size()); + sb.append("],[totalPages=").append(getTotalPages()); + sb.append("],[totalResults=").append(getTotalResults()); + sb.append("],[id=").append(getId()); + sb.append("]]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieCasts.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieCasts.java new file mode 100644 index 000000000..30183409c --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieCasts.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.PersonCast; +import com.omertron.themoviedbapi.model.PersonCrew; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class WrapperMovieCasts { + /* + * Logger + */ + + private static final Logger LOG = LoggerFactory.getLogger(WrapperMovieCasts.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("cast") + private List cast; + @JsonProperty("crew") + private List crew; + + // + public List getCast() { + return cast; + } + + public List getCrew() { + return crew; + } + + public int getId() { + return id; + } + // + + // + public void setCast(List cast) { + this.cast = cast; + } + + public void setCrew(List crew) { + this.crew = crew; + } + + public void setId(int id) { + this.id = id; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieKeywords.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieKeywords.java new file mode 100644 index 000000000..d7da5bf23 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieKeywords.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.Keyword; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class WrapperMovieKeywords { + /* + * Logger + */ + + private static final Logger LOG = LoggerFactory.getLogger(WrapperMovieKeywords.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("keywords") + private List keywords; + + // + public int getId() { + return id; + } + + public List getKeywords() { + return keywords; + } + // + + // + public void setId(int id) { + this.id = id; + } + + public void setKeywords(List keywords) { + this.keywords = keywords; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieList.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieList.java new file mode 100644 index 000000000..3dec844fb --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieList.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.MovieList; +import java.util.List; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class WrapperMovieList extends WrapperBase { + /* + * Properties + */ + + @JsonProperty("results") + private List movieList; + + public WrapperMovieList() { + super(LoggerFactory.getLogger(WrapperMovieList.class)); + } + + public List getMovieList() { + return movieList; + } + + public void setMovieList(List movieList) { + this.movieList = movieList; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperPerson.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperPerson.java new file mode 100644 index 000000000..70d5ab6ac --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperPerson.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.Person; +import java.util.List; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +public class WrapperPerson extends WrapperBase { + /* + * Properties + */ + + @JsonProperty("results") + private List results; + + public WrapperPerson() { + super(LoggerFactory.getLogger(WrapperPerson.class)); + } + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperPersonCredits.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperPersonCredits.java new file mode 100644 index 000000000..2ba1dec94 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperPersonCredits.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.PersonCredit; +import java.util.List; +import org.slf4j.LoggerFactory; + +/** + * + * @author stuart.boston + */ +public class WrapperPersonCredits extends WrapperBase { + /* + * Properties + */ + + @JsonProperty("cast") + private List cast; + @JsonProperty("crew") + private List crew; + + public WrapperPersonCredits() { + super(LoggerFactory.getLogger(WrapperMovieCasts.class)); + } + + public List getCast() { + return cast; + } + + public void setCast(List cast) { + this.cast = cast; + } + + public List getCrew() { + return crew; + } + + public void setCrew(List crew) { + this.crew = crew; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperReleaseInfo.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperReleaseInfo.java new file mode 100644 index 000000000..caf4b59b7 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperReleaseInfo.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.ReleaseInfo; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class WrapperReleaseInfo { + /* + * Logger + */ + + private static final Logger LOG = LoggerFactory.getLogger(WrapperReleaseInfo.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("countries") + private List countries; + + // + public List getCountries() { + return countries; + } + + public int getId() { + return id; + } + // + + // + public void setCountries(List countries) { + this.countries = countries; + } + + public void setId(int id) { + this.id = id; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperTrailers.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperTrailers.java new file mode 100644 index 000000000..0f19e69bc --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperTrailers.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.Trailer; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class WrapperTrailers { + /* + * Logger + */ + + private static final Logger LOG = LoggerFactory.getLogger(WrapperTrailers.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("quicktime") + private List quicktime; + @JsonProperty("youtube") + private List youtube; + + // + public int getId() { + return id; + } + + public List getQuicktime() { + return quicktime; + } + + public List getYoutube() { + return youtube; + } + // + + // + public void setId(int id) { + this.id = id; + } + + public void setQuicktime(List quicktime) { + this.quicktime = quicktime; + } + + public void setYoutube(List youtube) { + this.youtube = youtube; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperTranslations.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperTranslations.java new file mode 100644 index 000000000..507cc0bc9 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperTranslations.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.Translation; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class WrapperTranslations { + /* + * Logger + */ + + private static final Logger LOG = LoggerFactory.getLogger(WrapperTranslations.class); + /* + * Properties + */ + @JsonProperty("id") + private int id; + @JsonProperty("translations") + private List translations; + + // + public void setId(int id) { + this.id = id; + } + + public void setTranslations(List translations) { + this.translations = translations; + } + // + + // + public int getId() { + return id; + } + + public List getTranslations() { + return translations; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/resources/bin.xml b/src/main/resources/bin.xml new file mode 100644 index 000000000..c12f07f36 --- /dev/null +++ b/src/main/resources/bin.xml @@ -0,0 +1,39 @@ + + bin + + ${distribution.format} + + false + + + + ${project.build.directory} + + + version.txt + + + + + + ${basedir} + + + readme.txt + + + + + + ${project.build.directory} + + + **/*.jar + + + + + + diff --git a/src/test/java/com/omertron/themoviedbapi/TestLogger.java b/src/test/java/com/omertron/themoviedbapi/TestLogger.java new file mode 100644 index 000000000..bd7a4cc5e --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/TestLogger.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of the FanartTV API. + * + * The FanartTV API 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 + * any later version. + * + * The FanartTV API 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 the FanartTV API. If not, see . + * + */ +package com.omertron.themoviedbapi; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.LogManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestLogger { + + private static final Logger LOG = LoggerFactory.getLogger(TestLogger.class); + private static final String CRLF = "\n"; + + private TestLogger() { + throw new UnsupportedOperationException("Class can not be instantiated"); + } + + /** + * Configure the logger with a simple in-memory file for the required log level + * + * @param level The logging level required + * @return True if successful + */ + public static boolean Configure(String level) { + StringBuilder config = new StringBuilder("handlers = java.util.logging.ConsoleHandler\n"); + config.append(".level = ").append(level).append(CRLF); + config.append("java.util.logging.ConsoleHandler.level = ").append(level).append(CRLF); + // Only works with Java 7 or later + config.append("java.util.logging.SimpleFormatter.format = [%1$tc %4$s] %2$s - %5$s %6$s%n").append(CRLF); + // Exclude http logging + config.append("sun.net.www.protocol.http.HttpURLConnection.level = OFF").append(CRLF); + + InputStream ins = new ByteArrayInputStream(config.toString().getBytes()); + try { + LogManager.getLogManager().readConfiguration(ins); + } catch (IOException e) { + LOG.warn("Failed to configure log manager due to an IO problem", e); + return Boolean.FALSE; + } + LOG.debug("Logger initialized to '{}' level", level); + return Boolean.TRUE; + } + + /** + * Set the logging level to "ALL" + * + * @return True if successful + */ + public static boolean Configure() { + return Configure("ALL"); + } +} diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java new file mode 100644 index 000000000..31453f7a4 --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java @@ -0,0 +1,665 @@ +/* + * Copyright (c) 2004-2013 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API 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 + * any later version. + * + * TheMovieDB API 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 TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi; + +import com.omertron.themoviedbapi.model.AlternativeTitle; +import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model.Collection; +import com.omertron.themoviedbapi.model.CollectionInfo; +import com.omertron.themoviedbapi.model.Company; +import com.omertron.themoviedbapi.model.Genre; +import com.omertron.themoviedbapi.model.Keyword; +import com.omertron.themoviedbapi.model.KeywordMovie; +import com.omertron.themoviedbapi.model.MovieChanges; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.MovieDbList; +import com.omertron.themoviedbapi.model.MovieList; +import com.omertron.themoviedbapi.model.Person; +import com.omertron.themoviedbapi.model.PersonCredit; +import com.omertron.themoviedbapi.model.ReleaseInfo; +import com.omertron.themoviedbapi.model.TmdbConfiguration; +import com.omertron.themoviedbapi.model.TokenAuthorisation; +import com.omertron.themoviedbapi.model.TokenSession; +import com.omertron.themoviedbapi.model.Trailer; +import com.omertron.themoviedbapi.model.Translation; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.junit.*; +import static org.junit.Assert.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test cases for TheMovieDbApi API + * + * @author stuart.boston + */ +public class TheMovieDbApiTest { + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(TheMovieDbApiTest.class); + // API Key + private static final String API_KEY = "5a1a77e2eba8984804586122754f969f"; + private static TheMovieDbApi tmdb; + // Test data + private static final int ID_MOVIE_BLADE_RUNNER = 78; + private static final int ID_MOVIE_STAR_WARS_COLLECTION = 10; + private static final int ID_PERSON_BRUCE_WILLIS = 62; + private static final int ID_COMPANY_LUCASFILM = 1; + private static final String COMPANY_NAME = "Marvel Studios"; + private static final int ID_GENRE_ACTION = 28; + private static final String ID_KEYWORD = "1721"; + // Languages + private static final String LANGUAGE_DEFAULT = ""; + private static final String LANGUAGE_ENGLISH = "en"; + private static final String LANGUAGE_RUSSIAN = "ru"; + + public TheMovieDbApiTest() throws MovieDbException { + } + + @BeforeClass + public static void setUpClass() throws Exception { + tmdb = new TheMovieDbApi(API_KEY); + TestLogger.Configure(); + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getConfiguration method, of class TheMovieDbApi. + */ + @Test + public void testConfiguration() throws IOException { + LOG.info("Test Configuration"); + + TmdbConfiguration tmdbConfig = tmdb.getConfiguration(); + assertNotNull("Configuration failed", tmdbConfig); + assertTrue("No base URL", StringUtils.isNotBlank(tmdbConfig.getBaseUrl())); + assertTrue("No backdrop sizes", tmdbConfig.getBackdropSizes().size() > 0); + assertTrue("No poster sizes", tmdbConfig.getPosterSizes().size() > 0); + assertTrue("No profile sizes", tmdbConfig.getProfileSizes().size() > 0); + LOG.info(tmdbConfig.toString()); + } + + /** + * Test of searchMovie method, of class TheMovieDbApi. + */ + @Test + public void testSearchMovie() throws MovieDbException { + LOG.info("searchMovie"); + + // Try a movie with less than 1 page of results + List movieList = tmdb.searchMovie("Blade Runner", 0, "", true, 0); +// List movieList = tmdb.searchMovie("Blade Runner", "", true); + assertTrue("No movies found, should be at least 1", movieList.size() > 0); + + // Try a russian langugage movie + movieList = tmdb.searchMovie("О чём говорят мужчины", 0, LANGUAGE_RUSSIAN, true, 0); + assertTrue("No 'RU' movies found, should be at least 1", movieList.size() > 0); + + // Try a movie with more than 20 results + movieList = tmdb.searchMovie("Star Wars", 0, LANGUAGE_ENGLISH, false, 0); + assertTrue("Not enough movies found, should be over 15, found " + movieList.size(), movieList.size() >= 15); + } + + /** + * Test of getMovieInfo method, of class TheMovieDbApi. + */ + @Test + public void testGetMovieInfo() throws MovieDbException { + LOG.info("getMovieInfo"); + MovieDb result = tmdb.getMovieInfo(ID_MOVIE_BLADE_RUNNER, LANGUAGE_ENGLISH); + assertEquals("Incorrect movie information", "Blade Runner", result.getOriginalTitle()); + } + + /** + * Test of getMovieAlternativeTitles method, of class TheMovieDbApi. + */ + @Test + public void testGetMovieAlternativeTitles() throws MovieDbException { + LOG.info("getMovieAlternativeTitles"); + String country = ""; + List results = tmdb.getMovieAlternativeTitles(ID_MOVIE_BLADE_RUNNER, country); + assertTrue("No alternative titles found", results.size() > 0); + + country = "US"; + results = tmdb.getMovieAlternativeTitles(ID_MOVIE_BLADE_RUNNER, country); + assertTrue("No alternative titles found", results.size() > 0); + + } + + /** + * Test of getMovieCasts method, of class TheMovieDbApi. + */ + @Test + public void testGetMovieCasts() throws MovieDbException { + LOG.info("getMovieCasts"); + List people = tmdb.getMovieCasts(ID_MOVIE_BLADE_RUNNER); + assertTrue("No cast information", people.size() > 0); + + String name1 = "Harrison Ford"; + String name2 = "Charles Knode"; + boolean foundName1 = Boolean.FALSE; + boolean foundName2 = Boolean.FALSE; + + for (Person person : people) { + if (!foundName1 && person.getName().equalsIgnoreCase(name1)) { + foundName1 = Boolean.TRUE; + } + + if (!foundName2 && person.getName().equalsIgnoreCase(name2)) { + foundName2 = Boolean.TRUE; + } + } + assertTrue("Couldn't find " + name1, foundName1); + assertTrue("Couldn't find " + name2, foundName2); + } + + /** + * Test of getMovieImages method, of class TheMovieDbApi. + */ + @Test + public void testGetMovieImages() throws MovieDbException { + LOG.info("getMovieImages"); + String language = ""; + List result = tmdb.getMovieImages(ID_MOVIE_BLADE_RUNNER, language); + assertFalse("No artwork found", result.isEmpty()); + } + + /** + * Test of getMovieKeywords method, of class TheMovieDbApi. + */ + @Test + public void testGetMovieKeywords() throws MovieDbException { + LOG.info("getMovieKeywords"); + List result = tmdb.getMovieKeywords(ID_MOVIE_BLADE_RUNNER); + assertFalse("No keywords found", result.isEmpty()); + } + + /** + * Test of getMovieReleaseInfo method, of class TheMovieDbApi. + */ + @Test + public void testGetMovieReleaseInfo() throws MovieDbException { + LOG.info("getMovieReleaseInfo"); + List result = tmdb.getMovieReleaseInfo(ID_MOVIE_BLADE_RUNNER, ""); + assertFalse("Release information missing", result.isEmpty()); + } + + /** + * Test of getMovieTrailers method, of class TheMovieDbApi. + */ + @Test + public void testGetMovieTrailers() throws MovieDbException { + LOG.info("getMovieTrailers"); + List result = tmdb.getMovieTrailers(ID_MOVIE_BLADE_RUNNER, ""); + assertFalse("Movie trailers missing", result.isEmpty()); + } + + /** + * Test of getMovieTranslations method, of class TheMovieDbApi. + */ + @Test + public void testGetMovieTranslations() throws MovieDbException { + LOG.info("getMovieTranslations"); + List result = tmdb.getMovieTranslations(ID_MOVIE_BLADE_RUNNER); + assertFalse("No translations found", result.isEmpty()); + } + + /** + * Test of getCollectionInfo method, of class TheMovieDbApi. + */ + @Test + public void testGetCollectionInfo() throws MovieDbException { + LOG.info("getCollectionInfo"); + String language = ""; + CollectionInfo result = tmdb.getCollectionInfo(ID_MOVIE_STAR_WARS_COLLECTION, language); + assertFalse("No collection information", result.getParts().isEmpty()); + } + + /** + * Test of createImageUrl method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testCreateImageUrl() throws MovieDbException { + LOG.info("createImageUrl"); + MovieDb movie = tmdb.getMovieInfo(ID_MOVIE_BLADE_RUNNER, ""); + String result = tmdb.createImageUrl(movie.getPosterPath(), "original").toString(); + assertTrue("Error compiling image URL", !result.isEmpty()); + } + + /** + * Test of getMovieInfoImdb method, of class TheMovieDbApi. + */ + @Test + public void testGetMovieInfoImdb() throws MovieDbException { + LOG.info("getMovieInfoImdb"); + MovieDb result = tmdb.getMovieInfoImdb("tt0076759", "en-US"); + assertTrue("Error getting the movie from IMDB ID", result.getId() == 11); + } + + /** + * Test of getApiKey method, of class TheMovieDbApi. + */ + @Test + public void testGetApiKey() { + // Not required + } + + /** + * Test of getApiBase method, of class TheMovieDbApi. + */ + @Test + public void testGetApiBase() { + // Not required + } + + /** + * Test of getConfiguration method, of class TheMovieDbApi. + */ + @Test + public void testGetConfiguration() { + // Not required + } + + /** + * Test of searchPeople method, of class TheMovieDbApi. + */ + @Test + public void testSearchPeople() throws MovieDbException { + LOG.info("searchPeople"); + String personName = "Bruce Willis"; + boolean includeAdult = false; + List result = tmdb.searchPeople(personName, includeAdult, 0); + assertTrue("Couldn't find the person", result.size() > 0); + } + + /** + * Test of getPersonInfo method, of class TheMovieDbApi. + */ + @Test + public void testGetPersonInfo() throws MovieDbException { + LOG.info("getPersonInfo"); + Person result = tmdb.getPersonInfo(ID_PERSON_BRUCE_WILLIS); + assertTrue("Wrong actor returned", result.getId() == ID_PERSON_BRUCE_WILLIS); + } + + /** + * Test of getPersonCredits method, of class TheMovieDbApi. + */ + @Test + public void testGetPersonCredits() throws MovieDbException { + LOG.info("getPersonCredits"); + + List people = tmdb.getPersonCredits(ID_PERSON_BRUCE_WILLIS); + assertTrue("No cast information", people.size() > 0); + } + + /** + * Test of getPersonImages method, of class TheMovieDbApi. + */ + @Test + public void testGetPersonImages() throws MovieDbException { + LOG.info("getPersonImages"); + + List artwork = tmdb.getPersonImages(ID_PERSON_BRUCE_WILLIS); + assertTrue("No cast information", artwork.size() > 0); + } + + /** + * Test of getLatestMovie method, of class TheMovieDbApi. + */ + @Test + public void testGetLatestMovie() throws MovieDbException { + LOG.info("getLatestMovie"); + MovieDb result = tmdb.getLatestMovie(); + assertTrue("No latest movie found", result != null); + assertTrue("No latest movie found", result.getId() > 0); + } + + /** + * Test of compareMovies method, of class TheMovieDbApi. + */ + @Test + public void testCompareMovies() { + // Not required + } + + /** + * Test of setProxy method, of class TheMovieDbApi. + */ + @Test + public void testSetProxy() { + // Not required + } + + /** + * Test of setTimeout method, of class TheMovieDbApi. + */ + @Test + public void testSetTimeout() { + // Not required + } + + /** + * Test of getNowPlayingMovies method, of class TheMovieDbApi. + */ + @Test + public void testGetNowPlayingMovies() throws MovieDbException { + LOG.info("getNowPlayingMovies"); + List results = tmdb.getNowPlayingMovies(LANGUAGE_DEFAULT, 0); + assertTrue("No now playing movies found", !results.isEmpty()); + } + + /** + * Test of getPopularMovieList method, of class TheMovieDbApi. + */ + @Test + public void testGetPopularMovieList() throws MovieDbException { + LOG.info("getPopularMovieList"); + List results = tmdb.getPopularMovieList(LANGUAGE_DEFAULT, 0); + assertTrue("No popular movies found", !results.isEmpty()); + } + + /** + * Test of getTopRatedMovies method, of class TheMovieDbApi. + */ + @Test + public void testGetTopRatedMovies() throws MovieDbException { + LOG.info("getTopRatedMovies"); + List results = tmdb.getTopRatedMovies(LANGUAGE_DEFAULT, 0); + assertTrue("No top rated movies found", !results.isEmpty()); + } + + /** + * Test of getCompanyInfo method, of class TheMovieDbApi. + */ + @Test + public void testGetCompanyInfo() throws MovieDbException { + LOG.info("getCompanyInfo"); + Company company = tmdb.getCompanyInfo(ID_COMPANY_LUCASFILM); + assertTrue("No company information found", company.getCompanyId() > 0); + } + + /** + * Test of getCompanyMovies method, of class TheMovieDbApi. + */ + @Test + public void testGetCompanyMovies() throws MovieDbException { + LOG.info("getCompanyMovies"); + List results = tmdb.getCompanyMovies(ID_COMPANY_LUCASFILM, LANGUAGE_DEFAULT, 0); + assertTrue("No company movies found", !results.isEmpty()); + } + + /** + * Test of searchCompanies method, of class TheMovieDbApi. + */ + @Test + public void testSearchCompanies() throws MovieDbException { + LOG.info("searchCompanies"); + List results = tmdb.searchCompanies(COMPANY_NAME, 0); + assertTrue("No company information found", !results.isEmpty()); + } + + /** + * Test of getSimilarMovies method, of class TheMovieDbApi. + */ + @Test + public void testGetSimilarMovies() throws MovieDbException { + LOG.info("getSimilarMovies"); + List results = tmdb.getSimilarMovies(ID_MOVIE_BLADE_RUNNER, LANGUAGE_DEFAULT, 0); + assertTrue("No similar movies found", !results.isEmpty()); + } + + /** + * Test of getGenreList method, of class TheMovieDbApi. + */ + @Test + public void testGetGenreList() throws MovieDbException { + LOG.info("getGenreList"); + List results = tmdb.getGenreList(LANGUAGE_DEFAULT); + assertTrue("No genres found", !results.isEmpty()); + } + + /** + * Test of getGenreMovies method, of class TheMovieDbApi. + */ + @Test + public void testGetGenreMovies() throws MovieDbException { + LOG.info("getGenreMovies"); + List results = tmdb.getGenreMovies(ID_GENRE_ACTION, LANGUAGE_DEFAULT, 0, Boolean.TRUE); + assertTrue("No genre movies found", !results.isEmpty()); + } + + /** + * Test of getUpcoming method, of class TheMovieDbApi. + */ + @Test + public void testGetUpcoming() throws Exception { + LOG.info("getUpcoming"); + List results = tmdb.getUpcoming(LANGUAGE_DEFAULT, 0); + assertTrue("No upcoming movies found", !results.isEmpty()); + } + + /** + * Test of getCollectionImages method, of class TheMovieDbApi. + */ + @Test + public void testGetCollectionImages() throws Exception { + LOG.info("getCollectionImages"); + List result = tmdb.getCollectionImages(ID_MOVIE_STAR_WARS_COLLECTION, LANGUAGE_DEFAULT); + assertFalse("No artwork found", result.isEmpty()); + } + + /** + * Test of getAuthorisationToken method, of class TheMovieDbApi. + */ + @Test + public void testGetAuthorisationToken() throws Exception { + LOG.info("getAuthorisationToken"); + TokenAuthorisation result = tmdb.getAuthorisationToken(); + assertFalse("Token is null", result == null); + assertTrue("Token is not valid", result.getSuccess()); + LOG.info(result.toString()); + } + + /** + * Test of getSessionToken method, of class TheMovieDbApi. + * + * TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication + */ + public void testGetSessionToken() throws Exception { + LOG.info("getSessionToken"); + TokenAuthorisation token = tmdb.getAuthorisationToken(); + assertFalse("Token is null", token == null); + assertTrue("Token is not valid", token.getSuccess()); + LOG.info(token.toString()); + + TokenSession result = tmdb.getSessionToken(token); + assertFalse("Session token is null", result == null); + assertTrue("Session token is not valid", result.getSuccess()); + LOG.info(result.toString()); + } + + /** + * Test of getGuestSessionToken method, of class TheMovieDbApi. + */ + @Test + public void testGetGuestSessionToken() throws Exception { + LOG.info("getGuestSessionToken"); + TokenSession result = tmdb.getGuestSessionToken(); + + assertTrue("Failed to get guest session", result.getSuccess()); + } + + @Test + public void testGetMovieLists() throws Exception { + LOG.info("getMovieLists"); + List results = tmdb.getMovieLists(ID_MOVIE_BLADE_RUNNER, LANGUAGE_ENGLISH, 0); + assertNotNull("No results found", results); + assertTrue("No results found", results.size() > 0); + } + + /** + * Test of getMovieChanges method,of class TheMovieDbApi + * + * TODO: Do not test this until it is fixed + */ + public void testGetMovieChanges() throws Exception { + LOG.info("getMovieChanges"); + + String startDate = ""; + String endDate = null; + List results = Collections.EMPTY_LIST; + + // Get some popular movies + List movieList = tmdb.getPopularMovieList(LANGUAGE_DEFAULT, 0); + for (MovieDb movie : movieList) { + results = tmdb.getMovieChanges(movie.getId(), startDate, endDate); + LOG.info("{} has {} changes.", new Object[]{movie.getTitle(), results.size()}); + } + + assertNotNull("No results found", results); + assertTrue("No results found", results.size() > 0); + } + + @Test + public void testGetPersonLatest() throws Exception { + LOG.info("getPersonLatest"); + + Person result = tmdb.getPersonLatest(); + + assertNotNull("No results found", result); + assertTrue("No results found", StringUtils.isNotBlank(result.getName())); + } + + /** + * Test of searchCollection method, of class TheMovieDbApi. + */ + @Test + public void testSearchCollection() throws Exception { + LOG.info("searchCollection"); + String query = "batman"; + int page = 0; + List result = tmdb.searchCollection(query, LANGUAGE_DEFAULT, page); + assertFalse("No collections found", result == null); + assertTrue("No collections found", result.size() > 0); + } + + /** + * Test of searchList method, of class TheMovieDbApi. + */ + @Test + public void testSearchList() throws Exception { + LOG.info("searchList"); + String query = "watch"; + int page = 0; + List result = tmdb.searchList(query, LANGUAGE_DEFAULT, page); + assertFalse("No lists found", result == null); + assertTrue("No lists found", result.size() > 0); + } + + /** + * Test of searchKeyword method, of class TheMovieDbApi. + */ + @Test + public void testSearchKeyword() throws Exception { + LOG.info("searchKeyword"); + String query = "action"; + int page = 0; + List result = tmdb.searchKeyword(query, page); + assertFalse("No keywords found", result == null); + assertTrue("No keywords found", result.size() > 0); + } + + /** + * Test of postMovieRating method, of class TheMovieDbApi. + * + * TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication + */ + public void testPostMovieRating() throws Exception { + LOG.info("postMovieRating"); + String sessionId = ""; + String rating = ""; + boolean expResult = false; + boolean result = tmdb.postMovieRating(sessionId, rating); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getPersonChanges method, of class TheMovieDbApi. + * + * TODO: Fix the method before testing + */ + public void testGetPersonChanges() throws Exception { + LOG.info("getPersonChanges"); + String startDate = ""; + String endDate = ""; + tmdb.getPersonChanges(ID_PERSON_BRUCE_WILLIS, startDate, endDate); + } + + /** + * Test of getList method, of class TheMovieDbApi. + */ + @Test + public void testGetList() throws Exception { + LOG.info("getList"); + String listId = "509ec17b19c2950a0600050d"; + MovieDbList result = tmdb.getList(listId); + assertFalse("List not found", result.getItems().isEmpty()); + } + + /** + * Test of getKeyword method, of class TheMovieDbApi. + */ + @Test + public void testGetKeyword() throws Exception { + LOG.info("getKeyword"); + Keyword result = tmdb.getKeyword(ID_KEYWORD); + assertEquals("fight", result.getName()); + } + + /** + * Test of getKeywordMovies method, of class TheMovieDbApi. + */ + @Test + public void testGetKeywordMovies() throws Exception { + LOG.info("getKeywordMovies"); + int page = 0; + List result = tmdb.getKeywordMovies(ID_KEYWORD, LANGUAGE_DEFAULT, page); + assertFalse("No keyword movies found", result.isEmpty()); + } +}