Prevent load of initial data of the broadleaf heat clinic shop - broadleaf-commerce

How can i prevent the demo site to load the catalog of the heat clinic demo?
all i need is an empty shop with admin roles and permissions, no catalog data, no translations.

This is configured with a property, import.sql.enabled. If you set this to false then no data will be loaded at all.
To include or exclude specific import SQL, we do not have a great way to manage that piece by piece yet. Specifically for admin roles/permissions you would need this import to execute, which would be as easy as moving this #Bean method inside of your own #Configuration classes in your project (like CorePersisteceConfig).

Related

How to mock model objects in SAP Hybris?

while writing integration tests in SAP Hybris, I am getting exceptions which imply that the model objects are not available during the test case.
It seems like normally the ImpEx which run normally during initialization are not running here.It is becoming hectic creating objects using model service.
Is there some other way?What about the custom objects defined by me in the product(like ABCProduct extending Product) and also values for them?Is it possible to mock them as well?What about BaseSite and PriceRow?
There are some things you need to know about the test system.
Tenants
Usually you work with the master tenant. The test system however has its own tenant called junit. A tenant is meant to be kind of like a separate data set for the hybris server running the same code. That way you can run different shops on the same infrastructure but every shop can only access the data that is meant for the tenant. How does it work? Every tenant has a table prefix, only the tenant master has an empty one. So the products table for the master tenant is called "products", but the "products" table for the junit tenant is called "junit_products".
Further reading: https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/8c14e7ae866910148e59ebf4a2685857.html
Initialization
When you use the initialization using ant initialize or the admin console, you usually only initialize the master tenant. When you want to initialize the junit tenant, you need to either change to the junit tenant in the admin console or run ant initialize -Dtenant=junit. However this creates only the most basic data.
More on how to execute initialization in admin console in section "Executing Tests": https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/aae25ecb74ab4bd69cc5270ffd455459.html
Creating test data
There are a few classes you can inherit from, to create an integration test, but only ServicelayerTest provides methods to create sample data. All those methods import impex files located in /hybris/bin/platform/ext/core/resources/servicelayer/test/
createCoreData() Creates languages, currencies, units etc. See: testBasics.csv
createDefaultCatalog() Creates a sample product catalog with an online catalog version and basic sample products. See: testCatalog.csv
createHardwareCatalog() Creates a sample product catalog with staged and online version, products and classifications. See testHwcatalog.csv and testClassification.csv
createDefaultUsers() Creates sample customers with addresses etc. See testUser.csv
Importing custom data
To import data not covered by the ServicelayerTest methods, I recommend one of two approaches.
Using ModelService and other services to create your data. E.g. you can use the OrderService to create sample orders. You can as well create utility classes that provide you with creating sample data. You can wire every service you need by annotating it with the #Resource annotation.
Using impex files to create all data you need. You can split those up into different files that serve different needs (e.g. customers, orders, products...). The method importCsv(String pathToFile, String encoding) in ServicelayerTest provides you the opportunity to import those.

Best Practice Advice - Loopback API

I want to make a webservice and it looks like Loopback is good starting point.
To explain my question, I will describe situation
I have 2 MySQL Tables:
Users
Companies
Every User has it's Company. It's like master User for it's company.
I wish to create Products table for each company next way:
company1_Products,
company2_Products,
company3_Products
Each company have internal Users, like:
company1_Users,
company2_Users,
company3_Users
Internal users are logging in from corresponding subdomain, like
company1.myservice.com
company2.myservice.com
For the API, I want datasource to get Products from the corresponding table. So the question is, how to change datasource dynamically?
And how to handle Users? Storing in one table is not good, because internal company users could be in different companies...
Maybe there's better way to do such models?
Disclaimer: I am co-author and one of current maintainers of LoopBack.
how to change datasource dynamically?
The following StackOverflow answer describes a solution how to attach a single model (e.g. Product) to multiple datasources: https://stackoverflow.com/a/28327323/69868 This solution would work if you were creating one MySQL database per company instead of using company's name as the prefix of Product table name.
To achieve what you described, you can use model subclassing. For each company, define a new company-specific Product model inheriting from the shared Product model and changing the table name.
// common/models/company1-product.json
{
"name": "Company1_Product",
"base": "Product",
"mysql": {
"tableName": "company1_Products"
}
// etc.
}
You can even create these models on the fly using app.registry.createModel() and app.model() APIs, and then run dataSource.autoupdate to create SQL tables for the new model(s).
And how to handle Users? Storing in one table is not good, because internal company users could be in different companies...
I suppose you can use the same approach as you do for Products and as you described in your question.
Maybe there's better way to do such models?
The problem you are facing is calling multi-tenancy. I am afraid we haven't figured out an easy to use solution yet. There are many possible ways how to implement multi-tenancy.
For example, you can create one LoopBack application for each Company (tenant) and then create a top-level LoopBack or Express application to route incoming requests to appropriate tenant-specific LB app instance. See the following repository for a proof-of-concept implementation: https://github.com/strongloop/loopback-multitenant-poc

