Package org.codehaus.jettison.json

Examples of org.codehaus.jettison.json.JSONObject


        }
        Result<SpotifyAlbum> result = new Result<SpotifyAlbum>();

        if (entity != null) {
            try {
                JSONObject object = Client.create().resource("http://ws.spotify.com/search/1/album.json?q=album:" + URLEncoder.encode(entity.getName(), "utf8")).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                result.setCount(object.getJSONObject("info").getInt("num_results"));
                List<ResultItem<SpotifyAlbum>> albums = new ArrayList<ResultItem<SpotifyAlbum>>();
                JSONArray array = object.getJSONArray("albums");
                for (int i = 0; i < array.length(); i++) {
                    ResultItem<SpotifyAlbum> item = createFromJSON(array.getJSONObject(i));
                    if (item != null) {
                        if((firstItem==null || result.getCount()>=firstItem) && (maxItems==null || maxItems>albums.size())) {
                            albums.add(item);
                        }
                        result.setCount(result.getCount()+1);
                    }
                }
                result.setItems(albums);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else if (currentId.startsWith(SpotifyArtist.class.getSimpleName() + ":")) {
            try {
                JSONObject object = Client.create().resource("http://ws.spotify.com/lookup/1/.json?uri=" + currentId.substring(14) + "&extras=album").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<SpotifyAlbum>> albums = new ArrayList<ResultItem<SpotifyAlbum>>();
                JSONArray array = object.getJSONObject("artist").getJSONArray("albums");
                for (int i = 0; i < array.length(); i++) {
                    ResultItem<SpotifyAlbum> item = createFromJSON(array.getJSONObject(i).getJSONObject("album"));
                    if (item != null) {
                        if((firstItem==null || result.getCount()>=firstItem) && (maxItems==null || maxItems>albums.size())) {
                            albums.add(item);
View Full Code Here


    }

    @Override
    public ResultItem<SpotifyAlbum> findById(String id) {
        try {
            JSONObject object = Client.create().resource("http://ws.spotify.com/lookup/1/.json?uri=" + id).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
            return createFromJSON(object.getJSONObject("album"));
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
    }
View Full Code Here

    @Override
    public List<OnlinePlayableElement> find(List<String> criteriaList) {
        List<OnlinePlayableElement> result = new ArrayList<OnlinePlayableElement>();
        for (String criteria : criteriaList) {
            if (criteria.startsWith(SpotifyAlbum.class.getSimpleName())) {
                JSONObject object = Client.create().resource("http://ws.spotify.com/lookup/1/.json?uri=" + criteria.substring(13) + "&extras=track").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                try {
                    JSONArray array = object.getJSONObject("album").getJSONArray("tracks");
                    for (int i = 0; i < array.length(); i++) {
                        result.add(new OnlinePlayableElement(array.getJSONObject(i).getString("href")));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
View Full Code Here

        if (!objectId.startsWith(SpotifyAlbum.class.getSimpleName() + ":")) {
            return new CommandResult(false, "Invalid object, needs album identity");
        }
        try {
            objectId = objectId.substring(SpotifyAlbum.class.getSimpleName().length() + 1);
            JSONObject object = Client.create().resource("http://ws.spotify.com/lookup/1/.json?uri=" + objectId + "&extras=trackdetail").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
            JSONObject jsonAlbum = object.getJSONObject("album");

            ReleaseEntity release = new ReleaseEntity();
            release.setName(jsonAlbum.getString("name"));
            if (jsonAlbum.has("released")) {
                release.setDate(new SimpleDateFormat("yyyy").parse(jsonAlbum.getString("released")));
            }
            release.setLastUpdated(currentTime);
            release.setLastUpdatedBy(SPOTIFY_SOURCE);
            releaseRepository.create(release);

            GlobalIdentityEntity globalIdentity = new GlobalIdentityEntity();
            globalIdentity.setSource(SPOTIFY_SOURCE);
            globalIdentity.setUri(jsonAlbum.getString("href"));
            globalIdentity.setEntityId(release.getId());
            globalIdentity.setLastUpdated(currentTime);
            globalIdentity.setLastUpdatedBy(SPOTIFY_SOURCE);
            globalIdentityRepository.create(globalIdentity);

            JSONArray array = jsonAlbum.getJSONArray("tracks");
            for (int i = 0; i < array.length(); i++) {
                JSONObject jsonTrack = array.getJSONObject(i);

                WorkEntity work = new WorkEntity();
                work.setName(jsonTrack.getString("name"));
                work.setLastUpdated(currentTime);
                work.setLastUpdatedBy(SPOTIFY_SOURCE);
                workRepository.create(work);

                RecordingEntity recording = new RecordingEntity();
                recording.setLastUpdated(currentTime);
                recording.setLastUpdatedBy(SPOTIFY_SOURCE);
                recordingRepository.create(recording);
                recording.getWorks().add(work);

                TrackEntity track = new TrackEntity();
                if (jsonTrack.has("track-number")) {
                    track.setNumber(jsonTrack.getInt("track-number"));
                }
                track.setRecording(recording);
                release.addTrack(track);
                track.setLastUpdated(currentTime);
                track.setLastUpdatedBy(SPOTIFY_SOURCE);
                trackRepository.create(track);

                PlayableElementEntity playableElement = new PlayableElementEntity();
                playableElement.setSmdID(jsonTrack.getString("href"));
                playableElement.setUri(jsonTrack.getString("href"));
                playableElement.setFormat(SPOTIFY_SOURCE);
                playableElement.setLastUpdated(currentTime);
                playableElement.setLastUpdatedBy(SPOTIFY_SOURCE);
                playableElementRepository.create(playableElement);
                track.getPlayableElements().add(playableElement);

                JSONArray jsonArtists = jsonTrack.optJSONArray("artists");
                if (jsonArtists != null && jsonArtists.length() > 0) {
                    for (int j = 0; j < jsonArtists.length(); j++) {
                        JSONObject jsonArtist = jsonArtists.getJSONObject(j);
                        String name = jsonArtist.getString("name");
                        Collection<ArtistEntity> artists = artistRepository.findByName(name);
                        if (artists.size() == 0) {
                            artists = new ArrayList<ArtistEntity>();
                            ArtistEntity artist = new ArtistEntity();
                            artist.setName(name);
                            artist.setLastUpdated(currentTime);
                            artist.setLastUpdatedBy(SPOTIFY_SOURCE);
                            artistRepository.create(artist);
                            artists.add(artist);

                            globalIdentity = new GlobalIdentityEntity();
                            globalIdentity.setSource(SPOTIFY_SOURCE);
                            globalIdentity.setUri(jsonArtist.getString("href"));
                            globalIdentity.setEntityId(artist.getId());
                            globalIdentity.setLastUpdated(currentTime);
                            globalIdentity.setLastUpdatedBy(SPOTIFY_SOURCE);
                            globalIdentityRepository.create(globalIdentity);
                        }
View Full Code Here

        }
        Result<LastFMAlbum> result = new Result<LastFMAlbum>();

        if (entity != null) {
            try {
                JSONObject object = Client.create().resource(getLastFmUrl("album.search&album=" + urlEncode(entity.getName()))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<LastFMAlbum>> albums = new ArrayList<ResultItem<LastFMAlbum>>();
                JSONArray array = object.getJSONObject("results").getJSONObject("albummatches").getJSONArray("album");
                result.setCount(array.length());
                for (int i = 0; i < array.length(); i++) {
                    if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>albums.size())) {
                        albums.add(createFromJSON(array.getJSONObject(i)));
                    }
                }
                result.setCount(albums.size());
                result.setItems(albums);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else if (currentId.startsWith(LastFMArtist.class.getSimpleName() + ":")) {
            try {
                String artistId = currentId.substring(13);
                JSONObject object = Client.create().resource(getLastFmUrl("artist.gettopalbums" + createQueryFromId(artistId))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<LastFMAlbum>> albums = new ArrayList<ResultItem<LastFMAlbum>>();
                if (object.getJSONObject("topalbums").has("album")) {
                    JSONArray array = object.getJSONObject("topalbums").getJSONArray("album");
                    result.setCount(array.length());
                    for (int i = 0; i < array.length(); i++) {
                        if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>albums.size())) {
                            albums.add(createFromJSON(array.getJSONObject(i)));
                        }
View Full Code Here

    }

    @Override
    public ResultItem<LastFMAlbum> findById(String id) {
        try {
            JSONObject object = Client.create().resource(getLastFmUrl("album.getinfo" + createQueryFromId(id))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
            return createFromJSON(object.getJSONObject("album"));
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
    }
View Full Code Here

        }
        Result<LastFMArtist> result = new Result<LastFMArtist>();

        if (entity != null) {
            try {
                JSONObject object = Client.create().resource(getLastFmUrl("artist.search&artist=" + urlEncode(entity.getName()))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<LastFMArtist>> artists = new ArrayList<ResultItem<LastFMArtist>>();
                JSONArray array = object.getJSONObject("results").getJSONObject("artistmatches").getJSONArray("artist");
                result.setCount(array.length());
                for (int i = 0; i < array.length(); i++) {
                    if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>artists.size())) {
                        artists.add(createFromJSON(array.getJSONObject(i)));
                    }
View Full Code Here

    }

    @Override
    public ResultItem<LastFMArtist> findById(String id) {
        try {
            JSONObject object = Client.create().resource(getLastFmUrl("artist.getinfo" + createQueryFromId(id))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
            return createFromJSON(object.getJSONObject("artist"));
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
    }
View Full Code Here

        }
        Result<LastFMImage> result = new Result<LastFMImage>();

        if (entity != null) {
            try {
                JSONObject object = Client.create().resource(getLastFmUrl("artist.getimages&artist=" + urlEncode(entity.getName()))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<LastFMImage>> images = new ArrayList<ResultItem<LastFMImage>>();
                if (object.getJSONObject("images").has("image")) {
                    JSONArray array = object.getJSONObject("images").getJSONArray("image");
                    result.setCount(array.length());
                    for (int i = 0; i < array.length(); i++) {
                        if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>images.size())) {
                            images.add(createFromJSON("artist="+urlEncode(entity.getName()),array.getJSONObject(i)));
                        }
                    }
                }
                result.setItems(images);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else if (currentId.startsWith(LastFMArtist.class.getSimpleName() + ":")) {
            try {
                String artistId = currentId.substring(13);
                JSONObject object = Client.create().resource(getLastFmUrl("artist.getimages" + createQueryFromId(artistId))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<LastFMImage>> images = new ArrayList<ResultItem<LastFMImage>>();
                if (object.getJSONObject("images").has("image")) {
                    JSONArray array = object.getJSONObject("images").getJSONArray("image");
                    result.setCount(array.length());
                    for (int i = 0; i < array.length(); i++) {
                        if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>images.size())) {
                            images.add(createFromJSON(createQueryFromId(artistId).substring(1),array.getJSONObject(i)));
                        }
View Full Code Here

    @Override
    public ResultItem<LastFMImage> findById(String id) {
        try {
            String artistId = id.substring(0,id.indexOf(":image"));
            JSONObject object = Client.create().resource(getLastFmUrl("artist.getimages" + createQueryFromId(artistId))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
            if (object.getJSONObject("images").has("image")) {
                JSONArray array = object.getJSONObject("images").getJSONArray("image");
                for (int i = 0; i < array.length(); i++) {
                    String imageId = id.substring(id.lastIndexOf(":")+1);
                    if(array.getJSONObject(i).getString("url").endsWith("/"+imageId)) {
                        return createFromJSON(id.substring(0,id.lastIndexOf(":image:")),array.getJSONObject(i));
                    }
View Full Code Here

TOP

Related Classes of org.codehaus.jettison.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.