How do I restrict insert in Hybris? - sap-commerce-cloud

Like I know, I can use SearchRestrictions to restrict get operations. But what about insert_update? For instance, I want to remove an opportunity to insert Products with CHECK approvalStatus.

Search restrictions don't work like that. They restrict queries that are made against the database. How? The condition you add to a search restriction is added to the where clause of the select statement of the query. An INSERT query does not have a where clause. At least not those, that are generated when using impex.
Also impex is not the right tool for your purpose. Impex should only be used to import flawless data. It is just a simpler way of inserting data into a database, just like an insert statement in sql. You don't want data in an impex file that needs further checks.
Just filter those lines, that have undesired values. Then you can import the rest.

Related

how do i correctly set up a parameterized information link in spotfire?

Also posted on super users:
I'm a spotfire novice trying to create a parameterized info link. Ultimate goal is to create a default template that may be customized to return specific rows in a very large table. I've not been able to cobble together enough information from online searches to get me from point A to Z.
Spotfire version is 7.11 on an Oracle 11.2 SE DB.
Currently I've got a date/time prompt in the info link that will be global to all users. What I need is to be able to further filter to 1 of 2 columns (one is real, the other a string) in order to minimize loading times. There are 17 other on-demand tables that are related to the main one. Limiting the initial query will greatly speed up performance.
In information designer for the information link, if I edit the SQL in the WHERE and explicitly define the value or string for the column, I get the rows I want. When I try to define it using an input parameter (?ParamName), I either get nothing when I reload or get asked to input a parameter "for testing".
Q1: In the document properties for the analysis, I've been adding in properties that I assume is supposed to get picked up by the query.
- What part do scripts play in passing this variable to the SQL?
- Do I just need to define a value for a property name or include a IronPython script? - If script is required, can I just define the parameter to pass?
Q2: In the info link SQL, what is the correct syntax for defining the parameter variable depending on the type (real v string)? If I use a string, I need to include LIKE in order to pick up the desired rows. If I use a real, is it possible to define it as a list of values?
Thanks in advance.
Though not exactly clear from your description, I think you should be able to accomplish your goals using the "Load on demand" dialog that is accessed either when you add your data table to your analysis, or subsequently using the Data Table Properties>Type of Data>Settings dialog.
Spotfire uses this dialog to dynamically modify your SQL. Thus, you do not need to explicitly include the LIKE statement in your SQL. Spotfire will add it in based on what you define in the On-Demand settings. For example, you could have an Input Field where you type a constraint that will be stored as a Document Property and then refer to that Document Property in your On-Demand settings to control the table loading.

Is it possible to save on database without a PXGraph or a Screen?

The entry for that screen is not needed. All the records are automatically generated. or probably by using DAC only.
The Graph/DAC logic is preferred as you get all of the framework freebies such as field defaulting and calculated formula fields.
You can however get around this using PXDatabase.Insert or PXDatabase.Update PXDatabase.Delete
I use these for upgrade processes or bulk delete of processing records. These calls do not require a graph to execute but ignore all DAC attributes which may or may not default values, calculate values, etc.
If you search on PXDatabase in the Acumatica code browser you can find examples. Here is one from EmployeeMaint.Location_RowPersisted:
PXDatabase.Update<Location>(
new PXDataFieldAssign("VAPAccountLocationID", _KeyToAbort),
new PXDataFieldRestrict("LocationID", _KeyToAbort),
PXDataFieldRestrict.OperationSwitchAllowed);
PXDataFieldAssign is setting column values.
PXDataFieldRestrict is your where condition.
It is best to find multiple examples of PXDatabase in Acumatica and confirm your query results using a tool such as SQL profiler to make sure its executing the correct statement you intend to run.
You can't use DAC without Graph. All BQL queries require PXGraph instance. The only way to save data without using BQL is using ODBC or any other ORM to connect strictly to database and do your changes. But it is not recommended way as in case of doing it in that way you will ignore all the Business Logic.

Is it possible to remove records from an itemtype using Flexible search service?

Is it possible to remove records from an itemtype using Flexible search service? As far as i know, Flexible search is only used for SELECT Operations.
Please suggest ways to remove records from an itemtype using a cron job? Thanks, Appreciate a lot.
Flexible search queries are not made to manipulate data (source), if you want to delete data you could :
Use the Model Service
Run an impex file with the remove header (source)
You can simply use sql query as well to remove the data.
Go to HAC -> Console -> Flexible Search
Switch the tab to SQL Query
Execute SQL delete query (DELETE FROM table_name)
Make sure you run query in commit mode otherwise Hybris will rollback the changes.
You can create a Groovy script to delete all the records in a table using the modelService as mentioned aboved.
Other option if you want to delete massively records from a table is to run an impex with the batchmode setted to true. ej:
REMOVE StockLevel[batchmode=true];itemtype(code)[unique = true]
;StockLevel
Where the itemtype is the parameter that will be use to delete the table, you can change that parameter for the one that fills your needs of course.

How to make filters in queries optional

How to make a query filter bound to a request parameter inactive if the parameter is not present?
For example: I have a query MyQuery that can be accessed through the projection MyProjection. I add a filter to that query where I say that MyDate field should be equal to {Request.QueryString:MyDate}. I want URLs like ~/MyProjection?MyDate=2016-03-08 to filter content items by the given value, but the url ~/MyProjection to just not filter by that field. But this is not what happens: a condition gets added to the query anyway and it's of the form '[minimum DateTime value] < MyDate < [maximum DateTime value]'. This is not good because it will filter out fields with NULL values. If I try to do the same with a numeric field, it's even worse because it throws exceptions when the parameter is not present.
I know I can create a new query and projection to get different options, but that seems like an overkill - also, what if I wanted to create an advanced search form, it would have to target a single projection.
Is there an "official" way to do this? Or a workaround? Or is this simply not supported in Orchard?
I'm not aware of a way to do this out of the box. However, you could pretty easily create your own filter with the behavior you want by implementing IFilterProvider.
Take a look at the Orchard.Projections module. That's where you'll find many of the default query filters (including the date field filter you referenced). Your's will likely be even simpler if you only need to handle a specific case.
For a very simple example, checkout the Orchard.Tags module (look in the projections folder). The contents of this folder will give you pretty much all the boilerplate you'll need to get started creating your own. Just plug in your own logic.

Dynamically updating the jdbc:inbound-channel-adapter query statement

We are using a jdbc:inbound-channel-adapter with a poller to select from a table. The requirement is to select rows with a timestamp within a specific range. That range must be updated each time the database is polled (so rows are not read twice). Originally I envisioned having a separate table to store a datetime, and use the adapter's update attribute to update this table. This value would then have been used in the SELECT statement defined in the query attribute, as part of the WHERE clause against the main table.
We have now been told that while we will have read access to the main table, we will not be given permission to add anything to the existing schema, or have write permissions. This rules out using a separate table in which to continually update the timestamp used by the main SQL query.
The option of defining in the query attribute some SpEL which would return a dynamically generated SELECT statement will also not work. This is because the SpEL will only be evaluated once when Spring loads.
Is there another way to dynamically update the SQL in the query attribute?
Otherwise, what is the correct strategy for this use case, where the SQL which is used by the adapter must change each time the database is polled?
Thanks
You can add a parameter source to the adapter and use queries like:
"SELECT * from FOO where KEY=:key"
See attribute select-sql-parameter-source.
You can write your own parameter source, but also see ExpressionEvaluatingSqlParameterSourceFactory.

Resources