Fetching Initial Data from CloudKit

Here is a common scenario: app is installed the first time and needs some initial data. You could bundle it in the app and have it load from a plist or something, or a CSV file. Or you could go get it from a remote store.
I want to get it from CloudKit. Yes, I know that CloudKit is not to be treated as a remote database but rather a hub. I am fine with that. Frankly I think this use case is one of the only holes in that strategy.
Imagine I have an object graph I need to get that has one class at the base and then 3 or 4 related classes. I want the new user to install the app and then get the latest version of this class. If I use CloudKit, I have to load each entity with a separate fetch and assemble the whole. It's ugly and not generic. Once I do that, I will go into change tracking mode. Listening for updates and syncing my local copy.
In some ways this is similar to the challenge that you have using Services on Android: suppose I have a service for the weather forecast. When I subscribe to it, I will not get the weather until tomorrow when it creates its next new forecast. To handle the deficiency of this, the Android Services SDK allows me to make 'sticky' services where I can get the last message that service produced upon subscribing.
I am thinking of doing something similar in a generic way: making it possible to hold a snapshot of some object graph, probably in JSON, with a version token, and then for initial loads, just being able to fetch those and turn them into CoreData object graphs locally.
Question is does this strategy make sense or should I hold my nose and write pyramid of doom code with nested queries? (Don't suggest using CoreData syncing as that has been deprecated.)
Your question is a bit old, so you probably already moved on from this, but I figured I'd suggest an option.
You could create a record type called Data in the Public database in your CloudKit container. Within Data, you could have a field named structure that is a String (or a CKAsset if you wanted to attach a JSON file).
Then on every app load, you query the public database and pull down the structure string that has your classes definitions and use it how you like. Since it's in the public database, all your users would have access to it. Good luck!

storing metadata from the spotify api

I want to use the spotify api to create a webapp. Without going into too much detail about the project, I want to clear up whether it would be against the terms and conditions or not.
After reading the terms and conditions, i read this line under things NOT to do: "aggregate Metadata to create data bases, or any other compilations of Metadata".
I don't plan to do any automated requests, for example, hammering the service with different queries to build a database... I'm just wondering whether I can store results from users who have performed searches via my application to the api, so that I can build content from my database on other parts of the application.
Thanks
I'm not a lawyer, so you'll need to have a lawyer confirm this (contracts, including ToS contracts, are important), but the general gist is that if you cache the results of user-generated requests to create features then you're ok. If you start caching stuff not generated by a user, you're in muddy water.
Good:
Other users who searched for "Madonna" in MyAwesomeApp also searched for "Backstreet Boys"!
Bad:
Here's a list of all the blue cover arts on Spotify: [list]
To generate the first example you can cache and work with searches explicitly done by users of your application. The second would require scraping all of the coverart in the service, which isn't allowed.

Orchard CMS Custom Data Importer

I have custom code that reads a bunch of xml documents and creates a custom data import recipe that I upload using the Import/Export module in Orchard. The imported documents are of a content type "Api Documentation" that I created using the Orchard admin UI. Now, I would like to make this recipe file generation code part of a custom Orchard module (if that is the right approach, I am not sure) and let the admin user do the following:
Use a form in the admin Dashboard section to upload the xml documents that need to be run through the recipe file generator
That form submits the recipe file to the Import/Export module, so that it can perform its import process as usual
What would be the best approach to handle this? I am not even sure that creating a custom module is the right approach. If there are other extensibility options that I should take advantage of, that would be great to know.
The IImportExportService interface has a member called Import:
void Import(string recipeText);
Once you've generated your recipe you can call this method and it will execute the recipe and update the shell.
If you are just importing data then if I'm not mistaken you can get away without updating the shell (which you only need to do if features have been enabled or disabled) - in which case you can make a couple of calls to the IRecipeParser and IRecipeManager interfaces instead:
var recipe = _recipeParser.ParseRecipe(recipeText);
_recipeManager.Execute(recipe);
I've written something similar which does some importing/exporting so you can move pieces of content between sites; it also does some encryption so the details are hidden from prying eyes. A great place to start if is to read the source for the ImportExportService as it isn't all that complicated.

Resources