is it possible way to customize the sub resource api platform? - symfony

The goal was i aiming to is to change identifier from id of entity to JWT token that user has attached at specific path.
#ApiResource(
itemOperations = {
"get" ={
"security" = "is_granted('VIEW',object)",
"normalization_context" = {"groups" = {"read"}}
},
"put" = {
"security" = "is_granted('WRITE',object)",
"normalization_context" = {"groups" = {"get"}},
"denormalization_context" = {"groups" = {"put"}}
},
"api_users_cart_subresource" = {
"method" = "GET",
"path" = "/users/{id}/carts",
"security" = "is_granted('VIEW',object)",
"normalization_context" = {"groups" = {"user:cart"}}
}
},
collectionOperations = {
"post" = {
"denormalization_context" = {"groups" = {"post"}},
"normalization_context" = {"groups" = {"get"}}
},
"get" = {
"access_control" = "is_granted('ROLE_ADMIN')",
"normalization_context" = {"groups" = {"admin:read"}}
}
}
)
is it possible to change the path to /users/carts and return normalized data that belong to the user base from their token?
ps. sorry for my grammar

Related

Why can't I use get_children_by_id() on this widget

I want to access the internal widgets but it gives me an error, that I can't index a nil value.
My widget:
local previewWidget = wibox()
previewWidget:setup {
widget = wibox.widget {
{
widget = wibox.widget {
{
widget = awful.widget.clienticon,
client = "",
id = "clientIcon"
},
{
widget = wibox.widget.textbox,
id = "titleText"
},
nil
},
layout = wibox.layout.align.horizontal,
id = "titleBox"
},
{
widget = wibox.widget.imagebox,
id = "clientImage"
},
nil
},
id = "previewBox",
layout = wibox.layout.align.vertical,
border_width = 10,
border_color = "FF0000",
}
This command doesn't give error:
local previewBox = previewWidget:get_children_by_id("previewBox")[1]
But this does:
local titleBox = previewWidget:get_children_by_id("titleBox")[1]
local clientIcon = previewWidget:get_children_by_id("clientIcon")[1]
What am I doing wrong here?
local previewWidget = wibox.widget {
{
{
widget = awful.widget.clienticon,
client = "",
id = "clientIcon"
},
{
widget = wibox.widget.textbox,
id = "titleText"
},
nil,
layout = wibox.layout.align.horizontal,
id = "titleBox"
},
{
widget = wibox.widget.imagebox,
id = "clientImage"
},
nil,
layout = wibox.layout.align.vertical,
id = "previewBox",
}
I incorrectly used the layout:
All 3 widgets needs to be where the layout is called
local some_widget = wibox.widget {
{ widget nr.1 },
{ widget nr.2 },
{ widget nr.3 },
layout = wibox.layout.align.vertical
}
P.S. it's enough to declare a layout without a widget

Mocking of Where method in Data Repository is returning null at its actual implementation in repository

I have written a test for edit model of a class in EF core.
public async Task<Expense> EditExpense(Expense model)
{
var expense = _dataRepository.Where<Expense>(x => x.Id == model.Id).ToList();
if(expense != null)
{
expense.ForEach(x =>
{
x.Name = model.Name;
x.AddedOn = model.AddedOn;
x.Amount = model.Amount;
x.Type = model.Type;
x.SplitOption = model.SplitOption;
x.Notes = model.Notes;
x.IsGroupExpense = model.IsGroupExpense;
});
return expense.FirstOrDefault();
}
else
{
return null;
}
}
I want to test this method using xUnit and Moq and I have also written a method for it as below.
[Fact]
public async void UnitTest_IsExpenseEdited_ReturnsTrue()
{
var expenseCurrent = new Expense()
{
Id = 5,
Name = "Test Expense",
Amount = 1500,
AddedBy = "44db32c3-ad6a-4d68-a683-862be363f59c",
AddedOn = DateTime.Now,
Notes = "",
IsDeleted = false,
IsGroupExpense = false,
SplitOption = 1,
Type = 0
};
var expenseList = (new List<Expense>{ expenseCurrent });
var expenseAfterEdit = new Expense()
{
Id = 5,
Name = "Test Expense Edited",
Amount = 2000,
AddedBy = "44db32c3-ad6a-4d68-a683-862be363f59c",
AddedOn = DateTime.Now,
Notes = "Edited !!!",
IsDeleted = false,
IsGroupExpense = true,
SplitOption = 2,
Type = 0
};
_dataRepositoryMock.Setup(x => x.Where<Expense>(a => a.Id == expenseCurrent.Id)).Returns(expenseList as IQueryable<Expense>);
var expenseEdited = await _exepenseRepository.EditExpense(expenseAfterEdit);
Assert.Equal(expenseEdited, expenseAfterEdit);
}
But here, the Where method is returning null
public async Task<Expense> EditExpense(Expense model)
{
var expense = _dataRepository.Where<Expense>(x => x.Id == model.Id).ToList(); in repository
}
I am getting var expense null in above code.
Please suggest what should I include in the code to get the value in above var expense?
To test this method, I want to create a fake data which is going to be updated. Please suggest how this thing needs to be written properly?

