mercredi 5 août 2015

What should pe POJO for given JSON


I am integrating 3rd party REST API.I have written pojo for given json. Form 3rd party I am getting response in form of json as

"custom_fields": {
            "Field_68092": {
                "type": "char", 
                "required": true, 
                "value": "1", 
                "label": "orderId"
            }
        }

I tried with following POJO

public class Field_68092 {
    private String type;
    private String value;
    private String label;
    private boolean required;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public boolean isRequired() {
        return required;
    }

    public void setRequired(boolean required) {
        this.required = required;
    }
}

and custom filed's pojo is

public class Custom_fields {
    private Field_68092 Field_68092;

    public Field_68092 getField_68092() {
        return Field_68092;
    }

    public void setField_68092(Field_68092 field_68092) {
        Field_68092 = field_68092;
    }
}

Field_68092 every time coming null. can some one help me to find ut what is wrong with POJO structure?



via Chebli Mohamed

Dynamically change Logback level for web app running on tomcat


I have a logback.xml in the resources folder of my java web application which is running on Tomcat 7. Is there a way to change the debug level of some class of the application dynamically as the application is running?

The standard thing to do it is a normal java jar running from the CLI is to just edit logback.xml with say vim and after a while the log is updated. Is this possible with tomcat as I tried it and id does not seem to work.

Is there any better way?



via Chebli Mohamed

Maven 4.0.0 Swagger 1.3.12 build fails


I'm trying to get maven to build with swagger. But I get this error:

Failed to execute goal com.github.kongchen:swagger-maven-plugin:2.3.4:generate (default) on project web: Execution default of goal com.github.kongchen:swagger-maven-plugin:2.3.4:generate failed: An API incompatibility was encountered while executing com.github.kongchen:swagger-maven-plugin:2.3.4:generate: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/LockModeType

The pom.xml dependency:

    <dependency>
        <groupId>com.wordnik</groupId>
        <artifactId>swagger-annotations</artifactId>
        <scope>compile</scope>
        <version>1.3.12</version>
        <exclusions>
            <exclusion>
                <groupId>javax.ws.rs</groupId>
                <artifactId>jsr311-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

The pom.xml Plugin:

<plugin>
            <groupId>com.github.kongchen</groupId>
            <artifactId>swagger-maven-plugin</artifactId>
            <version>2.3.4</version>
            <configuration>
                <apiSources>
                    <apiSource>
                        <supportSpringMvc>false</supportSpringMvc>
                        <locations>package.rest</locations>
                        <apiVersion>0.1</apiVersion>
                        <basePath>/api</basePath>
                        <outputTemplate>${basedir}/swaggerTempl/strapdown.html.mustache</outputTemplate>
                        <mustacheFileRoot>${basedir}/swaggerTempl</mustacheFileRoot>
                        <outputPath>${project.build.directory}/swaggerFolder/document.html</outputPath>
                        <swaggerDirectory>${project.build.directory}/swaggerFolder</swaggerDirectory>
                    </apiSource>
                </apiSources>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Can anyone help me? What do I have to change to build it correctly? Do I have to install swagger on my PC? These folders don't exist, do I have to create them or should maven/swagger do it automatically?:

${basedir}/swaggerTempl/strapdown.html.mustache

${basedir}/swaggerTempl



via Chebli Mohamed

ASTRewrite for a QuickFix: How to position the cursor?


I work on a Eclipse Plugin and create a QuickFix using ASTRewrite. Briefly it's constructed in the following way:

public class MyQFXProcessor implements IQuickFixProcessor {
    public IJavaCompletionProposal[] getCorrections(IInvocationContext context,
                                                    IProblemLocation[] locations) {
        AST ast = context.getASTRoot().getAST();
        ASTRewrite rw = ASTRewrite.create(ast);
        ASTNode replacement = astRoot.getAST().newSimpleName("Test");
        rewrite.replace(context.getCoveringNode(), replacement);
        IJavaCompletionProposal p = new ASTRewriteCorrectionProposal("My QFX",
                                                     context.getCompilationUnit(), rw, 10);
        return new IJavaCompletionProposal[]{p};
    }
}

