I'm trying to make a method in java which will put back the previous revision in my repository. I've tried several options but haven't had any succes until now. I think the best option I tried is in the following Test class:
package svntest;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.internal.wc.SVNSynchronizeEditor;
import org.tmatesoft.svn.core.io.ISVNReporter;
import org.tmatesoft.svn.core.io.ISVNReporterBaton;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
public class Test {
static String url = "myhost:8080/svn/sonic76/branches/TEST/myproject";
public static void main(String[] args) {
try {
DAVRepositoryFactory.setup();
SVNRepositoryFactoryImpl.setup();
FSRepositoryFactory.setup();
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(user, password);
SVNRepository srcRepos = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
srcRepos.setAuthenticationManager(authManager);
SVNRepository destRepos = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
destRepos.setAuthenticationManager(authManager);
SVNSynchronizeEditor syncher = new SVNSynchronizeEditor(destRepos, null, SVNRevision.BASE.getNumber(), null);
srcRepos.update(SVNURL.parseURIEncoded(url), SVNRevision.BASE.getNumber()-1, null, SVNDepth.INFINITY, new MyReporterBaton(), syncher);
} catch (Exception e) {
e.printStackTrace();
}
}
private static class MyReporterBaton implements ISVNReporterBaton {
#Override
public void report(ISVNReporter reporter) throws SVNException {
reporter.setPath("", null, 32981, false);
reporter.finishReport();
}
}
}
The error I am getting is:
org.tmatesoft.svn.core.SVNException: svn: E160024: File or directory 'xml/myfile.xml' is out of date; try updating
svn: E160024: resource out of date; try updating
The file myfile.xml in the folder xml is exactly the file which had changed between the current and the previous revision and I want to put back the previous version. Any ideas?
As you can see I am using svnkit, but any other API would also do.
Related
I am developing a simple application where I would like to read the files from a remote URL and add them to the #ExampleObject. I am able to achieve this using CustomClass SchemaFileReader implements OASFilter but the only problem is that I need to manually specify the name of the file in the ref such as #ExampleObject(name = "Example1", ref = "Example1.json").
Since I am reading the URL there can be many files and I do not know the name of all the files so I need an approach where I can add the #ExampleObject dynamically directly without specifying ref. Rather it should read all the data from the examples. Can someone please specify some logic on how to achieve this?
I have posted my complete code on GitHub: https://github.com/Aravinda93/code-with-quarkus.
As of now, I have added manually 2 files to my #ExampleObject by specifying the ref but I need a dynamic approach to add all the 3 files present in the resourses/jsonfiles without providing the ref for all the files individually.
To run the application, please follow the following steps:
Open the terminal for the project and run mvn compile quarkus:dev
Press d in the command line this should open the Swagger-UI.
Select swagger-ui from SmallRye OpenAPI
Expand api/generate and there we will see only 2 files under examples. I need an approach to get all 3 field without specifying the ref for all of them.
After trying some things, finally, this worked for me. Posting here as it can be useful to someone in the future:
Following is my RestControllerResponse:
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.Map;
#Path("/api")
public class RestControllerResponse {
#Path("/generate")
#POST
#Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
#Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
#RequestBody(description = "Testing Example without ref",
content = #Content())
public String generator(final Map<String, Object> input) throws Exception {
return "Hello From Generator Method";
}
}
Following is my SchemaFileReader which has the capability to read all files and respective subfolder with files and get the file contents and add to examples, pass the required URL to the getFolderData method:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.eclipse.microprofile.openapi.OASFactory;
import org.eclipse.microprofile.openapi.OASFilter;
import org.eclipse.microprofile.openapi.models.Components;
import org.eclipse.microprofile.openapi.models.OpenAPI;
import org.eclipse.microprofile.openapi.models.examples.Example;
import org.json.JSONArray;
import org.json.JSONObject;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
public class SchemaFileReader implements OASFilter {
private final ObjectMapper objectMapper = new ObjectMapper();
private final CloseableHttpClient httpClient = HttpClients.createDefault();
#Override
public void filterOpenAPI(OpenAPI openAPI) {
Components defaultComponents = OASFactory.createComponents();
if (openAPI.getComponents() == null) {
openAPI.setComponents(defaultComponents);
}
try {
//generateExamples().forEach(openAPI.getComponents()::addExample);
generateExamples().entrySet().forEach(ex -> openAPI.getPaths().getPathItem("/api/generate").getPOST().getRequestBody().getContent().getMediaType(MediaType.APPLICATION_JSON).addExample(ex.getKey(), ex.getValue()));
} catch (Exception e) {
e.printStackTrace();
}
}
Map<String, Example> generateExamples() throws Exception {
final Map<String, Example> examples = new LinkedHashMap<>();
getFolderData(examples, "PLACE YOUR URL HERE");
//getExamples(examples);
return examples;
}
//If user has provided the folder then recursively loop over it to get the files and their contents
private void getFolderData(final Map<String, Example> examples, final String inputURL) throws IOException {
//Make the request to provided folder path and get the folder/files from it.
final CloseableHttpResponse folderResponse = httpClient.execute(new HttpGet(inputURL));
final String responseBody = EntityUtils.toString(folderResponse.getEntity(), StandardCharsets.UTF_8);
//If the folder API request provides valid response and contains the list of files or folders then loop over it else its plain/text with direct contents
if (folderResponse.getStatusLine().getStatusCode() == 200 && ContentType.get(folderResponse.getEntity()).toString().equalsIgnoreCase("application/json; charset=utf-8")) {
final JSONArray jsonArray = new JSONArray(responseBody);
jsonArray.forEach(item -> {
final JSONObject obj = (JSONObject) item;
if (obj.getString("type").equalsIgnoreCase("file")) {
//Make request to each file in the GitHub folder and obtain its contents
try {
final CloseableHttpResponse fileResponse = httpClient.execute(new HttpGet(obj.getString("download_url")));
//If the response code is 200 then add the contents to Example
if (fileResponse.getStatusLine().getStatusCode() == 200) {
final String fileResponseBody = EntityUtils.toString(fileResponse.getEntity(), StandardCharsets.UTF_8);
if (obj.getString("download_url").contains(".json")) {
examples.put(obj.getString("name"), OASFactory.createExample().value(objectMapper.readValue(fileResponseBody, ObjectNode.class)));
} else if (obj.getString("download_url").contains(".xml")) {
examples.put(obj.getString("name"), OASFactory.createExample().value(fileResponseBody));
}
}
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
getFolderData(examples, obj.getString("url"));
} catch (IOException e) {
e.printStackTrace();
}
}
});
} else if (folderResponse.getStatusLine().getStatusCode() == 200 && ContentType.get(folderResponse.getEntity()).toString().equalsIgnoreCase("text/plain; charset=utf-8")) {
//if direct file provided then add its content
examples.put(inputURL.substring(inputURL.lastIndexOf("/")), OASFactory.createExample().value(objectMapper.readValue(responseBody, ObjectNode.class)));
}
}
}
When i start the server this error comes :
I am using IntelliJ Idea and MySQL jar is added to the src and in the project modules.
Error pastebin
Here is my code
package com.okaam.jaajhome;
import org.bukkit.plugin.java.JavaPlugin;
import pro.husk.mysql.MySQL;
import java.sql.Connection;
import java.sql.SQLException;
public class JaaJHome extends JavaPlugin {
static JaaJHome instance = null;
MySQL MySQL = new MySQL("address", "port", "schema", "user", "password", "");
static Connection c = null;
#Override
public void onEnable() {
System.out.println("Plugin JaaJHome active");
getCommand("sethome").setExecutor(new SetHomeExecutor());
getCommand("home").setExecutor(new HomeExecutor());
try {
c = MySQL.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
instance = this;
}
public static JaaJHome getInstance() {
return instance;
}
}
It seems like you're missing on some dependencies, make sure you have them either in the plugins folder as a non plugin or in the classpath to make sure they're loaded.
I am trying to connect a java program through my local organization git repository, and I am using gitlab4j-api open source API, I am able to login & get the project details from basic Java program. But which method can help me to do check out(individual user can get latest copy from their branch) process ?
Thanks
package git4j.git4j;
import java.util.ArrayList;
import java.util.List;
import org.gitlab4j.api.CommitsApi;
import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.GitLabApiException;
import org.gitlab4j.api.ProjectApi;
import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.CommitAction;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.CommitAction.Action;
import org.gitlab4j.api.models.CommitAction.Encoding;
public class App
{
#SuppressWarnings("deprecation")
public static void main( String[] args )throws GitLabApiException
{
GitLabApi api = GitLabApi.login("http://organizationt_git.ad.com/", "username", "password");
ProjectApi projApi=api.getProjectApi();
Project p = projApi.getProject(project_id);
System.out.println("project rendered is"+p.getName());
List <Project> pList=projApi.getProjects("project_name");
for(Project p:pList){
System.out.println(p.getName());
}
CommitAction ca= new CommitAction();
Action a = Action.UPDATE;
ca.setAction(a);
ca.setFilePath("c/");
ca.setPreviousPath("c/");
ca.setContent("test content");
ca.setEncoding(Encoding.TEXT);
ca.setLastCommitId("");
List<CommitAction> caList = new
ArrayList<CommitAction>();
caList.add(ca);
CommitsApi cApi=api.getCommitsApi();
Commit c = cApi.createCommit(project_id,"branch", "commit message", "branch_refer_to", "", "username", caList);
}
}
This code was mostly taken from Pentaho's website on sample programs. The goal is to use their API to generate HTML output with a Pentaho report.
The report was created with Pentaho 3.5.0-RC2
The version of jars I am using are the following:
pentaho-reporting-engine-classic-core-3.5.0-RC2.jar
libloader-1.1.1.jar
libbase-1.1.1.jar
The exception I am getting is the following:
org.pentaho.reporting.libraries.resourceloader.ContentNotRecognizedException: None of the selected factories was able to handle the given data: ResourceKey{schema=org.pentaho.reporting.libraries.resourceloader.loader.URLResourceLoader, identifier=file:/C:/Users/elias.kopsiaftis/workspace_experimental/TestPentahoReport/bin/Test.prpt, factoryParameters={}, parent=null}
at org.pentaho.reporting.libraries.resourceloader.DefaultResourceManagerBackend.create(DefaultResourceManagerBackend.java:295)
at org.pentaho.reporting.libraries.resourceloader.ResourceManager.create(ResourceManager.java:387)
at org.pentaho.reporting.libraries.resourceloader.ResourceManager.create(ResourceManager.java:342)
at org.pentaho.reporting.libraries.resourceloader.ResourceManager.createDirectly(ResourceManager.java:205)
at ReportTester.getReportDefinition(ReportTester.java:74)
at ReportTester.getReport(ReportTester.java:25)
at ReportTester.main(ReportTester.java:84)
java.lang.NullPointerException
at ReportTester.getReport(ReportTester.java:26)
at ReportTester.main(ReportTester.java:84)
And finally, the code snippet!
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Map;
import java.util.HashMap;
import java.io.*;
import org.pentaho.reporting.engine.classic.core.DataFactory;
import org.pentaho.reporting.engine.classic.core.MasterReport;
import org.pentaho.reporting.engine.classic.core.ReportProcessingException;
import org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlReportUtil;
import org.pentaho.reporting.libraries.resourceloader.Resource;
import org.pentaho.reporting.libraries.base.util.StackableException;
import org.pentaho.reporting.libraries.resourceloader.ResourceException;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
public class ReportTester {
private String reportName = "FormCompleteUsagePerPartnerByMonth.prpt";
private String reportPath = "";
public void getReport() {
try {
final MasterReport report = getReportDefinition();
report.getParameterValues().put("partner", "");
report.getParameterValues().put("startingdate", "2015-03-01");
report.getParameterValues().put("endingdate", "2015-03-05");
HtmlReportUtil.createStreamHTML(report, System.out);
} catch(Exception e) {
e.printStackTrace();
}
}
private MasterReport getReportDefinition() {
try {
// Using the classloader, get the URL to the reportDefinition file
final ClassLoader classloader = this.getClass().getClassLoader();
final URL reportDefinitionURL = classloader.getResource(reportPath + reportName);
if(reportDefinitionURL == null) {
System.out.println("URL was null");
}
// Parse the report file
final ResourceManager resourceManager = new ResourceManager();
resourceManager.registerDefaults();
final Resource directly = resourceManager.createDirectly(reportDefinitionURL, MasterReport.class);
return (MasterReport) directly.getResource();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
ReportTester rt = new ReportTester();
rt.getReport();
}
}
Any advice on this would be much appreciated as I have been scratching my head on this all day. Thanks in advance!
I am writing a code in Java to upload videos to youtube from mu application.
My code is :
package com.youtube.video;
import java.io.IOException;
import java.net.URL;
import com.google.gdata.client.youtube.YouTubeService;
import com.google.gdata.data.media.mediarss.MediaCategory;
import com.google.gdata.data.media.mediarss.MediaDescription;
import com.google.gdata.data.media.mediarss.MediaKeywords;
import com.google.gdata.data.media.mediarss.MediaTitle;
import com.google.gdata.data.youtube.FormUploadToken;
import com.google.gdata.data.youtube.VideoEntry;
import com.google.gdata.data.youtube.YouTubeMediaGroup;
import com.google.gdata.data.youtube.YouTubeNamespace;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;
public class YouTubeController {
public static YouTubeService service;
public void init() {
if (service == null) {
service = new YouTubeService("mail#gmail.com", "A...A");
String username = "mail#gmail.com";
String password = "xxxxxxxxx";
try {
service.setUserCredentials(username, password);
} catch (AuthenticationException ae) {
ae.printStackTrace();
}
}
}
static String token;
static String formUrl;
public static void setFormDetails() throws IOException {
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
String videoTitle = "this is a title";
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Autos"));
mg.setTitle(new MediaTitle());
mg.setPrivate(false);
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("");
mg.getTitle().setPlainTextContent(videoTitle);
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent(videoTitle);
URL uploadUrl = new URL("http://gdata.youtube.com/action/GetUploadToken");
try {
FormUploadToken fut = service.getFormUploadToken(uploadUrl, newEntry);
token = fut.getToken();
System.out.println(">>>>>"+token);
formUrl = fut.getUrl();
} catch (ServiceException se) {
se.printStackTrace();
}
}
public static void main(String s[]) throws IOException {
YouTubeController yc = new YouTubeController();
yc.init();
yc.setFormDetails();
}
}
I have the following jars in lib folder :
gdata-client-1.0.jar
gdata-youtube-2.0.jar
gdata-core-1.0.jar
gdata-media-1.0.jar
google-collect-1.0.jar
guava-13.0.1.jar
mail.jar
activation.jar
But while running this piece of code, it is giving me the following error :
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399)
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableXmlTypes(AltFormat.java:387)
at com.google.gdata.wireformats.AltFormat.<clinit>(AltFormat.java:49)
at com.google.gdata.client.Service.<clinit>(Service.java:558)
at com.zeta.video.YouTubeController.init(YouTubeController.java:23)
at com.zeta.video.YouTubeController.main(YouTubeController.java:66)
I tried all solutions over net, and all of them points out that this error is because i am missing some JAR files. But i am having all the JARs. Can someone help me with this issue?
It looks as though you are referencing both google-collections and guava. Since guava is a superset of google-collections you actually only need to reference guava. Remove the reference to google-collections and you should find the problem is resolved.