//asset nullpointer exception
Asset asset = assetMgr.createAsset(assetDetails.getDamPath(), inputStream, "image/jpeg", true);
Resource metadataRes = asset.adaptTo(Resource.class).getChild("jcr:content/metadata");
ModifiableValueMap map = metadataRes.adaptTo(ModifiableValueMap.class);
map.remove("dc:title");
map.put("dc:description", assetDetails.getAssetDescription());
map.put("sourceId", assetDetails.getSourceId());
map.put("dc:title", assetDetails.getAssetTitle());
resourceResolver.commit();
Getting asset as null.
Is any other way to get Resource?
Related
strong text [Plugin error at Note entity][1]
[1]: http://i.stack.imgur.com/hRIi9.png
Hi,Anyone resolved my issue i got a Plug-in error which i worked at Update of "Note" entity.Basically i want a Plugin which converted pre-exiting Note attachment XML file into new .MMP extension file with the same name.
I have done following procedure firstly i created a "Converter_Code.cs" dll which contains Convert() method that converted XML file to .MMP file here is the constructor of the class.
public Converter(string xml, string defaultMapFileName, bool isForWeb)
{
Xml = xml;
DefaultMapFileName = defaultMapFileName;
Result = Environment.NewLine;
IsForWeb = isForWeb;
IsMapConverted = false;
ResultFolder = CreateResultFolder(MmcGlobal.ResultFolder);
}
In ConvertPlugin.cs Plug-in class firstly i retrieved Note entity attachment XML file in a string using following method in
IPluginExecutionContext context =(IPluginExecutionContext)serviceProvider.
GetService (typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory= (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService
(context.UserId);
if (context.InputParameters.Contains("Target")
&& context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
var annotationid = entity.GetAttributeValue<Guid>("annotationid");
if (entity.LogicalName != "annotation")
{
return;
}
else
{
try
{
//retrieve annotation file
QueryExpression Notes = new QueryExpression { EntityName ="annotation"
,ColumnSet = new ColumnSet("filename", "subject", "annotationid",
"documentbody") };
Notes.Criteria.AddCondition("annotationid", ConditionOperator.Equal,
annotationid);
EntityCollection NotesRetrieve = service.RetrieveMultiple(Notes);
if (NotesRetrieve != null && NotesRetrieve.Entities.Count > 0)
{
{
//converting document body content to bytes
byte[] fill = Convert.FromBase64String(NotesRetrieve.Entities[0]
.Attributes["documentbody"].ToString());
//Converting to String
string content = System.Text.Encoding.UTF8.GetString(fill);
Converter objConverter = new Converter(content, "TestMap", true);
objConverter.Convert();
}
}
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("something is going wrong");
}
}
}
}
and than A string is passed to "Converter" constructor as a parameter.
finally i merged all dll using ILMerge following method:
ilmerge /out:NewConvertPlugin.dll ConvertPlugin.dll Converter_Code.dll
and NewConvertPlugin is registered successfully but while its working its generate following error:
Unexpected exception from plug-in (Execute): ConverterPlugin.Class1: System.Security.SecurityException: That assembly does not allow partially trusted callers.
i also debug the plugin using Error-log but its not worked so i could not get a reason whats going wrong.
The error is caused by the library you merged inside your plugin.
First of all you are using CRM Online (from your screenshot) and with CRM Online you can use only register plugins inside sandbox.
Sandbox means that your plugins are limited and they run in a partial-trust environment.
You merged an external library that requires full-trust permissions, so your plugin can't work and this is the reason of your error.
Because you are in CRM Online, or you find another library (the Converter) that requires only partial-trust, hoping that the merge process will work, or you include (if you have it) the source code of the converter library directly inside your plugin.
I am using following code to get URI but it gives exception:
s3.putObject(bucket, fileToPut, file.ref.file)
val s3Object = s3.getObject(bucket, fileToPut).orNull
if(s3Object != null){
val assetUrl = s3Object.getObjectContent.getHttpRequest.getURI
}
I am unable to get uploaded object URI
Please help
If you just want the url of the object you could use
s3Client.getResourceUrl("your-bucket", "path/file.txt");
I'm looking for a way (preferably a workflow) that removes/cleans renditions!
My problem is that over time I have loads of images with renditions that are no longer used.
Is there a good way to clean this and "reclaim" my disk space? :)
Though i would like to suggest you sling servlet route to remove as you will have more control over what should be deleted and from which path.
You can reuse some of the code from below as well.
I created a sample program a few weeks back to remove renditions except the original one whenever a new image was added and i was using workflows:
The code below was a component. A workflow was created and this class was then added as a process step to a workflow and the same workflow was set in any launcher and event type was created.
Basically, i used Query builder api and workflow api and was able to achieve the same. If you use servlet way as suggested you can take path as a parameter and then use query builder api to locate the renditions folder and then iterate over the same and remove the nodes.
Sample values that will be extracted via query builder:
http://localhost:4502/bin/querybuilder.json?path=%2fcontent%2fdam%2fgeometrixx%2ficons&property=jcr%3aprimaryType&property.1_value=nt%3afolder
public void execute(WorkItem item, WorkflowSession wfsession, MetaDataMap args)
throws WorkflowException {
try {
resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
WorkflowData workflowData = item.getWorkflowData();
String path = workflowData.getPayload().toString();
path = path.replace("/jcr:content/renditions", "");
session = resourceResolver.adaptTo(Session.class);
Map<String, String> map = new HashMap<String, String>();
map.put("path", path);
map.put("property", "jcr:primaryType");
map.put("property.1_value", "nt:folder");
Query query = builder.createQuery(PredicateGroup.create(map), session);
SearchResult result = query.getResult();
List<Hit> hits = result.getHits();
Resource renditionResource = resourceResolver.resolve(hits.get(0).getPath());
Iterator<Resource> reneditionIterator = renditionResource.listChildren();
while(reneditionIterator.hasNext()){
Resource specificResource= reneditionIterator.next();
Node renditionNode = specificResource.adaptTo(Node.class);
if(!renditionNode.getName().equals("original")){
renditionNode.remove();
}
}
} catch (LoginException e) {
e.printStackTrace();
}
Servlet
ResourceResolver resourceResolver = slingHTTPrequest.getResourceResolver();
String path = slingHTTPrequest.getParameter("path");
session = resourceResolver.adaptTo(Session.class);
Map<String, String> map = new HashMap<String, String>();
map.put("path", path);
map.put("property", "jcr:primaryType");
map.put("property.1_value", "nt:folder");
Query query = builder.createQuery(PredicateGroup.create(map), session);
SearchResult result = query.getResult();
List<Hit> hits = result.getHits();
for(Hit hit: hits){
Resource renditionResource = resourceResolver.resolve(hit.getPath());
Iterator<Resource> reneditionIterator = renditionResource.listChildren();
while(reneditionIterator.hasNext()){
Resource specificResource= reneditionIterator.next();
Node renditionNode = specificResource.adaptTo(Node.class);
LoggerUtil.debugLog(this.getClass(),"Node name will be {}",renditionNode.getName());
if(!renditionNode.getName().equals("original")){
LoggerUtil.debugLog(this.getClass(), "removing rendition, parent node name is{}",renditionNode.getParent().getParent().getParent().getName());
renditionNode.remove();
}
}
}
I'm using the twitter4j library to access the public twitter stream. I'm trying to make a project involving geotagged tweets, and I need to collect a large number of them for testing.
Right now I am getting the unfiltered stream from twitter and only saving tweets with geotags. This is slow though because the VAST majority of tweets don't have geo tags. I want the twitter stream to send me only tweets with geotags.
I have tried using the method mentioned in [this question][1], where you filter with a bounding box of size 360* by 180* but that's not working for me. I'm not getting any errors when using that filter, but I'm still getting 99% of tweets with no geotags. Here is how I'm doing it:
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler());
HttpGet httpget = new HttpGet("https://developers.facebook.com/docs/reference/api/examples/");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
entity.consumeContent();
}
List<Cookie> cookies = httpclient.getCookieStore().getCookies();
HttpPost httpost = new HttpPost(
"https://www.facebook.com/login.php?login_attempt=1");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("email", "xxxxxxxxxxxxxx"));
nvps.add(new BasicNameValuePair("pass", "ssssssss"));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
entity = response.getEntity();
if (entity != null) {
entity.consumeContent();
}
CookieStore cookiestrore = httpclient.getCookieStore();
//cookies = httpclient.getCookieStore().getCookies();
//httpclient.getConnectionManager().shutdown();
return cookiestrore;
Any this is not getting any error but i am not getting any results.
When you track keyword it is separate job from tracking locations. These are logical ORs
I'm having problems when I try to do a HTTP Post in my Plugin (in PostUpdate). I'm getting the "The Operation Has Timed Out"-Error...
Here below you have the C#-code :
//PUBLISH TO ROBAROV
WebRequest webRequest = WebRequest.Create(newUri);
webRequest.Timeout = 2000;
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(parameters);
Stream os = null;
try
{
webRequest.ContentLength = bytes.Length;
os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
}
catch (WebException ex)
{
throw new Exception(ex.Message);
}
finally
{
if (os != null)
{
os.Close();
}
}
//ERROR HAPPENS HERE
string responseText = "";
try
{ // get the response
WebResponse webResponse = webRequest.GetResponse();
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
responseText = sr.ReadToEnd().Trim();
}
catch (WebException ex)
{
throw new Exception("Error with response : " + ex.Message);
}
The error happens when I'm trying to get the response => webRequest.GetResponse();!
I've tried the code out in a simple "Class"-library and there it works like a charm! Is there something I'm doing wrong? The HTTP Post is to a webpage that's not in the same domain....
UPDATE :
Same happens when I do the following with a webclient... And it works in a normal "Console"-application :
private string HttpPostTest(string URL)
{
WebClient webClient = new WebClient();
System.Collections.Specialized.NameValueCollection formData = new System.Collections.Specialized.NameValueCollection();
formData["state"] = "yes";
byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
string Result = Encoding.UTF8.GetString(responseBytes);
return Result;
}
I'm getting the following error in the "Event Viewer" :
Inner Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Crm.Setup.DiffBuilder, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
It looks like it can't find a CRM assembly: Microsoft.Crm.Setup.DiffBuilder.dll, is this something which you explicitly call methods from? If so I'd check if the assembly is registered with the plug-in (some instructions below). If not then there are some errors associated with this library from roll up 6, which roll up are you using? You may consider roll up 7 if you are not using that.
Is your plug-in registered in the database or on disk?
If registered on disk then you will need your external assembly in the /server/bin/assembly directory under the CRM installation folder.
If it is registered in the database and you are including a custom external assembly (the error suggests that an assembly cannot be loaded, so this sounds possible), then you will have to ILMerge your assemblies before registering them in the database. This would explain why it works for your local console application and not when run as a plug-in.
If this is the case then you can follow a script like below to ILMerge and register your 'combined' assembly:-
http://www.2wconsulting.com/2010/11/using-ilmerge-with-crm-plugin-assemblies/