how show images from site in google search result - sitemap

search result example
I made sitemap.xml for website and have question -
what to do with website, to show images in google search results?
  <url>
    <loc>http://example.com/sample1.html</loc>
    <image:image>
      <image:loc>http://example.com/image.jpg</image:loc>
    </image:image>
    <image:image>
      <image:loc>http://example.com/photo.jpg</image:loc>
    </image:image>
  </url>
does image.jpg will be displayed with http://example.com/sample1.html reference? (I checked sitemap from picture - no image tag in it)

Related

Insert into SQL Server table selected columns from spark dataframe

I have a SQL Server table that has a different schema than my dataframe. I would like to select some columns from my dataframe and "insert into" the table the values I selected.
Basically something similar to the code below but in pyspark:
INSERT INTO Cust_Diff_Schema_tbl
(acct_num, name)
SELECT account_no, name
FROM customers
WHERE customer_id > 5000;
I can read the data using jdbc using spark.read. Just like below:
df_s3 = spark.read.format("jdbc")\
                .option("driver", db_driver_name)\
                .option("url", db_url+ ":1433;databaseName="+stage_db)\
                .option("dbtable", tbl_name)\
                .option("query", """(select * from customers)""")\
                .option("user", db_username)\
                .option("password", db_password)\
                .load()
   
    df_s3.printSchema()
    df_s3.show(20)
To write/append the data to the table with the selected values, I believe I can still use "df_s3.write" but I need an example on how to use the insert statement using ".option" function or another approach if this does not work.
Thanks in advance.
//create dataframe
val df = //fetch from db,read file or other options
df.write.format("jdbc")
.option("numPartitions", 20)
.option("batchsize", 10000)
.option("truncate", "true")
.option("url", "jdbcURL")
.option("driver", "Driver name")
.option("dbtable", "tablename")
.mode("append")
.save()

Chrome browsers stay open while running "fake parallelism" with TestCafe

I'm currently using TestCafe as my main test framework in my company. I just encountered a problem recently: we have a designed pipeline that launches tests in a parallel way, but not the way Testcafe is supposed to work.
I know that testcafe can handle parallelism though concurrent test execution this way :
testcafe -c 3 chrome tests/test.js
However, our pipeline plays each testcafe test in its own browser without using the concurrent test execution procedure. The result is that, at the end of the execution, we have A LOT of chrome browsers still open in the task manager. I don't know how to handle this problem... I already tried to insert some code about window.close() at the "aftereach" of my fixtures but this is not working ...
I have to mention that, executing one test at a time doesn't produce this effect and all chrome browsers are closed correctly.
Thanks for your help!
Sylvain
This is the code that is executed :
execution {
    String nodejsPath = pathfileOfTestDirectory("nodejs/")
    String nodejsModulePath = nodejsPath + "/lib/node_modules"
    String npmPath = pathfileOfTestDirectory("nodejs/npm.cmd")
    new File(resultDir).mkdirs();
    logcatoutput resultDir + "logcat.log"
    inDirectory pathfileOfTestDirectory("tests-e2e")
    within 60, TimeUnit.MINUTES
    env "Path", readEnv("Path") + ";" + nodejsPath
    env "NODE_PATH", nodejsModulePath
    String browserPath;
    switch(browser) {
        case "firefox":
            //browserPath = pathfileOfTestDirectory("/resources/browsers/firefox/firefox.exe")
            browserPath = pathfileOfTestDirectory("/resources/browsers/chrome/Application/chrome.exe")
            break
        case "chrome" :
            browserPath = pathfileOfTestDirectory("/resources/browsers/chrome/Application/chrome.exe")
            break
    }
    command npmPath, "run",
            "testcafe",
            "--scripts-prepend-node-path",// ensure the nodejs installation of the workspace is used
            "--",
            "path:`${browserPath}`",
            "testcafe/",
            "--targetEnv=" + targetEnv,
            "--targetPage=" + targetPage,
            "--test=\"${testName}\"", "-q",
            "-r", "json:${resultDir}result.json",
            "-s", "${resultDir}"
    logger.info("Execution done")
}

Acumatica postal code validation and match

