following parametered script in java is not supported?why? - gremlin

i send parametered script to remote gremlin-server, but some scripts are success, some scripts are wrong.
for example, the following testcase is success, and the gremlin server returns the expect result
List<Long> ids = Lists.newArrayList(19496288L, 40076200L, 8717992L, 36070256L, 39303024L, 53232552L);
Map<String, Object> parameters = new HashMap<>();
parameters.put("ids1", ids);
parameters.put("ret", new String[]{"linkid", "locnwid", "remnwid"});
String strIds = "19496288,40076200,8717992,36070256,39303024,53232552";
String script = String.format("g.V(ids1).outE('L2_LINK').where(otherV().hasId(%s)).valueMap(ret).by(unfold())", strIds)
// this query script is also ok
// String.format("g.V().hasId(ids1).outE('L2_LINK').where(otherV().hasId(%s)).valueMap(ret).by(unfold())", strIds)
client.submit(script, parameters).all().get()
but the following testcase is wrong, the gremlin server return nothing
List<Long> ids = Lists.newArrayList(19496288L, 40076200L, 8717992L, 36070256L, 39303024L, 53232552L);
Map<String, Object> parameters = new HashMap<>();
parameters.put("ids1", ids);
parameters.put("ret", new String[]{"linkid", "locnwid", "remnwid"});
String strIds = "19496288,40076200,8717992,36070256,39303024,53232552";
String script = String.format("g.V(%s).outE('L2_LINK').where(otherV().hasId(ids1)).valueMap(ret).by(unfold())", strIds)
client.submit(script, parameters).all().get()
there is any wrong of my second query script? how to fix it?
another question:
i want to query the edges connecting nodes in a group, and the number of nodes exceeds 255, how to construct the query script to getting the edges by searching once?

after many tries, following script can work, but i do not known why.
String script = String.format("g.V(ids1).outE('L2_LINK').where(otherV().id().is(within(ids1))).valueMap(ret).by(unfold())", strIds)

Related

Spring-test cannot set #RequestPart. It always send it as null

