// ============================================================================
//
// Copyright (C) 2006-2015 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.components.salesforce.tsalesforcegetservertimestamp;

import java.util.Collections;
import java.util.Set;

import org.apache.avro.LogicalTypes;
import org.apache.avro.Schema;
import org.apache.avro.SchemaBuilder;
import org.talend.components.api.component.Connector;
import org.talend.components.api.component.PropertyPathConnector;
import org.talend.components.common.FixedConnectorsComponentProperties;
import org.talend.components.common.SchemaProperties;
import org.talend.components.salesforce.SalesforceConnectionProperties;
import org.talend.components.salesforce.SalesforceProvideConnectionProperties;
import org.talend.daikon.avro.SchemaConstants;
import org.talend.daikon.properties.presentation.Form;

public class TSalesforceGetServerTimestampProperties extends FixedConnectorsComponentProperties
        implements SalesforceProvideConnectionProperties {

    //
    // Collections
    //
    public SalesforceConnectionProperties connection = new SalesforceConnectionProperties("connection");

    // Just holds the server timestamp
    public SchemaProperties schema = new SchemaProperties("schema");

    public TSalesforceGetServerTimestampProperties(String name) {
        super(name);
    }

    @Override
    public void setupProperties() {
        super.setupProperties();
        Schema date = LogicalTypes.timestampMillis().addToSchema(Schema.create(Schema.Type.LONG));
        date.addProp(SchemaConstants.TALEND_COLUMN_PATTERN, "yyyy-MM-dd'T'HH:mm:ss'.000Z'");
        Schema s = SchemaBuilder.record("Root").fields().name("ServerTimeStamp").type(date).noDefault().endRecord();
        schema.schema.setValue(s);
    }

    @Override
    public void setupLayout() {
        super.setupLayout();
        Form mainForm = new Form(this, Form.MAIN);
        mainForm.addRow(connection.getForm(Form.REFERENCE));
        mainForm.addRow(schema.getForm(Form.REFERENCE));

        Form advancedForm = new Form(this, Form.ADVANCED);
        advancedForm.addRow(connection.getForm(Form.ADVANCED));
    }

    @Override
    public void refreshLayout(Form form) {
        super.refreshLayout(form);
        if (form.getName().equals(Form.ADVANCED)) {
            form.getChildForm(connection.getName()).getWidget(connection.bulkConnection.getName()).setVisible(false);
            form.getChildForm(connection.getName()).getWidget(connection.httpTraceMessage.getName()).setVisible(false);
        }
    }

    @Override
    public SalesforceConnectionProperties getConnectionProperties() {
        return connection;
    }

    @Override
    protected Set<PropertyPathConnector> getAllSchemaPropertiesConnectors(boolean isOutputConnection) {
        if (isOutputConnection) {
            return Collections.singleton(new PropertyPathConnector(Connector.MAIN_NAME, "schema"));
        } else {
            return Collections.EMPTY_SET;
        }
    }

}

@@ -1221,36 +1221,139 @@
 kon.
-properties.presentation.Form
+avro.util.AvroTypes;%0Aimport org.talend.daikon.properties.presentation.Form;%0Aimport org.talend.daikon.talend6.Talend6SchemaConstants
 ;%0A%0Ap
@@ -1951,109 +1951,294 @@
 ema 
-date = LogicalTypes.timestampMillis().addToSchema(Schema.create(Schema.Type.LONG));%0A        date.addP
+s = SchemaBuilder.record(%22Main%22)%0A                .prop(Talend6SchemaConstants.TALEND6_IS_READ_ONLY, %22true%22)//$NON-NLS-1$%0A                .fields().name(%22ServerTimeStamp%22)%0A                .prop(Talend6SchemaConstants.TALEND6_COLUMN_TALEND_TYPE, %22id_Date%22)//$NON-NLS-1$%0A                .p
 rop(
@@ -2307,17 +2307,16 @@
 .000Z'%22)
-;
 %0A       
@@ -2320,90 +2320,126 @@
     
-Schema s = SchemaBuilder.record(%22Root%22).fields().name(%22ServerTimeStamp%22).type(
+        .prop(Talend6SchemaConstants.TALEND6_COLUMN_LENGTH, %2220%22)//$NON-NLS-1$%0A                .type(AvroTypes._
 date
+()
 ).no

Fix default schema of tSalesforceGetServerTimestamp https://jira.talendforge.org/browse/TUP-4485