I have a Java Application that implements a hook using the Atlassian Bitbucket API.
The class that implements the hook is defined as follows:
import com.atlassian.plugin.spring.scanner.annotation.export.ExportAsService;
import com.atlassian.bitbucket.hook.repository.PreRepositoryHook;
import com.atlassian.bitbucket.hook.repository.RepositoryHookRequest;
import com.atlassian.bitbucket.hook.repository.PreRepositoryHookContext;
import com.atlassian.bitbucket.hook.repository.RepositoryHookResult;
import com.atlassian.bitbucket.hook.repository.PreRepositoryHookRequest;
import com.atlassian.bitbucket.repository.Repository;
import javax.annotation.Nonnull;
/* Other imports */
#ExportAsService({SCMAdapter.class})
public class SCMAdapter implements PreRepositoryHook<RepositoryHookRequest>, ISCMAdapter{
/*Methods from both interfaces*/
}
The methods from the ISCMAdapter interface are irrelevant for this problem.
The PreRepositoryHook interface contains two methods. One of them is the following:
public RepositoryHookResult preUpdate(#Nonnull PreRepositoryHookContext context, #Nonnull RepositoryHookRequest request){
/*Returns a RepositoryHookResult object */
}
I can obtain the repository involved in the hook with the following call:
Repository repo = request.getRepository();
From that object, I can obtain the project's key, the slug, the ID, the name and the state:
String pkey=repo.getProject().getKey();
String slug=repo.getSlug();
String name=repo.getName();
int id=repo.getId();
Repository.State state=repo.getState();
The method is currently working fine. However, I got a requirement that each repository must have a hidden directory with the same name for all repositories (lets say ".myHiddenDir") and that directory must contain a YAML file named config.yml
Is it possible, with the information obtained as listed above to obtain the content of an specific file in the repo?
Thanks in advance.
P.D.: If you find that this description is lacking more info, please let me know and I will check the code.
Related
I recently started out with Spring-Security and in this context found a project on GitHub matching my interests.
While reading some code i discovered that a class (facade\impl\UserFacadeImpl.java) was linked to the target package. This means, when i run
mvn package: the target-file is created and the import-link is valid
mvn clean: the target-file is destroyed and my IDE marks the import-link as invalid
Imports from the target-directory and the class being used normally:
import com.boza.swaggergen.model.Credential;
import com.boza.swaggergen.model.User;
public class UserFacadeImpl implements UserFacade {
#Override
public User createUser(final User user) {
UserModel userModel = modelMapper.map(user, UserModel.class);
userModel = userService.createUser(userModel);
return modelMapper.map(userModel, User.class);
}
The UserModel class shares the same fields with use User class, but the methods are different.
I have never seen anything like this and am completly baffled. I looked in the configuration files, but couldn`t find a hint where those classes are generated.
Those class are generated by Swagger Codegen. The general workflow is:
Describe API using OpenAPI spec.
Configure Maven 's POM to use swagger-codegen-maven-plugin to generate the codes.
Generate codes by mvn generate-sources (mvn package will call it behind scene)
It only generates an abstract #RestController that is configured with #RequestMapping and the request/response POJO for each API endpoint. You still have to implement the actual logic by extending the generated #RestController.
I am trying to follow this tutorial for Retrofit2 Getting Started and Create an Android Client.
The imports are fine
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
and I can follow the tutorial fine except for one thing. I am trying to create the GitHubService Interface and I run into two problems: The Call<V> says that it doesn't take any type parameters and I am also unsure where to put the Contributor class since it's according to the tutorial only declared as static, does that mean it's nested somewhere?
import okhttp3.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
public interface GitHubClient {
#GET("/repos/{owner}/{repo}/contributors")
Call<List<Contributor>> contributors(
#Path("owner") String owner,
#Path("repo") String repo
);
}
static class Contributor {
String login;
int contributions;
}
I have the Contributor class in a separate file and have it as public.
Also, the Call class does not import automatically in Android Studio, I have to select it manually, but it's the only Call I got (except for Androids phone api)
Please help me with why I get this errors, from what I can see there is no one around with the same thing so I am missing something fundamental.
Accordingly to the compile time error you are getting you did import Call from the wrong package. Please, check your import and be sure that you have
import retrofit2.Call;
everything Retrofit related import should be from the package retrofit2.
On the other hand
Call contributors(
it can't guess what you want to return. A Contributor ? a List<Contributor> maybe? E.g.
public interface GitHubClient {
#GET("/repos/{owner}/{repo}/contributors")
Call<List<Contributor>> contributors(
#Path("owner") String owner,
#Path("repo") String repo
);
}
I am trying to implement my custom View with secure social
"ws.securesocial" % "securesocial_2.11" % "3.0-M3",
But I am getting some error:
object TemplatesPlugin is not a member of package securesocial.controllers
So I visit the github project and found there is no TemplatesPlugin
https://github.com/jaliss/securesocial/tree/3.0-M3/module-code/app/securesocial/controllers
package app.com.myApp.plugin;
import play.api.mvc.{RequestHeader, Request};
import play.api.templates.Html;
import securesocial.controllers.TemplatesPlugin;
import securesocial.core.{SecuredRequest, SocialUser};
import play.api.data.Form;
import securesocial.core.SecureSocial._;
import securesocial.controllers.PasswordChange.ChangeInfo;
class MyViews(application: App) extends TemplatesPlugin {
override def getLoginPage[A](implicit request: Request[A], form: Form[(String, String)],
msg: Option[String] = None): Html =
{
views.html.Secure.login(form, msg)
}
//...
}
and my play.plugins
1500:com.typesafe.plugin.CommonsMailerPlugin
9997:app.com.myApp.plugin.MyViews
Then How I go further, What to change?
The module does not use Play plugins any more. All what used to be a plugin is now a service that needs to get configured in the RuntimeEnvironment for your app.
Check out the sample apps to see how they provide their environments. You will need to override the viewTemplates attribute to use your custom views.
I have been deconstructing someone's project which retrieves a response from a 3rd party API and prints it to a Vaadin web GUI.
My version is supposed to retrieve an API response from an anime website, parse this automatically (??) into an object and then print the object attribute to my screen mainly so I can see if it bloody works.
I converted a sample XML file to XSD then used JAXB to generate a class from it (and a builder but I'm not quite sure how that is used yet) in order to store my response from the API.
I have a getservice java class that performs the get request. This worked previously when all I was doing was printing the result of the request to a string and before I tried to put it into an object.
Lastly I have a main JavaApplication4 class that was apparently necessary to create an instance of the request (I'm pretty new to OO programming but it sort of makes sense maybe).
The application runs however I now get an error message:
Exception in thread "main" java.lang.NullPointerException
at javaapplication4.getservice.fetchMovie(getservice.java:36)
at javaapplication4.JavaApplication4.main(JavaApplication4.java:17)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
This points me to the line
return target.queryParam("anime", "4658")
.request(MediaType.TEXT_HTML)
.header("Content-type", "text/html")//application_json or text_html or xml
.get(Ann.class);
I used a breakpoint and found that my client and target remain as null both here and on the above lines:
#PostConstruct
protected void init() {
client = ClientBuilder.newClient();
//target = client.target("http://www.omdbapi.com");
target = client.target("http://cdn.animenewsnetwork.com/encyclopedia/api.xml");
}
Looking back at the original guy's project, I think the problem is because I am using annotations like #PostConstruct but do not have an #Inject annotation. I tried to add an #Inject to my Main/JavaApplication4 file but it either doesn't do anything (and looks completely wrong) or it tells me its not applicable where I put it.
I would totally appreciate someone to have a quick look and see if its those annotations causing the problem... I don't understand how to use them in any context yet and it is so hard to find examples that do things in a particular way, I am just left trying to reposition bits and pieces for hours and obviously that doesn't work XD
The full code of the project, MINUS the Ann.java class (which should store the API response in the form of anime , title, name, etc etc) and the ObjectFactory.java class which was generated alongside it (and im not sure what it does yet but thats another step):
Ann.java
(getters and setters and xml stuff i think)
ObjectFactory.java
JavaApplication4.java
package javaapplication4;
import generated.Ann;
import javax.inject.Inject;
public class JavaApplication4 {
//#Inject
//getservice gt;
public static void main(String[] args) {
//#Inject
getservice gt = new getservice();
String output = gt.fetchMovie().getAnime().getName();
System.out.println(output);
}
}
getservice.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication4;
import generated.Ann;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
/**
*
* #author J
*/
#ApplicationScoped
public class getservice {
private Client client;
private WebTarget target;
#PostConstruct
protected void init() {
client = ClientBuilder.newClient();
//target = client.target("http://www.omdbapi.com");
target = client.target("http://cdn.animenewsnetwork.com/encyclopedia/api.xml");
}
// these apparently stay null when i run JavaAppliation4
// do i need an #Inject somewhere or something completely similar or different?
public Ann fetchMovie() {
//return target.queryParam("anime", "4658")
return target.queryParam("anime", "4658")
.request(MediaType.TEXT_HTML)
.header("Content-type", "text/html")//application_json or text_html or xml
.get(Ann.class);
}
}
Thankyou. Its just one of those parts where "i'm stuck so i'll keep trying" doesn't look like its going to get me very far...idk... :)
#Inject and #Postconstruct relates to "managed beans", CDI. All Java EE servers provide CDI by default. If you wish to use it with plain Java SE environment, you need a CDI implementation like Weld. See this blog entry how that can be done.
I am using play 2.2.1 and trying to implement Page for 404 requests.
For that I have created a errorPage.scala.html in my views and created a Global class inside MyProject->app->controller
Global.java (Source)
import play.*;
import play.mvc.*;
import play.mvc.Http.*;
import play.libs.F.*;
import static play.mvc.Results.*;
public class Global extends GlobalSettings {
public Promise<SimpleResult> onHandlerNotFound(RequestHeader request) {
return Promise.<SimpleResult>pure(notFound(
views.html.errorPage.render(request.uri())
));
}
}
But Its not working.When I am entering the wrong url it shows action not found page and display my routes file in browser.
Is there anything I am missing?
I have been trying other stack threds also but din't get any solution.
Thanks
Your Global class needs to be at the root package, i.e. within app and not wihtin the controller package. The link you posted documents that in the second sentence:
Defining a Global object in your project allows you to handle global
settings for your application. This object must be defined in the root package.