I'm developing a plugin for my software that will manage Microsoft TFS. Each plugin operation(check out, create label, check in, etc.) has to be run individually. My checkout operation creates a workspace, downloads that workspace, and then deletes the workspace mapping, but leaves the files behind to be built or modified.
Now, once the files are modified I need to check them back in. Since I deleted the workspace already, I'll have to make a new one.
I'm having trouble making a PendingChange[] object from the files in the workspace. Could anyone give any samples on how this would be done?
This is the code I'm using to create my workspace, if it helps:
public Workspace createWorkspace(String pWorkspaceName, String pLocalPath, String pServerPath)
{
WorkingFolder[] foldersToMap = null;
if (pServerPath != null && pLocalPath != null)
{
final List<WorkingFolder> folderList = new ArrayList<WorkingFolder>();
folderList.add(new WorkingFolder(pServerPath, LocalPath.canonicalize(pLocalPath), WorkingFolderType.MAP, RecursionType.FULL));
foldersToMap = folderList.toArray(EMPTY_WORKING_FOLDER_ARRAY);
}
else if (pServerPath == null || pServerPath.isEmpty())
{
//throw
}
else if (pLocalPath == null || pLocalPath.isEmpty())
{
//throw
}
Workspace w =
mVersionControlClient.createWorkspace(foldersToMap, pWorkspaceName, VersionControlConstants.AUTHENTICATED_USER, VersionControlConstants.AUTHENTICATED_USER, null /*Comment*/,
WorkspaceLocation.SERVER, WorkspaceOptions.NONE);
return w;
}
Microsoft's documentation isn't great on the java sdk, so any help is appreciated.
P.S. If there's anything wrong with my question, or if you want clarification, leave a comment and let me know before you downvote, I'll get it fixed.
Workspace ws = vcc.getWorkspace(workspaceName, ownerName);
PendingSet pendings = ws.getPendingChanges();
for (PendingChange pending : pendings.getPendingChanges()) {
ItemType type = pending.getItemType();
/*Don't download if it is a Folder*/
if (type.getWebServiceObject().getName()
.equals("Folder"))
continue;
ChangeType change = pending.getChangeType();
Item item = vcc.getItem(pending.getServerItem());
String itemName = StringUtils.getItemName(item.getServerItem());
/*My business rule: can't download if isn't in Lock with owner*/
if (!change.toString().contains("(512): Lock")) {
returns.add(new Return("ERROR", "The object "
+ item.getServerItem()
+ " isn't in Lock with " + owner
+ "."));
continue;
}
String destinationFile = destinationPath + "\\" + itemName;
item.downloadFile(vcc, destinationFile);
}
Hope to be helpful.
Related
I'm working on a java application that interacts with Word through an OLE library (org.eclipse.swt.ole.win32) to merge documents (mail merge).
the java method which makes it possible to merge has been working for several years without any particular problem.
but recently the data source can no longer be associated with the merge document.
This problem is random (on some workstations it works and on others it doesn't, yet same system configuration)
I have no explicit error reported on the java side
Here is the method that communicates with Word:
public void mergeDocument(File model, File source) throws Exception {
OleAutomation autoMailMerge = null;
LOGGER.log(new Status(IStatus.INFO, pluginID, "Merge d un document"));
LOGGER.log(new Status(IStatus.INFO, pluginID, "fichier modele: " + model.getCanonicalPath()));
LOGGER.log(new Status(IStatus.INFO, pluginID, "fichier source: " + source.getPath()));
openDocumentReadOnly(model);
autoMailMerge = OLEHelper.getAutomationProperty(autoDocument, "MailMerge");
if ((source != null) && (source.exists()) && (!source.isDirectory())) {
OLEHelper.invoke(autoMailMerge, "OpenDataSource", source.getPath());
} else {
throw new MSWordOleInterfaceException(MSWordOleInterfaceCst.MSG_ERROR_EMPTY_SOURCE_PATH
+ ((source == null) ? "null" : source.getPath()));
}
OLEHelper.invoke(autoMailMerge, "Execute");
OleAutomation autoDocumentMerged = getActiveDocument();
closeDocument(autoDocument);
activateDocument(autoDocumentMerged);
autoDocument = autoDocumentMerged;
autoMailMerge.dispose();
}
Merging by hand from Word (associating the data source and merging) works on workstations where the java application does not work.
thanks to the OLE command I validated that it is the data source which is not passed (on a workstation which works I have a return with the name of the source, on one or it does not work the return is empty)
LOGGER.log(new Status(IStatus.INFO, pluginID, "data source name: "
+ OLEHelper.getVariantProperty(autoDataSource, "Name").getString()));
-a temporary solution has been found, by deleting the registry key related to office:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Word\DocumentTemplateCache
but this is only a temporary solution, the problem comes back.
I need to call a method from another project in eclipse, I tried to add the project to classpath of the current project (Right click on project -> properties -> java build path -> projects) but I got an error and exception (java.lang.NoClassDefFoundError) and ( java.lang.ClassNotFoundException) and I couldn't fix that. I know there is another way to do this job by using Rest Api. please help me!! Thanks.
I want to call (getSample2) to my current project:
public List<String> getSample2 (String fileName, int minFrequency, int maxFrequency) {
List<SampleMultyFreq> fd = getSamples(fileName, minFrequency, maxFrequency);
List<String> ls = new ArrayList<>();
for(SampleMultyFreq ss: fd) {
ls.add(ss.getFrequencies().toString());
}
return ls;
}
I created this method in the same project with (getsample2) for calling (getSample2) method easy. I don't know it is a right way or not.
#GET
#Path("GET_SAMPLE_API")
public Response getSampleApi (String fileName) {
List<String> ss = new DataReader2NewPods().getSample2(fileName, 1, 9);
return Response.status(Response.Status.OK).entity(ss).build();
}
and Finally I wrote this method in my current project for sending request to get (getSampleApi) like this but I don't know the methods that I used is correct or not I copied another method that was for download a file from AWS cloud by using rest api:
public String getSampleMethdByRest (String fileName) {
if (StringUtils.isNoneBlank(fileName)) {
System.out.println(" print to test 1:");
String url = "http://localhost:8080/project-dev/ss/GET_SAMPLE_API/";
final Response resp = client.target(url).request(MediaType.APPLICATION_OCTET_STREAM).get(Response.class);
if (resp.getStatus() == Response.Status.OK.getStatusCode()) {
System.out.println(" print to test 2:");
InputStream inputStream = (InputStream)resp.getEntity();
}
}
System.out.println(" print to test 3:");
return Constants.root + File.separator +
Config.getInstance().getProperties().getProperty("temp_folder") + File.separator + fileName;
}
and this is the output:
print to test 1:
print to test 3:
C:\home\project\temp_folder\data_98F4ABFB7806_16480262_1595325764285_len_2528.txt
Would you please help me. many thanks in advance.
I am exporting a .jar file from a GUI built in Netbeans IDE. It works fine within Netbeans but once it is exported, some logic in the code does not execute properly.
I have tried debugging by running test cases displaying which items are passing through the if clauses. It seems to work well in IDE but not when it is run through .jar file.
for(Chamber chamber: chs)
{
if(!scheduledTools.containsKey(chamber))//unscheduled chambers
{
JOptionPane.showMessageDialog(this, chamber.getName()+": is unscheduled");
model.addElement(chamber.getName());
}
else//scheduled
{
if((scheduledTools.get(chamber).size()/range) > .25)
{
System.out.println("Range: " +range+" Scheduled: " +scheduledTools.get(chamber).size());
System.out.println("Cannot use this chambers:" +chamber.getName());
JOptionPane.showMessageDialog(this, chamber.getName()+": Cannot use this chamber");
}
else{
System.out.println("Scheduled but can use"+chamber.getName());
altModel.addElement(chamber.getName());
}
}
}
alternateChambers.setModel(altModel);alternateChambers.setSelectedIndex(0);
suggestedChambers.setModel(model);suggestedChambers.setSelectedIndex(0);
if(altModel.size()>1){JOptionPane.showMessageDialog(this, "Scheduled but can use these chambers:"+altModel);}
After making the necessary queries in seekDates method below:
private void seekDates(ResultSet rs) throws SQLException
{
ArrayList<String> entries;
//get how many dates we have so we can update progressbar
int results = 0;
setProgress(results);
if(rs.last()){results=rs.getRow();rs.beforeFirst();}
// processing returned data and printing into console
while(rs.next()) {
String scheduledChamber = rs.getString(2);
for(Chamber chamber : chambers){
//if the scheduled tool is a thermal chamber
//chambers get listed so far
if(!scheduledChamber.trim().toLowerCase().contains(chamber.getName().toLowerCase()))
{}//print chambers im not saving
else{
if(scheduledTools.containsKey(chamber))
{
//if key already used, just grab the list and add date
entries = scheduledTools.get(chamber);
entries.add(rs.getString(1).split(" ")[0]);
}
else
{
//if chamber hasnt been saved, add chamber and date
entries = new ArrayList<String>();
entries.add(rs.getString(1).split(" ")[0]);
scheduledTools.put(chamber, entries);
}
//System.out.println("Just saved this chamber:" +scheduledChamber+" with this date:" +scheduledTools.get(chamber));
}
;
}
publish(rs.getRow());
Thread.yield();
setProgress(100*(rs.getRow()/results));
}
}
The GUI should display the chambers found in the queries in one text field while displaying the rest of the chambers in another text field.
When I run this in the IDE. I get the correct outcome but once I compile using the package-for-store option in the build.xml file, the outcome then just lists all of the chambers in one text field.
In the .jar file, it seems that all of the chambers only satisfy the first if clause and none of the others.
I'm using this code to create a powerpoint with changed files:
try (Git git = new Git(repo)) {
DiffFormatter df = new DiffFormatter(NullOutputStream.INSTANCE);
df.setRepository( git.getRepository() );
Iterable<RevCommit> commits = git.log().all().call();
for (RevCommit commit : commits) {
if(commit.getParents().length != 0) {
System.out.println("LogCommit: " + commit);
List<DiffEntry> entries = df.scan(commit.getId(), commit.getParent(0).getId());
for( DiffEntry entry : entries ) {
String filename = entry.getPath(DiffEntry.Side.NEW);
if(!filename.equals("/dev/null")) {
Integer currentCount = 0;
if(fileChanges.containsKey(filename)) {
currentCount = fileChanges.get(filename);
}else {
System.out.println(" DiffEntry: " +entry.getPath(DiffEntry.Side.NEW));
}
fileChanges.put(filename, new Integer(currentCount + 1));
}
}
}
}
}
However when I run it on a repo:
org.eclipse.jgit.api.errors.NoHeadException: No HEAD exists and no explicit starting revision was specified
at org.eclipse.jgit.api.LogCommand.call(LogCommand.java:154)
at .GitAccessor.getFilesChanged(GitAccessor.java:47)
at Main.main(Main.java:45)
I've tried to replicate it (since it is on a client's machine) by making this repo without a master:
https://github.com/davidahines/no_master
I've tried deleting the HEAD, ORIG_HEAD, and FETCH_HEAD and still can't seem to get this error.
I think what I need to do is bypass this check somehow, or find another head within the refs folder but I can't find that within jgit.
I don't currently have access to the client's repo because it is closed source.
The problem was that jgit doesn't support the tilde shortcut for /home/username, once that was removed it worked.
I am working on an android app used to access a Box account. The problem I am facing is how to determine a folder/file in the user's account is read only (shared with him/her as a Viewer) so that the upload/delete operations can be disabled.
What I currently do is:
1) Get the items in a folder:
BoxCollection itemsCollection = _boxClient.getFoldersManager()
.getFolderItems(folderId, folderContentRequest);
String userMail = ...
ArrayList<BoxTypedObject> result = null;
2) Determine which one is folder, get it's collaborations, check if it's accessible by the logged-in user, and check whether he is an editor:
if (itemsCollection != null) {
result = itemsCollection.getEntries();
for(BoxTypedObject boxObject : result) {
if(boxObject instanceof BoxAndroidFolder) {
BoxAndroidFolder folder = (BoxAndroidFolder)boxObject;
List<BoxCollaboration> folderCollaborations = _boxClient.getFoldersManager().getFolderCollaborations(folder.getId(), null);
for(BoxCollaboration collaboration : folderCollaborations) {
if( userMail.equalsIgnoreCase(collaboration.getAccessibleBy().getLogin()) &&
!BoxCollaborationRole.EDITOR.equalsIgnoreCase(collaboration.getRole()))
System.out.println("" + folder.getName() + " is readonly");
}
}
}
}
So, is there a simpler and faster (fewer requests) way to get that property of a folder with the android SDK?
You can first check the owner of the folder (folder.getOwnedBy()), if it's the current user then you don't need to check collaborations. However if it's not the current user you'll have to check collaborations.