Example usage for org.joda.time DateTime now

List of usage examples for org.joda.time DateTime now

Introduction

In this page you can find the example usage for org.joda.time DateTime now.

Prototype

public static DateTime now() 

Source Link

Document

Obtains a DateTime set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:com.atlassian.jira.ComponentManager.java

private void initComponentContainer(boolean useEagerInitialization, String name) {
    if (container != null) {
        throw new IllegalStateException("Component container is already initialized");
    }// w ww . j a  v  a 2s .  c o  m

    container = new WrappedComponentContainer(new ComponentContainer(useEagerInitialization));
    container.getPicoContainer().setName(name + "_" + DateTime.now().toString());
}

From source file:com.auditbucket.engine.service.MediationFacade.java

License:Open Source License

public Integer createHeaders(final Company company, final Fortress fortress,
        final List<MetaInputBean> inputBeans) throws DatagioException {
    fortress.setCompany(company);//from  w  ww .jav  a2s  .  c o  m
    Long id = DateTime.now().getMillis();
    StopWatch watch = new StopWatch();
    watch.start();
    logger.info("Starting Batch [{}] - size [{}]", id, inputBeans.size());
    boolean newMode = true;
    if (newMode) {

        // Tune to balance against concurrency and batch transaction insert efficiency.
        List<List<MetaInputBean>> splitList = Lists.partition(inputBeans, 20);

        for (List<MetaInputBean> metaInputBeans : splitList) {

            class DLCommand implements Command {
                Iterable<MetaInputBean> headers = null;

                DLCommand(List<MetaInputBean> processList) {
                    this.headers = new CopyOnWriteArrayList<>(processList);
                }

                @Override
                public Command execute() throws DatagioException {
                    //fortressService.registerFortress(company, new FortressInputBean(headers.iterator().next().getFortress()), true);
                    Iterable<TrackResultBean> resultBeans = trackService.createHeaders(headers, company,
                            fortress);
                    processLogs(company, resultBeans);
                    return this;
                }
            }
            DeadlockRetry.execute(new DLCommand(metaInputBeans), "creating headers", 20);
        }

    } else {
        logger.info("Processing in slow Transaction mode");
        for (MetaInputBean inputBean : inputBeans) {
            createHeader(company, fortress, inputBean);
        }
    }
    watch.stop();
    logger.info("Completed Batch [{}] - secs= {}, RPS={}", id, f.format(watch.getTotalTimeSeconds()),
            f.format(inputBeans.size() / watch.getTotalTimeSeconds()));
    return inputBeans.size();
}

From source file:com.autodesk.client.auth.OAuth2ThreeLegged.java

License:Apache License

/**
 * Get the access token for a 3-legged flow
 * @return/*from   ww  w  . j av a 2  s . com*/
 */
public ThreeLeggedCredentials getAccessToken(String code) throws Exception {

    if (flow == OAuthFlow.accessCode) {

        Map<String, String> formParams = new HashMap<>();
        formParams.put("client_id", this.clientId);
        formParams.put("client_secret", this.clientSecret);
        formParams.put("code", code);
        formParams.put("grant_type", "authorization_code");
        formParams.put("redirect_uri", this.redirectUri);

        Map<String, String> headers = new HashMap<>();
        headers.put("content-type", "application/x-www-form-urlencoded");

        ThreeLeggedCredentials response = null;
        try {
            String responseBody = post(this.tokenUrl, formParams, headers);

            JSONObject jsonObject = null;

            // get the access token from json
            try {
                jsonObject = (JSONObject) new JSONParser().parse(responseBody);

                String access_token = (String) jsonObject.get("access_token");
                String refresh_token = (String) jsonObject.get("refresh_token");
                //calculate "expires at"
                long expires_in = (long) jsonObject.get("expires_in");
                DateTime later = DateTime.now().plusSeconds((int) expires_in * 1000);
                Long expiresAt = later.toDate().getTime();

                response = new ThreeLeggedCredentials(access_token, expiresAt, refresh_token);

            } catch (ParseException e) {
                throw new RuntimeException("Unable to parse json " + responseBody);
            }

        } catch (IOException e) {
            System.err.println("Exception when trying to get access token");
            e.printStackTrace();
        }
        return response;
    } else {
        throw new Exception("getAuthToken requires accessCode flow type");
    }
}

