use of com.google.api.ads.admanager.axis.v202205.Activity in project googleads-java-lib by googleads.
the class GetAllActivities method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
// Get the ActivityService.
ActivityServiceInterface activityService = adManagerServices.get(session, ActivityServiceInterface.class);
// Create a statement to get all activities.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get activities by statement.
ActivityPage page = activityService.getActivitiesByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Activity activity : page.getResults()) {
System.out.printf("%d) Activity with ID %d, name '%s', and type '%s' was found.%n", i++, activity.getId(), activity.getName(), activity.getType());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
use of com.google.api.ads.admanager.axis.v202205.Activity in project olca-modules by GreenDelta.
the class ProcessImport method checkImport.
private void checkImport(DataSet ds) {
if (!valid(ds)) {
log.warn("invalid data set -> not imported");
return;
}
Activity activity = Spold2.getActivity(ds);
try {
String refId = RefId.forProcess(ds);
boolean contains = dao.contains(refId);
if (contains) {
log.info("process '" + activity.id + "' is already in the database");
return;
}
log.info("import process: " + activity.name);
runImport(ds, refId);
} catch (Exception e) {
log.error("Failed to import process", e);
}
}
use of com.google.api.ads.admanager.axis.v202205.Activity in project olca-modules by GreenDelta.
the class ProcessImport method runImport.
private void runImport(DataSet ds, String refId) {
Activity activity = Spold2.getActivity(ds);
Process p = new Process();
// map meta data
p.refId = refId;
p.name = getProcessName(ds);
p.processType = activity.type == 2 ? ProcessType.LCI_RESULT : ProcessType.UNIT_PROCESS;
p.description = Stream.of(RichText.join(activity.generalComment), activity.includedActivitiesStart, activity.includedActivitiesEnd, RichText.join(activity.allocationComment)).filter(Objects::nonNull).collect(Collectors.joining("\n\n"));
// map the process category
Category category = null;
for (Classification clazz : Spold2.getClassifications(ds)) {
category = index.getProcessCategory(clazz.id);
if (category != null)
break;
}
p.category = category;
// tags
if (!activity.tags.isEmpty()) {
var tags = activity.tags.toArray(new String[0]);
p.tags = String.join(",", tags);
}
if (config.withParameters) {
handleParameters(ds, p);
}
// create inputs and outputs
createProductExchanges(ds, p);
createElementaryExchanges(ds, p);
p.exchangeDqSystem = dqSystem;
new DocImportMapper(config.db).map(ds, p);
new ProcessDao(config.db).insert(p);
index.putProcessId(refId, p.id);
flushLinkQueue(p);
}
Aggregations