I have created a new custom field(postal code - Usrpostalcode) in Sales Order screen and I am trying to make this field required(not working even after adding [PXDefault]
[PXUIField(..., Required = true)] ),validate it and make sure that it matches with the Postal code in the Shipping Settings.
Can anyone help me with this?
Getting this error while creating shipment on sales order screen
enter image description here
Adding PXDefault attribute should be enough to make the field required. PXDefault will prevent saving if the value is null or empty. It will raise an error and highlight the field.
Adding the custom field in SOOrder DAC:
Adding the custom field to Sales Order screen:
Testing required field by saving without providing Postal Code value:
Using Inspect Element, locate the field you want to validate against:
In the code section, create a Graph Extension for SOOrderEntry where you will put your validations:
Write your validation code in that graph extension:
namespace PX.Objects.SO
{
  public class SOOrderEntry_Extension:PXGraphExtension<SOOrderEntry>
  {
    public const string postalCodeErrorMessage = "Sales Order postal code must match shipping address postal code.";
    // Validate just before saving, triggered when graph save function is called
    public void SOOrder_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
    {
      if (!ValidatePostalCode(sender, e.Row as SOOrder))
      {
         // Raise field error
         PXUIFieldAttribute.SetError<SOOrderExt.usrPostalCode>(sender, e.Row, postalCodeErrorMessage);
      }
    }
    // Validation function
    public bool ValidatePostalCode(PXCache sender, SOOrder soOrder)
    {
      if (soOrder != null)
      {
        // Get SOOrder custom field Postal Code
        SOOrderExt soOrderExt = sender.GetExtension<SOOrderExt>(soOrder);
        if (soOrderExt != null)
        {
          string soPostalCode = soOrderExt.UsrPostalCode;
  
          // Get current shipping address displayed on Sales Order
          SOShippingAddress shippingAddress = Base.Shipping_Address.Current as SOShippingAddress;
  
          if (shippingAddress != null)
          {
              // Special case to handle null values
              if (soPostalCode == null || shippingAddress.PostalCode == null)
              {
                  return soPostalCode == shippingAddress.PostalCode;
              }
  
              // Compare postal codes
              soPostalCode =soPostalCode.Trim().Replace(" ", "");
              string shippingPostalCode = shippingAddress.PostalCode.Trim().Replace(" ", "");
              
              return soPostalCode.Equals(shippingPostalCode, StringComparison.OrdinalIgnoreCase);
          }
        }
      }
      return false;
    }
  }
}
When saving or when the custom postal code field lose focus, validation will be triggered:
You can check for the value by either adding a selector or implementing FieldVerifying.
If using a PXSelector by default the selector will throw an error if not found in the backing table.
Alternatively, you can use the fields FieldVerifying event by adding it to the graph extension on sales order like the example below...
public class SOOrderEntryExtension : PXGraphExtension<SOOrderEntry>
{
protected virtual void SOOrder_Usrpostalcode_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
{
//search for table value...
// if not found...
throw new PXSetPropertyException<SOOrder.usrpostalcode>("Invalid postal code");
}
}

jquery ajax request with authentication

I have a JSP-servlets application which is deployed on tomcat.Now from my html I need to make web(Ajax) call and call the CQ5 webpage(which is entirely running in CQ instance). When i click on submit button, it goes in the error method of ajax call.
Here is the code
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://crypto-js.googlecode.com/svn/tags/2.5.4/build/crypto/crypto-min.js"></script>
<script src="/resources/scripts/mysamplecode.js" type="text/javascript"></script>
<script type="text/javascript">
  
$(document).ready(function() {
  
 
 $("#myAjaxRequestForm").submit(function(e){
        e.preventDefault();
 });
   
 
 $("#myButton").click(function(e){
          
   //get the form data and then serialize that
         dataString = $("#myAjaxRequestForm").serialize();
   
   
var username = 'admin';
var password = 'admin';
var url = 'http://localhost:4502/content/geometrixx/en/products/triangle/jcr:content/par/text_0.infinity.json'; 
$.ajax({
type: 'GET',
url: 'http://localhost:4502/content/geometrixx/en/products/triangle/jcr:content/par/text_0.infinity.json',
dataType : 'json',
'beforeSend': function(xhr) {
var bytes = Crypto.charenc.Binary.stringToBytes('admin' + ":" + 'admin');
var base64 = Crypto.util.bytesToBase64(bytes);
xhr.setRequestHeader("Authorization", "Basic " + base64); //May need to use "Authorization" instead
},
error : function() {
alert('errro');
},
sucess: function(result) {
alert('done');
}
}); 
 }); 
  }); 