I cannot test Controller by using mockMvc in spring-test. I want to know right way to test API with #RequestPart.
The method to test is this.
#RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseEntity<Object> replaceFile(
#RequestPart("files") Map<String, Object> files,
#RequestPart("fileKey") String fileKey)
And to test I build a mock request like below.
MockMultipartFile blob = new MockMultipartFile("files", files.getBytes());
MockMultipartFile key = new MockMultipartFile("fileKey", fileKey.getBytes());
mockMvc.perform(fileUpload("/")
.file(blob)
.file(key))
.andDo(print())
.andExpect(status().isOk());
As you can see, I used fileUpload. But in past time, I tried to use post with content or requestAttr because all of them didn't work.
I think current code is the closest to answer among I tried, but can't get closer anymore.
The weird thing is, the real in-use API is almost same with them.
In client side, user sent a new FormData() object to request and server can get data properly.
The server side code is below.
#RequestMapping(value = "/api/{variable}", method = RequestMethod.POST)
public ResponseEntity<Object> apiMethod(
#PathVariable int variable,
#RequestPart("dto1") DTO1 dto1,
#RequestPart("dto2") DTO2 dto2,
#RequestPart("file") Map<String, Object> file)
"file" part consists of "file name" key and its blob value encoded base64.
For example, {"hello.txt": "SGVsbG8gd29ybGQh"}
What I want to know - Right way to test API with #RequestPart
What I tried
method - fileUpload / data - file, content, requestAttr but they send null.
method - post / data - file, content, requestAttr but they throw MultipartException.
Restriction - Cannot use multipart because the system is using a low version of Spring.
Thanks!
Thanks to #borino who commented to my question, I got the clue of problem.
It is certain to use fileUpload for testing API with #RequestPart arguments.
In that case, it caused from content type.
I declared MockMultipartFile without contentType.
MockMultipartFile blob = new MockMultipartFile("files", files.getBytes());
MockMultipartFile key = new MockMultipartFile("fileKey", fileKey.getBytes());
But the arguments of API have a type, Map<String,Object> and String each.
As #borino said to me, I changed constructor of MockMultipartFile to make sure contentType, and it works!
MockMultipartFile blob = new MockMultipartFile("files", "", "application/json", files.getBytes());
MockMultipartFile key = new MockMultipartFile("fileKey", "", "application/json", fileKey.getBytes());
Just add contentType when you have a problem like me. Thanks!

Workfront: Set predecessor when adding a task

I'm using the java and the Workfront API to create a new task and would like to specify a predecessor while creating the task. If I add the task first, then update it, I am able to add the predecessor but I'd prefer to specify the predecessor when adding the task if possible.
Here's what I've tried but I have no luck. I just get a 500 error (internal server error).
...
Map<String, Object> map = new HashMap<String, Object>();
map.put( "name", "Test Task" );
map.put( "projectID", projectId );
JSONArray array = new JSONArray();
JSONObject jsonObj = new JSONObject();
jsonObj.put( "predecessorID", predecessorId );
jsonObj.put( "predecessorType", "fs" );
array.put( jsonObj );
map.put( "predecessors", array );
client.post( "task", map );
Has anyone been able to do this? Am I just missing something?
I'm almost positive that you can't set dependencies in the same operation as object creation. You'll have to PUT an update on the object after its creation. I'm not sure about the syntax for your Java implementation, but this is what the raw HTTP call would look like:
PUT https://<url>.my.workfront.com/attask/api/v9.0/task/<uuid>?updates={predecessors:[{predecessorID:"<ID of dep>",predecessorType:"<ss/sf/fs/ff>"}]}&apiKey=<key>

Deleting in SailGraph

I am trying to delete a vertex in SailGraph. This works locally but not on the server. On the server the underlying neo4j database is left inconsistent.
graph = GraphFactory.createGraph(config.get("type").getAsString(),
name, dbpath);
sail = new GraphSail<KeyIndexableGraph>(graph);
sailGraph = new SailGraph(sail);
reasoner = new ForwardChainingRDFSInferencer(
new GraphSail<KeyIndexableGraph>(graph));
This is what i use to initialise then I load an RDF
public static void loadRDF(InputStream is, String baseURI, String format,
sailGraph.loadRDF(is, baseURI, format, baseGraph);
To remove I use
Vertex vertex = sailGraph.getVertex(uri);
vertex.remove();
Locally it works on the server it goes past the remove step but the vertex is still there. No exceptions or anything. I have set the permissions on the database directory to allow writing but still nothing. Any ideas?
Thanks

"Unexpected list type" exception when invoking ISessionAwareCoreService.GetList()

I am invoking the Tridion 2011 SP1 core service via the shipped client assembly. When I attempt to list the contents of a publication, I get an exception.
The code (simplified) looks like this:
ItemsFilterData filter = new Tridion.ContentManager.CoreService
.Client.RepositoryItemsFilterData.RepositoryItemsFilterData();
filter.ItemTypes = new ItemType[] {
ItemType.Folder,
ItemType.StructureGroup
};
filter.Recursive = false;
IEnumerable<IdentifiableObjectData> childItems = core.GetList("tcm:0-15-1", filter);
Note: the variable "core" refers to an ISessionAwareCoreService which I can successfully use to call, for example core.GetSystemWideList()
When .GetList is invoked, I get the following exception:
System.ServiceModel.FaultException`1 was unhandled
Message=Unexpected list type:
Tridion.ContentManager.Data.ContentManagement.RepositoryItemsFilterData.
What are the possible causes of this problem? Can you suggest a good general approach for interpreting this kind of message?
You can't get the direct children of a Publication using GetList. Instead you should just load the PublicationData with a client.Read and then access the RootFolder and RootStructureGroup on that.
PublicationData pub = (PublicationData)core.Read("tcm:0-1-1", new ReadOptions());
string rootFolder = pub.RootFolder.IdRef;
string rootSG = pub.RootStructureGroup.IdRef;
Alternatively you can call GetListXml with your RepositoryItemsFilterData and extract the items from the XML yourself.
XElement listResult = core.GetListXml(parent.ID, filter);

File not found error with FileStreamResult controller action

I have a controller action declared as follows:
[Authorize(Order = 0, Roles = "Requester,Controller,Installer")]
public FileStreamResult ExportJobCards()
The body of this method builds a collection of CSV lines, and attempts to return them as a file as follows:
using (var sw = new StreamWriter(new MemoryStream()))
{
foreach (var line in lines)
{
sw.WriteLine(line);
}
return new FileStreamResult(sw.BaseStream, "text/csv");
}
When I request this action using the following action link...
Html.ActionLink("Export to Excel", "ExportJobCards")
...the export method executes properly, i.e. all the required CSV data is present in the lines collection in the above code, but I get a File Not Found error rendered as the end result.
EDIT:
In agreement with Tommy's observation, I moved the return out of the using, and I now get a file, but the file is empty. The new code that actually produces a file, ableit empty, is:
var sw = new StreamWriter(new MemoryStream());
foreach (var line in lines)
{
sw.WriteLine(line);
}
sw.Flush();
return new FileStreamResult(sw.BaseStream, "text/csv");
With your current setup, the Using statement is disposing of the StringWriter before the return can complete, which is resulting in the null reference/file not found error. Remove the using statement or set the StringWriter to another variable before you exit out and you should be good to go on getting rid of the File Not Found error.
A thought on your second issue now, looking into memorystreams as filestream results, you may need to change your return to this
sw.BaseStream.seek(0, SeekOrigin.Begin)
return new FileStreamResult(sw.BaseStream, "text/csv");
as the pointer is still at the end of the stream when you return.
It throws that error because you're not giving it a file stream. What you want is the FileContentResult into which you can pass arbitrary content. This content needs to be a byte array of your content, probably easiest to:
use a stringbuilder rather than a streamwriter
get your string from the builder
use the static method System.Text.UnicodeEncoding.Unicode.GetBytes(string) to get the byte array
Give the byte array to FileContentResult
As you have to write this code anyway the easiest thing to do would be to create a new FileStringResult that inherits from the base FileResult that can take in a string or stringbuilder. Override WriteFile(HttpResponseBase response) to do the string to byte[] conversion and push that into the response. Take a look at the FileStreamResult class from the MVC sources, it's very small and easy to do.

Resources