how to send a post request?

How to consume web post service in C#? I did tests with POSTMAN and I got a response data, but in .net my response is empty. It works great in PostMan. The problem is how to format the Body Content and send it.
string idop = "";
List<ProductJSON> listProductsJSON = new List<ProductJSON>();
List<List<string>> productJSON = new List<List<string>>();
List<string> products = new List<string>();
products.Add("4");
products.Add("5");
products.Add("30.2");
products.Add("1");
products.Add("0");
products.Add("4");
productJSON.Add(products);
using (var client = new HttpClient())
{
var res = client.PostAsync("http://xyz.cti.lat/sant2/webservices/edd.php",
new StringContent(JsonConvert.SerializeObject(
new {
a = "pCatlog",
cnal = "RED",
tpo = "2",
fpago = "DETO",
pgdo = "0",
rc = "13123",
local = "BACK",
localorg = "BACK",
raz = "PPPPPP",
dir_ruc = "name",
log = "CREAVIR",
not = "DETO2",
del = "0",
dir = "",
ubi = "",
refe = "",
prod = productJSON
}),
Encoding.UTF8, "application/json")));
try
{
res.Result.EnsureSuccessStatusCode();
var x = res;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
Can you try this code inside of the try block?
if (res.IsCompleted)
{
var result = res.Result;
var response = result.Content.ReadAsStringAsync();
var data = response.Result;
}
The ideal would be to declare this as an async method and use the await operations to get the result as follows.
var res = await client.PostAsync(<url>, <string_content>);
var result = await res.Content.ReadAsStringAsync();

Create a inventory movement journal in Dynamics AX 2012

This problem is driving me nuts... I don't know how to fix it. I'm trying to create an inventory movement journal entry using the ProfitLossJournalService.
The code below runs, but it shows the transaction in the "inventory adjustment" journal. I want it in the inventory movement jounal.
public void UpdateInventoryForConsumableItem(InventoryUpdate update)
{
var svc = new ProfitLossJournalServiceClient();
var cc = new CallContext {Company = "SS"};
var journal = new AxdProfitLossJournal();
var table = new AxdEntity_InventJournalTable
{
InventDimFixedSpecified = false,
InventSiteId = "MC",
InventLocationId = "MAIN WH",
JournalType = AxdEnum_InventJournalType.Movement,
JournalNameId = "InvMovJour",
Description = Constants.InventoryMovementJournalDescription,
NumOfLines = 1,
NumOfLinesSpecified = true,
JournalTypeSpecified = true,
JournalId = "InvMovJour",
JournalIdOrignal = "InvMovJour",
action = AxdEnum_AxdEntityAction.update
};
var inventoryDims = new AxdEntity_InventDim
{
InventLocationId = "MAIN WH",
InventDimId = update.InventoryDimId,
InventColorId = update.Color,
InventSiteId = "MC",
InventSizeId = update.Size,
InventStyleId = update.Style,
action = AxdEnum_AxdEntityAction.create
};
var entry = new AxdEntity_InventJournalTrans
{
InventDimId = update.InventoryDimId,
TransDate = DateTime.Now,
ItemId = update.ItemId,
CostMarkupSpecified = false,
InventRefTypeSpecified = false,
LineNumSpecified = false,
JournalType = AxdEnum_InventJournalType.Movement,
JournalTypeSpecified = true,
Qty = update.Quantity,
QtySpecified = true,
InventDim = new AxdEntity_InventDim[1] {inventoryDims}
};
table.InventJournalTrans = new[] {entry};
journal.InventJournalTable = new[] {table};
try
{
var result = svc.create(cc, journal);
Logger.LogTrace(string.Format("sending InventoryTransferJournal {0}", result.GetValue(0)));
Logger.LogEvent(Logger.SentConsumableInventoryUpdateToDynamics);
}
catch (Exception e)
{
Logger.LogException(e);
throw;
}
}
When you use the ProfitLossJournalService that is essentially what you are creating, an Inventory adjustment.
If you want to create an inventory movement journal, unfortunately there is no standard AIF service that does that. You would need to implement that yourself and expose it to AIF.

Swift link in a Annotation -> Webview

I try to find a way to add a link to a Annotation in Swift MapFramework, this link should forward the user to a WebView, as far i see i can't find any way to add a "touchable" link into a Annotations SubTitle
Here is my Code yet
class CustomPointAnnotation: MKPointAnnotation {
var imageName: String!
}
var info1 = CustomPointAnnotation()
info1.coordinate = CLLocationCoordinate2DMake(42, -84)
info1.title = "Info1"
info1.subtitle = "Subtitle"
info1.imageName = "1.png"
var info2 = CustomPointAnnotation()
info2.coordinate = CLLocationCoordinate2DMake(32, -95)
info2.title = "Info2"
info2.subtitle = "Subtitle"
info2.imageName = "2.png"
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if !(annotation is CustomPointAnnotation) {
return nil
}
let reuseId = "test"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView.canShowCallout = true
}
else {
anView.annotation = annotation
}
//Set annotation-specific properties **AFTER**
//the view is dequeued or created...
let cpa = annotation as CustomPointAnnotation
anView.image = UIImage(named:cpa.imageName)
return anView
}
Is there maybe a way to use the UIGestureRecognizer for this?
I already tried it like
var longpress = UILongPressGestureRecognizer(target: self, action: "newInformation:")
longpress.minimumPressDuration = 2.0
info1.addGestureRecognizer(longpress)
But ending with "ViewController.CustomPointAnnotation does not have a member named addGestureRecognizer"
Here is a working solution
override func viewDidLoad() {
super.viewDidLoad()
//1
var lat1:CLLocationDegrees = 40.748708
var long1:CLLocationDegrees = -73.985643
var latDelta1:CLLocationDegrees = 0.01
var longDelta1:CLLocationDegrees = 0.01
var span1:MKCoordinateSpan = MKCoordinateSpanMake(latDelta1, longDelta1)
var location1:CLLocationCoordinate2D = CLLocationCoordinate2DMake(lat1, long1)
var region1:MKCoordinateRegion = MKCoordinateRegionMake(location1, span1)
Map.setRegion(region1, animated: true)
var info1 = CustomPointAnnotation()
info1.coordinate = location1
info1.title = "Test Title1!"
info1.subtitle = "Subtitle1"
info1.imageName = "1.png"
Map.addAnnotation(info1)
//2
var lat2:CLLocationDegrees = 41.748708
var long2:CLLocationDegrees = -72.985643
var latDelta2:CLLocationDegrees = 0.01
var longDelta2:CLLocationDegrees = 0.01
var span2:MKCoordinateSpan = MKCoordinateSpanMake(latDelta2, longDelta2)
var location2:CLLocationCoordinate2D = CLLocationCoordinate2DMake(lat2, long2)
var region2:MKCoordinateRegion = MKCoordinateRegionMake(location2, span2)
var info2 = CustomPointAnnotation()
info2.coordinate = location2
info2.title = "Test Title2!"
info2.subtitle = "Subtitle2"
info2.imageName = "2.png"
Map.addAnnotation(info2)
}
func mapView(mapView: MKMapView!, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == annotationView.rightCalloutAccessoryView {
println("Disclosure Pressed! \(self.title)")
}
}
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if !(annotation is CustomPointAnnotation) {
return nil
}
let reuseId = "test"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView.canShowCallout = true
anView.rightCalloutAccessoryView = UIButton.buttonWithType(.InfoDark) as UIButton
}
else {
anView.annotation = annotation
}
//Set annotation-specific properties **AFTER**
//the view is dequeued or created...
let cpa = annotation as CustomPointAnnotation
anView.image = UIImage(named:cpa.imageName)
return anView
}

Resources