From source file:com.autodesk.client.auth.OAuth2ThreeLegged.java

License:Apache License

/**
 * Refresh the access token for a 3-legged flow
 * @return//from   w  w w  .  j  a  va 2 s  .  c  o  m
 */
public ThreeLeggedCredentials refreshAccessToken(String refreshToken) {

    Map<String, String> formParams = new HashMap<>();
    formParams.put("client_id", this.clientId);
    formParams.put("client_secret", this.clientSecret);
    formParams.put("grant_type", "refresh_token");
    formParams.put("refresh_token", refreshToken);

    Map<String, String> headers = new HashMap<>();
    headers.put("content-type", "application/x-www-form-urlencoded");

    ThreeLeggedCredentials response = null;
    try {
        String responseBody = post(this.refreshTokenUrl, formParams, headers);

        JSONObject jsonObject = null;

        // get the access token from json
        try {
            jsonObject = (JSONObject) new JSONParser().parse(responseBody);

            String access_token = (String) jsonObject.get("access_token");
            String refresh_token = (String) jsonObject.get("refresh_token");
            //calculate "expires at"
            long expires_in = (long) jsonObject.get("expires_in");
            DateTime later = DateTime.now().plusSeconds((int) expires_in * 1000);
            Long expiresAt = later.toDate().getTime();

            response = new ThreeLeggedCredentials(access_token, expiresAt, refresh_token);

        } catch (ParseException e) {
            throw new RuntimeException("Unable to parse json " + responseBody);
        }

    } catch (IOException e) {
        System.err.println("Exception when trying to refresh token");
        e.printStackTrace();
    } catch (ApiException e) {
        System.err.println("Exception when trying to refresh token");
        e.printStackTrace();
    }
    return response;
}

From source file:com.autodesk.client.auth.OAuth2TwoLegged.java

License:Apache License

/**
 * Get the access token in a 2-legged flow
 * @return//from   w ww.j a v a2s  .c  o  m
 */
public Credentials authenticate() throws Exception {

    if (flow == OAuthFlow.application) {

        final String url = this.tokenUrl;

        Map<String, String> body = new HashMap<>();
        body.put("grant_type", "client_credentials");
        body.put("client_id", this.clientId);
        body.put("client_secret", this.clientSecret);

        String scopeStr = getScopes();
        if (!scopeStr.isEmpty()) {
            body.put("scope", scopeStr);
        }

        Credentials response = null;
        try {
            String bodyResponse = post(url, body, new HashMap<String, String>());
            JSONObject jsonObject = null;

            // get the access token from json
            try {
                jsonObject = (JSONObject) new JSONParser().parse(bodyResponse);

                String access_token = (String) jsonObject.get("access_token");
                //calculate "expires at"
                long expires_in = (long) jsonObject.get("expires_in");
                DateTime later = DateTime.now().plusSeconds((int) expires_in * 1000);
                Long expiresAt = later.toDate().getTime();

                this.credentials = new Credentials(access_token, expiresAt);
                response = new Credentials(access_token, expiresAt);

            } catch (ParseException e) {
                throw new RuntimeException("Unable to parse json " + body);
            }
        } catch (IOException e) {
            System.err.println("Exception when trying to get access token");
            e.printStackTrace();
        }
        return response;
    } else {
        throw new Exception("getAccessToken requires application flow type");
    }
}

From source file:com.avid.central.obsplugin.datamodel.ExportStoryData.java

public ExportStoryData(ExportConfiguration config) {
    this.id = null;
    this.date = DateTime.now();
    this.mdsMode = false;
    this.rundownAsXml = null;
    this.response = new InewsResponse();

    oncValidateFields = config.onc_verify_fields;
    oncCheckGraphics = config.onc_check_graphics;
    oncRetainFormatting = config.onc_include_tags;
    mdsValidateFields = config.mds_verify_fields;
    mdsCheckGraphics = config.mds_check_graphics;
    mdsRetainFormatting = config.mds_include_tags;

}

