Search in sources :

Example 16 with Label

use of com.google.api.ads.admanager.axis.v202202.Label in project googleads-java-lib by googleads.

the class DeactivateLabels method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param labelId the ID of the label to deactivate.
 * @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, long labelId) throws RemoteException {
    // Get the LabelService.
    LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
    // Create a statement to select a label.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", labelId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get labels by statement.
        LabelPage page = labelService.getLabelsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Label label : page.getResults()) {
                System.out.printf("%d) Label with ID %d will be deactivated.%n", i++, label.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of labels to be deactivated: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202108.DeactivateLabels action = new com.google.api.ads.admanager.axis.v202108.DeactivateLabels();
        // Perform action.
        UpdateResult result = labelService.performLabelAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of labels deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No labels were deactivated.");
        }
    }
}
Also used : Label(com.google.api.ads.admanager.axis.v202108.Label) LabelPage(com.google.api.ads.admanager.axis.v202108.LabelPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) LabelServiceInterface(com.google.api.ads.admanager.axis.v202108.LabelServiceInterface) UpdateResult(com.google.api.ads.admanager.axis.v202108.UpdateResult)

Example 17 with Label

use of com.google.api.ads.admanager.axis.v202202.Label in project googleads-java-lib by googleads.

the class GetAllLabels 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 LabelService.
    LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
    // Create a statement to select all labels.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get labels by statement.
        LabelPage page = labelService.getLabelsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Label label : page.getResults()) {
                System.out.printf("%d) Label with ID %d and name '%s' was found.%n", i++, label.getId(), label.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : LabelPage(com.google.api.ads.admanager.axis.v202108.LabelPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) LabelServiceInterface(com.google.api.ads.admanager.axis.v202108.LabelServiceInterface) Label(com.google.api.ads.admanager.axis.v202108.Label)

Example 18 with Label

use of com.google.api.ads.admanager.axis.v202202.Label in project googleads-java-lib by googleads.

the class DeactivateCreativeWrappersForLabel method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param labelId the ID of the creative wrapper label to deactivate.
 * @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, long labelId) throws RemoteException {
    // Get the CreativeWrapperService.
    CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
    // Create a statement to select the active creative wrappers for the
    // given label.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE status = :status AND labelId = :labelId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", CreativeWrapperStatus.ACTIVE.toString()).withBindVariableValue("labelId", labelId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get creative wrappers by statement.
        CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CreativeWrapper creativeWrapper : page.getResults()) {
                System.out.printf("%d) Creative wrapper with ID %d applying to label ID" + " %d will be deactivated.%n", i++, creativeWrapper.getId(), creativeWrapper.getLabelId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of creative wrappers to be deactivated: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        DeactivateCreativeWrappers action = new DeactivateCreativeWrappers();
        // Perform action.
        UpdateResult result = creativeWrapperService.performCreativeWrapperAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of creative wrappers deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No creative wrappers were deactivated.");
        }
    }
}
Also used : CreativeWrapper(com.google.api.ads.admanager.axis.v202202.CreativeWrapper) CreativeWrapperPage(com.google.api.ads.admanager.axis.v202202.CreativeWrapperPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) DeactivateCreativeWrappers(com.google.api.ads.admanager.axis.v202202.DeactivateCreativeWrappers) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202202.CreativeWrapperServiceInterface) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Example 19 with Label

use of com.google.api.ads.admanager.axis.v202202.Label in project googleads-java-lib by googleads.