This works fine so far. But what I didn't manage to achieve yet is to set the desired cursor position after the proposal is applied. For example this is how it's solved in JDT for add argument quick fix:

enter image description here

enter image description here

I think there should be an API for doing that, because Eclipse uses this kind of behavior for different use-cases (in auto-completion among others). Does anybody have an idea how to implement that?



via Chebli Mohamed

Inject Spel parameter on annotation parameter (like what is done with @Value on a field)


I'm using this annotation provided by spring-starter-elastic-searchto create a document and I would like to inject the parameter indexname dynamically:

@Entity
@Document(indexName = "myindex")
public class StockQuotation 

In another bean I have successfully done that by using @Valueon a field:

@Value("${elasticsearch.index.name}")
public String indexName;

However, I have tried to inject it in the same way in the annotation and the translation is not done:

@Entity
@Document(indexName = "${elasticsearch.index.name}")
public class StockQuotation

As I get this exception:

Caused by: org.elasticsearch.indices.IndexMissingException: [${elasticsearch.index.name}] missing

What would be the appropriate approach to do this?

Thanks



via Chebli Mohamed

Custom extended Android DatePickerDialog without title


I've an extended DatePickerDialog, but I'm not able to hide the title (on 5.+).

I tried the requestWindowFeature function on some places, but I don't know where the right is.

public MyDatePickerDialog(Context context, OnDateSetListener listener, Reklamation reklamation, int year, int monthOfYear, int dayOfMonth) {
    super(context, listener, year, monthOfYear, dayOfMonth);
    // Check if we're running on Android 5.0 or higher
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Log.d(getClass().getSimpleName(), "noTitle:" + requestWindowFeature(Window.FEATURE_NO_TITLE));
    }
}



via Chebli Mohamed

Spring declaration for interfaces with the same implementation


I have a problem with Spring.

I have two separate interfaces, findUnconditionalDiscountValuesStrategy and findConditionalDiscountValuesStrategy. These interfaces are implemented in the same class MmfgFindPricingWithCurrentPriceFactoryStrategy.

This is declared in the spring configuration file like this:

<alias name="mmfgFindPricingWithCurrentPriceFactoryStrategy" alias="currentFactoryFindPricingStrategy"/>
<bean id="mmfgFindPricingWithCurrentPriceFactoryStrategy" class="com.mmfg.mmfgacceleratorcore.order.strategies.calculation.impl.MmfgFindPricingWithCurrentPriceFactoryStrategy" parent="abstractBusinessService">
    <property name="findPricingWithCurrentPriceFactoryStrategy" ref="original-currentFactoryFindPricingStrategy"/>
    <property name="configurationService" ref="configurationService"/>
    <property name="mmfgSessionService" ref="mmfgSessionService"/>
    <property name="mmfgUtilsDao" ref="mmfgUtilsDao" />
</bean>

Now, I use the two interfaces in a class

private FindUnconditionalDiscountValuesStrategy findUnconditionalDiscountValuesStrategy;
private FindConditionalDiscountValuesStrategy findConditionalDiscountValueStrategy;

with getter and setter (getter protected and setter @Required).

Now I have declared this class in this way in the spring configuration file:

<bean id="mmfgOrderCalculationStrategy" class="com.mmfg.mmfgacceleratorcore.order.strategies.calculation.impl.DefaultMmfgOrderCalculationStrategy">
    <property name="findUnconditionalDiscountValuesStrategy" ref="currentFactoryFindPricingStrategy"/>
    <property name="findConditionalDiscountValuesStrategy" ref="currentFactoryFindPricingStrategy"/>
    <property name="modelService" ref="modelService" />
    <property name="commonI18NService" ref="commonI18NService" />
    <property name="calculationService" ref="calculationService"/>
</bean>

the ref is the same for the two interfaces, because the implementation class is the same.

But at runtime I obtain this error:

org.springframework.beans.factory.BeanInitializationException: Property 'findConditionalDiscountValueStrategy' is required for bean 'mmfgOrderCalculationStrategy'

How I have to declare the ref in the two properties?



via Chebli Mohamed