</script>
<div id="allContent">
  <div id="myExample">
 <form id="myAjaxRequestForm">  
   <h1> Please enter the Order Information -</h1>
    <label for="orderId">Order Id:</label>
  <input id="orderId" name="orderId" type="text"><br/>
<br/>
  <label for="zipCode">ZIP Code:</label>
  <input id="zipCode" name="zipCode" type="text"><br/>
    <br/>
    <input id="myButton" type="button" value="Submit">
</form>
</div>
 <div id="ajaxResponse">
</div>
</div>
</head></html>
Try to change your beforeSend handler a bit and also debug the error:
beforeSend: function (xhr) {
var base64 = btoa(username + ":" + password);
xhr.setRequestHeader("Authorization", "Basic " + base64);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
},
If it doesn't work, please paste the result of those 3 console.log()
I can see the json in the chrome console..but i get the parse error.Jquery17989898 was not called.
This is the code ...
var user = 'admin';
var pw = 'admin';
var url = 'http://localhost:4502/content/geometrixx/en/products/triangle/jcr:content/par/text_0.infinity.json'; 
alert("i1");
var authToken = null;
$.ajax({
url: 'http://localhost:4502/content/geometrixx/en/products/triangle/jcr:content/par/text_0.infinity.json',
type: "POST",
crossDomain: true,
dataType: "jsonp",
data: JSON.stringify({ "Username" : user, "Password" : pw, "Type" : "SaaSGrid"}),
success: function(data)
{
alert("dsadsadsa");
authToken = data.Token;
},
error: function (jqXHR, textStatus, errorThrown) {
alert("jqXHR : " + jqXHR +
" \n**** text Status : " + textStatus +
" \n**** text Status : " + errorThrown);
}
});
{"textIsRich":"true","jcr:lastModifiedBy":"admin","sling:resourceType":"foundation/components/text","jcr:createdBy":"admin","jcr:created":"Wed Nov 03 2010 00:41:59 GMT-0400","jcr:lastModified":"Fri Nov 05 2010 11:14:54 GMT-0400","jcr:primaryType":"nt:unstructured","text":"The measure of an exterior angle of a triangle is equal to the sum of the measures of the two interior angles that are not adjacent to it; this is the exterior angle theorem. The sum of the measures of the three exterior angles (one for each vertex) of any triangle is 360 degrees.</p>\n</p>\n"}
I think you should explain a bit more your scenario. You are trying to access a page from a CQ5 instance, but authentication for that is probably just needed in an author instance. when accessing a publish instance that page will likely not need any authentication.
Will you always access the author instance? if you will switch to a publish instance later it would be easier to just adjust permissions in CQ5 to make the page public.
from a security perspective, this sounds wrong - you are passing user & password to execute on the client side - exposing your authentication.
Better to open up the permissions on the resource so anonymous can write to it (the POST) then pass credentials out.

Posting JSON with AJAX request in play2

i'm using play framework 2.0.4
i have a route :
POST /addMail controllers.Application.addMail()
In my controller Application i define the addMail method :
public static Result addMail()
{
JsonNode json = request().body().asJson();
Long id = json.findPath("id").asLong(0);
String email = json.findPath("email").getTextValue();
GameScore gs = GameScore.findById(id);
gs.setEmail(email);
gs.save();
return ok();
}
If i call this method through CURL i have no problem :
curl --header "Content-type: application/json" --request POST --data '{"id": 13, "email": "test#DB.com"}' http://localhost:9000/addMail
But if i call this method through an AJX request i have a 500 response.
$addMailBtn.click(function(event) {
$this = $(this);
var id = $this.attr("id").substring(14);
var email = $("#saisieMailField_" + id).val();
$.ajax({
type: 'POST',
url: "#routes.Application.addMail()",
dataType:"json",
data: {"id":id, "email": '"' + email + '"'},
success: location.reload()
})
} );
If i print in my console my json data, json data is null when i perform my ajax request but is alright through curl.
I have tried to add
#BodyParser.Of(play.mvc.BodyParser.Json.class)
on my method but it doesn't change anything.
Thanks for your time.
This works for me. Note that i stringify the JSON object, and I think this is your problem.
$.ajax({
type: "POST",
url: "http://myservice:9000/api/v1/positions",
data: JSON.stringify({"nwLng":72.22,"nwLat":22.22, "seLng":22.22,"seLat":55.33}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) { alert(data); },
failure: function (errMsg) { alert(errMsg); }
});

Resources