From source file:com.avid.central.obsplugin.inewslibrary.ExportStories.java

public ExportStoryData ProcessRundown(List<Story> stories, ExportConfiguration config) {
    ExportStoryData exportData = new ExportStoryData(config);

    // create a new OBS_Export
    ExportRundown _export = new ExportRundown();

    // Represents the starting time of an item, can be calculated from previous item start time or set explicitly by the user
    int currentStartTime = 0;

    // Flags the fact that the previous Story parsed was a break with a defined time
    boolean lastStoryWasBreak = false;

    // Flags the fact that we have now validated the header
    boolean headerValid = false;

    // identifiers used in exporting cue sheets
    String CueSheetLocation = "<p family=\"0\" font=\"\" pitch=\"0\">" + config.cuesheet_id + "</p>";
    String BodyStart = "<body";
    String BodyEnd = "</body>";

    // do everything inside a try {} block
    // if we encounter any of the conditions listed above which preclude exporting the rundown
    // then we throw an exception which includes the reason why
    try {//from   ww w.  j av a  2 s.  c  o m
        // go through stories and decide what to do with each
        for (Story story : stories) {
            List<mos> vizGrapics = new ArrayList<mos>();

            // is this a break story?
            if (story.Story.getHead().getMeta().isBreak()) {
                // yes it is
                // need to get the content of the info Field
                String info = GetFieldStringValue(story.Story.getFields().getStringOrBooleanOrDate(),
                        config.info_field);
                if (null == info) {
                    RaiseError(String.format("field \"%s\" was not found", config.info_field));
                }

                String subject = GetFieldStringValue(story.Story.getFields().getStringOrBooleanOrDate(),
                        config.subject_field);
                if (null == subject) {
                    RaiseError(String.format("field \"%s\" was not found", config.subject_field));
                }

                // is it one of our "special" fields
                if (info.equalsIgnoreCase(config.obs_channel_id)) {
                    if (subject.length() == 0) {
                        // the channelID is missing so abort the export
                        RaiseError(String.format("the rundown %s was not found", config.obs_channel_id));
                    }

                    // this is the Story that contains the channel ID
                    _export.Rundown.ChannelID = subject;

                    // determine the mode, first test for MDS
                    if (subject.toUpperCase().startsWith(config.mds_prefix.toUpperCase())) {
                        exportData.setMdsMode(true);
                    } else if (!subject.toUpperCase().startsWith(config.onc_prefix.toUpperCase())
                            && config.onc_prefix.length() > 0) {
                        RaiseError(String.format("the %s was not identified as an ONC or MDS rundown",
                                config.obs_channel_id));
                    }

                } else if (info.equalsIgnoreCase(config.title_id)) {
                    if (subject.length() == 0 && exportData.getValidateFields()) {
                        // the rundown name is missing so abort the export
                        RaiseError(String.format("the rundown %s was not found", config.title_id));
                    }

                    // this is the Story that contains the rundown name
                    _export.Rundown.Title = subject;
                } else if (info.equalsIgnoreCase(config.day_id)) {
                    // this is the Story that contains the rundown day
                    if (subject.length() > 0) {
                        _export.Rundown.Day = subject;
                    }

                } else if (info.equalsIgnoreCase(config.date_id)) {
                    // this is the Story that contains the rundown date
                    if (subject.length() > 0) {
                        _export.Rundown.Date = subject;
                    }
                }

                String startTime = GetFieldStringValue(story.Story.getFields().getStringOrBooleanOrDate(),
                        config.start_time_field);
                if (null == startTime && exportData.getValidateFields()) {
                    RaiseError(String.format("field \"%s\" was not found", config.start_time_field));
                }

                // check for start and end time data
                if (subject.equalsIgnoreCase(config.start_id) && startTime.length() > 0) {
                    if (startTime.charAt(0) == '@') {
                        // we have an absolute start time
                        currentStartTime = Integer.parseInt(startTime.substring(1));
                        _export.Rundown.RundownStartTime = currentStartTime;
                    } else {
                        // start time is relative to start of show
                        currentStartTime = Integer.parseInt(startTime.substring(1))
                                + _export.Rundown.RundownStartTime;
                        _export.Rundown.RundownStartTime = currentStartTime;
                    }
                } else if (subject.equalsIgnoreCase(config.end_id) && startTime.length() > 0) {
                    if (startTime.charAt(0) == '@') {
                        // we have an absolute end time
                        _export.Rundown.RundownEndTime = Integer.parseInt(startTime.substring(1));
                    } else {
                        // start time is relative to start of show
                        _export.Rundown.RundownEndTime = Integer.parseInt(startTime.substring(1))
                                + _export.Rundown.RundownStartTime;
                    }

                    lastStoryWasBreak = true;
                }
            } else {
                if (!story.Story.getHead().getMeta().isFloat()) {
                    // this is not a floated Story so we must have passed the "header"
                    // if we haven't validated the "header" at this point then now is the time to do so!
                    if (!headerValid) {
                        if (-1 == _export.Rundown.RundownStartTime && exportData.getValidateFields()) {
                            // the start time has not been set so abort the export
                            RaiseError("the rundown start time is missing");
                        }

                        headerValid = true;
                    }

                    // every time we encounter a non-break, non-floated Story reset the rundown end time to unspecified
                    // it should get set to the correct value by the final break Story
                    _export.Rundown.RundownEndTime = -1;

                    // get the subject
                    String subject = GetFieldStringValue(story.Story.getFields().getStringOrBooleanOrDate(),
                            config.subject_field);
                    if (null == subject) {
                        RaiseError(String.format("field \"%s\" was not found", config.subject_field));
                    }

                    if (subject.length() == 0 && exportData.getValidateFields()) {
                        RaiseError("at least one story is missing its Subject details");
                    }

                    // check for an update and retrieve modification time
                    String updatedTimestamp = null;
                    int update = GetFieldIntegerValue(story.Story.getFields().getStringOrBooleanOrDate(),
                            config.update_field);
                    DateTime modificationTime = GetFieldDateValue(
                            story.Story.getFields().getStringOrBooleanOrDate(), config.modified_field);
                    if (null != modificationTime) {
                        DateTimeFormatter fmt = ISODateTimeFormat.dateHourMinuteSecond();
                        updatedTimestamp = modificationTime.toString(fmt);
                    }

                    // get the start time
                    String startTime = GetFieldStringValue(story.Story.getFields().getStringOrBooleanOrDate(),
                            config.start_time_field);

                    // do we have start time data?
                    if (startTime != null && !startTime.isEmpty()) {
                        // update the running start time
                        if (startTime.charAt(0) == '@') {
                            // we have an absolute start time
                            currentStartTime = Integer.parseInt(startTime.substring(1));
                        } else {
                            // start time is relative to start of show
                            currentStartTime = Integer.parseInt(startTime.substring(1))
                                    + _export.Rundown.RundownStartTime;
                        }
                    } else {
                        // no start time specified so we need to get it from the previous item
                        // if there are not yet any stories in the list then just use the start time we are carrying forward
                        if (_export.Stories.size() > 0 && !lastStoryWasBreak) {
                            // there is at least one Story
                            currentStartTime += _export.Stories.get(_export.Stories.size() - 1).StoryDuration;
                        }
                    }

                    // get the VideoID
                    String videoID = GetFieldStringValue(story.Story.getFields().getStringOrBooleanOrDate(),
                            config.video_id_field);
                    if (exportData.getMdsMode()) {
                        if (null == videoID) {
                            RaiseError(String.format("field \"%s\" was not found", config.video_id_field));
                        }
                        if (videoID.length() == 0 && exportData.getValidateFields()) {
                            RaiseError("at least one story is missing its VideoID details");
                        }
                    } else if (null == videoID || videoID.isEmpty()) {
                        videoID = "";
                    }

                    // get the Type
                    String type = GetFieldStringValue(story.Story.getFields().getStringOrBooleanOrDate(),
                            config.type_field);
                    if (exportData.getMdsMode()) {
                        if (null == type) {
                            RaiseError(String.format("field \"%s\" was not found", config.type_field));
                        }
                        if (type.length() == 0 && exportData.getValidateFields()) {
                            RaiseError("at least one story is missing its type details");
                        }
                    }

                    // get the Upmix
                    String upMix = GetFieldStringValue(story.Story.getFields().getStringOrBooleanOrDate(),
                            config.upmix_field);
                    if (exportData.getMdsMode()) {
                        if (null == upMix) {
                            RaiseError(String.format("field \"%s\" was not found", config.upmix_field));
                        }
                        if (upMix.length() == 0 && exportData.getValidateFields()) {
                            RaiseError("at least one story is missing its upmix details");
                        }
                    }

                    // get the Music
                    String music = GetFieldStringValue(story.Story.getFields().getStringOrBooleanOrDate(),
                            config.music_field);
                    if (exportData.getMdsMode()) {
                        if (null == music || music.length() == 0) {
                            exportData.getResponse()
                                    .setMessage("At least one story is missing its music element");
                        }
                    }

                    if (!exportData.getMdsMode() && exportData.getValidateFields()) {
                        // get the Endorsement details
                        String endorseBy = GetFieldStringValue(
                                story.Story.getFields().getStringOrBooleanOrDate(), config.endorse_field);
                        if (null == endorseBy) {
                            RaiseError(String.format("field \"%s\" was not found", config.endorse_field));
                        }
                        if (endorseBy.length() == 0) {
                            exportData.getResponse().setMessage("At least one story has not been approved");
                            //                                RaiseError("at least one story has not been approved");
                        }

                        // get the Export Approval flags
                        int approved = GetFieldIntegerValue(story.Story.getFields().getStringOrBooleanOrDate(),
                                config.export_field);
                        if (approved == 0) {
                            RaiseError("at least one story is not ready for export");
                        }
                    }

                    // get VIZ production cue
                    // are there any anchored elements?
                    if (exportData.getCheckGrahics()) {
                        if (null != story.Story.getAeset() && story.Story.getAeset().getAe().size() > 0) {
                            // is there one for VIZ?
                            for (Ae ae : story.Story.getAeset().getAe()) {

                                for (Object ap : ae.getMcOrAp()) {
                                    if (ap.getClass() != Nsml.Aeset.Ae.Mc.class) {
                                        continue;
                                    }

                                    Nsml.Aeset.Ae.Mc mc = (Nsml.Aeset.Ae.Mc) ap;
                                    for (Object content : mc.getAp()) {
                                        if (content.getClass() != ApContent.class) {
                                            continue;
                                        }

                                        ApContent apContent = (ApContent) content;
                                        for (Object data : apContent.getContent()) {
                                            if (data.getClass() == String.class) {
                                                String graphic = (String) data;
                                                if (!graphic.contains(config.viz_id)) {
                                                    continue;
                                                }

                                                for (AttachmentType at : story.Story.getAesetAtts()
                                                        .getAttachment()) {
                                                    if (mc.getIdref().equals(at.getId())) {
                                                        // found it!
                                                        String graphicData = at.getValue();
                                                        if (graphicData != null) {
                                                            try {
                                                                AttachmentContent ac = AttachmentContent
                                                                        .Parse(graphicData);
                                                                if (ac != null) {
                                                                    vizGrapics.add(ac.mos);
                                                                }
                                                            } catch (Exception ex) {
                                                            }

                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (0 == vizGrapics.size()) {
                            exportData.getResponse()
                                    .setMessage("At least one story is missing its graphic element");
                        }
                    }

                    // Story looks OK so add it to the export
                    OBSStory obsStory = new OBSStory();

                    obsStory.Subject = subject;
                    obsStory.Type = type;
                    obsStory.StoryStartTime = currentStartTime;
                    obsStory.StoryDuration = GetFieldIntegerValue(
                            story.Story.getFields().getStringOrBooleanOrDate(), config.duration_field);
                    obsStory.VideoID = videoID;

                    if (exportData.getMdsMode()) {
                        obsStory.Upmix = upMix.equals("1") || upMix.equals("true");
                        obsStory.Music = music;
                        obsStory.Graphics = vizGrapics;
                    } else {
                        if (null != updatedTimestamp) {
                            obsStory.Modified = updatedTimestamp;
                            obsStory.Update = update == 1;
                        }
                    }

                    // the story body as NSML
                    String formattedBody;

                    // unformatted version of the story body
                    String unformattedBody;

                    // the contents of the script info tag
                    String scriptInfo = null;

                    // the contents of the cue sheet tag
                    String cueSheet = null;

                    int cueSheetLocation = -1;

                    // get the story body free of all formatting
                    unformattedBody = GetStoryBody(story.Story);

                    // look for escape characters in the value and encode them
                    unformattedBody = unformattedBody.replace("&", "&amp;");
                    unformattedBody = unformattedBody.replace("\"", "&quot;");
                    unformattedBody = unformattedBody.replace("<", "&lt;");
                    unformattedBody = unformattedBody.replace(">", "&gt;");
                    unformattedBody = unformattedBody.replace("'", "&apos;");

                    // now look for a cue sheet
                    cueSheetLocation = unformattedBody.indexOf(config.cuesheet_id);

                    if (cueSheetLocation >= 0) {
                        // there is a cue sheet so extract it from the unformatted body if MDS mode
                        if (exportData.getMdsMode() && unformattedBody
                                .length() > (cueSheetLocation + config.cuesheet_id.length())) {
                            cueSheet = unformattedBody
                                    .substring(cueSheetLocation + config.cuesheet_id.length());
                        }

                        // crop the cue sheet from the unformatted body
                        unformattedBody = unformattedBody.substring(0, cueSheetLocation);
                    }

                    // we now have the unformatted body free of cue sheet data together with the cue sheet if it exists

                    // are we exporting the story in its formatted version?
                    if (exportData.getRetainFormatting()) {
                        formattedBody = "";

                        // get the formatted story body
                        // first get offsets to body tags
                        int storyStart = story.StoryAsNSML.indexOf(BodyStart);
                        int storyEnd = story.StoryAsNSML.indexOf(BodyEnd);

                        // check for non-empty body
                        if (-1 != storyEnd) {
                            // make sure we extract the end tag
                            storyEnd += BodyEnd.length();
                            formattedBody = story.StoryAsNSML.substring(storyStart, storyEnd);
                            // now we have the formatted story body

                            // if the story is not empty and has a cue sheet section we need to remove it
                            cueSheetLocation = formattedBody.indexOf(CueSheetLocation);

                            if (cueSheetLocation >= 0 && unformattedBody.length() > 0) {
                                // there is a cue sheet and the story isn't empty so we need to remove the cue sheet from the formatted body
                                String script = formattedBody.substring(0, cueSheetLocation);
                                // add back the body end tag
                                script += BodyEnd;
                                scriptInfo = "<![CDATA[\n" + script + "]]>";

                            } else if (unformattedBody.length() > 0) {
                                scriptInfo = "<![CDATA[\n" + formattedBody + "]]>";
                            }

                        }

                    } else {
                        // simply export the unformatted body
                        scriptInfo = unformattedBody;
                    }

                    obsStory.ScriptInfo = scriptInfo;
                    if (exportData.getMdsMode() && null != cueSheet) {
                        obsStory.CueSheet = cueSheet;
                    }

                    _export.Stories.add(obsStory);

                    lastStoryWasBreak = false;
                }
            }
        }

        // check that we have an end time
        if (-1 == _export.Rundown.RundownEndTime) {
            if (exportData.getValidateFields()) {
                // nope, reject this one
                RaiseError("the rundown end time is missing");
            } else {
                _export.Rundown.RundownEndTime = _export.Rundown.RundownStartTime;
            }
        }

        // check for Channel ID
        if (_export.Rundown.ChannelID.length() == 0 && exportData.getValidateFields()) {
            RaiseError(String.format("the rundown %s is missing", config.obs_channel_id));
        }

        // check for Channel Name
        if (_export.Rundown.Title.length() == 0 && exportData.getValidateFields()) {
            RaiseError(String.format("the rundown %s is missing", config.title_id));
        }

        // check for Date
        if (_export.Rundown.Date.length() == 0) {
            // log a warning here (no date specified)
            // set date to today's date
            DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-mm-dd");
            _export.Rundown.Date = DateTime.now().toString(dtf);
            if (null == exportData.getResponse().getMessage()) {
                exportData.getResponse().setMessage("The date information was missing from the rundown");
            }
        }
        exportData.getResponse().setDate(_export.Rundown.Date);

        // check for Day
        if (_export.Rundown.Day.length() == 0) {
            // log a warning here (no day specified)
            // set date to today's date
            _export.Rundown.Day = String.format("%02d", DateTime.now().dayOfMonth().get());
            if (null == exportData.getResponse().getMessage()) {
                exportData.getResponse().setMessage("The day information was missing from the rundown");
            }
        }
        exportData.getResponse().setDay(_export.Rundown.Day);

        exportData.setRundownAsXml(_export.GenerateXML(exportData.getMdsMode()));

        exportData.getResponse().setChannelID(_export.Rundown.ChannelID);
        exportData.getResponse().setStartTime(_export.Rundown.GetStartTime());
        exportData.getResponse().setEndTime(_export.Rundown.GetEndTime());
        exportData.getResponse().setTitle(_export.Rundown.Title);

        exportData.getResponse().setFileName(_export.GenerateFileName());
        exportData.getResponse().setResult(1);
    } catch (Exception ex) {
        exportData.getResponse().setMessage(ex.getMessage());
    }

    return exportData;
}

From source file:com.axelor.apps.base.service.administration.ExportDbObjectService.java

License:Open Source License

@Transactional
public MetaFile exportObject() {

    //      group = AuthUtils.getUser().getGroup();
    group = Beans.get(GroupRepository.class).all().filter("self.code = 'admins'").fetchOne();
    try {/*from w  w w  . ja v  a2s. c  om*/
        log.debug("Attachment dir: {}", AppSettings.get().get("file.upload.dir"));
        String uploadDir = AppSettings.get().get("file.upload.dir");
        if (uploadDir == null || !new File(uploadDir).exists()) {
            return null;
        }
        String appSrc = AppSettings.get().get("application.src");
        log.debug("Module dir: {}", appSrc);
        if (appSrc == null) {
            return null;
        }
        File moduleDir = new File(appSrc);
        if (!moduleDir.exists()) {
            return null;
        }

        MetaFile metaFile = new MetaFile();
        String fileName = "ExportObject-" + DateTime.now().toString("yyyMMddHHmmSS") + ".csv";
        metaFile.setFileName(fileName);
        metaFile.setFilePath(fileName);
        metaFile = Beans.get(MetaFileRepository.class).save(metaFile);

        SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
        updateObjectMap(Arrays.asList(moduleDir.listFiles()), saxParserFactory.newSAXParser(),
                new XmlHandler());

        writeObjects(MetaFiles.getPath(metaFile).toFile());

        return metaFile;

    } catch (ParserConfigurationException | SAXException | IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.axelor.apps.message.service.MessageServiceImpl.java

License:Open Source License

@Inject
public MessageServiceImpl(MetaAttachmentRepository metaAttachmentRepository,
        MailAccountService mailAccountService) {
    this.todayTime = DateTime.now();
    this.metaAttachmentRepository = metaAttachmentRepository;
    this.mailAccountService = mailAccountService;
}

From source file:com.axelor.apps.stock.db.repo.InventoryManagementRepository.java

License:Open Source License

@Override
public Inventory copy(Inventory entity, boolean deep) {

    Inventory copy = super.copy(entity, deep);

    copy.setStatusSelect(STATUS_DRAFT);//from  w  ww.java2s  . co  m
    copy.setInventorySeq(null);
    copy.setDateT(DateTime.now());
    return copy;
}