the class GetActiveCreativeWrappers 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 {
    CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
    // Create a statement to select creative wrappers.
    StatementBuilder statementBuilder = new StatementBuilder().where("status = :status").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", CreativeWrapperStatus.ACTIVE.toString());
    // Retrieve a small amount of creative wrappers at a time, paging through
    // until all creative wrappers have been retrieved.
    int totalResultSetSize = 0;
    do {
        CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each creative wrapper.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CreativeWrapper creativeWrapper : page.getResults()) {
                System.out.printf("%d) Creative wrapper with ID %d and label ID %d was found.%n", i++, creativeWrapper.getId(), creativeWrapper.getLabelId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : CreativeWrapper(com.google.api.ads.admanager.axis.v202202.CreativeWrapper) CreativeWrapperPage(com.google.api.ads.admanager.axis.v202202.CreativeWrapperPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202202.CreativeWrapperServiceInterface)

Example 20 with Label

use of com.google.api.ads.admanager.axis.v202202.Label in project jodd by oblac.

the class ProxyAspectData method readAdviceData.

// ---------------------------------------------------------------- read
/**
	 * Parse advice class to gather some advice data. Should be called before any advice use.
	 * Must be called only *once* per advice.
	 */
private void readAdviceData() {
    if (ready) {
        return;
    }
    adviceClassReader.accept(new EmptyClassVisitor() {

        /**
			 * Stores advice reference.
			 */
        @Override
        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
            adviceReference = name;
            super.visit(version, access, name, signature, superName, interfaces);
        }

        /**
			 * Prevents advice to have inner classes.
			 */
        @Override
        public void visitInnerClass(String name, String outerName, String innerName, int access) {
            if (outerName.equals(adviceReference)) {
                throw new ProxettaException("Proxetta doesn't allow inner classes in/for advice: " + advice.getName());
            }
            super.visitInnerClass(name, outerName, innerName, access);
        }

        /**
			 * Clones advices fields to destination.
			 */
        @Override
        public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
            // [A5]
            wd.dest.visitField(access, adviceFieldName(name, aspectIndex), desc, signature, value);
            return super.visitField(access, name, desc, signature, value);
        }

        /**
			 * Copies advices methods to destination.
			 */
        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            if (name.equals(CLINIT)) {
                // [A6]
                if (!desc.equals(DESC_VOID)) {
                    throw new ProxettaException("Invalid static initialization block description for advice: " + advice.getName());
                }
                name = clinitMethodName + methodDivider + aspectIndex;
                access |= AsmUtil.ACC_PRIVATE | AsmUtil.ACC_FINAL;
                wd.addAdviceClinitMethod(name);
                return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {

                    @Override
                    public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
                    }

                    @Override
                    public void visitLineNumber(int line, Label start) {
                    }

                    @Override
                    public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean isInterface) {
                        if (opcode == INVOKESTATIC) {
                            if (owner.equals(adviceReference)) {
                                owner = wd.thisReference;
                                name = adviceMethodName(name, aspectIndex);
                            }
                        }
                        super.visitMethodInsn(opcode, owner, name, desc, isInterface);
                    }

                    @Override
                    public void visitFieldInsn(int opcode, String owner, String name, String desc) {
                        // [F6]
                        if (owner.equals(adviceReference)) {
                            // [F5]
                            owner = wd.thisReference;
                            name = adviceFieldName(name, aspectIndex);
                        }
                        super.visitFieldInsn(opcode, owner, name, desc);
                    }
                };
            } else if (name.equals(INIT)) {
                // [A7]
                if (!desc.equals(DESC_VOID)) {
                    throw new ProxettaException("Advices can have only default constructors. Invalid advice: " + advice.getName());
                }
                name = initMethodName + methodDivider + aspectIndex;
                access = ProxettaAsmUtil.makePrivateFinalAccess(access);
                wd.addAdviceInitMethod(name);
                return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {

                    @Override
                    public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
                    }

                    @Override
                    public void visitLineNumber(int line, Label start) {
                    }

                    // used to detect and to ignore the first super call()
                    int state;

                    @Override
                    public void visitVarInsn(int opcode, int var) {
                        // [F7]
                        if ((state == 0) && (opcode == ALOAD) && (var == 0)) {
                            state++;
                            return;
                        }
                        super.visitVarInsn(opcode, var);
                    }

                    @Override
                    public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean isInterface) {
                        if ((state == 1) && (opcode == INVOKESPECIAL)) {
                            state++;
                            return;
                        }
                        if ((opcode == INVOKEVIRTUAL) || (opcode == INVOKEINTERFACE)) {
                            if (owner.equals(adviceReference)) {
                                owner = wd.thisReference;
                                name = adviceMethodName(name, aspectIndex);
                            }
                        } else if (opcode == INVOKESTATIC) {
                            if (owner.equals(adviceReference)) {
                                owner = wd.thisReference;
                                name = adviceMethodName(name, aspectIndex);
                            }
                        }
                        super.visitMethodInsn(opcode, owner, name, desc, isInterface);
                    }

                    @Override
                    public void visitFieldInsn(int opcode, String owner, String name, String desc) {
                        // [F7]
                        if (owner.equals(adviceReference)) {
                            // [F5]
                            owner = wd.thisReference;
                            name = adviceFieldName(name, aspectIndex);
                        }
                        super.visitFieldInsn(opcode, owner, name, desc);
                    }
                };
            } else // other methods
            if (!name.equals(executeMethodName)) {
                name = adviceMethodName(name, aspectIndex);
                return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {

                    @Override
                    public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
                    }

                    @Override
                    public void visitLineNumber(int line, Label start) {
                    }

                    @Override
                    public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean isInterface) {
                        if ((opcode == INVOKEVIRTUAL) || (opcode == INVOKEINTERFACE)) {
                            if (owner.equals(adviceReference)) {
                                owner = wd.thisReference;
                                name = adviceMethodName(name, aspectIndex);
                            }
                        } else if (opcode == INVOKESTATIC || opcode == INVOKESPECIAL) {
                            if (owner.equals(adviceReference)) {
                                owner = wd.thisReference;
                                name = adviceMethodName(name, aspectIndex);
                            }
                        }
                        super.visitMethodInsn(opcode, owner, name, desc, isInterface);
                    }

                    @Override
                    public void visitFieldInsn(int opcode, String owner, String name, String desc) {
                        // replace field references
                        if (owner.equals(adviceReference)) {
                            owner = wd.thisReference;
                            name = adviceFieldName(name, aspectIndex);
                        }
                        super.visitFieldInsn(opcode, owner, name, desc);
                    }
                };
            }
            //return new MethodAdapter(new EmptyMethodVisitor()) {		// toask may we replace this with the following code?
            return new EmptyMethodVisitor() {

                @Override
                public void visitVarInsn(int opcode, int var) {
                    if (isStoreOpcode(opcode)) {
                        if (var > maxLocalVarOffset) {
                            // find max local var offset
                            maxLocalVarOffset = var;
                        }
                    }
                    super.visitVarInsn(opcode, var);
                }
            };
        //					return super.visitMethod(access, name, desc, signature, exceptions);
        }
    }, 0);
    // increment offset by 2 because var on last index may be a dword value
    maxLocalVarOffset += 2;
    ready = true;
}
Also used : ProxettaException(jodd.proxetta.ProxettaException) Label(jodd.asm5.Label) FieldVisitor(jodd.asm5.FieldVisitor) EmptyClassVisitor(jodd.asm.EmptyClassVisitor) EmptyMethodVisitor(jodd.asm.EmptyMethodVisitor) MethodVisitor(jodd.asm5.MethodVisitor) MethodAdapter(jodd.asm.MethodAdapter) EmptyMethodVisitor(jodd.asm.EmptyMethodVisitor)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)7 Label (org.apache.xbean.asm9.Label)7 Label (com.google.api.ads.admanager.axis.v202108.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202108.LabelServiceInterface)5 Label (com.google.api.ads.admanager.axis.v202111.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202111.LabelServiceInterface)5 Label (com.google.api.ads.admanager.axis.v202202.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202202.LabelServiceInterface)5 MethodVisitor (org.apache.xbean.asm9.MethodVisitor)5 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)4 LabelPage (com.google.api.ads.admanager.axis.v202108.LabelPage)4 LabelPage (com.google.api.ads.admanager.axis.v202111.LabelPage)4 CreativeWrapper (com.google.api.ads.admanager.axis.v202202.CreativeWrapper)4 CreativeWrapperServiceInterface (com.google.api.ads.admanager.axis.v202202.CreativeWrapperServiceInterface)4 LabelPage (com.google.api.ads.admanager.axis.v202202.LabelPage)4 CreativeWrapperPage (com.google.api.ads.admanager.axis.v202202.CreativeWrapperPage)3 Random (java.util.Random)3 net.sf.cglib.asm.$Label (net.sf.cglib.asm.$Label)3 UpdateResult (com.google.api.ads.admanager.axis.v202202.UpdateResult)2